-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tags to the Volume and Cluster dashboards (#3273)
* feat: add tags field in volume table * feat: add tags in cluster dashboard * feat: minor change * feat: minor change * feat: update volume dashboard with tags * feat: adding volume_tags and cluster_tags metrics * feat: skip zapi counters * feat: sorted slice * feat: join with volume_labels * feat: update cluster dashboard * feat: update test
- Loading branch information
Showing
15 changed files
with
345 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package cluster | ||
|
||
import ( | ||
"github.com/netapp/harvest/v2/cmd/poller/plugin" | ||
"github.com/netapp/harvest/v2/pkg/conf" | ||
"github.com/netapp/harvest/v2/pkg/matrix" | ||
"github.com/netapp/harvest/v2/pkg/slogx" | ||
"github.com/netapp/harvest/v2/pkg/tree/node" | ||
"github.com/netapp/harvest/v2/pkg/util" | ||
"log/slog" | ||
"strings" | ||
) | ||
|
||
type Cluster struct { | ||
*plugin.AbstractPlugin | ||
tags *matrix.Matrix | ||
} | ||
|
||
func New(p *plugin.AbstractPlugin) plugin.Plugin { | ||
return &Cluster{AbstractPlugin: p} | ||
} | ||
|
||
func (c *Cluster) Init(_ conf.Remote) error { | ||
var err error | ||
|
||
if err := c.InitAbc(); err != nil { | ||
return err | ||
} | ||
|
||
c.tags = matrix.New(c.Parent+".Cluster", "cluster", "cluster") | ||
exportOptions := node.NewS("export_options") | ||
instanceKeys := exportOptions.NewChildS("instance_keys", "") | ||
instanceKeys.NewChildS("", "tag") | ||
c.tags.SetExportOptions(exportOptions) | ||
_, err = c.tags.NewMetricFloat64("tags", "tags") | ||
if err != nil { | ||
c.SLogger.Error("add metric", slogx.Err(err)) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Cluster) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) { | ||
data := dataMap[c.Object] | ||
|
||
// Based on the tags array, cluster_tags instances/metrics would be created | ||
c.handleTags(data) | ||
|
||
return []*matrix.Matrix{c.tags}, nil, nil | ||
} | ||
|
||
func (c *Cluster) handleTags(data *matrix.Matrix) { | ||
var ( | ||
tagInstance *matrix.Instance | ||
err error | ||
) | ||
|
||
// Purge and reset data | ||
c.tags.PurgeInstances() | ||
c.tags.Reset() | ||
|
||
// Set all global labels | ||
c.tags.SetGlobalLabels(data.GetGlobalLabels()) | ||
|
||
// Based on the tags array, cluster_tags instances/metrics would be created. | ||
for _, cluster := range data.GetInstances() { | ||
if tags := cluster.GetLabel("tags"); tags != "" { | ||
for _, tag := range strings.Split(tags, ",") { | ||
tagInstanceKey := data.GetGlobalLabels()["cluster"] + tag | ||
if tagInstance, err = c.tags.NewInstance(tagInstanceKey); err != nil { | ||
c.SLogger.Error( | ||
"Failed to create tag instance", | ||
slogx.Err(err), | ||
slog.String("tagInstanceKey", tagInstanceKey), | ||
) | ||
return | ||
} | ||
|
||
tagInstance.SetLabel("tag", tag) | ||
|
||
m := c.tags.GetMetric("tags") | ||
// populate numeric data | ||
value := 1.0 | ||
if err = m.SetValueFloat64(tagInstance, value); err != nil { | ||
c.SLogger.Error("Failed to parse value", slogx.Err(err), slog.Float64("value", value)) | ||
} else { | ||
c.SLogger.Debug("added value", slog.Float64("value", value)) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,7 @@ var ( | |
"_labels", | ||
"volume_arw_status", | ||
"ALERTS", | ||
"_tags", | ||
} | ||
|
||
// Exclude extra metrics for ZAPI | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.