From f558adf837ad919c2e686ad03537342e8e09e1ff Mon Sep 17 00:00:00 2001 From: Tanmay Jain Date: Wed, 6 Nov 2024 16:50:41 +0530 Subject: [PATCH] fixing dc and xdr stat collection --- info/as_parser.go | 69 ++++++++++++++++++++++-------------------- info/as_parser_test.go | 6 ++-- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/info/as_parser.go b/info/as_parser.go index b561798..e379479 100644 --- a/info/as_parser.go +++ b/info/as_parser.go @@ -41,23 +41,20 @@ const ( ) const ( - DefaultTimeout = 2 * time.Second - // Explicit constants are defined with `const` prefix when // 1. string values which are not commands // 2. string values which are used to generate other commands // 3. string values which are both command and constant - constStatXDRPre50 = "statistics/xdr" // StatXdr - constStatXDR = "get-stats:context=xdr" - constStatNS = "namespace/" // StatNamespace - constStatDCpre50 = "dc/" // statDC - constStatDC = "get-stats:context=xdr;dc=" - constStatSet = "sets/" // StatSets - constStatBin = "bins/" // StatBins - constStatSIndex = "sindex/" // StatSindex - constStatNSNames = "namespaces" // StatNamespaces - constStatDCNames = "dcs" // StatDcs need dc names - constStatLogIDs = "logs" // StatLogs need logging id + constStatXDR = "statistics/xdr" // StatXdr + constStatNS = "namespace/" // StatNamespace + constStatDCpre50 = "dc/" // statDC + constStatDC = "get-stats:context=xdr;dc=" + constStatSet = "sets/" // StatSets + constStatBin = "bins/" // StatBins + constStatSIndex = "sindex/" // StatSindex + constStatNSNames = "namespaces" // StatNamespaces + constStatDCNames = "dcs" // StatDcs need dc names + constStatLogIDs = "logs" // StatLogs need logging id cmdConfigNetwork = "get-config:context=network" // ConfigNetwork cmdConfigService = "get-config:context=service" // ConfigService @@ -417,7 +414,27 @@ func ParseNamespaceNames(m map[string]string) []string { // ParseDCNames parses all DC names func ParseDCNames(m map[string]string) []string { - return getNames(m[constStatDCNames]) + if r, _ := lib.CompareVersions(m[cmdMetaBuild], "5.0"); r == -1 { + return getNames(m[constStatDCNames]) + } + + rawXDRConfig := m[cmdConfigXDR] + xdrConfig := ParseIntoMap(rawXDRConfig, ";", "=") + rawNames, ok := xdrConfig[constStatDCNames].(string) + + var dcNames []string + + if ok { + if rawNames == "" { + dcNames = []string{} + } else { + dcNames = strings.Split(rawNames, ",") + } + } else { + dcNames = []string{} + } + + return dcNames } // ParseTLSNames parses all TLS names @@ -467,7 +484,7 @@ func ParseSetNames(m map[string]string, ns string) []string { func (info *AsInfo) getCoreInfo() (map[string]string, error) { m, err := info.RequestInfo( - constStatNSNames, constStatDCNames, constStatSIndex, constStatLogIDs, cmdMetaBuild, + constStatNSNames, cmdConfigXDR, constStatSIndex, constStatLogIDs, cmdMetaBuild, ) if err != nil { return nil, err @@ -510,7 +527,7 @@ func (info *AsInfo) createCmdList( } func (info *AsInfo) createStatCmdList(m map[string]string) []string { - cmdList := []string{ConstStat, constStatXDRPre50, constStatNSNames, constStatDCNames} + cmdList := []string{ConstStat, cmdConfigXDR, constStatNSNames} nsNames := getNames(m[constStatNSNames]) for _, ns := range nsNames { @@ -641,22 +658,8 @@ func (info *AsInfo) createXDRConfigCmdList(build string, m map[string]string) ([ return nil, err } - var dcNames []string - m = mergeDicts(m, resp) - rawXDRConfig := resp[cmdConfigXDR] - xdrConfig := ParseIntoMap(rawXDRConfig, ";", "=") - rawNames, ok := xdrConfig[constStatDCNames].(string) - - if ok { - if rawNames == "" { - dcNames = []string{} - } else { - dcNames = strings.Split(rawNames, ",") - } - } else { - dcNames = []string{} - } + dcNames := ParseDCNames(m) results := make(chan error, len(dcNames)) @@ -929,10 +932,10 @@ func parseStatInfo(rawMap map[string]string) lib.Stats { // AllDCStats returns statistics of all dc's on the host. func parseAllDcStats(rawMap map[string]string) lib.Stats { dcStats := make(lib.Stats) - dcNames := getNames(rawMap[constStatDCNames]) + dcNames := ParseDCNames(rawMap) for _, dc := range dcNames { - newCmd := constStatDC + "/" + dc + newCmd := constStatDC + dc s := parseBasicInfo(rawMap[newCmd]) dcStats[dc] = s } diff --git a/info/as_parser_test.go b/info/as_parser_test.go index 9b0f2e5..57d2b00 100644 --- a/info/as_parser_test.go +++ b/info/as_parser_test.go @@ -136,7 +136,7 @@ func (s *AsParserTestSuite) TestAsInfoGetAsConfig() { for _, tc := range testCases { s.Run(tc.context, func() { // Call GetAsInfo with the input from the test case - s.mockConn.EXPECT().RequestInfo([]string{"namespaces", "dcs", "sindex/", "logs", "build"}).Return(tc.coreInfoResp, nil) + s.mockConn.EXPECT().RequestInfo([]string{"namespaces", "get-config:context=xdr", "sindex/", "logs", "build"}).Return(tc.coreInfoResp, nil) if tc.req != nil { s.mockConn.EXPECT().RequestInfo(tc.req).Return(tc.resp, nil) @@ -155,7 +155,7 @@ func (s *AsParserTestSuite) TestAsInfoGetAsConfigXDR5Enabled() { coreInfoResp := map[string]string{"build": "5.0.0.0"} // Call GetAsInfo with the input from the test case - s.mockConn.EXPECT().RequestInfo([]string{"namespaces", "dcs", "sindex/", "logs", "build"}).Return(coreInfoResp, nil) + s.mockConn.EXPECT().RequestInfo([]string{"namespaces", "get-config:context=xdr", "sindex/", "logs", "build"}).Return(coreInfoResp, nil) s.mockConn.EXPECT().RequestInfo([]string{"get-config:context=xdr"}).Return(map[string]string{"get-config:context=xdr": "dcs=DC1,DC2;src-id=0;trace-sample=0"}, nil) s.mockConn.EXPECT().RequestInfo([]string{"get-config:context=xdr;dc=DC1"}).Return(map[string]string{"get-config:context=xdr;dc=DC1": "auth-mode=none;auth-password-file=null;auth-user=null;connector=false;max-recoveries-interleaved=0;node-address-port=;period-ms=100;tls-name=null;use-alternate-access-address=false;namespaces=test"}, nil) s.mockConn.EXPECT().RequestInfo([]string{"get-config:context=xdr;dc=DC2"}).Return(map[string]string{"get-config:context=xdr;dc=DC2": "auth-mode=none;auth-password-file=null;auth-user=null;connector=false;max-recoveries-interleaved=0;node-address-port=;period-ms=100;tls-name=null;use-alternate-access-address=false;namespaces=bar"}, nil) @@ -185,7 +185,7 @@ func (s *AsParserTestSuite) TestAsInfoGetAsConfigXDR5Disabled() { coreInfoResp := map[string]string{"build": "5.0.0.0"} // Call GetAsInfo with the input from the test case - s.mockConn.EXPECT().RequestInfo([]string{"namespaces", "dcs", "sindex/", "logs", "build"}).Return(coreInfoResp, nil) + s.mockConn.EXPECT().RequestInfo([]string{"namespaces", "get-config:context=xdr", "sindex/", "logs", "build"}).Return(coreInfoResp, nil) s.mockConn.EXPECT().RequestInfo([]string{"get-config:context=xdr"}).Return(map[string]string{"get-config:context=xdr": "dcs=;src-id=0;trace-sample=0"}, nil) expected := lib.Stats{"xdr": lib.Stats{