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

fix: support multi key for Disk plugin ZapiPerf #2449

Merged
merged 2 commits into from
Oct 27, 2023
Merged
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be needed as key will always be there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to generate shelf_multipath_labels

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
Loading