Skip to content

Commit

Permalink
Merge pull request #1643 from openmeterio/wire-config
Browse files Browse the repository at this point in the history
refactor: move config to a different wire set
  • Loading branch information
sagikazarmark authored Oct 9, 2024
2 parents a32a84a + 3bf8af5 commit 2ae5789
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cmd/balance-worker/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Application struct {

func initializeApplication(ctx context.Context, conf config.Configuration, logger *slog.Logger) (Application, func(), error) {
wire.Build(
app.Config,
NewOtelResource,
app.Telemetry,
NewMeter,
Expand All @@ -52,7 +53,7 @@ func initializeApplication(ctx context.Context, conf config.Configuration, logge

// TODO: is this necessary? Do we need a logger first?
func initializeLogger(conf config.Configuration) *slog.Logger {
wire.Build(NewOtelResource, app.Logger)
wire.Build(app.Config, NewOtelResource, app.Logger)

return new(slog.Logger)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/notification-service/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Application struct {

func initializeApplication(ctx context.Context, conf config.Configuration, logger *slog.Logger) (Application, func(), error) {
wire.Build(
app.Config,
NewOtelResource,
app.Telemetry,
NewMeter,
Expand All @@ -52,7 +53,7 @@ func initializeApplication(ctx context.Context, conf config.Configuration, logge

// TODO: is this necessary? Do we need a logger first?
func initializeLogger(conf config.Configuration) *slog.Logger {
wire.Build(NewOtelResource, app.Logger)
wire.Build(app.Config, NewOtelResource, app.Logger)

return new(slog.Logger)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Application struct {

func initializeApplication(ctx context.Context, conf config.Configuration, logger *slog.Logger) (Application, func(), error) {
wire.Build(
app.Config,
NewOtelResource,
app.Telemetry,
NewMeter,
Expand All @@ -65,7 +66,7 @@ func initializeApplication(ctx context.Context, conf config.Configuration, logge

// TODO: is this necessary? Do we need a logger first?
func initializeLogger(conf config.Configuration) *slog.Logger {
wire.Build(NewOtelResource, app.Logger)
wire.Build(app.Config, NewOtelResource, app.Logger)

return new(slog.Logger)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/sink-worker/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Application struct {

func initializeApplication(ctx context.Context, conf config.Configuration, logger *slog.Logger) (Application, func(), error) {
wire.Build(
app.Config,
NewOtelResource,
app.Telemetry,
NewMeter,
Expand All @@ -44,8 +45,7 @@ func initializeApplication(ctx context.Context, conf config.Configuration, logge

// TODO: is this necessary? Do we need a logger first?
func initializeLogger(conf config.Configuration) *slog.Logger {
// wire.Build(NewOtelResource, app.Logger)
wire.Build(NewOtelResource, NewLogger)
wire.Build(app.Config, NewOtelResource, app.Logger)

return new(slog.Logger)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/sink-worker/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 17 additions & 13 deletions openmeter/app/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,30 @@ import (
"github.com/openmeterio/openmeter/openmeter/streaming/clickhouse_connector"
)

var ClickHouse = wire.NewSet(
var Config = wire.NewSet(
wire.FieldsOf(new(config.Configuration), "Aggregation"),
wire.FieldsOf(new(config.AggregationConfiguration), "ClickHouse"),

wire.FieldsOf(new(config.Configuration), "Postgres"),

wire.FieldsOf(new(config.Configuration), "Telemetry"),
TelemetryConfig,

wire.FieldsOf(new(config.Configuration), "Meters"),
wire.FieldsOf(new(config.Configuration), "Namespace"),
)

var TelemetryConfig = wire.NewSet(
wire.FieldsOf(new(config.TelemetryConfig), "Metrics"),
wire.FieldsOf(new(config.TelemetryConfig), "Trace"),
wire.FieldsOf(new(config.TelemetryConfig), "Log"),
)

var ClickHouse = wire.NewSet(
NewClickHouse,
)

var Database = wire.NewSet(
wire.FieldsOf(new(config.Configuration), "Postgres"),

NewPostgresDriver,
NewDB,
NewEntPostgresDriver,
Expand All @@ -39,10 +53,6 @@ var Kafka = wire.NewSet(
)

var Telemetry = wire.NewSet(
wire.FieldsOf(new(config.Configuration), "Telemetry"),
wire.FieldsOf(new(config.TelemetryConfig), "Metrics"),
wire.FieldsOf(new(config.TelemetryConfig), "Trace"),

NewMeterProvider,
wire.Bind(new(metric.MeterProvider), new(*sdkmetric.MeterProvider)),
NewTracerProvider,
Expand All @@ -55,15 +65,10 @@ var Telemetry = wire.NewSet(
)

var Logger = wire.NewSet(
wire.FieldsOf(new(config.Configuration), "Telemetry"),
wire.FieldsOf(new(config.TelemetryConfig), "Log"),

NewLogger,
)

var OpenMeter = wire.NewSet(
wire.FieldsOf(new(config.Configuration), "Meters"),

NewMeterRepository,
wire.Bind(new(meter.Repository), new(*meter.InMemoryRepository)),

Expand All @@ -77,7 +82,6 @@ var OpenMeter = wire.NewSet(
NewKafkaNamespaceHandler,
NewIngestCollector,

wire.FieldsOf(new(config.Configuration), "Namespace"),
NewNamespaceHandlers,
NewNamespaceManager,
)
Expand Down

0 comments on commit 2ae5789

Please sign in to comment.