Skip to content

Commit

Permalink
feat: support metric for module type in frus (#3411)
Browse files Browse the repository at this point in the history
* feat: support metric for module type in frus
  • Loading branch information
Hardikl authored Jan 9, 2025
1 parent 5a9f42a commit 2bedc55
Show file tree
Hide file tree
Showing 5 changed files with 645 additions and 42 deletions.
96 changes: 58 additions & 38 deletions cmd/collectors/restperf/plugins/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,42 +147,19 @@ func (d *Disk) Init(remote conf.Remote) error {
objectName = strings.TrimSpace(x[1])
}

d.instanceLabels[attribute] = make(map[string]string)

d.shelfData[attribute] = matrix.New(d.Parent+".Shelf", "shelf_"+objectName, "shelf_"+objectName)
d.shelfData[attribute].SetGlobalLabel("datacenter", d.ParentParams.GetChildContentS("datacenter"))

exportOptions := node.NewS("export_options")
instanceLabels := exportOptions.NewChildS("instance_labels", "")
instanceKeys := exportOptions.NewChildS("instance_keys", "")
instanceKeys.NewChildS("", "shelf")
instanceKeys.NewChildS("", "channel")

// artificial metric for status of child object of shelf
_, _ = d.shelfData[attribute].NewMetricUint8("status")

for _, c := range obj.GetAllChildContentS() {
metricName, display, kind, _ := util.ParseMetric(c)

switch kind {
case "key":
d.instanceKeys[attribute] = append(d.instanceKeys[attribute], metricName)
d.instanceLabels[attribute][metricName] = display
instanceLabels.NewChildS("", display)
instanceKeys.NewChildS("", display)
case "label":
d.instanceLabels[attribute][metricName] = display
instanceLabels.NewChildS("", display)
case "float":
_, err := d.shelfData[attribute].NewMetricFloat64(metricName, display)
if err != nil {
d.SLogger.Error("add metric", slogx.Err(err))
return err
}
// frus has 2 types[psu, module], special handling to create 2 different metrics
if attribute == "frus" {
if err := d.initMetrics(attribute+"-psu", "psu", obj); err != nil {
return err
}
if err := d.initMetrics(attribute+"-module", "module", obj); err != nil {
return err
}
} else {
if err := d.initMetrics(attribute, objectName, obj); err != nil {
return err
}
}

d.shelfData[attribute].SetExportOptions(exportOptions)
}

d.initShelfPowerMatrix()
Expand All @@ -193,6 +170,50 @@ func (d *Disk) Init(remote conf.Remote) error {
return nil
}

func (d *Disk) initMetrics(attribute, objectName string, obj *node.Node) error {
d.instanceLabels[attribute] = make(map[string]string)

d.shelfData[attribute] = matrix.New(d.Parent+".Shelf", "shelf_"+objectName, "shelf_"+objectName)
d.shelfData[attribute].SetGlobalLabel("datacenter", d.ParentParams.GetChildContentS("datacenter"))

exportOptions := node.NewS("export_options")
instanceLabels := exportOptions.NewChildS("instance_labels", "")
instanceKeys := exportOptions.NewChildS("instance_keys", "")
instanceKeys.NewChildS("", "shelf")
instanceKeys.NewChildS("", "channel")

// artificial metric for status of child object of shelf
_, _ = d.shelfData[attribute].NewMetricUint8("status")

for _, c := range obj.GetAllChildContentS() {
metricName, display, kind, _ := util.ParseMetric(c)

switch kind {
case "key":
// For shelf child level object's id field converted to psu_id or module_id based on the type.
if strings.Contains(attribute, "frus") {
display = objectName + "_" + display
}
d.instanceKeys[attribute] = append(d.instanceKeys[attribute], metricName)
d.instanceLabels[attribute][metricName] = display
instanceLabels.NewChildS("", display)
instanceKeys.NewChildS("", display)
case "label":
d.instanceLabels[attribute][metricName] = display
instanceLabels.NewChildS("", display)
case "float":
_, err := d.shelfData[attribute].NewMetricFloat64(metricName, display)
if err != nil {
d.SLogger.Error("add metric", slogx.Err(err))
return err
}
}
}

d.shelfData[attribute].SetExportOptions(exportOptions)
return nil
}

func (d *Disk) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) {

data := dataMap[d.Object]
Expand Down Expand Up @@ -250,14 +271,13 @@ func (d *Disk) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.M
d.SLogger.Warn("no instance keys defined for object, skipping", slog.String("attribute", attribute))
continue
}

if childObj := shelf.Get(attribute); childObj.Exists() {
attributeName, attributeValue, _ := strings.Cut(attribute, "-")
if childObj := shelf.Get(attributeName); childObj.Exists() {
if childObj.IsArray() {
for _, obj := range childObj.Array() {

// This is special condition, because child records can't be filterable in parent REST call
// frus type can be [module, psu] and we would only need psu for our use-case.
if attribute == "frus" && obj.Get("type").Exists() && obj.Get("type").ClonedString() != "psu" {
if attributeName == "frus" && obj.Get("type").Exists() && obj.Get("type").ClonedString() != attributeValue {
continue
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/collectors/zapiperf/plugins/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,11 @@ func (d *Disk) handleCMode(shelves []*node.Node) ([]*matrix.Matrix, error) {

for label, labelDisplay := range d.instanceLabels[attribute] {
if value := obj.GetChildContentS(label); value != "" {
// This is to parity with rest for modules, Convert A -> 0, B -> 1 in zapi
if attribute == "shelf-modules" && len(value) == 1 {
num := int(value[0] - 'A')
value = strconv.Itoa(num)
}
instance.SetLabel(labelDisplay, value)
}
}
Expand Down
4 changes: 3 additions & 1 deletion conf/restperf/9.12.0/disk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ plugins:
- ^location
- ^state => status
- current => reading
# psu and module type of frus detail would be handled in plugin
- frus => psu:
- ^^id => psu_id
- ^^id => id
- ^firmware_version => firmware_version
- ^installed => enabled
# - ^location
- ^part_number
Expand Down
11 changes: 10 additions & 1 deletion conf/zapiperf/cdot/9.8.0/disk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ plugins:
- power-supply-units => psu:
storage-shelf-power-supply-unit-info:
# - ^psu-crest-factor => crest_factor
# - ^psu-fw-version => fw_version
- ^psu-fw-version => firmware_version
- ^^psu-id
- ^psu-is-enabled => enabled
- ^psu-location => location
Expand All @@ -78,6 +78,15 @@ plugins:
- ^psu-serial-number => serial
- ^psu-type => type
- ^psu-op-status => status
- shelf-modules => module:
storage-shelf-module-info:
- ^^module-id
- ^module-fw-revision => firmware_version
- ^is-monitor-active => enabled
- ^module-location => location
- ^module-part-number => part_number
- ^es-serial-number => serial
- ^module-op-status => status
- temperature-sensors => temperature:
storage-shelf-temperature-sensor-info:
- ^high-critical-threshold => high_critical
Expand Down
Loading

0 comments on commit 2bedc55

Please sign in to comment.