-
Bug
-
Resolution: Done
-
Critical
-
None
-
None
I've spotted an issue where sometimes when a service is running for long, the metrics are not properly created.
The problem seems to be due to how we are building the metrics, for example:
private void incrementMeteredTotal(BillableUsageAggregate usage) { BillableUsageAggregateKey aggregateKey = usage.getAggregateKey(); var swatchProducerMeteredTotal = Counter.builder(METERED_TOTAL_METRIC); if (Objects.nonNull(aggregateKey.getBillingProvider())) { swatchProducerMeteredTotal.tag("billing_provider", aggregateKey.getBillingProvider()); } if (Objects.nonNull(usage.getStatus())) { swatchProducerMeteredTotal.tag("status", usage.getStatus().toString()); } if (Objects.nonNull(usage.getErrorCode())) { swatchProducerMeteredTotal.tag("error_code", usage.getErrorCode().toString()); } swatchProducerMeteredTotal .withRegistry(meterRegistry) .withTags( "product", aggregateKey.getProductId(), "metric_id", MetricId.fromString(aggregateKey.getMetricId()).getValue()) .increment( usage.getTotalValue().doubleValue() / getBillingFactor( usage.getAggregateKey().getProductId(), usage.getAggregateKey().getMetricId())); }
This is because the `metric.withRegistry(registry).increment(yy)` causes Micrometer to try to dinamically create a new object every time we invoke this process instead of reusing existing ones.
According to the micrometer official guide, the recommended way is to use `registry.counter(name, tags).increment(yy)`: https://docs.micrometer.io/micrometer/reference/concepts/naming.html
Acceptance Criteria
- Replace the counter.builder by the registry.counter to avoid missing increment in metrics