Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding serveroption for metrics.MetricHandler #2978

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions temporal/fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type (
TLSConfigProvider encryption.TLSConfigProvider
EsConfig *esclient.Config
EsClient esclient.Client
MetricHandler metrics.MetricHandler
}
)

Expand Down Expand Up @@ -180,16 +181,20 @@ func ServerOptionsProvider(opts []ServerOption) (serverOptionsProvider, error) {
clientFactoryProvider = client.NewFactoryProvider()
}

// MetricHandler
handler := so.metricHandler
if handler == nil {
if so.config.Global.Metrics != nil {
handler = metrics.MetricHandlerFromConfig(logger, so.config.Global.Metrics)
} else {
handler = metrics.NoopMetricHandler
}
}

// ServerReporter
serverReporter := so.metricsReporter
if serverReporter == nil {
if so.config.Global.Metrics == nil {
logger.Warn("no metrics config provided, using noop reporter")
serverReporter = metrics.NoopReporter
} else {
handler := metrics.MetricHandlerFromConfig(logger, so.config.Global.Metrics)
serverReporter = metrics.NewEventsReporter(handler)
}
serverReporter = metrics.NewEventsReporter(handler)
}

// MetricsClient
Expand Down Expand Up @@ -275,6 +280,7 @@ func ServerOptionsProvider(opts []ServerOption) (serverOptionsProvider, error) {
TLSConfigProvider: tlsConfigProvider,
EsConfig: esConfig,
EsClient: esClient,
MetricHandler: handler,
}, nil
}

Expand Down
9 changes: 9 additions & 0 deletions temporal/server_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func WithAudienceGetter(audienceGetter func(cfg *config.Config) authorization.JW
// handler, err := NewCustomHandlerImplementation(logger)
// reporter, err2 := metrics.NewEventsReporter(handler)
// server := temporal.NewServer(temporal.WithCustomMetricsReporter(repoter))
// Deprecated use WithCustomMetricHandler
func WithCustomMetricsReporter(reporter metrics.Reporter) ServerOption {
return newApplyFuncContainer(func(s *serverOptions) {
s.metricsReporter = reporter
Expand Down Expand Up @@ -190,3 +191,11 @@ func WithChainedFrontendGrpcInterceptors(
s.customInterceptors = interceptors
})
}

// WithCustomerMetricsHandler sets a custom implementation of the metrics.MetricHandler interface
// metrics.MetricHandler is the base interface for publishing metric events
func WithCustomMetricHandler(handler metrics.MetricHandler) ServerOption {
return newApplyFuncContainer(func(s *serverOptions) {
s.metricHandler = handler
})
}
2 changes: 2 additions & 0 deletions temporal/server_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type (
clientFactoryProvider client.FactoryProvider
searchAttributesMapper searchattribute.Mapper
customInterceptors []grpc.UnaryServerInterceptor
metricHandler metrics.MetricHandler
}
)

Expand Down Expand Up @@ -127,6 +128,7 @@ func (so *serverOptions) validateConfig() error {
}
return nil
}

func isValidService(service string) bool {
for _, s := range Services {
if s == service {
Expand Down