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

Added _total suffix to OTEL counter metrics. #5810

Merged
merged 15 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion internal/metrics/otelmetrics/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewFactory(meterProvider metric.MeterProvider) metrics.Factory {
}

func (f *otelFactory) Counter(opts metrics.Options) metrics.Counter {
name := f.subScope(opts.Name)
name := CounterNamingConvention(f.subScope(opts.Name))
counter, err := f.meter.Int64Counter(name)
if err != nil {
log.Printf("Error creating OTEL counter: %v", err)
Expand Down Expand Up @@ -131,3 +131,10 @@ func attributeSetOption(tags map[string]string) metric.MeasurementOption {
}
return metric.WithAttributes(attributes...)
}

func CounterNamingConvention(name string) string {
if !strings.HasSuffix(name, "_total") {
name += "_total"
Wise-Wizard marked this conversation as resolved.
Show resolved Hide resolved
}
return name
}
11 changes: 11 additions & 0 deletions internal/metrics/otelmetrics/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ func TestCounter(t *testing.T) {
assert.Equal(t, expectedLabels, promLabelsToMap(metrics[0].GetLabel()))
}

func TestCounterNamingConvention(t *testing.T) {
input := "test_counter"
expected := "test_counter_total"

result := otelmetrics.CounterNamingConvention(input)

if result != expected {
t.Errorf("Expected %s, but got %s", expected, result)
}
}

func TestGauge(t *testing.T) {
registry := promReg.NewPedanticRegistry()
factory := newTestFactory(t, registry)
Expand Down
9 changes: 2 additions & 7 deletions scripts/compare_metrics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Run the following commands first to create the JSON files:
# Run V1 Binary
# prom2json http://localhost:14269/metrics > V1_Metrics.json
# Run V2 Binary
# prom2json http://localhost:8888/metrics > V2_Metrics.json

import json

v1_metrics_path = "./V1_Metrics.json"
Expand Down Expand Up @@ -41,7 +35,7 @@ def extract_metrics_with_labels(metrics, strip_prefix=None):
for name, labels in v1_metrics_with_labels.items():
if name in v2_metrics_with_labels:
common_metrics[name] = labels
else:
elif not name.startswith("jaeger_agent"):
v1_only_metrics[name] = labels

for name, labels in v2_metrics_with_labels.items():
Expand All @@ -54,6 +48,7 @@ def extract_metrics_with_labels(metrics, strip_prefix=None):
"v2_only_metrics": v2_only_metrics
}

# Write the differences to a new JSON file
differences_path = "./differences.json"
with open(differences_path, 'w') as file:
json.dump(differences, file, indent=4)
Expand Down
Loading