Skip to content

Commit

Permalink
fix: qos policy not updated in workload counters
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Aug 22, 2023
1 parent 8f44053 commit c6c63b5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
29 changes: 17 additions & 12 deletions cmd/collectors/restperf/restperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,25 +1402,16 @@ func (r *RestPerf) pollInstance(records []gjson.Result) (map[string]*matrix.Matr
if oldInstances.Has(instanceKey) {
// instance already in cache
oldInstances.Remove(instanceKey)
instance := mat.GetInstance(instanceKey)
r.updateQosLabels(instanceData, instance, instanceKey)
r.Logger.Debug().Msgf("updated instance [%s%s%s%s]", color.Bold, color.Yellow, instanceKey, color.End)
} else if instance, err := mat.NewInstance(instanceKey); err != nil {
r.Logger.Error().Err(err).Str("instanceKey", instanceKey).Msg("add instance")
} else {
r.Logger.Trace().
Str("key", instanceKey).
Msg("Added new instance")
if isWorkloadObject(r.Prop.Query) || isWorkloadDetailObject(r.Prop.Query) {
for label, display := range r.perfProp.qosLabels {
if value := instanceData.Get(label); value.Exists() {
instance.SetLabel(display, strings.Clone(value.String()))
} else {
// lun,file,qtree may not always exist for workload
r.Logger.Trace().Str("label", label).Str("instanceKey", instanceKey).Msg("Missing label")

}
}
r.Logger.Debug().Str("query", r.Prop.Query).Str("key", instanceKey).Str("qos labels", instance.GetLabels().String()).Msg("")
}
r.updateQosLabels(instanceData, instance, instanceKey)
}
}

Expand All @@ -1442,6 +1433,20 @@ func (r *RestPerf) pollInstance(records []gjson.Result) (map[string]*matrix.Matr
return nil, err
}

func (r *RestPerf) updateQosLabels(qos gjson.Result, instance *matrix.Instance, key string) {
if isWorkloadObject(r.Prop.Query) || isWorkloadDetailObject(r.Prop.Query) {
for label, display := range r.perfProp.qosLabels {
if value := qos.Get(label); value.Exists() {
instance.SetLabel(display, strings.Clone(value.String()))
} else {
// lun,file,qtree may not always exist for workload
r.Logger.Trace().Str("label", label).Str("key", key).Msg("Missing label")
}
}
r.Logger.Debug().Str("query", r.Prop.Query).Str("key", key).Str("qos labels", instance.GetLabels().String()).Send()
}
}

func (r *RestPerf) handleError(err error, href string) (map[string]*matrix.Matrix, error) {
if errs.IsRestErr(err, errs.TableNotFound) || errs.IsRestErr(err, errs.APINotFound) {
// the table or API does not exist. return ErrAPIRequestRejected so the task goes to stand-by
Expand Down
22 changes: 14 additions & 8 deletions cmd/collectors/zapiperf/zapiperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,8 @@ func (z *ZapiPerf) PollInstance() (map[string]*matrix.Matrix, error) {
} else if oldInstances.Has(key) {
// instance already in cache
oldInstances.Remove(key)
instance := mat.GetInstance(key)
z.updateQosLabels(i, instance, key)
z.Logger.Trace().Msgf("updated instance [%s%s%s%s]", color.Bold, color.Yellow, key, color.End)
continue
} else if instance, err := mat.NewInstance(key); err != nil {
Expand All @@ -1476,14 +1478,7 @@ func (z *ZapiPerf) PollInstance() (map[string]*matrix.Matrix, error) {
z.Logger.Trace().
Str("key", key).
Msg("Added new instance")
if z.Query == objWorkload || z.Query == objWorkloadDetail || z.Query == objWorkloadVolume || z.Query == objWorkloadDetailVolume {
for label, display := range z.qosLabels {
if value := i.GetChildContentS(label); value != "" {
instance.SetLabel(display, value)
}
}
z.Logger.Debug().Msgf("(%s) [%s] added QOS labels: %s", z.Query, key, instance.GetLabels().String())
}
z.updateQosLabels(i, instance, key)
}
}
}
Expand All @@ -1506,6 +1501,17 @@ func (z *ZapiPerf) PollInstance() (map[string]*matrix.Matrix, error) {
return nil, err
}

func (z *ZapiPerf) updateQosLabels(qos *node.Node, instance *matrix.Instance, key string) {
if z.Query == objWorkload || z.Query == objWorkloadDetail || z.Query == objWorkloadVolume || z.Query == objWorkloadDetailVolume {
for label, display := range z.qosLabels {
if value := qos.GetChildContentS(label); value != "" {
instance.SetLabel(display, value)
}
}
z.Logger.Debug().Str("query", z.Query).Str("key", key).Str("qos labels", instance.GetLabels().String()).Send()
}
}

// Interface guards
var (
_ collector.Collector = (*ZapiPerf)(nil)
Expand Down

0 comments on commit c6c63b5

Please sign in to comment.