Skip to content

Commit

Permalink
feat: add otel collector and prom on benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 23, 2024
1 parent b740083 commit 2cf0838
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 124 deletions.
53 changes: 53 additions & 0 deletions pkg/testserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package testserver
import (
"context"
"fmt"
"github.com/formancehq/go-libs/otlp"
"github.com/formancehq/go-libs/otlp/otlpmetrics"
"github.com/formancehq/go-libs/publish"
"github.com/google/uuid"
"github.com/nats-io/nats.go"
Expand All @@ -29,11 +31,16 @@ type T interface {
Logf(format string, args ...any)
}

type OTLPConfig struct {
Metrics *otlpmetrics.ModuleConfig
}

type Configuration struct {
PostgresConfiguration bunconnect.ConnectionOptions
NatsURL string
Output io.Writer
Debug bool
OTLPConfig *OTLPConfig
}

type Server struct {
Expand Down Expand Up @@ -87,6 +94,52 @@ func (s *Server) Start() {
"--"+publish.PublisherTopicMappingFlag, fmt.Sprintf("*:%s", s.id),
)
}
if s.configuration.OTLPConfig != nil {
if s.configuration.OTLPConfig.Metrics != nil {
args = append(
args,
"--"+otlpmetrics.OtelMetricsFlag,
"--"+otlpmetrics.OtelMetricsExporterFlag, s.configuration.OTLPConfig.Metrics.Exporter,
)
if s.configuration.OTLPConfig.Metrics.OTLPConfig != nil {
args = append(
args,
"--"+otlpmetrics.OtelMetricsExporterOTLPEndpointFlag, s.configuration.OTLPConfig.Metrics.OTLPConfig.Endpoint,
"--"+otlpmetrics.OtelMetricsExporterOTLPModeFlag, s.configuration.OTLPConfig.Metrics.OTLPConfig.Mode,
)
if s.configuration.OTLPConfig.Metrics.OTLPConfig.Insecure {
args = append(args, "--"+otlpmetrics.OtelMetricsExporterOTLPInsecureFlag)
}
}
if s.configuration.OTLPConfig.Metrics.RuntimeMetrics {
args = append(args, "--"+otlpmetrics.OtelMetricsRuntimeFlag)
}
if s.configuration.OTLPConfig.Metrics.MinimumReadMemStatsInterval != 0 {
args = append(
args,
"--"+otlpmetrics.OtelMetricsRuntimeMinimumReadMemStatsIntervalFlag,
s.configuration.OTLPConfig.Metrics.MinimumReadMemStatsInterval.String(),
)
}
if s.configuration.OTLPConfig.Metrics.PushInterval != 0 {
args = append(
args,
"--"+otlpmetrics.OtelMetricsExporterPushIntervalFlag,
s.configuration.OTLPConfig.Metrics.PushInterval.String(),
)
}
if len(s.configuration.OTLPConfig.Metrics.ResourceAttributes) > 0 {
args = append(
args,
"--"+otlp.OtelResourceAttributesFlag,
strings.Join(s.configuration.OTLPConfig.Metrics.ResourceAttributes, ","),
)
}
if s.configuration.OTLPConfig.Metrics.ServiceName != "" {
args = append(args, "--"+otlp.OtelServiceNameFlag, s.configuration.OTLPConfig.Metrics.ServiceName)
}
}
}

if s.configuration.Debug {
args = append(args, "--"+service.DebugFlag)
Expand Down
103 changes: 0 additions & 103 deletions test/performance/env_core_test.go

This file was deleted.

20 changes: 17 additions & 3 deletions test/performance/env_testserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package performance_test

import (
"context"
"github.com/formancehq/go-libs/otlp/otlpmetrics"
"github.com/formancehq/go-libs/testing/platform/otelcollector"
"io"
"os"
"testing"
Expand Down Expand Up @@ -56,7 +58,8 @@ func (e *TestServerEnv) Executor() TransactionExecutor {
var _ Env = (*TestServerEnv)(nil)

type TestServerEnvFactory struct {
pgServer *pgtesting.PostgresServer
pgServer *pgtesting.PostgresServer
otelCollector *otelcollector.Server
}

func (f *TestServerEnvFactory) Create(ctx context.Context, b *testing.B, ledger ledger.Ledger) Env {
Expand All @@ -77,6 +80,16 @@ func (f *TestServerEnvFactory) Create(ctx context.Context, b *testing.B, ledger
PostgresConfiguration: connectionOptions,
Debug: testing.Verbose(),
Output: output,
OTLPConfig: &testserver.OTLPConfig{
Metrics: &otlpmetrics.ModuleConfig{
Exporter: "otlp",
OTLPConfig: &otlpmetrics.OTLPConfig{
Mode: "grpc",
Endpoint: "127.0.0.1:" + f.otelCollector.GRPCPort,
Insecure: true,
},
},
},
})

_, err := testServer.Client().Ledger.V2.
Expand All @@ -98,8 +111,9 @@ func (f *TestServerEnvFactory) Create(ctx context.Context, b *testing.B, ledger

var _ EnvFactory = (*TestServerEnvFactory)(nil)

func NewTestServerEnvFactory(pgServer *pgtesting.PostgresServer) *TestServerEnvFactory {
func NewTestServerEnvFactory(pgServer *pgtesting.PostgresServer, otelCollector *otelcollector.Server) *TestServerEnvFactory {
return &TestServerEnvFactory{
pgServer: pgServer,
pgServer: pgServer,
otelCollector: otelCollector,
}
}
Loading

0 comments on commit 2cf0838

Please sign in to comment.