diff --git a/cmd/serve.go b/cmd/serve.go index 29ca6bb4c..c4a8eb96e 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -49,8 +49,6 @@ func NewServeCommand() *cobra.Command { return err } - otelMetricsExporter, _ := cmd.Flags().GetString(otlpmetrics.OtelMetricsExporterFlag) - options := []fx.Option{ fx.NopLogger, otlp.FXModuleFromFlags(cmd), @@ -87,7 +85,6 @@ func NewServeCommand() *cobra.Command { }, ) chi.Router { return assembleFinalRouter( - otelMetricsExporter == "memory", service.IsDebug(cmd), params.MeterProvider, params.Exporter, @@ -139,7 +136,7 @@ func discoverServeConfiguration(cmd *cobra.Command) serveConfiguration { } func assembleFinalRouter( - exportMetrics, exportPProf bool, + exportPProf bool, meterProvider *metric.MeterProvider, exporter *otlpmetrics.InMemoryExporter, healthController *health.HealthController, @@ -147,7 +144,7 @@ func assembleFinalRouter( ) *chi.Mux { wrappedRouter := chi.NewRouter() wrappedRouter.Route("/_/", func(r chi.Router) { - if exportMetrics { + if exporter != nil { r.Handle("/metrics", otlpmetrics.NewInMemoryExporterHandler( meterProvider, exporter, diff --git a/examples/otlp-exporter/otel-collector-config.yaml b/deployments/otel-collector-config.yaml similarity index 85% rename from examples/otlp-exporter/otel-collector-config.yaml rename to deployments/otel-collector-config.yaml index 052d0b27a..09760168e 100644 --- a/examples/otlp-exporter/otel-collector-config.yaml +++ b/deployments/otel-collector-config.yaml @@ -18,7 +18,11 @@ exporters: # metric_expiration: 180m resource_to_telemetry_conversion: enabled: true - logging: +# logging: + otlp/2: + endpoint: jaeger:4317 + tls: + insecure: true processors: batch: @@ -41,16 +45,14 @@ connectors: - name: http.method service: - telemetry: - logs: - level: "debug" +# telemetry: +# logs: +# level: "debug" extensions: [pprof, zpages, health_check] pipelines: traces: receivers: [otlp] -# processors: [batch] - exporters: [spanmetrics] + exporters: [spanmetrics, otlp/2] metrics: receivers: [otlp, spanmetrics] -# processors: [batch] exporters: [prometheus] diff --git a/examples/otlp-exporter/prometheus.yaml b/deployments/prometheus.yaml similarity index 100% rename from examples/otlp-exporter/prometheus.yaml rename to deployments/prometheus.yaml diff --git a/docker-compose.yml b/docker-compose.yml index a9b6545e6..0dc85c461 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ version: '3.8' services: + postgres: image: "postgres:16-alpine" healthcheck: @@ -16,6 +17,20 @@ services: POSTGRES_PASSWORD: "ledger" POSTGRES_DB: "ledger" + prometheus: + image: prom/prometheus:latest + restart: always + volumes: + - ./deployments/prometheus.yaml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" + + otel: + image: "otel/opentelemetry-collector-contrib:0.81.0" + command: [ "--config=/etc/otel-collector-config.yaml" ] + volumes: + - ./deployments/otel-collector-config.yaml:/etc/otel-collector-config.yaml + jaeger: image: jaegertracing/opentelemetry-all-in-one ports: @@ -36,10 +51,14 @@ services: condition: service_started environment: GOWORK: off - DEBUG: "true" + DEBUG: "${DEBUG:-false}" OTEL_SERVICE_NAME: ledger - OTEL_METRICS_EXPORTER: "memory" + OTEL_METRICS_EXPORTER: "otlp" + OTEL_METRICS_EXPORTER_OTLP_ENDPOINT: otel:4317 + OTEL_METRICS_EXPORTER_OTLP_INSECURE: "true" + OTEL_METRICS_KEEP_IN_MEMORY: "true" OTEL_TRACES_EXPORTER: otlp - OTEL_TRACES_EXPORTER_OTLP_ENDPOINT: jaeger:4317 + OTEL_TRACES_EXPORTER_OTLP_ENDPOINT: otel:4317 OTEL_TRACES_EXPORTER_OTLP_INSECURE: "true" + OTEL_TRACES_BATCH: "true" POSTGRES_URI: "postgresql://ledger:ledger@postgres/ledger?sslmode=disable" diff --git a/examples/otlp-exporter/docker-compose.yml b/examples/otlp-exporter/docker-compose.yml deleted file mode 100644 index 753a295ee..000000000 --- a/examples/otlp-exporter/docker-compose.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -volumes: - postgres: -services: - postgres: - extends: - file: ../../docker-compose.yml - service: postgres - prometheus: - image: prom/prometheus:latest - restart: always - volumes: - - ./prometheus.yaml:/etc/prometheus/prometheus.yml - ports: - - "9090:9090" - otel: - image: "otel/opentelemetry-collector-contrib:0.81.0" - command: [ "--config=/etc/otel-collector-config.yaml" ] - volumes: - - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml - ledger: - extends: - file: ../../docker-compose.yml - service: ledger - depends_on: - - postgres - - otel - image: golang:1.19-alpine - entrypoint: go run main.go serve - volumes: - - ../..:/src - working_dir: /src - environment: - CGO_ENABLED: 0 - DEBUG: "true" - OTEL_TRACES_EXPORTER: otlp - OTEL_TRACES_EXPORTER_OTLP_ENDPOINT: otel:4317 - OTEL_TRACES_EXPORTER_OTLP_INSECURE: "true" - OTEL_METRICS_EXPORTER: otlp - OTEL_METRICS_EXPORTER_OTLP_ENDPOINT: otel:4317 - OTEL_METRICS_EXPORTER_OTLP_INSECURE: "true" - OTEL_SERVICE_NAME: ledger - OTEL_RESOURCE_ATTRIBUTES: version=develop - OTEL_METRICS_RUNTIME: "true" diff --git a/go.mod b/go.mod index b778bfbe6..f1a86f06d 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/alitto/pond v1.9.2 github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 github.com/bluele/gcache v0.0.2 - github.com/formancehq/go-libs v1.7.2-0.20241012213333-313b8d5bcb17 + github.com/formancehq/go-libs v1.7.2-0.20241014102030-f397c44a5d47 github.com/formancehq/stack/ledger/client v0.0.0-00010101000000-000000000000 github.com/go-chi/chi/v5 v5.1.0 github.com/go-chi/cors v1.2.1 diff --git a/go.sum b/go.sum index efcc1749f..927760530 100644 --- a/go.sum +++ b/go.sum @@ -117,6 +117,10 @@ github.com/formancehq/go-libs v1.7.2-0.20241012201526-5cfbdd7cbd3a h1:hmw8sXFvgd github.com/formancehq/go-libs v1.7.2-0.20241012201526-5cfbdd7cbd3a/go.mod h1:B/KB2mPjFqybLDZufMcZQKpXcHg8Va6JaoUWda1KGU4= github.com/formancehq/go-libs v1.7.2-0.20241012213333-313b8d5bcb17 h1:XqPFlmZJQ8ImRpVnc+jqslo0IANuUqnu0+EuoRQ341o= github.com/formancehq/go-libs v1.7.2-0.20241012213333-313b8d5bcb17/go.mod h1:bvfMYwpyRQF6fBkBWty1HiCsKSyYe4RkaEYJEip9Lrw= +github.com/formancehq/go-libs v1.7.2-0.20241014095913-315cdf91b020 h1:i8HwBih7/huczgl58ikbt/XNtQV+UrgSp9ntzdOOjGg= +github.com/formancehq/go-libs v1.7.2-0.20241014095913-315cdf91b020/go.mod h1:bvfMYwpyRQF6fBkBWty1HiCsKSyYe4RkaEYJEip9Lrw= +github.com/formancehq/go-libs v1.7.2-0.20241014102030-f397c44a5d47 h1:FxRRkcLvDj8mrnNQmItxZyrpctJ5KchwTnT9Q1uITrI= +github.com/formancehq/go-libs v1.7.2-0.20241014102030-f397c44a5d47/go.mod h1:bvfMYwpyRQF6fBkBWty1HiCsKSyYe4RkaEYJEip9Lrw= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= diff --git a/pkg/testserver/server.go b/pkg/testserver/server.go index e2f28375d..542553a64 100644 --- a/pkg/testserver/server.go +++ b/pkg/testserver/server.go @@ -33,7 +33,7 @@ type T interface { type OTLPConfig struct { BaseConfig otlp.Config - Metrics *otlpmetrics.ModuleConfig + Metrics *otlpmetrics.ModuleConfig } type Configuration struct { @@ -101,6 +101,12 @@ func (s *Server) Start() { args, "--"+otlpmetrics.OtelMetricsExporterFlag, s.configuration.OTLPConfig.Metrics.Exporter, ) + if s.configuration.OTLPConfig.Metrics.KeepInMemory { + args = append( + args, + "--"+otlpmetrics.OtelMetricsKeepInMemoryFlag, + ) + } if s.configuration.OTLPConfig.Metrics.OTLPConfig != nil { args = append( args, diff --git a/test/performance/benchmark_test.go b/test/performance/benchmark_test.go index e4cf3c961..00c42fb84 100644 --- a/test/performance/benchmark_test.go +++ b/test/performance/benchmark_test.go @@ -89,9 +89,11 @@ func (benchmark *Benchmark) Run(ctx context.Context) map[string][]Result { // Fetch otel metrics rsp, err := http.Get(env.URL() + "/_/metrics") require.NoError(b, err) - ret := make(map[string]any) - require.NoError(b, json.NewDecoder(rsp.Body).Decode(&ret)) - report.InternalMetrics = ret + if rsp.StatusCode == http.StatusOK { + ret := make(map[string]any) + require.NoError(b, json.NewDecoder(rsp.Body).Decode(&ret)) + report.InternalMetrics = ret + } // Compute final results result = report.GetResult() diff --git a/test/performance/env_testserver_test.go b/test/performance/env_testserver_test.go index ed6d828e9..94800d86b 100644 --- a/test/performance/env_testserver_test.go +++ b/test/performance/env_testserver_test.go @@ -64,7 +64,7 @@ func (f *TestServerEnvFactory) Create(ctx context.Context, b *testing.B, ledger Output: output, OTLPConfig: &testserver.OTLPConfig{ Metrics: &otlpmetrics.ModuleConfig{ - Exporter: "memory", + KeepInMemory: true, RuntimeMetrics: true, }, },