-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make /api/debug/health return error when no backends are available (#692
- Loading branch information
Showing
14 changed files
with
186 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package namespace | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/tiproxy/pkg/balance/router" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestReady(t *testing.T) { | ||
nsMgr := NewNamespaceManager() | ||
require.NoError(t, nsMgr.Init(zap.NewNop(), nil, nil, nil, nil, nil, nil)) | ||
require.False(t, nsMgr.Ready()) | ||
|
||
rt := router.NewStaticRouter([]string{}) | ||
nsMgr.nsm = map[string]*Namespace{ | ||
"test": { | ||
router: rt, | ||
}, | ||
} | ||
require.False(t, nsMgr.Ready()) | ||
|
||
rt = router.NewStaticRouter([]string{"127.0.0.1:4000"}) | ||
ns, ok := nsMgr.GetNamespace("test") | ||
require.True(t, ok) | ||
ns.router = rt | ||
require.True(t, nsMgr.Ready()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package api | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"sync/atomic" | ||
|
||
"github.com/pingcap/tiproxy/lib/config" | ||
"github.com/pingcap/tiproxy/pkg/balance/metricsreader" | ||
"github.com/pingcap/tiproxy/pkg/balance/observer" | ||
mconfig "github.com/pingcap/tiproxy/pkg/manager/config" | ||
"github.com/pingcap/tiproxy/pkg/manager/namespace" | ||
"github.com/pingcap/tiproxy/pkg/util/http" | ||
"go.uber.org/zap" | ||
) | ||
|
||
var _ namespace.NamespaceManager = (*mockNamespaceManager)(nil) | ||
|
||
type mockNamespaceManager struct { | ||
success atomic.Bool | ||
} | ||
|
||
func newMockNamespaceManager() *mockNamespaceManager { | ||
mgr := &mockNamespaceManager{} | ||
mgr.success.Store(true) | ||
return mgr | ||
} | ||
|
||
func (m *mockNamespaceManager) Init(_ *zap.Logger, _ []*config.Namespace, _ observer.TopologyFetcher, | ||
_ metricsreader.PromInfoFetcher, _ *http.Client, _ *mconfig.ConfigManager, _ metricsreader.MetricsReader) error { | ||
return nil | ||
} | ||
|
||
func (m *mockNamespaceManager) GetNamespace(_ string) (*namespace.Namespace, bool) { | ||
return nil, false | ||
} | ||
|
||
func (m *mockNamespaceManager) GetNamespaceByUser(_ string) (*namespace.Namespace, bool) { | ||
return nil, false | ||
} | ||
|
||
func (m *mockNamespaceManager) SetNamespace(_ context.Context, _ string, _ *config.Namespace) error { | ||
if m.success.Load() { | ||
return nil | ||
} | ||
return errors.New("mock error") | ||
} | ||
|
||
func (m *mockNamespaceManager) GetConfigChecksum() string { | ||
return "" | ||
} | ||
|
||
func (m *mockNamespaceManager) Ready() bool { | ||
return m.success.Load() | ||
} | ||
|
||
func (m *mockNamespaceManager) RedirectConnections() []error { | ||
if m.success.Load() { | ||
return nil | ||
} | ||
return []error{errors.New("mock error")} | ||
} | ||
|
||
func (m *mockNamespaceManager) Close() error { | ||
return nil | ||
} | ||
|
||
func (m *mockNamespaceManager) CommitNamespaces(_ []*config.Namespace, _ []bool) error { | ||
if m.success.Load() { | ||
return nil | ||
} | ||
return errors.New("mock error") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters