Skip to content

Commit

Permalink
fix: support multi key for Disk plugin ZapiPerf (#2449)
Browse files Browse the repository at this point in the history
* fix: support multi key for Disk plugin ZapiPerf
  • Loading branch information
rahulguptajss authored Oct 27, 2023
1 parent a785f1b commit f11c765
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cmd/collectors/zapiperf/plugins/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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
}
Expand All @@ -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 != "" {
Expand Down

0 comments on commit f11c765

Please sign in to comment.