Skip to content

Commit

Permalink
feat: refine metrics and docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 23, 2024
1 parent ecdaf7d commit 465d610
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 65 deletions.
7 changes: 2 additions & 5 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ func NewServeCommand() *cobra.Command {
return err
}

otelMetricsExporter, _ := cmd.Flags().GetString(otlpmetrics.OtelMetricsExporterFlag)

options := []fx.Option{
fx.NopLogger,
otlp.FXModuleFromFlags(cmd),
Expand Down Expand Up @@ -87,7 +85,6 @@ func NewServeCommand() *cobra.Command {
},
) chi.Router {
return assembleFinalRouter(
otelMetricsExporter == "memory",
service.IsDebug(cmd),
params.MeterProvider,
params.Exporter,
Expand Down Expand Up @@ -139,15 +136,15 @@ func discoverServeConfiguration(cmd *cobra.Command) serveConfiguration {
}

func assembleFinalRouter(
exportMetrics, exportPProf bool,
exportPProf bool,
meterProvider *metric.MeterProvider,
exporter *otlpmetrics.InMemoryExporter,
healthController *health.HealthController,
handler http.Handler,
) *chi.Mux {
wrappedRouter := chi.NewRouter()
wrappedRouter.Route("/_/", func(r chi.Router) {
if exportMetrics {
if exporter != nil {
r.Handle("/metrics", otlpmetrics.NewInMemoryExporterHandler(
meterProvider,
exporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
File renamed without changes.
25 changes: 22 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '3.8'

services:

postgres:
image: "postgres:16-alpine"
healthcheck:
Expand All @@ -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:
Expand All @@ -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"
44 changes: 0 additions & 44 deletions examples/otlp-exporter/docker-compose.yml

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 7 additions & 1 deletion pkg/testserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type T interface {

type OTLPConfig struct {
BaseConfig otlp.Config
Metrics *otlpmetrics.ModuleConfig
Metrics *otlpmetrics.ModuleConfig
}

type Configuration struct {
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions test/performance/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/performance/env_testserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down

0 comments on commit 465d610

Please sign in to comment.