Skip to content

Commit

Permalink
Merge pull request #1751 from openmeterio/metric-rename-ingest
Browse files Browse the repository at this point in the history
refactor(ingest): prefix metrics with openmeter
  • Loading branch information
sagikazarmark authored Oct 25, 2024
2 parents a971486 + c65ca95 commit fca4118
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion openmeter/ingest/ingestadapter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
)
Expand All @@ -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}"),
Expand All @@ -44,6 +66,9 @@ func WithMetrics(collector ingest.Collector, metricMeter metric.Meter) (ingest.C

ingestEventsCounter: ingestEventsCounter,
ingestErrorsCounter: ingestErrorsCounter,

ingestEventsCounterOld: ingestEventsCounterOld,
ingestErrorsCounterOld: ingestErrorsCounterOld,
}, nil
}

Expand All @@ -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
}
Expand Down

0 comments on commit fca4118

Please sign in to comment.