Skip to content

Commit

Permalink
feat: keyperf collector templates (#3194)
Browse files Browse the repository at this point in the history
* feat: keyperf collector templates

* feat: address review comments

* feat: add slogx error
  • Loading branch information
rahulguptajss authored Oct 8, 2024
1 parent d230760 commit 9d28189
Show file tree
Hide file tree
Showing 19 changed files with 464 additions and 16 deletions.
44 changes: 42 additions & 2 deletions cmd/collectors/keyperf/keyperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ func (kp *KeyPerf) loadParamInt(name string, defaultValue int) int {
}

func (kp *KeyPerf) buildCounters() {
for k := range kp.Prop.Metrics {
staticCounterDef, err := loadStaticCounterDefinitions(kp.Prop.Object, "cmd/collectors/keyperf/static_counter_definitions.yaml", kp.Logger)
if err != nil {
// It's acceptable to continue even if there are errors, as the remaining counters will still be processed.
// Any counters that require counter metadata will be skipped.
kp.Logger.Error("Failed to load static counter definitions", slogx.Err(err))
}

for k, v := range kp.Prop.Metrics {
if _, exists := kp.perfProp.counterInfo[k]; !exists {
var ctr *counter

Expand Down Expand Up @@ -170,6 +177,36 @@ func (kp *KeyPerf) buildCounters() {
counterType: "delta",
unit: "sec",
}
default:
// look up metric in staticCounterDef
if counterDef, exists := staticCounterDef.CounterDefinitions[v.Name]; exists {
ctr = &counter{
name: k,
counterType: counterDef.Type,
denominator: counterDef.BaseCounter,
}
if counterDef.BaseCounter != "" {
// Ensure denominator exists in counterInfo
if _, denomExists := kp.perfProp.counterInfo[counterDef.BaseCounter]; !denomExists {
var baseCounterType string
if baseCounterDef, baseCounterExists := staticCounterDef.CounterDefinitions[counterDef.BaseCounter]; baseCounterExists {
baseCounterType = baseCounterDef.Type
}
if baseCounterType != "" {
kp.perfProp.counterInfo[counterDef.BaseCounter] = &counter{
name: counterDef.BaseCounter,
counterType: staticCounterDef.CounterDefinitions[counterDef.BaseCounter].Type,
}
if _, dExists := kp.Prop.Metrics[counterDef.BaseCounter]; !dExists {
m := &rest.Metric{Label: "", Name: counterDef.BaseCounter, MetricType: "", Exportable: false}
kp.Prop.Metrics[counterDef.BaseCounter] = m
}
}
}
}
} else {
slog.Warn("Skipping metric due to unknown metricType", slog.String("name", k), slog.String("metricType", v.MetricType))
}
}

if ctr != nil {
Expand Down Expand Up @@ -304,7 +341,8 @@ func (kp *KeyPerf) pollData(
orderedDenominatorKeys = append(orderedDenominatorKeys, key)
}
} else {
kp.Logger.Warn("Counter is missing or unable to parse", slog.String("counter", metric.GetName()))
kp.Logger.Error("Counter is missing or unable to parse", slog.String("counter", metric.GetName()))
metric.SetExportable(false)
}
}

Expand Down Expand Up @@ -375,6 +413,8 @@ func (kp *KeyPerf) pollData(
slog.String("denominator", counter.denominator),
slog.Int("instIndex", instIndex),
)
skips = curMat.Skip(key)
totalSkips += skips
continue
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/collectors/keyperf/static_counter_definitions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
objects:
node:
counter_definitions:
- name: statistics.processor_utilization_raw
type: percent
base_counter: statistics.processor_utilization_base
- name: statistics.processor_utilization_base
type: delta
65 changes: 65 additions & 0 deletions cmd/collectors/keyperf/templating.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package keyperf

import (
"gopkg.in/yaml.v3"
"log/slog"
"os"
)

type CounterDefinition struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
BaseCounter string `yaml:"base_counter,omitempty"`
}

type ObjectCounters struct {
CounterDefinitions map[string]CounterDefinition `yaml:"-"`
}

type Object struct {
CounterDefinitions []CounterDefinition `yaml:"counter_definitions"`
}

type StaticCounterDefinitions struct {
Objects map[string]Object `yaml:"objects"`
}

func loadStaticCounterDefinitions(object string, filePath string, logger *slog.Logger) (ObjectCounters, error) {
var staticDefinitions StaticCounterDefinitions
var objectCounters ObjectCounters

data, err := os.ReadFile(filePath)
if err != nil {
return objectCounters, err
}

err = yaml.Unmarshal(data, &staticDefinitions)
if err != nil {
return objectCounters, err
}

if obj, exists := staticDefinitions.Objects[object]; exists {
allCounterDefs := make(map[string]CounterDefinition)
for _, def := range obj.CounterDefinitions {
allCounterDefs[def.Name] = def
}

objectCounters.CounterDefinitions = make(map[string]CounterDefinition)
for _, def := range obj.CounterDefinitions {
if def.Type == "" {
logger.Error("Missing type in counter definition", slog.String("filePath", filePath), slog.String("counterName", def.Name))
continue
}
if def.BaseCounter != "" {
if _, baseCounterExists := allCounterDefs[def.BaseCounter]; !baseCounterExists {
logger.Error("Base counter definition not found", slog.String("filePath", filePath), slog.String("counterName", def.Name), slog.String("baseCounter", def.BaseCounter))
continue
}
}
objectCounters.CounterDefinitions[def.Name] = def
}
return objectCounters, nil
}

return objectCounters, nil
}
2 changes: 2 additions & 0 deletions cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ func (r *Rest) HandleResults(mat *matrix.Matrix, result []gjson.Result, prop *pr
slogx.Err(err),
slog.String("name", metric.Name),
)
} else {
metr.SetExportable(metric.Exportable)
}
}
f := instanceData.Get(metric.Name)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const toConf = "../../../conf"

