Skip to content

Commit

Permalink
feat: Adding plugin to tracking cluster image update
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardikl committed Nov 19, 2024
1 parent dfa366a commit 7bd59fe
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 10 deletions.
92 changes: 92 additions & 0 deletions cmd/collectors/rest/plugins/clusterupdate/clusterupdate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package clusterupdate

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"
"github.com/tidwall/gjson"
"log/slog"
)

type ClusterUpdate struct {
*plugin.AbstractPlugin
data *matrix.Matrix
}

func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &ClusterUpdate{AbstractPlugin: p}
}

func (c *ClusterUpdate) Init(conf.Remote) error {
if err := c.InitAbc(); err != nil {
return err
}

c.data = matrix.New(c.Parent+".ClusterUpdate", "cluster_update", "cluster_update")
exportOptions := node.NewS("export_options")
instanceKeys := exportOptions.NewChildS("instance_keys", "")
instanceKeys.NewChildS("", "phase")
instanceKeys.NewChildS("", "state")
instanceKeys.NewChildS("", "node")
c.data.SetExportOptions(exportOptions)

if _, err := c.data.NewMetricFloat64("status", "status"); err != nil {
c.SLogger.Error("Failed to create metric", slogx.Err(err), slog.String("metric", "status"))
return err
}

return nil
}

func (c *ClusterUpdate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) {
var (
clusterUpdateInstance *matrix.Instance
key string
err error
)
// Purge and reset data
c.data.PurgeInstances()
c.data.Reset()

// Set all global labels
data := dataMap[c.Object]
c.data.SetGlobalLabels(data.GetGlobalLabels())

for _, instance := range data.GetInstances() {
instance.SetExportable(false)
updateDetails := instance.GetLabel("update_details")
updateDetailsJSON := gjson.Result{Type: gjson.JSON, Raw: "[" + updateDetails + "]"}
for _, updateDetail := range updateDetailsJSON.Array() {
phase := updateDetail.Get("phase").String()
state := updateDetail.Get("state").String()
nodeName := updateDetail.Get("node.name").String()
key = phase + state + nodeName

if clusterUpdateInstance, err = c.data.NewInstance(key); err != nil {
c.SLogger.Error("Failed to create instance", slogx.Err(err), slog.String("key", key))
continue
}
clusterUpdateInstance.SetLabel("node", nodeName)
clusterUpdateInstance.SetLabel("state", state)
clusterUpdateInstance.SetLabel("phase", phase)

// populate numeric data
value := 0.0
if state == "completed" {
value = 1.0
}

met := c.data.GetMetric("status")
if err := met.SetValueFloat64(clusterUpdateInstance, 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))
}
}
}

return []*matrix.Matrix{c.data}, nil, nil
}
3 changes: 3 additions & 0 deletions cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/aggregate"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/certificate"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/cluster"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/clusterupdate"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/disk"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/health"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/metroclustercheck"
Expand Down Expand Up @@ -487,6 +488,8 @@ func (r *Rest) LoadPlugin(kind string, abc *plugin.AbstractPlugin) plugin.Plugin
return aggregate.New(abc)
case "Cluster":
return cluster.New(abc)
case "ClusterUpdate":
return clusterupdate.New(abc)
case "Disk":
return disk.New(abc)
case "Health":
Expand Down
16 changes: 6 additions & 10 deletions conf/rest/9.6.0/clusterupdate.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@

name: ClusterUpdate
query: api/private/cli/cluster/image/show-update-progress
query: api/cluster/software
object: cluster_update

counters:
- ^^ndu_phase => phase
- ^^phase_description => phase_name
- ^^phase_status => status
- ^update_details => update_details

plugins:
- ClusterUpdate


export_options:
instance_keys:
- phase
- status
instance_labels:
- phase_name

0 comments on commit 7bd59fe

Please sign in to comment.