Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Description fetched from ontap docs via cli #2454

Merged
merged 7 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/tools/generate/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func updateDescription(description string) string {
return s
}

func generateCounterTemplate(counters map[string]Counter, client *rest.Client) {
func generateCounterTemplate(counters map[string]Counter, version [3]int) {
targetPath := "docs/ontap-metrics.md"
t, err := template.New("counter.tmpl").ParseFiles("cmd/tools/generate/counter.tmpl")
if err != nil {
Expand Down Expand Up @@ -644,7 +644,7 @@ func generateCounterTemplate(counters map[string]Counter, client *rest.Client) {
}
}

verWithDots := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(client.Cluster().Version)), "."), "[]")
verWithDots := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(version)), "."), "[]")
c := CounterTemplate{
Counters: values,
CounterMetaData: CounterMetaData{
Expand Down
38 changes: 19 additions & 19 deletions cmd/tools/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ func doDockerCompose(cmd *cobra.Command, _ []string) {

func doGenerateMetrics(cmd *cobra.Command, _ []string) {
addRootOptions(cmd)
generateMetricsWithDoc(true)
counters, cluster := generateMetrics()
generateCounterTemplate(counters, cluster.Version)
}

func doDescription(cmd *cobra.Command, _ []string) {
addRootOptions(cmd)
counters := generateMetricsWithDoc(false)
counters, _ := generateMetrics()
grafana.VisitDashboards(
[]string{"grafana/dashboards/cmode"},
func(path string, data []byte) {
Expand Down Expand Up @@ -499,7 +500,7 @@ func writeAdminSystemd(configFp string) {
println(color.Colorize("✓", color.Green) + " HTTP SD file: " + harvestAdminService + " created")
}

func generateMetricsWithDoc(isUpdateMetricDoc bool) map[string]Counter {
func generateMetrics() (map[string]Counter, rest.Cluster) {
var (
poller *conf.Poller
err error
Expand Down Expand Up @@ -537,11 +538,7 @@ func generateMetricsWithDoc(isUpdateMetricDoc bool) map[string]Counter {
zapiCounters := processZapiCounters(zapiClient)
counters := mergeCounters(restCounters, zapiCounters)
counters = processExternalCounters(counters)
if !isUpdateMetricDoc {
return counters
}
generateCounterTemplate(counters, restClient)
return nil
return counters, restClient.Cluster()
}

func checkDesc(dPath string, data []byte, counters map[string]Counter) {
Hardikl marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -566,7 +563,7 @@ func checkDesc(dPath string, data []byte, counters map[string]Counter) {
if description == "" {
if len(targetsSlice) == 1 {
expr := targetsSlice[0].Get("expr").String()
if !(strings.Contains(expr, "/") || strings.Contains(expr, "*") || strings.Contains(expr, "+") || strings.Contains(expr, "-") || strings.Contains(expr, "on")) {
if !(strings.Contains(expr, "/") || strings.Contains(expr, "+") || strings.Contains(expr, "-") || strings.Contains(expr, "on")) {
allMatches := metricRe.FindAllStringSubmatch(expr, -1)
for _, match := range allMatches {
m := match[1]
Expand All @@ -575,30 +572,26 @@ func checkDesc(dPath string, data []byte, counters map[string]Counter) {
}
expr = m
}
panelPath := strings.Replace(strings.Replace(path, "[", ".", -1), "]", ".", -1) + "description"
// description should end with period
desc := counters[expr].Description
if desc != "" && !strings.HasSuffix(desc, ".") {
desc = desc + "."
}
panelDescriptionMap[panelPath] = desc
panelPath, updatedDescription := generatePanelPathWithDescription(path, counters[expr].Description)
panelDescriptionMap[panelPath] = updatedDescription
}
}
} else if !strings.HasPrefix(description, "$") && !strings.HasSuffix(description, ".") {
// Few panels have description text from variable, which would be ignored.
panelPath := strings.Replace(strings.Replace(path, "[", ".", -1), "]", ".", -1) + "description"
description = description + "."
panelDescriptionMap[panelPath] = description
panelPath, updatedDescription := generatePanelPathWithDescription(path, description)
panelDescriptionMap[panelPath] = updatedDescription
}
})

// Update the dashboard with description
for path, value := range panelDescriptionMap {
data, err = sjson.SetBytes(data, path, value)
if err != nil {
log.Fatalf("error while updating the panel in dashboard %s err: %+v", dPath, err)
}
}

// Sorted json
sorted := pretty.PrettyOptions(data, &pretty.Options{
SortKeys: true,
Indent: " ",
Expand All @@ -609,6 +602,13 @@ func checkDesc(dPath string, data []byte, counters map[string]Counter) {
}
}

func generatePanelPathWithDescription(path string, desc string) (string, string) {
if desc != "" && !strings.HasSuffix(desc, ".") {
desc = desc + "."
}
return strings.Replace(strings.Replace(path, "[", ".", -1), "]", ".", -1) + "description", desc
}

func init() {
Cmd.AddCommand(systemdCmd)
Cmd.AddCommand(metricCmd)
Expand Down
19 changes: 11 additions & 8 deletions grafana/dashboards/cmode/aggregate.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Percent of space used.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -502,7 +502,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Aggregate details.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -2396,6 +2396,7 @@
"panels": [
{
"datasource": "${DS_PROMETHEUS}",
"description": "Storage efficiency ratio of space used.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -2451,6 +2452,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Storage efficiency ratio without snapshot.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -2507,6 +2509,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Storage efficiency ratio without snapshots and flexclones.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -4998,7 +5001,7 @@
"panels": [
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Average latency in microseconds for the WAFL filesystem to process read request to the volume; not including request processing or network communication time.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -5087,7 +5090,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Bytes read per second.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -5177,7 +5180,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Number of read operations per second from the volume.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -5266,7 +5269,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Average latency in microseconds for the WAFL filesystem to process write request to the volume; not including request processing or network communication time.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -5355,7 +5358,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Bytes written per second.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -5444,7 +5447,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Number of write operations per second to the volume.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down
9 changes: 8 additions & 1 deletion grafana/dashboards/cmode/cdot.json
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@
"panels": [
{
"datasource": "${DS_PROMETHEUS}",
"description": "SVM space used percent.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -784,6 +785,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Volume space used percent.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -914,6 +916,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Aggregate space used percent.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -1052,6 +1055,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "SVM space used percent.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -1141,6 +1145,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Volume space used percent.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -1230,6 +1235,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Aggregate space used percent.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -1423,6 +1429,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "SVM total throughput.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -1706,7 +1713,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Volume total throughput.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down
14 changes: 10 additions & 4 deletions grafana/dashboards/cmode/cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Node total throughput.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -886,6 +887,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Node total throughput.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -1203,7 +1205,7 @@
"panels": [
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Node details.",
"fieldConfig": {
"defaults": {
"custom": {
Expand Down Expand Up @@ -1710,7 +1712,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Cluster subsystem details.",
"fieldConfig": {
"defaults": {
"custom": {
Expand Down Expand Up @@ -2113,7 +2115,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Aggregate space used percent.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -2467,6 +2469,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Volume total throughput.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -3035,6 +3038,7 @@
"panels": [
{
"datasource": "${DS_PROMETHEUS}",
"description": "Storage efficiency ratio of space used.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -3090,6 +3094,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Storage efficiency ratio without snapshot.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -3145,6 +3150,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "Storage efficiency ratio without snapshot and flexclone.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -3805,7 +3811,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "SVM total throughput.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down
2 changes: 1 addition & 1 deletion grafana/dashboards/cmode/data_protection_snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Volumes details of snapshot copy reserve space.",
"fieldConfig": {
"defaults": {
"custom": {
Expand Down
6 changes: 3 additions & 3 deletions grafana/dashboards/cmode/disk.json
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Disk capacity per aggregate detail.",
"fieldConfig": {
"defaults": {
"custom": {
Expand Down Expand Up @@ -1161,7 +1161,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Average number of blocks transferred in each user read operation. aggr_disk_max_user_read_chain is the maximum of [disk_user_read_chain](#disk_user_read_chain) for label `aggr`.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -1253,7 +1253,7 @@
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"description": "Average number of blocks transferred in each user write operation. aggr_disk_max_user_write_chain is the maximum of [disk_user_write_chain](#disk_user_write_chain) for label `aggr`.",
"fieldConfig": {
"defaults": {
"color": {
Expand Down
Loading
Loading