From de0ab9e2cf6e07644c4b9dbdf3b59bfda24d6c18 Mon Sep 17 00:00:00 2001 From: aoiasd <45024769+aoiasd@users.noreply.github.com> Date: Fri, 9 Dec 2022 14:31:21 +0800 Subject: [PATCH] Refactor showConfigurations to allow return global config rather than only return config of this component (#21063) Signed-off-by: aoiasd Signed-off-by: aoiasd --- internal/config/manager.go | 73 +++++++++++++++++++------ internal/datacoord/metrics_info.go | 23 -------- internal/datacoord/server_test.go | 2 +- internal/datacoord/services.go | 17 +++++- internal/datanode/data_node.go | 16 +++++- internal/datanode/data_node_test.go | 2 +- internal/datanode/metrics_info.go | 23 -------- internal/indexcoord/index_coord.go | 17 +++++- internal/indexcoord/index_coord_test.go | 2 +- internal/indexcoord/metrics_info.go | 23 -------- internal/indexnode/indexnode.go | 17 +++++- internal/indexnode/metrics_info.go | 23 -------- internal/querycoordv2/services.go | 7 +-- internal/querycoordv2/services_test.go | 4 +- internal/querynode/impl.go | 17 +++++- internal/querynode/metrics_info.go | 23 -------- internal/querynode/metrics_info_test.go | 30 ---------- internal/rootcoord/metrics_info.go | 23 -------- internal/rootcoord/root_coord.go | 17 +++++- internal/rootcoord/root_coord_test.go | 2 +- internal/util/paramtable/base_table.go | 15 +++-- internal/util/paramtable/param_item.go | 2 +- 22 files changed, 170 insertions(+), 208 deletions(-) diff --git a/internal/config/manager.go b/internal/config/manager.go index 9135a1053c..d1c1cf5d79 100644 --- a/internal/config/manager.go +++ b/internal/config/manager.go @@ -29,6 +29,54 @@ const ( TombValue = "TOMB_VAULE" ) +type Filter func(key string) (string, bool) + +func WithSubstr(substring string) Filter { + substring = strings.ToLower(substring) + return func(key string) (string, bool) { + return key, strings.Contains(key, substring) + } +} + +func WithPrefix(prefix string) Filter { + prefix = strings.ToLower(prefix) + return func(key string) (string, bool) { + return key, strings.HasPrefix(key, prefix) + } +} + +func WithOneOfPrefixs(prefixs ...string) Filter { + for id, prefix := range prefixs { + prefixs[id] = strings.ToLower(prefix) + } + return func(key string) (string, bool) { + for _, prefix := range prefixs { + if strings.HasPrefix(key, prefix) { + return key, true + } + } + return key, false + } +} + +func RemovePrefix(prefix string) Filter { + prefix = strings.ToLower(prefix) + return func(key string) (string, bool) { + return strings.Replace(key, prefix, "", 1), true + } +} + +func filterate(key string, filters ...Filter) (string, bool) { + var ok bool + for _, filter := range filters { + key, ok = filter(key) + if !ok { + return key, ok + } + } + return key, ok +} + type Manager struct { sync.RWMutex Dispatcher *EventDispatcher @@ -64,34 +112,23 @@ func (m *Manager) GetConfig(key string) (string, error) { return m.getConfigValueBySource(realKey, sourceName) } -//GetConfigsByPattern returns key values that matched pattern -// withPrefix : whether key include the prefix of pattern -func (m *Manager) GetConfigsByPattern(pattern string, withPrefix bool) map[string]string { - +func (m *Manager) GetBy(filters ...Filter) map[string]string { m.RLock() defer m.RUnlock() matchedConfig := make(map[string]string) - pattern = strings.ToLower(pattern) - for key, value := range m.keySourceMap { - result := strings.HasPrefix(key, pattern) - if result { + for key, value := range m.keySourceMap { + newkey, ok := filterate(key, filters...) + if ok { sValue, err := m.getConfigValueBySource(key, value) if err != nil { + log.Error("Get some invalid config", zap.String("key", key)) continue } - - checkAndCutOffKey := func() string { - if withPrefix { - return key - } - return strings.Replace(key, pattern, "", 1) - } - - finalKey := checkAndCutOffKey() - matchedConfig[finalKey] = sValue + matchedConfig[newkey] = sValue } } + return matchedConfig } diff --git a/internal/datacoord/metrics_info.go b/internal/datacoord/metrics_info.go index 2eb577bc54..df8b27263d 100644 --- a/internal/datacoord/metrics_info.go +++ b/internal/datacoord/metrics_info.go @@ -25,7 +25,6 @@ import ( "github.com/milvus-io/milvus-proto/go-api/commonpb" "github.com/milvus-io/milvus-proto/go-api/milvuspb" "github.com/milvus-io/milvus/internal/log" - "github.com/milvus-io/milvus/internal/proto/internalpb" "github.com/milvus-io/milvus/internal/util/hardware" "github.com/milvus-io/milvus/internal/util/metricsinfo" "github.com/milvus-io/milvus/internal/util/paramtable" @@ -40,28 +39,6 @@ func (s *Server) getQuotaMetrics() *metricsinfo.DataCoordQuotaMetrics { } } -//getComponentConfigurations returns the configurations of dataNode matching req.Pattern -func getComponentConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) *internalpb.ShowConfigurationsResponse { - prefix := "datacoord." - matchedConfig := Params.GetByPattern(prefix + req.Pattern) - configList := make([]*commonpb.KeyValuePair, 0, len(matchedConfig)) - for key, value := range matchedConfig { - configList = append(configList, - &commonpb.KeyValuePair{ - Key: key, - Value: value, - }) - } - - return &internalpb.ShowConfigurationsResponse{ - Status: &commonpb.Status{ - ErrorCode: commonpb.ErrorCode_Success, - Reason: "", - }, - Configuations: configList, - } -} - // getSystemInfoMetrics composes data cluster metrics func (s *Server) getSystemInfoMetrics( ctx context.Context, diff --git a/internal/datacoord/server_test.go b/internal/datacoord/server_test.go index a3d925f5c8..32b4db452e 100644 --- a/internal/datacoord/server_test.go +++ b/internal/datacoord/server_test.go @@ -1009,7 +1009,7 @@ func TestServer_watchQueryCoord(t *testing.T) { func TestServer_ShowConfigurations(t *testing.T) { svr := newTestServer(t, nil) defer closeTestServer(t, svr) - pattern := "Port" + pattern := "datacoord.Port" req := &internalpb.ShowConfigurationsRequest{ Base: &commonpb.MsgBase{ MsgType: commonpb.MsgType_WatchQueryChannels, diff --git a/internal/datacoord/services.go b/internal/datacoord/services.go index 08abd824e8..d0e95bb3e1 100644 --- a/internal/datacoord/services.go +++ b/internal/datacoord/services.go @@ -830,7 +830,22 @@ func (s *Server) ShowConfigurations(ctx context.Context, req *internalpb.ShowCon }, nil } - return getComponentConfigurations(ctx, req), nil + configList := make([]*commonpb.KeyValuePair, 0) + for key, value := range Params.GetComponentConfigurations(ctx, "datacoord", req.Pattern) { + configList = append(configList, + &commonpb.KeyValuePair{ + Key: key, + Value: value, + }) + } + + return &internalpb.ShowConfigurationsResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_Success, + Reason: "", + }, + Configuations: configList, + }, nil } // GetMetrics returns DataCoord metrics info diff --git a/internal/datanode/data_node.go b/internal/datanode/data_node.go index b3acca403e..31ba43705f 100644 --- a/internal/datanode/data_node.go +++ b/internal/datanode/data_node.go @@ -736,8 +736,22 @@ func (node *DataNode) ShowConfigurations(ctx context.Context, req *internalpb.Sh Configuations: nil, }, nil } + configList := make([]*commonpb.KeyValuePair, 0) + for key, value := range Params.GetComponentConfigurations(ctx, "datanode", req.Pattern) { + configList = append(configList, + &commonpb.KeyValuePair{ + Key: key, + Value: value, + }) + } - return getComponentConfigurations(ctx, req), nil + return &internalpb.ShowConfigurationsResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_Success, + Reason: "", + }, + Configuations: configList, + }, nil } // GetMetrics return datanode metrics diff --git a/internal/datanode/data_node_test.go b/internal/datanode/data_node_test.go index 47dd1726ef..9fb30c3daa 100644 --- a/internal/datanode/data_node_test.go +++ b/internal/datanode/data_node_test.go @@ -387,7 +387,7 @@ func TestDataNode(t *testing.T) { }) t.Run("Test ShowConfigurations", func(t *testing.T) { - pattern := "Port" + pattern := "datanode.Port" req := &internalpb.ShowConfigurationsRequest{ Base: &commonpb.MsgBase{ MsgType: commonpb.MsgType_WatchQueryChannels, diff --git a/internal/datanode/metrics_info.go b/internal/datanode/metrics_info.go index 4ab0e378b3..3a0d03fa5c 100644 --- a/internal/datanode/metrics_info.go +++ b/internal/datanode/metrics_info.go @@ -21,7 +21,6 @@ import ( "github.com/milvus-io/milvus-proto/go-api/commonpb" "github.com/milvus-io/milvus-proto/go-api/milvuspb" - "github.com/milvus-io/milvus/internal/proto/internalpb" "github.com/milvus-io/milvus/internal/util/hardware" "github.com/milvus-io/milvus/internal/util/metricsinfo" "github.com/milvus-io/milvus/internal/util/paramtable" @@ -61,28 +60,6 @@ func (node *DataNode) getQuotaMetrics() (*metricsinfo.DataNodeQuotaMetrics, erro }, nil } -//getComponentConfigurations returns the configurations of dataNode matching req.Pattern -func getComponentConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) *internalpb.ShowConfigurationsResponse { - prefix := "datanode." - matchedConfig := Params.GetByPattern(prefix + req.Pattern) - configList := make([]*commonpb.KeyValuePair, 0, len(matchedConfig)) - for key, value := range matchedConfig { - configList = append(configList, - &commonpb.KeyValuePair{ - Key: key, - Value: value, - }) - } - - return &internalpb.ShowConfigurationsResponse{ - Status: &commonpb.Status{ - ErrorCode: commonpb.ErrorCode_Success, - Reason: "", - }, - Configuations: configList, - } -} - func (node *DataNode) getSystemInfoMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) { // TODO(dragondriver): add more metrics usedMem := hardware.GetUsedMemoryCount() diff --git a/internal/indexcoord/index_coord.go b/internal/indexcoord/index_coord.go index 52ba6aec48..9f53b6aa6f 100644 --- a/internal/indexcoord/index_coord.go +++ b/internal/indexcoord/index_coord.go @@ -946,7 +946,22 @@ func (i *IndexCoord) ShowConfigurations(ctx context.Context, req *internalpb.Sho }, nil } - return getComponentConfigurations(ctx, req), nil + configList := make([]*commonpb.KeyValuePair, 0) + for key, value := range Params.GetComponentConfigurations(ctx, "indexcoord", req.Pattern) { + configList = append(configList, + &commonpb.KeyValuePair{ + Key: key, + Value: value, + }) + } + + return &internalpb.ShowConfigurationsResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_Success, + Reason: "", + }, + Configuations: configList, + }, nil } // GetMetrics gets the metrics info of IndexCoord. diff --git a/internal/indexcoord/index_coord_test.go b/internal/indexcoord/index_coord_test.go index ff7210925c..3995eeb13e 100644 --- a/internal/indexcoord/index_coord_test.go +++ b/internal/indexcoord/index_coord_test.go @@ -479,7 +479,7 @@ func testIndexCoord(t *testing.T) { }) t.Run("Showconfigurations, port", func(t *testing.T) { - pattern := "Port" + pattern := "indexcoord.Port" req := &internalpb.ShowConfigurationsRequest{ Base: &commonpb.MsgBase{ MsgType: commonpb.MsgType_WatchQueryChannels, diff --git a/internal/indexcoord/metrics_info.go b/internal/indexcoord/metrics_info.go index 9327f8fc6b..8190985e96 100644 --- a/internal/indexcoord/metrics_info.go +++ b/internal/indexcoord/metrics_info.go @@ -24,7 +24,6 @@ import ( "github.com/milvus-io/milvus-proto/go-api/commonpb" "github.com/milvus-io/milvus-proto/go-api/milvuspb" "github.com/milvus-io/milvus/internal/log" - "github.com/milvus-io/milvus/internal/proto/internalpb" "github.com/milvus-io/milvus/internal/util/hardware" "github.com/milvus-io/milvus/internal/util/metricsinfo" "github.com/milvus-io/milvus/internal/util/paramtable" @@ -32,28 +31,6 @@ import ( "github.com/milvus-io/milvus/internal/util/uniquegenerator" ) -//getComponentConfigurations returns the configurations of indexCoord matching req.Pattern -func getComponentConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) *internalpb.ShowConfigurationsResponse { - prefix := "indexcoord." - matchedConfig := Params.GetByPattern(prefix + req.Pattern) - configList := make([]*commonpb.KeyValuePair, 0, len(matchedConfig)) - for key, value := range matchedConfig { - configList = append(configList, - &commonpb.KeyValuePair{ - Key: key, - Value: value, - }) - } - - return &internalpb.ShowConfigurationsResponse{ - Status: &commonpb.Status{ - ErrorCode: commonpb.ErrorCode_Success, - Reason: "", - }, - Configuations: configList, - } -} - // TODO(dragondriver): add more detailed metrics func getSystemInfoMetrics( ctx context.Context, diff --git a/internal/indexnode/indexnode.go b/internal/indexnode/indexnode.go index 567a131ce8..0ddaa900fc 100644 --- a/internal/indexnode/indexnode.go +++ b/internal/indexnode/indexnode.go @@ -325,7 +325,22 @@ func (i *IndexNode) ShowConfigurations(ctx context.Context, req *internalpb.Show }, nil } - return getComponentConfigurations(ctx, req), nil + configList := make([]*commonpb.KeyValuePair, 0) + for key, value := range Params.GetComponentConfigurations(ctx, "indexnode", req.Pattern) { + configList = append(configList, + &commonpb.KeyValuePair{ + Key: key, + Value: value, + }) + } + + return &internalpb.ShowConfigurationsResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_Success, + Reason: "", + }, + Configuations: configList, + }, nil } func (i *IndexNode) SetAddress(address string) { diff --git a/internal/indexnode/metrics_info.go b/internal/indexnode/metrics_info.go index f1bb55cdd8..9bb7d8fa8b 100644 --- a/internal/indexnode/metrics_info.go +++ b/internal/indexnode/metrics_info.go @@ -21,35 +21,12 @@ import ( "github.com/milvus-io/milvus-proto/go-api/commonpb" "github.com/milvus-io/milvus-proto/go-api/milvuspb" - "github.com/milvus-io/milvus/internal/proto/internalpb" "github.com/milvus-io/milvus/internal/util/hardware" "github.com/milvus-io/milvus/internal/util/metricsinfo" "github.com/milvus-io/milvus/internal/util/paramtable" "github.com/milvus-io/milvus/internal/util/typeutil" ) -//getComponentConfigurations returns the configurations of queryNode matching req.Pattern -func getComponentConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) *internalpb.ShowConfigurationsResponse { - prefix := "indexnode." - matchedConfig := Params.GetByPattern(prefix + req.Pattern) - configList := make([]*commonpb.KeyValuePair, 0, len(matchedConfig)) - for key, value := range matchedConfig { - configList = append(configList, - &commonpb.KeyValuePair{ - Key: key, - Value: value, - }) - } - - return &internalpb.ShowConfigurationsResponse{ - Status: &commonpb.Status{ - ErrorCode: commonpb.ErrorCode_Success, - Reason: "", - }, - Configuations: configList, - } -} - // TODO(dragondriver): maybe IndexNode should be an interface so that we can mock it in the test cases func getSystemInfoMetrics( ctx context.Context, diff --git a/internal/querycoordv2/services.go b/internal/querycoordv2/services.go index 416dc90ae6..92caad0c13 100644 --- a/internal/querycoordv2/services.go +++ b/internal/querycoordv2/services.go @@ -507,11 +507,8 @@ func (s *Server) ShowConfigurations(ctx context.Context, req *internalpb.ShowCon Status: utils.WrapStatus(commonpb.ErrorCode_UnexpectedError, msg, ErrNotHealthy), }, nil } - - prefix := "querycoord." - matchedConfig := Params.GetByPattern(prefix + req.Pattern) - configList := make([]*commonpb.KeyValuePair, 0, len(matchedConfig)) - for key, value := range matchedConfig { + configList := make([]*commonpb.KeyValuePair, 0) + for key, value := range Params.GetComponentConfigurations(ctx, "querycoord", req.Pattern) { configList = append(configList, &commonpb.KeyValuePair{ Key: key, diff --git a/internal/querycoordv2/services_test.go b/internal/querycoordv2/services_test.go index 6607dcde11..3b5b420bed 100644 --- a/internal/querycoordv2/services_test.go +++ b/internal/querycoordv2/services_test.go @@ -753,7 +753,7 @@ func (suite *ServiceSuite) TestShowConfigurations() { server := suite.server req := &internalpb.ShowConfigurationsRequest{ - Pattern: "Port", + Pattern: "querycoord.Port", } resp, err := server.ShowConfigurations(ctx, req) suite.NoError(err) @@ -764,7 +764,7 @@ func (suite *ServiceSuite) TestShowConfigurations() { // Test when server is not healthy server.UpdateStateCode(commonpb.StateCode_Initializing) req = &internalpb.ShowConfigurationsRequest{ - Pattern: "Port", + Pattern: "querycoord.Port", } resp, err = server.ShowConfigurations(ctx, req) suite.NoError(err) diff --git a/internal/querynode/impl.go b/internal/querynode/impl.go index 4a92574970..480ad2da33 100644 --- a/internal/querynode/impl.go +++ b/internal/querynode/impl.go @@ -1216,7 +1216,22 @@ func (node *QueryNode) ShowConfigurations(ctx context.Context, req *internalpb.S node.wg.Add(1) defer node.wg.Done() - return getComponentConfigurations(ctx, req), nil + configList := make([]*commonpb.KeyValuePair, 0) + for key, value := range Params.GetComponentConfigurations(ctx, "querynode", req.Pattern) { + configList = append(configList, + &commonpb.KeyValuePair{ + Key: key, + Value: value, + }) + } + + return &internalpb.ShowConfigurationsResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_Success, + Reason: "", + }, + Configuations: configList, + }, nil } // GetMetrics return system infos of the query node, such as total memory, memory usage, cpu usage ... diff --git a/internal/querynode/metrics_info.go b/internal/querynode/metrics_info.go index cc408d2d6c..d7913c6bc8 100644 --- a/internal/querynode/metrics_info.go +++ b/internal/querynode/metrics_info.go @@ -21,7 +21,6 @@ import ( "github.com/milvus-io/milvus-proto/go-api/commonpb" "github.com/milvus-io/milvus-proto/go-api/milvuspb" - "github.com/milvus-io/milvus/internal/proto/internalpb" "github.com/milvus-io/milvus/internal/util/hardware" "github.com/milvus-io/milvus/internal/util/metricsinfo" "github.com/milvus-io/milvus/internal/util/paramtable" @@ -29,28 +28,6 @@ import ( "github.com/milvus-io/milvus/internal/util/typeutil" ) -//getComponentConfigurations returns the configurations of queryNode matching req.Pattern -func getComponentConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) *internalpb.ShowConfigurationsResponse { - prefix := "querynode." - matchedConfig := Params.GetByPattern(prefix + req.Pattern) - configList := make([]*commonpb.KeyValuePair, 0, len(matchedConfig)) - for key, value := range matchedConfig { - configList = append(configList, - &commonpb.KeyValuePair{ - Key: key, - Value: value, - }) - } - - return &internalpb.ShowConfigurationsResponse{ - Status: &commonpb.Status{ - ErrorCode: commonpb.ErrorCode_Success, - Reason: "", - }, - Configuations: configList, - } -} - // getQuotaMetrics returns QueryNodeQuotaMetrics. func getQuotaMetrics(node *QueryNode) (*metricsinfo.QueryNodeQuotaMetrics, error) { var err error diff --git a/internal/querynode/metrics_info_test.go b/internal/querynode/metrics_info_test.go index 37b06378b2..6ec14ff6c9 100644 --- a/internal/querynode/metrics_info_test.go +++ b/internal/querynode/metrics_info_test.go @@ -25,7 +25,6 @@ import ( "github.com/milvus-io/milvus-proto/go-api/commonpb" "github.com/milvus-io/milvus-proto/go-api/milvuspb" - "github.com/milvus-io/milvus/internal/proto/internalpb" "github.com/milvus-io/milvus/internal/util/etcd" "github.com/milvus-io/milvus/internal/util/metricsinfo" "github.com/milvus-io/milvus/internal/util/sessionutil" @@ -65,32 +64,3 @@ func TestGetSystemInfoMetrics(t *testing.T) { assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode()) rateCol.Register(metricsinfo.NQPerSecond) } - -func TestGetComponentConfigurationsFailed(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - node, err := genSimpleQueryNode(ctx) - require.NoError(t, err) - defer node.Stop() - - etcdCli, err := etcd.GetEtcdClient( - Params.EtcdCfg.UseEmbedEtcd.GetAsBool(), - Params.EtcdCfg.EtcdUseSSL.GetAsBool(), - Params.EtcdCfg.Endpoints.GetAsStrings(), - Params.EtcdCfg.EtcdTLSCert.GetValue(), - Params.EtcdCfg.EtcdTLSKey.GetValue(), - Params.EtcdCfg.EtcdTLSCACert.GetValue(), - Params.EtcdCfg.EtcdTLSMinVersion.GetValue()) - assert.NoError(t, err) - defer etcdCli.Close() - node.session = sessionutil.NewSession(node.queryNodeLoopCtx, Params.EtcdCfg.MetaRootPath.GetValue(), etcdCli) - - req := &internalpb.ShowConfigurationsRequest{ - Base: genCommonMsgBase(commonpb.MsgType_WatchQueryChannels, node.session.ServerID), - Pattern: "Cache", - } - - resq := getComponentConfigurations(ctx, req) - assert.Equal(t, resq.Status.ErrorCode, commonpb.ErrorCode_Success) -} diff --git a/internal/rootcoord/metrics_info.go b/internal/rootcoord/metrics_info.go index 5e268050a1..66ab780949 100644 --- a/internal/rootcoord/metrics_info.go +++ b/internal/rootcoord/metrics_info.go @@ -24,35 +24,12 @@ import ( "github.com/milvus-io/milvus-proto/go-api/commonpb" "github.com/milvus-io/milvus-proto/go-api/milvuspb" "github.com/milvus-io/milvus/internal/log" - "github.com/milvus-io/milvus/internal/proto/internalpb" "github.com/milvus-io/milvus/internal/util/hardware" "github.com/milvus-io/milvus/internal/util/metricsinfo" "github.com/milvus-io/milvus/internal/util/paramtable" "github.com/milvus-io/milvus/internal/util/typeutil" ) -//getComponentConfigurations returns the configurations of rootcoord matching req.Pattern -func getComponentConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) *internalpb.ShowConfigurationsResponse { - prefix := "rootcoord." - matchedConfig := Params.GetByPattern(prefix + req.Pattern) - configList := make([]*commonpb.KeyValuePair, 0, len(matchedConfig)) - for key, value := range matchedConfig { - configList = append(configList, - &commonpb.KeyValuePair{ - Key: key, - Value: value, - }) - } - - return &internalpb.ShowConfigurationsResponse{ - Status: &commonpb.Status{ - ErrorCode: commonpb.ErrorCode_Success, - Reason: "", - }, - Configuations: configList, - } -} - func (c *Core) getSystemInfoMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) { rootCoordTopology := metricsinfo.RootCoordTopology{ Self: metricsinfo.RootCoordInfos{ diff --git a/internal/rootcoord/root_coord.go b/internal/rootcoord/root_coord.go index c146354ec4..77eaec0760 100644 --- a/internal/rootcoord/root_coord.go +++ b/internal/rootcoord/root_coord.go @@ -1412,7 +1412,22 @@ func (c *Core) ShowConfigurations(ctx context.Context, req *internalpb.ShowConfi }, nil } - return getComponentConfigurations(ctx, req), nil + configList := make([]*commonpb.KeyValuePair, 0) + for key, value := range Params.GetComponentConfigurations(ctx, "rootcoord", req.Pattern) { + configList = append(configList, + &commonpb.KeyValuePair{ + Key: key, + Value: value, + }) + } + + return &internalpb.ShowConfigurationsResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_Success, + Reason: "", + }, + Configuations: configList, + }, nil } // GetMetrics get metrics diff --git a/internal/rootcoord/root_coord_test.go b/internal/rootcoord/root_coord_test.go index 4af3145619..d96172a802 100644 --- a/internal/rootcoord/root_coord_test.go +++ b/internal/rootcoord/root_coord_test.go @@ -693,7 +693,7 @@ func TestRootCoord_ShowConfigurations(t *testing.T) { t.Run("normal case", func(t *testing.T) { Params.InitOnce() - pattern := "Port" + pattern := "rootcoord.Port" req := &internalpb.ShowConfigurationsRequest{ Base: &commonpb.MsgBase{ MsgID: rand.Int63(), diff --git a/internal/util/paramtable/base_table.go b/internal/util/paramtable/base_table.go index 574410c835..11597c2008 100644 --- a/internal/util/paramtable/base_table.go +++ b/internal/util/paramtable/base_table.go @@ -12,6 +12,7 @@ package paramtable import ( + "context" "fmt" "os" "path" @@ -55,6 +56,11 @@ const ( DefaultMaxBackups = 20 ) +//Const of Global Config List +func globalConfigPrefixs() []string { + return []string{"metastore.", "localStorage.", "etcd.", "mysql.", "minio.", "pulsar.", "kafka.", "rocksmq.", "log.", "grpc.", "common.", "quotaAndLimits."} +} + var defaultYaml = DefaultMilvusYaml // Base abstracts BaseTable @@ -247,12 +253,13 @@ func (gp *BaseTable) Get(key string) string { return value } -func (gp *BaseTable) GetByPattern(pattern string) map[string]string { - return gp.mgr.GetConfigsByPattern(pattern, true) +func (gp *BaseTable) GetConfigSubSet(pattern string) map[string]string { + return gp.mgr.GetBy(config.WithPrefix(pattern), config.RemovePrefix(pattern)) } -func (gp *BaseTable) GetConfigSubSet(pattern string) map[string]string { - return gp.mgr.GetConfigsByPattern(pattern, false) +func (gp *BaseTable) GetComponentConfigurations(ctx context.Context, componentName string, sub string) map[string]string { + allownPrefixs := append(globalConfigPrefixs(), componentName+".") + return gp.mgr.GetBy(config.WithSubstr(sub), config.WithOneOfPrefixs(allownPrefixs...)) } func (gp *BaseTable) GetAll() map[string]string { diff --git a/internal/util/paramtable/param_item.go b/internal/util/paramtable/param_item.go index f38034d2a6..a8d6ec29d0 100644 --- a/internal/util/paramtable/param_item.go +++ b/internal/util/paramtable/param_item.go @@ -131,7 +131,7 @@ func (pg *ParamGroup) GetValue() map[string]string { if pg.GetFunc != nil { return pg.GetFunc() } - values := pg.manager.GetConfigsByPattern(pg.KeyPrefix, false) + values := pg.manager.GetBy(config.WithPrefix(pg.KeyPrefix), config.RemovePrefix(pg.KeyPrefix)) return values }