Skip to content

Commit

Permalink
feat: metric doc needs to handle templates with same object names (#2426
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rahulguptajss authored Oct 16, 2023
1 parent 92d526f commit 450732c
Show file tree
Hide file tree
Showing 2 changed files with 1,101 additions and 198 deletions.
63 changes: 61 additions & 2 deletions cmd/tools/generate/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"sort"
"strings"
"text/template"
Expand Down Expand Up @@ -63,6 +64,11 @@ var (
"fabricpool_throughput_ops",
"iw_",
}
// Special handling perf objects
specialPerfObjects = map[string]bool{
"svm_nfs": true,
"node_nfs": true,
}
)

type Counters struct {
Expand Down Expand Up @@ -449,6 +455,10 @@ func processZAPIPerfCounters(path string, client *zapi.Client) map[string]Counte
}
counters[co.Name] = co
}
// handling for templates with common object names
if specialPerfObjects[model.Object] {
return specialHandlingPerfCounters(counters, model)
}
return counters
}

Expand Down Expand Up @@ -651,10 +661,46 @@ func generateCounterTemplate(counters map[string]Counter, client *rest.Client) {
}
}

// Regex to match NFS version and operation
var reRemove = regexp.MustCompile(`NFSv\d+\.\d+`)

func mergeCounters(restCounters map[string]Counter, zapiCounters map[string]Counter) map[string]Counter {
// handle special counters
for k, v := range restCounters {
hashIndex := strings.Index(k, "#")
if hashIndex != -1 {
if v1, ok := restCounters[v.Name]; !ok {
v.Description = reRemove.ReplaceAllString(v.Description, "")
// Remove extra spaces from the description
v.Description = strings.Join(strings.Fields(v.Description), " ")
restCounters[v.Name] = v
} else {
v1.APIs = append(v1.APIs, v.APIs...)
restCounters[v.Name] = v1
}
delete(restCounters, k)
}
}

for k, v := range zapiCounters {
hashIndex := strings.Index(k, "#")
if hashIndex != -1 {
if v1, ok := zapiCounters[v.Name]; !ok {
v.Description = reRemove.ReplaceAllString(v.Description, "")
// Remove extra spaces from the description
v.Description = strings.Join(strings.Fields(v.Description), " ")
zapiCounters[v.Name] = v
} else {
v1.APIs = append(v1.APIs, v.APIs...)
zapiCounters[v.Name] = v1
}
delete(zapiCounters, k)
}
}

for k, v := range zapiCounters {
if v1, ok := restCounters[k]; ok {
v1.APIs = append(v1.APIs, v.APIs[0])
v1.APIs = append(v1.APIs, v.APIs...)
restCounters[k] = v1
} else {
zapiDef := v.APIs[0]
Expand Down Expand Up @@ -783,10 +829,23 @@ func processRestPerfCounters(path string, client *rest.Client) map[string]Counte
}
counters[co.Name] = co
}

// handling for templates with common object names/metric name
if specialPerfObjects[model.Object] {
return specialHandlingPerfCounters(counters, model)
}
return counters
}

func specialHandlingPerfCounters(counters map[string]Counter, model template2.Model) map[string]Counter {
// handling for templates with common object names
modifiedCounters := make(map[string]Counter)
for originalKey, value := range counters {
modifiedKey := model.Name + "#" + originalKey
modifiedCounters[modifiedKey] = value
}
return modifiedCounters
}

func addAggregatedCounter(c *Counter, metric plugin.DerivedMetric, withPrefix string, noPrefix string) {
if !strings.HasSuffix(c.Description, ".") {
c.Description = c.Description + "."
Expand Down
Loading

0 comments on commit 450732c

Please sign in to comment.