Skip to content

Commit

Permalink
Added _total suffix to OTEL counter metrics. (#5810)
Browse files Browse the repository at this point in the history
**Which problem is this PR solving?**

This PR addresses a part of the issue [#5633
](#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]>
  • Loading branch information
Wise-Wizard authored Aug 8, 2024
1 parent 052c89c commit eaacbf0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
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"
}
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

0 comments on commit eaacbf0

Please sign in to comment.