Skip to content

Commit

Permalink
OM126 - unit test cases
Browse files Browse the repository at this point in the history
enhanced mockdata with 7.0 stats and configs
fixed failed test-cases
sorted newly added 7.0 stats/configs in gauge-list
  • Loading branch information
mphanias committed Nov 3, 2023
1 parent 6105b98 commit 3a8b80e
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 68 deletions.
14 changes: 6 additions & 8 deletions gauge_stats_list.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,16 @@ namespace_gauge_stats =[
"xdr_tombstones",

# added in 7.0
"data_avail_pct",
"data_compression_ratio",
"data_total_bytes",
"data_used_bytes",
"data_used_pct",
"index_mounts_used_pct",
"index_used_bytes",
"set_index_used_bytes",
"sindex_used_bytes",
"index_used_bytes",
"index_mounts_used_pct",
"sindex_used_bytes",
"sindex_mounts_used_pct",
"data_total_bytes",
"data_used_pct",
"data_avail_pct",
"data_compression_ratio",
"sindex_used_bytes",
"truncating",

]
4 changes: 2 additions & 2 deletions gauge_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func TestGetGaugesCounts(t *testing.T) {
initGaugeStats(METRICS_CONFIG_FILE, gaugeList)

glist := gaugeList.NamespaceStats
assert.Equal(t, len(glist), 88)
assert.Equal(t, len(glist), 99)

glist = gaugeList.NodeStats
assert.Equal(t, len(glist), 69)

glist = gaugeList.SetsStats
assert.Equal(t, len(glist), 7)
assert.Equal(t, len(glist), 9)

glist = gaugeList.SindexStats
assert.Equal(t, len(glist), 13)
Expand Down
5 changes: 3 additions & 2 deletions helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ func splitAndRetrieveStats(s, sep string) map[string]string {
}

func convertValue(s string) (float64, error) {
if f, err := strconv.ParseFloat(s, 64); err == nil {
temp_s := strings.TrimSpace(s)
if f, err := strconv.ParseFloat(temp_s, 64); err == nil {
return f, nil
}

if b, err := strconv.ParseBool(s); err == nil {
if b, err := strconv.ParseBool(temp_s); err == nil {
if b {
return 1, nil
}
Expand Down
6 changes: 4 additions & 2 deletions mock_data_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ type MockNamespacePromMetricGenerator struct {
func (nsw *MockNamespacePromMetricGenerator) createNamespaceWatcherExpectedOutputs(mas *MockAerospikeServer, nsName string, addNsToKey bool) (map[string][]string, map[string][]string) {

// regex to check if a stat is storage-engine
seDynamicExtractor := regexp.MustCompile(`storage\-engine\.(?P<type>file|device)\[(?P<idx>\d+)\]\.(?P<metric>.+)`)
seDynamicExtractor := regexp.MustCompile(`storage\-engine\.(?P<type>file|device|stripe)\[(?P<idx>\d+)\]\.(?P<metric>.+)`)
itDynamicExtractor := regexp.MustCompile(`index\-type\.(?P<type>mount)\[(?P<idx>\d+)\]\.(?P<metric>.+)`)
sintDynamicExtractor := regexp.MustCompile(`sindex\-type\.(?P<type>mount)\[(?P<idx>\d+)\]\.(?P<metric>.+)`)

Expand Down Expand Up @@ -331,8 +331,9 @@ func (nsw *MockNamespacePromMetricGenerator) createNamespaceWatcherExpectedOutpu
labelsMap["index"] = stats["index-type"]
} else if strings.HasPrefix(key, "sindex-type") {
labelsMap["sindex"] = stats["sindex-type"]
} else {
labelsMap["storage_engine"] = stats["storage-engine"]
}

key = strings.ReplaceAll(key, "-", "_")
key = strings.ReplaceAll(key, ".", "_")

Expand Down Expand Up @@ -382,6 +383,7 @@ func (nsw *MockNamespacePromMetricGenerator) createNamespaceWatcherExpectedOutpu
metricName = match[3]
deviceOrFileName = stats["storage-engine."+metricType+"["+metricIndex+"]"]
metric = "aerospike_namespace_storage_engine_" + metricType + "_" + metricName
labelsMap["storage_engine"] = stats["storage-engine"]

} else if strings.HasPrefix(key, "index-type") {
match := itDynamicExtractor.FindStringSubmatch(key)
Expand Down
95 changes: 42 additions & 53 deletions tests/mock_test_data.txt

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions tests/pre7x_mock_test_data.txt

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion watcher_sindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func TestSindex_PassTwoKeys(t *testing.T) {
expectedOutputs := mas.createSindexPassTwoExpectedOutputs(mas)
outputs := watcher.passTwoKeys(mas.passone_outputs_map)

assert.Equal(t, outputs, expectedOutputs)
// fmt.Println("\texpectedOutputs: ", expectedOutputs, "\n\toutputs: ", outputs)

assert.ElementsMatch(t, outputs, expectedOutputs)
}

func TestSindex_RefreshDefault(t *testing.T) {
Expand Down Expand Up @@ -225,6 +227,8 @@ func sindex_runTestCase(t *testing.T) {
outputMetricValues := lOutputValues[key]
outpuMetricLabels := lOutputLabels[key]

fmt.Println("Key: ", key, "\n\texpectedValues: ", expectedValues, "\n\toutputMetricValues: ", outputMetricValues, "\n\texpectedLabels: ", expectedLabels, "\n\toutpuMetricLabels: ", outpuMetricLabels)

// assert - only if the value belongs to the namespace/set we read expected values and processing
if strings.HasPrefix(key, namespaceWithSindexName) {
assert.Contains(t, expectedValues, outputMetricValues)
Expand Down

0 comments on commit 3a8b80e

Please sign in to comment.