var allTemplatesButEms = []string{"rest", "restperf", "storagegrid", "zapi", "zapiperf"}
var allTemplatesButEms = []string{"rest", "restperf", "storagegrid", "zapi", "zapiperf", "keyperf"}

// validates each template file name:
// - ends with yaml
Expand Down
30 changes: 30 additions & 0 deletions conf/keyperf/9.15.0/aggr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Aggregate
query: api/storage/aggregates
object: aggr

counters:
- ^^uuid => uuid
- ^name => aggr
- ^node.name => node
- ^statistics.status => status
- statistics.iops_raw.other => other_ops
- statistics.iops_raw.read => read_ops
- statistics.iops_raw.total => total_ops
- statistics.iops_raw.write => write_ops
- statistics.latency_raw.other => other_latency
- statistics.latency_raw.read => read_latency
- statistics.latency_raw.total => total_latency
- statistics.latency_raw.write => write_latency
- statistics.throughput_raw.other => other_data
- statistics.throughput_raw.read => read_data
- statistics.throughput_raw.total => total_data
- statistics.throughput_raw.write => write_data
- statistics.timestamp(timestamp) => timestamp
- hidden_fields:
- statistics


export_options:
instance_keys:
- aggr
- node
27 changes: 27 additions & 0 deletions conf/keyperf/9.15.0/cifs_vserver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CIFSvserver
query: api/protocols/cifs/services
object: svm_cifs

counters:
- ^^svm.uuid => uuid
- ^statistics.status => status
- ^svm.name => svm
- statistics.iops_raw.other => other_ops
- statistics.iops_raw.read => read_ops
- statistics.iops_raw.total => total_ops
- statistics.iops_raw.write => write_ops
- statistics.latency_raw.other => other_latency
- statistics.latency_raw.read => read_latency
- statistics.latency_raw.total => total_latency
- statistics.latency_raw.write => write_latency
- statistics.throughput_raw.other => other_data
- statistics.throughput_raw.read => read_data
- statistics.throughput_raw.write => write_data
- statistics.timestamp(timestamp) => timestamp
- hidden_fields:
- statistics


export_options:
instance_keys:
- svm
27 changes: 27 additions & 0 deletions conf/keyperf/9.15.0/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Cluster
query: api/cluster
object: cluster

