Skip to content

Commit 4a67697

Browse files
Wise-WizardJaredTan95
authored andcommitted
Added _total suffix to OTEL counter metrics. (jaegertracing#5810)
**Which problem is this PR solving?** This PR addresses a part of the issue [jaegertracing#5633 ](jaegertracing#5633) **Description of the changes** This is a PR to achieve Observability Parity in metrics between V1 and V2 components by configuring OTEL Collector to emit desired metrics. **How was this change tested?** The changes were tested by running the following command: ```bash make test ``` ```bash CI actions and compare.py script ``` **Checklist** - [x] I have read [CONTRIBUTING_GUIDELINES.md](https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md) - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - `for jaeger: make lint test` - `for jaeger-ui: yarn lint` and `yarn test` --------- Signed-off-by: Wise-Wizard <[email protected]> Signed-off-by: Jared Tan <[email protected]>
1 parent cf224b9 commit 4a67697

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

internal/metrics/otelmetrics/factory.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewFactory(meterProvider metric.MeterProvider) metrics.Factory {
3232
}
3333

3434
func (f *otelFactory) Counter(opts metrics.Options) metrics.Counter {
35-
name := f.subScope(opts.Name)
35+
name := CounterNamingConvention(f.subScope(opts.Name))
3636
counter, err := f.meter.Int64Counter(name)
3737
if err != nil {
3838
log.Printf("Error creating OTEL counter: %v", err)
@@ -131,3 +131,10 @@ func attributeSetOption(tags map[string]string) metric.MeasurementOption {
131131
}
132132
return metric.WithAttributes(attributes...)
133133
}
134+
135+
func CounterNamingConvention(name string) string {
136+
if !strings.HasSuffix(name, "_total") {
137+
name += "_total"
138+
}
139+
return name
140+
}

internal/metrics/otelmetrics/factory_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ func TestCounter(t *testing.T) {
104104
assert.Equal(t, expectedLabels, promLabelsToMap(metrics[0].GetLabel()))
105105
}
106106

107+
func TestCounterNamingConvention(t *testing.T) {
108+
input := "test_counter"
109+
expected := "test_counter_total"
110+
111+
result := otelmetrics.CounterNamingConvention(input)
112+
113+
if result != expected {
114+
t.Errorf("Expected %s, but got %s", expected, result)
115+
}
116+
}
117+
107118
func TestGauge(t *testing.T) {
108119
registry := promReg.NewPedanticRegistry()
109120
factory := newTestFactory(t, registry)

scripts/compare_metrics.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
# Run the following commands first to create the JSON files:
2-
# Run V1 Binary
3-
# prom2json http://localhost:14269/metrics > V1_Metrics.json
4-
# Run V2 Binary
5-
# prom2json http://localhost:8888/metrics > V2_Metrics.json
6-
71
import json
82

93
v1_metrics_path = "./V1_Metrics.json"
@@ -41,7 +35,7 @@ def extract_metrics_with_labels(metrics, strip_prefix=None):
4135
for name, labels in v1_metrics_with_labels.items():
4236
if name in v2_metrics_with_labels:
4337
common_metrics[name] = labels
44-
else:
38+
elif not name.startswith("jaeger_agent"):
4539
v1_only_metrics[name] = labels
4640

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

51+
# Write the differences to a new JSON file
5752
differences_path = "./differences.json"
5853
with open(differences_path, 'w') as file:
5954
json.dump(differences, file, indent=4)

0 commit comments

Comments
 (0)