Skip to content

Commit

Permalink
OTEL / Prom metrics benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro committed Jun 24, 2024
1 parent f29cad5 commit 723d74a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 106 deletions.
70 changes: 46 additions & 24 deletions internal/metrics/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,66 @@
package benchmark_test

import (
"log"
"context"
"testing"

prometheus "github.com/prometheus/client_golang/prometheus"
"go.opentelemetry.io/otel/sdk/metric"
promsdk "github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"

"github.com/jaegertracing/jaeger/internal/metrics/otelmetrics"
prom "github.com/jaegertracing/jaeger/internal/metrics/prometheus"
"github.com/jaegertracing/jaeger/pkg/metrics"
promExporter "go.opentelemetry.io/otel/exporters/prometheus"
)

func benchmarkCounter(b *testing.B, factory metrics.Factory) {
counter := factory.Counter(metrics.Options{
func BenchmarkPrometheusCounter(b *testing.B) {
reg := promsdk.NewRegistry()
opts := promsdk.CounterOpts{
Name: "test_counter",
Tags: map[string]string{"tag1": "value1"},
})
Help: "help",
}
cv := promsdk.NewCounterVec(opts, []string{"tag1"})
reg.MustRegister(cv)
counter := cv.WithLabelValues("value1")

b.ResetTimer()
for i := 0; i < b.N; i++ {
counter.Inc(1)
counter.Add(1)
}
}

func BenchmarkPrometheusCounter(b *testing.B) {
reg := prometheus.NewRegistry()
factory := prom.New(prom.WithRegisterer(reg))
benchmarkCounter(b, factory)
func BenchmarkOTELCounter(b *testing.B) {
counter := otelCounter(b)
ctx := context.Background()

b.ResetTimer()
for i := 0; i < b.N; i++ {
counter.Add(ctx, 1)
}
}

func BenchmarkOTELCounter(b *testing.B) {
registry := prometheus.NewRegistry()
exporter, err := promExporter.New(promExporter.WithRegisterer(registry))
if err != nil {
log.Fatalf("Failed to create Prometheus exporter: %v", err)
func BenchmarkOTELCounterWithLabel(b *testing.B) {
counter := otelCounter(b)
ctx := context.Background()
attrSet := attribute.NewSet(attribute.String("tag1", "value1"))
attrOpt := metric.WithAttributeSet(attrSet)

b.ResetTimer()
for i := 0; i < b.N; i++ {
counter.Add(ctx, 1, attrOpt)
}
meterProvider := metric.NewMeterProvider(
metric.WithReader(exporter),
}

func otelCounter(b *testing.B) metric.Int64Counter {
registry := promsdk.NewRegistry()
exporter, err := promExporter.New(promExporter.WithRegisterer(registry))
require.NoError(b, err)
meterProvider := sdkmetric.NewMeterProvider(
sdkmetric.WithReader(exporter),
)
factory := otelmetrics.NewFactory(meterProvider)
benchmarkCounter(b, factory)

meter := meterProvider.Meter("test")
counter, err := meter.Int64Counter("test_counter")
require.NoError(b, err)
return counter
}
20 changes: 0 additions & 20 deletions internal/metrics/otelmetrics/counter.go

This file was deleted.

62 changes: 0 additions & 62 deletions internal/metrics/otelmetrics/factory.go

This file was deleted.

0 comments on commit 723d74a

Please sign in to comment.