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: log cluster name and version with poller metadata #3234

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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/collectors/ems/ems.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (e *Ems) InitMatrix() error {
// overwrite from abstract collector
mat.Object = e.Object
// Add system (cluster) name
mat.SetGlobalLabel("cluster", e.Client.Cluster().Name)
mat.SetGlobalLabel("cluster_uuid", e.Client.Cluster().UUID)
mat.SetGlobalLabel("cluster", e.Client.Remote().Name)
mat.SetGlobalLabel("cluster_uuid", e.Client.Remote().UUID)

if e.Params.HasChildS("labels") {
for _, l := range e.Params.GetChildS("labels").GetChildren() {
Expand Down
4 changes: 3 additions & 1 deletion cmd/collectors/keyperf/keyperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (kp *KeyPerf) Init(a *collector.AbstractCollector) error {
return err
}

kp.Remote = kp.Client.Remote()

if kp.Prop.TemplatePath, err = kp.LoadTemplate(); err != nil {
return err
}
Expand Down Expand Up @@ -105,7 +107,7 @@ func (kp *KeyPerf) InitMatrix() error {
// overwrite from abstract collector
mat.Object = kp.Prop.Object
// Add system (cluster) name
mat.SetGlobalLabel("cluster", kp.Client.Cluster().Name)
mat.SetGlobalLabel("cluster", kp.Remote.Name)
if kp.Params.HasChildS("labels") {
for _, l := range kp.Params.GetChildS("labels").GetChildren() {
mat.SetGlobalLabel(l.GetNameS(), l.GetContentS())
Expand Down
2 changes: 1 addition & 1 deletion cmd/collectors/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func collectChassisFRU(client *rest.Client, logger *slog.Logger) (map[string]int
if !cn.Exists() {
logger.Warn(
"fru has no connected nodes",
slog.String("cluster", client.Cluster().Name),
slog.String("cluster", client.Remote().Name),
slog.String("fru", r.Get("fru_name").String()),
)
continue
Expand Down
4 changes: 2 additions & 2 deletions cmd/collectors/rest/plugins/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (h *Health) initMatrix(name string, prefix string, inputMat map[string]*mat
func (h *Health) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) {
data := dataMap[h.Object]
h.client.Metadata.Reset()
clusterVersion := h.client.Cluster().GetVersion()
clusterVersion := h.client.Remote().Version
ontapVersion, err := goversion.NewVersion(clusterVersion)
if err != nil {
h.SLogger.Error(
Expand Down Expand Up @@ -270,7 +270,7 @@ func (h *Health) collectVolumeRansomwareAlerts() int {
instance *matrix.Instance
)
volumeRansomwareAlertCount := 0
clusterVersion := h.client.Cluster().GetVersion()
clusterVersion := h.client.Remote().Version
ontapVersion, err := goversion.NewVersion(clusterVersion)
if err != nil {
h.SLogger.Error("Failed to parse version", slogx.Err(err), slog.String("version", clusterVersion))
Expand Down
2 changes: 1 addition & 1 deletion cmd/collectors/rest/plugins/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (v *Volume) Init() error {
// Read template to decide inclusion of flexgroup constituents
v.includeConstituents = collectors.ReadPluginKey(v.Params, "include_constituents")
// ARW feature is supported from 9.10 onwards, If we ask this field in Rest call in plugin, then it will be failed.
v.isArwSupportedVersion, err = util.VersionAtLeast(v.client.Cluster().GetVersion(), ARWSupportedVersion)
v.isArwSupportedVersion, err = util.VersionAtLeast(v.client.Remote().Version, ARWSupportedVersion)
if err != nil {
return fmt.Errorf("unable to get version %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr
v.client.Metadata.Reset()

cluster := data.GetGlobalLabels()["cluster"]
clusterVersion := v.client.Cluster().GetVersion()
clusterVersion := v.client.Remote().Version
ontapVersion, err := goversion.NewVersion(clusterVersion)
if err != nil {
v.SLogger.Error("Failed to parse version",
Expand Down
23 changes: 15 additions & 8 deletions cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
"log/slog"
"os"
"regexp"
"slices"
"sort"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -201,6 +201,8 @@ func (r *Rest) InitClient() error {
}
r.Client.TraceLogSet(r.Name, r.Params)

r.Remote = r.Client.Remote()

return nil
}

Expand All @@ -209,7 +211,7 @@ func (r *Rest) InitMatrix() error {
// overwrite from abstract collector
mat.Object = r.Prop.Object
// Add system (cluster) name
mat.SetGlobalLabel("cluster", r.Client.Cluster().Name)
mat.SetGlobalLabel("cluster", r.Remote.Name)

if r.Params.HasChildS("labels") {
for _, l := range r.Params.GetChildS("labels").GetChildren() {
Expand Down Expand Up @@ -333,7 +335,7 @@ func (r *Rest) PollCounter() (map[string]*matrix.Matrix, error) {
apiD := time.Since(startTime)

startTime = time.Now()
v, err := util.VersionAtLeast(r.Client.Cluster().GetVersion(), "9.11.1")
v, err := util.VersionAtLeast(r.Remote.Version, "9.11.1")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -709,6 +711,7 @@ func (r *Rest) CollectAutoSupport(p *collector.Payload) {
for k := range r.Prop.Counters {
counters = append(counters, k)
}
slices.Sort(counters)

var schedules = make([]collector.Schedule, 0)
tasks := r.Params.GetChildS("schedule")
Expand Down Expand Up @@ -745,14 +748,18 @@ func (r *Rest) CollectAutoSupport(p *collector.Payload) {
InstanceInfo: &info,
})

if (r.Name == "Rest" && (r.Object == "Volume" || r.Object == "Node")) || r.Name == "Ems" {
version := r.Client.Cluster().Version
p.Target.Version = strconv.Itoa(version[0]) + "." + strconv.Itoa(version[1]) + "." + strconv.Itoa(version[2])
isRest := r.Name == "Rest"
isKeyPerf := r.Name == "KeyPerf"
isEMS := r.Name == "Ems"
isOneOfVolumeNode := r.Object == "Volume" || r.Object == "Node"

if ((isRest || isKeyPerf) && isOneOfVolumeNode) || isEMS {
p.Target.Version = r.Remote.Version
p.Target.Model = "cdot"
if p.Target.Serial == "" {
p.Target.Serial = r.Client.Cluster().UUID
p.Target.Serial = r.Remote.UUID
}
p.Target.ClusterUUID = r.Client.Cluster().UUID
p.Target.ClusterUUID = r.Remote.UUID

if r.Object == "Node" || r.Name == "ems" {
var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/collectors/rest/templating.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func (r *Rest) LoadTemplate() (string, error) {

jitter := r.Params.GetChildContentS("jitter")
template, path, err := r.ImportSubTemplate("", TemplateFn(r.Params, r.Object), jitter, r.Client.Cluster().Version)
template, path, err := r.ImportSubTemplate("", TemplateFn(r.Params, r.Object), jitter, r.Remote.Version)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/collectors/restperf/restperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (r *RestPerf) InitMatrix() error {
// overwrite from abstract collector
mat.Object = r.Prop.Object
// Add system (cluster) name
mat.SetGlobalLabel("cluster", r.Client.Cluster().Name)
mat.SetGlobalLabel("cluster", r.Remote.Name)
if r.Params.HasChildS("labels") {
for _, l := range r.Params.GetChildS("labels").GetChildren() {
mat.SetGlobalLabel(l.GetNameS(), l.GetContentS())
Expand Down
21 changes: 8 additions & 13 deletions cmd/collectors/storagegrid/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"math"
"net/http"
"net/url"
"strconv"
"strings"
"time"
)
Expand All @@ -35,7 +36,7 @@ type Client struct {
buffer *bytes.Buffer
Logger *slog.Logger
baseURL string
Cluster Cluster
Remote conf.Remote
token string
Timeout time.Duration
logRest bool // used to log Rest request/response
Expand All @@ -44,13 +45,6 @@ type Client struct {
Metadata *util.Metadata
}

type Cluster struct {
Name string
Info string
UUID string
Version [3]int
}

func NewClient(pollerName string, clientTimeout string, c *auth.Credentials) (*Client, error) {
var (
poller *conf.Poller
Expand Down Expand Up @@ -303,13 +297,13 @@ func (c *Client) Init(retries int) error {
}

results = gjson.ParseBytes(content)
c.Cluster.Name = results.Get("data.name").String()
c.Remote.Name = results.Get("data.name").String()

if content, err = c.GetGridRest("grid/license"); err != nil {
continue
}
results = gjson.ParseBytes(content)
c.Cluster.UUID = results.Get("data.systemId").String()
c.Remote.UUID = results.Get("data.systemId").String()
return nil
}

Expand All @@ -324,9 +318,10 @@ func (c *Client) SetVersion(v string) error {
// e.g 11.6.0.3-20220802.2201.f58633a
segments := newVersion.Segments()
if len(segments) >= 3 {
c.Cluster.Version[0] = check(segments[0])
c.Cluster.Version[1] = check(segments[1])
c.Cluster.Version[2] = check(segments[2])
v0 := check(segments[0])
v1 := check(segments[1])
v2 := check(segments[2])
c.Remote.Version = strconv.Itoa(v0) + "." + strconv.Itoa(v1) + "." + strconv.Itoa(v2)
} else {
return fmt.Errorf("failed to parse version %s", v)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/collectors/storagegrid/rest/dummyclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rest

import (
"bytes"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/util"
"log/slog"

Expand All @@ -20,11 +21,10 @@ func NewDummyClient() *Client {

buffer := new(bytes.Buffer)

cluster := Cluster{
remote := conf.Remote{
Name: "TestCluster",
Info: "TestInfo",
UUID: "TestUUID",
Version: [3]int{1, 2, 3},
Version: "1.2.3",
}

client := &Client{
Expand All @@ -33,7 +33,7 @@ func NewDummyClient() *Client {
buffer: buffer,
Logger: slog.Default(),
baseURL: "http://example.com",
Cluster: cluster,
Remote: remote,
token: "TestToken",
Timeout: time.Second * 10,
logRest: true,
Expand Down
14 changes: 9 additions & 5 deletions cmd/collectors/storagegrid/storagegrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/netapp/harvest/v2/pkg/util"
"github.com/tidwall/gjson"
"log/slog"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -91,7 +92,7 @@ func (s *StorageGrid) InitMatrix() error {
// overwrite from abstract collector
mat.Object = s.Props.Object
// Add system (cluster) name
mat.SetGlobalLabel("cluster", s.client.Cluster.Name)
mat.SetGlobalLabel("cluster", s.client.Remote.Name)

if s.Params.HasChildS("labels") {
for _, l := range s.Params.GetChildS("labels").GetChildren() {
Expand Down Expand Up @@ -441,6 +442,8 @@ func (s *StorageGrid) initClient() error {
}
s.client.TraceLogSet(s.Name, s.Params)

s.Remote = s.client.Remote

return nil
}

Expand Down Expand Up @@ -492,7 +495,7 @@ func (s *StorageGrid) LoadTemplate() (string, error) {

jitter := s.Params.GetChildContentS("jitter")

template, path, err = s.ImportSubTemplate("", rest.TemplateFn(s.Params, s.Object), jitter, s.client.Cluster.Version)
template, path, err = s.ImportSubTemplate("", rest.TemplateFn(s.Params, s.Object), jitter, s.Remote.Version)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -540,6 +543,7 @@ func (s *StorageGrid) CollectAutoSupport(p *collector.Payload) {
for k := range s.Props.Counters {
counters = append(counters, k)
}
slices.Sort(counters)

var schedules = make([]collector.Schedule, 0)
tasks := s.Params.GetChildS("schedule")
Expand Down Expand Up @@ -576,10 +580,10 @@ func (s *StorageGrid) CollectAutoSupport(p *collector.Payload) {
InstanceInfo: &info,
})

version := s.client.Cluster.Version
p.Target.Version = strconv.Itoa(version[0]) + "." + strconv.Itoa(version[1]) + "." + strconv.Itoa(version[2])
version := s.Remote.Version
p.Target.Version = version
p.Target.Model = "storagegrid"
p.Target.ClusterUUID = s.client.Cluster.UUID
p.Target.ClusterUUID = s.Remote.UUID

if p.Nodes == nil {
nodeIDs, err := s.getNodeUuids()
Expand Down
25 changes: 15 additions & 10 deletions cmd/collectors/zapi/collector/zapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/netapp/harvest/v2/pkg/slogx"
"github.com/netapp/harvest/v2/pkg/util"
"log/slog"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -93,7 +94,7 @@ func (z *Zapi) InitVars() error {
if z.Options.IsTest {
z.Client = client.NewTestClient()
templateName := z.Params.GetChildS("objects").GetChildContentS(z.Object)
template, path, err := z.ImportSubTemplate("cdot", templateName, jitter, [3]int{9, 8, 0})
template, path, err := z.ImportSubTemplate("cdot", templateName, jitter, "9.8.0")
if err != nil {
return err
}
Expand All @@ -119,13 +120,16 @@ func (z *Zapi) InitVars() error {
}

// save for ASUP messaging
z.HostUUID = z.Client.Serial()
version := z.Client.Version()
z.HostVersion = strconv.Itoa(version[0]) + "." + strconv.Itoa(version[1]) + "." + strconv.Itoa(version[2])
z.HostModel = model
templateName := z.Params.GetChildS("objects").GetChildContentS(z.Object)
versionT := z.Client.Version()
z.Remote = conf.Remote{
Name: z.Client.Name(),
UUID: z.Client.Serial(),
Model: model,
Version: strconv.Itoa(versionT[0]) + "." + strconv.Itoa(versionT[1]) + "." + strconv.Itoa(versionT[2]),
}

template, path, err := z.ImportSubTemplate(model, templateName, jitter, z.Client.Version())
templateName := z.Params.GetChildS("objects").GetChildContentS(z.Object)
template, path, err := z.ImportSubTemplate(model, templateName, jitter, z.Remote.Version)
if err != nil {
return err
}
Expand Down Expand Up @@ -436,6 +440,7 @@ func (z *Zapi) CollectAutoSupport(p *collector.Payload) {
c := z.Params.GetChildS("counters")
c.FlatList(&counters, "")
}
slices.Sort(counters)

var schedules = make([]collector.Schedule, 0)
tasks := z.Params.GetChildS("schedule")
Expand Down Expand Up @@ -480,10 +485,10 @@ func (z *Zapi) CollectAutoSupport(p *collector.Payload) {
})

if z.Name == "Zapi" && (z.Object == "Volume" || z.Object == "Node" || z.Object == "Qtree") {
p.Target.Version = z.GetHostVersion()
p.Target.Model = z.GetHostModel()
p.Target.Version = z.Remote.Version
p.Target.Model = z.Remote.Model
if p.Target.Serial == "" {
p.Target.Serial = z.GetHostUUID()
p.Target.Serial = z.Remote.UUID
}
p.Target.ClusterUUID = z.Client.ClusterUUID()

Expand Down
8 changes: 8 additions & 0 deletions cmd/poller/collector/asup.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ func BuildAndWriteAutoSupport(collectors []Collector, status *matrix.Matrix, pol
attachMemory(msg)

// give each collector the opportunity to attach autosupport information
slices.SortStableFunc(collectors, func(a, b Collector) int {
nameCmp := cmp.Compare(a.GetName(), b.GetName())
if nameCmp == 0 {
return cmp.Compare(a.GetObject(), b.GetObject())
}
return nameCmp
})

for _, c := range collectors {
c.CollectAutoSupport(msg)
}
Expand Down
Loading