Skip to content

Commit

Permalink
fixing dc and xdr stat collection
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Nov 6, 2024
1 parent 5562cfa commit f558adf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 36 deletions.
69 changes: 36 additions & 33 deletions info/as_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions info/as_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit f558adf

Please sign in to comment.