From f11c7659ce4122ef04a9537b29f6f6574b1542be Mon Sep 17 00:00:00 2001 From: Rahul Date: Fri, 27 Oct 2023 18:42:45 +0530 Subject: [PATCH] fix: support multi key for Disk plugin ZapiPerf (#2449) * fix: support multi key for Disk plugin ZapiPerf --- cmd/collectors/zapiperf/plugins/disk/disk.go | 25 ++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/collectors/zapiperf/plugins/disk/disk.go b/cmd/collectors/zapiperf/plugins/disk/disk.go index 1d025d816..92f188e46 100644 --- a/cmd/collectors/zapiperf/plugins/disk/disk.go +++ b/cmd/collectors/zapiperf/plugins/disk/disk.go @@ -43,7 +43,7 @@ type Disk struct { *plugin.AbstractPlugin shelfData map[string]*matrix.Matrix powerData map[string]*matrix.Matrix - instanceKeys map[string]string + instanceKeys map[string][]string instanceLabels map[string]map[string]string batchSize string client *zapi.Client @@ -128,7 +128,7 @@ func (d *Disk) Init() error { d.shelfData = make(map[string]*matrix.Matrix) d.powerData = make(map[string]*matrix.Matrix) - d.instanceKeys = make(map[string]string) + d.instanceKeys = make(map[string][]string) d.instanceLabels = make(map[string]map[string]string) objects := d.Params.GetChildS("objects") @@ -168,8 +168,9 @@ func (d *Disk) Init() error { switch kind { case "key": - d.instanceKeys[attribute] = metricName + d.instanceKeys[attribute] = append(d.instanceKeys[attribute], metricName) d.instanceLabels[attribute][metricName] = display + instanceLabels.NewChildS("", display) instanceKeys.NewChildS("", display) d.Logger.Debug().Msgf("added instance key: (%s) (%s) [%s]", attribute, x.GetNameS(), display) case "label": @@ -817,7 +818,7 @@ func (d *Disk) handleCMode(shelves []*node.Node) ([]*matrix.Matrix, error) { for attribute, data1 := range d.shelfData { if statusMetric := data1.GetMetric("status"); statusMetric != nil { - if d.instanceKeys[attribute] == "" { + if len(d.instanceKeys[attribute]) == 0 { d.Logger.Warn().Msgf("no instance keys defined for object [%s], skipping", attribute) continue } @@ -832,15 +833,25 @@ func (d *Disk) handleCMode(shelves []*node.Node) ([]*matrix.Matrix, error) { for _, obj := range objectElem.GetChildren() { - if key := obj.GetChildContentS(d.instanceKeys[attribute]); key != "" { - instanceKey := shelfUID + "#" + key + if keys := d.instanceKeys[attribute]; len(keys) != 0 { + var sKeys []string + for _, k := range keys { + v := obj.GetChildContentS(k) + sKeys = append(sKeys, v) + } + combinedKey := strings.Join(sKeys, "") + instanceKey := shelfUID + "#" + combinedKey instance, err := data1.NewInstance(instanceKey) if err != nil { d.Logger.Error().Err(err).Str("attribute", attribute).Msg("Failed to add instance") return nil, err } - d.Logger.Debug().Msgf("add (%s) instance: %s.%s", attribute, shelfID, key) + d.Logger.Debug(). + Str("attribute", attribute). + Str("shelfID", shelfID). + Str("key", combinedKey). + Msg("add instance") for label, labelDisplay := range d.instanceLabels[attribute] { if value := obj.GetChildContentS(label); value != "" {