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

accept metric list without including "metric_" prefix #155

Merged
merged 1 commit into from
Jan 17, 2025
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
10 changes: 7 additions & 3 deletions cmd/metrics/metric_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type MetricDefinition struct {
Evaluable *govaluate.EvaluableExpression // parse expression once, store here for use in metric evaluation
}

// define const metric name prefix
const metricPrefix = "metric_"

// LoadMetricDefinitions reads and parses metric definitions from an architecture-specific metric
// definition file. When the override path argument is empty, the function will load metrics from
// the file associated with the platform's architecture found in the provided metadata. When
Expand Down Expand Up @@ -62,7 +65,7 @@ func LoadMetricDefinitions(metricDefinitionOverridePath string, selectedMetrics
for _, metricName := range selectedMetrics {
found := false
for _, metric := range metricsInFile {
if metricName == metric.Name {
if metricPrefix+metricName == metric.Name || metricName == metric.Name {
found = true
break
}
Expand All @@ -74,7 +77,8 @@ func LoadMetricDefinitions(metricDefinitionOverridePath string, selectedMetrics
}
// build list of metrics based on provided list of metric names
for _, metric := range metricsInFile {
if !util.StringInList(metric.Name, selectedMetrics) {
trimmedName := strings.TrimPrefix(metric.Name, metricPrefix)
if !util.StringInList(trimmedName, selectedMetrics) {
continue
}
metrics = append(metrics, metric)
Expand Down Expand Up @@ -122,7 +126,7 @@ func ConfigureMetrics(loadedMetrics []MetricDefinition, uncollectableEvents []st
tmpMetric.Name = tmpMetric.NameTxn
}
// remove "metric_" prefix from metric names
tmpMetric.Name = strings.TrimPrefix(tmpMetric.Name, "metric_")
tmpMetric.Name = strings.TrimPrefix(tmpMetric.Name, metricPrefix)
// transform if/else to ?/:
var transformed string
if transformed, err = transformConditional(tmpMetric.Expression); err != nil {
Expand Down
Loading