Skip to content

Commit

Permalink
SWATCH-3295: Wrong format for metric_id in ingested usage total counter
Browse files Browse the repository at this point in the history
The counter "swatch_metrics_ingested_usage_total" is being displaying the metric as:
```
swatch_metrics_ingested_usage_total{billing_provider="aws",metric_id="Instance-hours",product="rosa"} 609.8702973568641
```

And it should be using the upper format:

```
swatch_metrics_ingested_usage_total{billing_provider="aws",metric_id="INSTANCE_HOURS",product="rosa"} 609.8702973568641
```

This is to work as the other metrics/counters.
  • Loading branch information
Sgitario committed Feb 5, 2025
1 parent aebd64b commit 4ca3d92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.candlepin.subscriptions.event;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.swatch.configuration.registry.MetricId;
import com.redhat.swatch.configuration.registry.SubscriptionDefinition;
import com.redhat.swatch.configuration.registry.Variant;
import com.redhat.swatch.configuration.util.ProductTagLookupParams;
Expand Down Expand Up @@ -396,10 +397,19 @@ private void updateIngestedUsageCounterFor(Event event, String tag, Measurement
if (event.getBillingProvider() != null) {
counter.tag("billing_provider", event.getBillingProvider().value());
}
counter
.withRegistry(meterRegistry)
.withTags("product", tag, "metric_id", measurement.getMetricId())
.increment(measurement.getValue());
try {
counter
.tag("metric_id", MetricId.fromString(measurement.getMetricId()).toUpperCaseFormatted())
.withRegistry(meterRegistry)
.withTags("product", tag)
.increment(measurement.getValue());
} catch (Exception e) {
log.error(
"Error to increment counter '{}'. Event was '{}' and measurement '{}'",
INGESTED_USAGE_METRIC,
event,
measurement);
}
}

private static class ServiceInstancesResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.swatch.configuration.registry.MetricId;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import jakarta.persistence.EntityManager;
Expand Down Expand Up @@ -622,7 +623,9 @@ private Optional<Meter> getIngestedUsageMetric(
m ->
INGESTED_USAGE_METRIC.equals(m.getId().getName())
&& productTag.equals(m.getId().getTag("product"))
&& metricId.equals(m.getId().getTag("metric_id"))
&& MetricId.fromString(metricId)
.toUpperCaseFormatted()
.equals(m.getId().getTag("metric_id"))
&& billingProvider.equals(m.getId().getTag("billing_provider")))
.findFirst();
}
Expand Down

0 comments on commit 4ca3d92

Please sign in to comment.