From c65ca9570b09653865d08c8561b4692b08756803 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Fri, 25 Oct 2024 12:53:41 +0200 Subject: [PATCH] refactor(ingest): prefix metrics with openmeter Signed-off-by: Mark Sagi-Kazar --- openmeter/ingest/ingestadapter/metrics.go | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/openmeter/ingest/ingestadapter/metrics.go b/openmeter/ingest/ingestadapter/metrics.go index 650a73317..dda767f6b 100644 --- a/openmeter/ingest/ingestadapter/metrics.go +++ b/openmeter/ingest/ingestadapter/metrics.go @@ -17,12 +17,16 @@ type collectorMetrics struct { ingestEventsCounter metric.Int64Counter ingestErrorsCounter metric.Int64Counter + + // TODO: remove after deprecation period + ingestEventsCounterOld metric.Int64Counter + ingestErrorsCounterOld metric.Int64Counter } // WithMetrics wraps an [ingest.Collector] and emits metrics for ingested events. func WithMetrics(collector ingest.Collector, metricMeter metric.Meter) (ingest.Collector, error) { ingestEventsCounter, err := metricMeter.Int64Counter( - "ingest.events", + "openmeter.ingest.events", metric.WithDescription("Number of events ingested"), metric.WithUnit("{event}"), ) @@ -31,6 +35,24 @@ func WithMetrics(collector ingest.Collector, metricMeter metric.Meter) (ingest.C } ingestErrorsCounter, err := metricMeter.Int64Counter( + "openmeter.ingest.errors", + metric.WithDescription("Number of failed event ingests"), + metric.WithUnit("{error}"), + ) + if err != nil { + return nil, fmt.Errorf("failed to create errors counter: %w", err) + } + + ingestEventsCounterOld, err := metricMeter.Int64Counter( + "ingest.events", + metric.WithDescription("Number of events ingested"), + metric.WithUnit("{event}"), + ) + if err != nil { + return nil, fmt.Errorf("failed to create events counter: %w", err) + } + + ingestErrorsCounterOld, err := metricMeter.Int64Counter( "ingest.errors", metric.WithDescription("Number of failed event ingests"), metric.WithUnit("{error}"), @@ -44,6 +66,9 @@ func WithMetrics(collector ingest.Collector, metricMeter metric.Meter) (ingest.C ingestEventsCounter: ingestEventsCounter, ingestErrorsCounter: ingestErrorsCounter, + + ingestEventsCounterOld: ingestEventsCounterOld, + ingestErrorsCounterOld: ingestErrorsCounterOld, }, nil } @@ -54,11 +79,13 @@ func (c collectorMetrics) Ingest(ctx context.Context, namespace string, ev event err := c.collector.Ingest(ctx, namespace, ev) if err != nil { c.ingestErrorsCounter.Add(ctx, 1, metric.WithAttributes(namespaceAttr)) + c.ingestErrorsCounterOld.Add(ctx, 1, metric.WithAttributes(namespaceAttr)) return err } c.ingestEventsCounter.Add(ctx, 1, metric.WithAttributes(namespaceAttr)) + c.ingestEventsCounterOld.Add(ctx, 1, metric.WithAttributes(namespaceAttr)) return nil }