counters:
- ^^uuid => uuid
- ^statistics.status => status
- statistics.iops_raw.other => other_ops
- statistics.iops_raw.read => read_ops
- statistics.iops_raw.total => total_ops
- statistics.iops_raw.write => write_ops
- statistics.latency_raw.other => other_latency
- statistics.latency_raw.read => read_latency
- statistics.latency_raw.total => total_latency
- statistics.latency_raw.write => write_latency
- statistics.throughput_raw.other => other_data
- statistics.throughput_raw.read => read_data
- statistics.throughput_raw.total => total_data
- statistics.throughput_raw.write => write_data
- statistics.timestamp(timestamp) => timestamp
- hidden_fields:
- statistics


export_options:
instance_keys:
- uuid
27 changes: 27 additions & 0 deletions conf/keyperf/9.15.0/iscsi_svm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ISCSISvm
query: api/protocols/san/iscsi/services
object: iscsi_svm

counters:
- ^^svm.name => svm
- ^statistics.status => status
- ^target.name => target
- statistics.iops_raw.other => other_ops
- statistics.iops_raw.read => read_ops
- statistics.iops_raw.total => total_ops
- statistics.iops_raw.write => write_ops
- statistics.latency_raw.other => other_latency
- statistics.latency_raw.read => read_latency
- statistics.latency_raw.total => total_latency
- statistics.latency_raw.write => write_latency
- statistics.throughput_raw.read => read_data
- statistics.throughput_raw.total => total_data
- statistics.throughput_raw.write => write_data
- statistics.timestamp(timestamp) => timestamp
- hidden_fields:
- statistics

export_options:
instance_keys:
- svm
- target
25 changes: 25 additions & 0 deletions conf/keyperf/9.15.0/lif.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: LIF
query: api/network/ip/interfaces
object: lif

counters:
- ^^uuid
- ^location.node.name => node
- ^location.port.name => port
- ^name => lif
- ^statistics.status => status
- ^svm.name => svm
- statistics.throughput_raw.read => sent_data
- statistics.throughput_raw.total => total_data
- statistics.throughput_raw.write => recv_data
- statistics.timestamp(timestamp) => timestamp
- hidden_fields:
- statistics


export_options:
instance_keys:
- lif
- node
- port
- svm
38 changes: 38 additions & 0 deletions conf/keyperf/9.15.0/lun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Lun
query: api/storage/luns
object: lun

counters:
- ^^uuid => uuid
- ^location.volume.name => volume
- ^name => path
- ^statistics.status => status
- ^svm.name => svm
- statistics.iops_raw.other => other_ops
- statistics.iops_raw.read => read_ops
- statistics.iops_raw.total => total_ops
- statistics.iops_raw.write => write_ops
- statistics.latency_raw.other => other_latency
- statistics.latency_raw.read => avg_read_latency
- statistics.latency_raw.total => total_latency
- statistics.latency_raw.write => avg_write_latency
- statistics.throughput_raw.other => other_data
- statistics.throughput_raw.read => read_data
- statistics.throughput_raw.total => total_data
- statistics.throughput_raw.write => write_data
- statistics.timestamp(timestamp) => timestamp
- hidden_fields:
- statistics


plugins:
LabelAgent:
split_regex:
- path `^/[^/]+/([^/]+)(?:/.*?|)/([^/]+)$` volume,lun
- path `^([^/]+)$` lun

export_options:
instance_keys:
- lun
- svm
- volume
36 changes: 36 additions & 0 deletions conf/keyperf/9.15.0/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Namespace
query: api/storage/namespaces
object: namespace

counters:
- ^^uuid => uuid
- ^name => path
- ^statistics.status => status
- ^svm.name => svm
- statistics.iops_raw.other => other_ops
- statistics.iops_raw.read => read_ops
- statistics.iops_raw.total => total_ops
- statistics.iops_raw.write => write_ops
- statistics.latency_raw.other => avg_other_latency
- statistics.latency_raw.read => avg_read_latency
- statistics.latency_raw.total => avg_total_latency
- statistics.latency_raw.write => avg_write_latency
- statistics.throughput_raw.other => other_data
- statistics.throughput_raw.read => read_data
- statistics.throughput_raw.total => total_data
- statistics.throughput_raw.write => write_data
- statistics.timestamp(timestamp) => timestamp
- hidden_fields:
- statistics

plugins:
LabelAgent:
split:
- path `/` ,,volume,namespace

export_options:
instance_keys:
- namespace
- path
- svm
- volume
Loading

0 comments on commit 9d28189

Please sign in to comment.