diff --git a/common/metrics/interfaces.go b/common/metrics/interfaces.go index 9ae98bdd025..0f436242b52 100644 --- a/common/metrics/interfaces.go +++ b/common/metrics/interfaces.go @@ -30,8 +30,6 @@ import ( "time" "github.com/uber-go/tally/v4" - - "go.temporal.io/server/common/log" ) type ( @@ -90,36 +88,6 @@ type ( // information to metrics Tagged(tags ...Tag) Scope } - - // UserScope is an interface for reporting metrics by user code - // Deprecated - UserScope interface { - // IncCounter increments a counter metric - IncCounter(counter string) - // AddCounter adds delta to the counter metric - AddCounter(counter string, delta int64) - // StartTimer starts a timer for the given metric name. - // Time will be recorded when stopwatch is stopped. - StartTimer(timer string) Stopwatch - // RecordTimer records a timer for the given metric name - RecordTimer(timer string, d time.Duration) - // RecordDistribution records a distribution (wrapper on top of timer) for the given - // metric name - RecordDistribution(id string, unit MetricUnit, d int) - // UpdateGauge reports Gauge type absolute value metric - UpdateGauge(gauge string, value float64) - // Tagged returns a new scope with added and/or overriden tags values that can be used - // to provide additional information to metrics - Tagged(tags map[string]string) UserScope - } - - // Reporter is an interface for base constructor for metrics client. - // Deprecated - Reporter interface { - MetricsHandler() MetricsHandler - Stop(logger log.Logger) - UserScope() UserScope - } ) var sanitizer = tally.NewSanitizer(tally.SanitizeOptions{ diff --git a/common/metrics/interfaces_mock.go b/common/metrics/interfaces_mock.go index 7779cd1c8d9..1517ebcdb54 100644 --- a/common/metrics/interfaces_mock.go +++ b/common/metrics/interfaces_mock.go @@ -33,7 +33,6 @@ import ( time "time" gomock "github.com/golang/mock/gomock" - log "go.temporal.io/server/common/log" ) // MockStopwatch is a mock of Stopwatch interface. @@ -313,177 +312,3 @@ func (mr *MockScopeMockRecorder) UpdateGauge(gauge, value interface{}) *gomock.C mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateGauge", reflect.TypeOf((*MockScope)(nil).UpdateGauge), gauge, value) } - -// MockUserScope is a mock of UserScope interface. -type MockUserScope struct { - ctrl *gomock.Controller - recorder *MockUserScopeMockRecorder -} - -// MockUserScopeMockRecorder is the mock recorder for MockUserScope. -type MockUserScopeMockRecorder struct { - mock *MockUserScope -} - -// NewMockUserScope creates a new mock instance. -func NewMockUserScope(ctrl *gomock.Controller) *MockUserScope { - mock := &MockUserScope{ctrl: ctrl} - mock.recorder = &MockUserScopeMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockUserScope) EXPECT() *MockUserScopeMockRecorder { - return m.recorder -} - -// AddCounter mocks base method. -func (m *MockUserScope) AddCounter(counter string, delta int64) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "AddCounter", counter, delta) -} - -// AddCounter indicates an expected call of AddCounter. -func (mr *MockUserScopeMockRecorder) AddCounter(counter, delta interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddCounter", reflect.TypeOf((*MockUserScope)(nil).AddCounter), counter, delta) -} - -// IncCounter mocks base method. -func (m *MockUserScope) IncCounter(counter string) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IncCounter", counter) -} - -// IncCounter indicates an expected call of IncCounter. -func (mr *MockUserScopeMockRecorder) IncCounter(counter interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IncCounter", reflect.TypeOf((*MockUserScope)(nil).IncCounter), counter) -} - -// RecordDistribution mocks base method. -func (m *MockUserScope) RecordDistribution(id string, unit MetricUnit, d int) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RecordDistribution", id, unit, d) -} - -// RecordDistribution indicates an expected call of RecordDistribution. -func (mr *MockUserScopeMockRecorder) RecordDistribution(id, unit, d interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordDistribution", reflect.TypeOf((*MockUserScope)(nil).RecordDistribution), id, unit, d) -} - -// RecordTimer mocks base method. -func (m *MockUserScope) RecordTimer(timer string, d time.Duration) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RecordTimer", timer, d) -} - -// RecordTimer indicates an expected call of RecordTimer. -func (mr *MockUserScopeMockRecorder) RecordTimer(timer, d interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordTimer", reflect.TypeOf((*MockUserScope)(nil).RecordTimer), timer, d) -} - -// StartTimer mocks base method. -func (m *MockUserScope) StartTimer(timer string) Stopwatch { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StartTimer", timer) - ret0, _ := ret[0].(Stopwatch) - return ret0 -} - -// StartTimer indicates an expected call of StartTimer. -func (mr *MockUserScopeMockRecorder) StartTimer(timer interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartTimer", reflect.TypeOf((*MockUserScope)(nil).StartTimer), timer) -} - -// Tagged mocks base method. -func (m *MockUserScope) Tagged(tags map[string]string) UserScope { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Tagged", tags) - ret0, _ := ret[0].(UserScope) - return ret0 -} - -// Tagged indicates an expected call of Tagged. -func (mr *MockUserScopeMockRecorder) Tagged(tags interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Tagged", reflect.TypeOf((*MockUserScope)(nil).Tagged), tags) -} - -// UpdateGauge mocks base method. -func (m *MockUserScope) UpdateGauge(gauge string, value float64) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "UpdateGauge", gauge, value) -} - -// UpdateGauge indicates an expected call of UpdateGauge. -func (mr *MockUserScopeMockRecorder) UpdateGauge(gauge, value interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateGauge", reflect.TypeOf((*MockUserScope)(nil).UpdateGauge), gauge, value) -} - -// MockReporter is a mock of Reporter interface. -type MockReporter struct { - ctrl *gomock.Controller - recorder *MockReporterMockRecorder -} - -// MockReporterMockRecorder is the mock recorder for MockReporter. -type MockReporterMockRecorder struct { - mock *MockReporter -} - -// NewMockReporter creates a new mock instance. -func NewMockReporter(ctrl *gomock.Controller) *MockReporter { - mock := &MockReporter{ctrl: ctrl} - mock.recorder = &MockReporterMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockReporter) EXPECT() *MockReporterMockRecorder { - return m.recorder -} - -// MetricsHandler mocks base method. -func (m *MockReporter) MetricsHandler() MetricsHandler { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "MetricsHandler") - ret0, _ := ret[0].(MetricsHandler) - return ret0 -} - -// MetricsHandler indicates an expected call of MetricsHandler. -func (mr *MockReporterMockRecorder) MetricsHandler() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MetricsHandler", reflect.TypeOf((*MockReporter)(nil).MetricsHandler)) -} - -// Stop mocks base method. -func (m *MockReporter) Stop(logger log.Logger) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Stop", logger) -} - -// Stop indicates an expected call of Stop. -func (mr *MockReporterMockRecorder) Stop(logger interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockReporter)(nil).Stop), logger) -} - -// UserScope mocks base method. -func (m *MockReporter) UserScope() UserScope { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UserScope") - ret0, _ := ret[0].(UserScope) - return ret0 -} - -// UserScope indicates an expected call of UserScope. -func (mr *MockReporterMockRecorder) UserScope() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserScope", reflect.TypeOf((*MockReporter)(nil).UserScope)) -} diff --git a/common/metrics/noop_impl.go b/common/metrics/noop_impl.go index b4703c9ef8d..b6f3e94078f 100644 --- a/common/metrics/noop_impl.go +++ b/common/metrics/noop_impl.go @@ -31,59 +31,19 @@ import ( ) var ( - NoopReporter Reporter = newNoopReporter() NoopClient Client = newNoopClient() NoopScope Scope = newNoopScope() - NoopUserScope UserScope = newNoopUserScope() NoopStopwatch Stopwatch = newNoopStopwatch() NoopMetricsHandler MetricsHandler = newNoopMetricsHandler() ) type ( - noopReporterImpl struct{} - noopClientImpl struct{} - noopMetricsUserScope struct{} - noopStopwatchImpl struct{} - noopScopeImpl struct{} - noopMetricsHandler struct{} + noopClientImpl struct{} + noopStopwatchImpl struct{} + noopScopeImpl struct{} + noopMetricsHandler struct{} ) -func newNoopReporter() *noopReporterImpl { - return &noopReporterImpl{} -} - -func (*noopReporterImpl) MetricsHandler() MetricsHandler { - return NoopMetricsHandler -} - -func (*noopReporterImpl) Stop(logger log.Logger) {} - -func (*noopReporterImpl) UserScope() UserScope { - return NoopUserScope -} - -func newNoopUserScope() *noopMetricsUserScope { - return &noopMetricsUserScope{} -} - -func (n *noopMetricsUserScope) IncCounter(counter string) {} - -func (n *noopMetricsUserScope) AddCounter(counter string, delta int64) {} - -func (n *noopMetricsUserScope) StartTimer(timer string) Stopwatch { - return NoopStopwatch -} - -func (n *noopMetricsUserScope) RecordTimer(timer string, d time.Duration) {} - -func (n *noopMetricsUserScope) RecordDistribution(id string, unit MetricUnit, d int) {} - -func (n *noopMetricsUserScope) UpdateGauge(gauge string, value float64) {} - -func (n *noopMetricsUserScope) Tagged(tags map[string]string) UserScope { - return n -} - func newNoopClient() *noopClientImpl { return &noopClientImpl{} } diff --git a/common/metrics/otel_metric_provider.go b/common/metrics/otel_metrics_handler.go similarity index 100% rename from common/metrics/otel_metric_provider.go rename to common/metrics/otel_metrics_handler.go diff --git a/common/metrics/otel_metric_provider_test.go b/common/metrics/otel_metrics_handler_test.go similarity index 100% rename from common/metrics/otel_metric_provider_test.go rename to common/metrics/otel_metrics_handler_test.go diff --git a/common/metrics/reporter.go b/common/metrics/reporter.go deleted file mode 100644 index 406257a7dfa..00000000000 --- a/common/metrics/reporter.go +++ /dev/null @@ -1,53 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package metrics - -import "go.temporal.io/server/common/log" - -type ( - metricsReporter struct { - provider MetricsHandler - } -) - -var _ Reporter = (*metricsReporter)(nil) - -func NewReporter(mp MetricsHandler) *metricsReporter { - return &metricsReporter{ - provider: mp, - } -} - -func (e *metricsReporter) MetricsHandler() MetricsHandler { - return e.provider -} - -func (e *metricsReporter) Stop(logger log.Logger) { - e.provider.Stop(logger) -} - -func (e *metricsReporter) UserScope() UserScope { - return newUserScope(e.provider, nil) -} diff --git a/common/metrics/tally_metric_provider.go b/common/metrics/tally_metrics_handler.go similarity index 84% rename from common/metrics/tally_metric_provider.go rename to common/metrics/tally_metrics_handler.go index 7c0d05a72ab..3c112c1e2f9 100644 --- a/common/metrics/tally_metric_provider.go +++ b/common/metrics/tally_metrics_handler.go @@ -36,7 +36,6 @@ type ( excludeTags map[string]map[string]struct{} tallyMetricsHandler struct { - tags []Tag scope tally.Scope perUnitBuckets map[MetricUnit]tally.Buckets excludeTags excludeTags @@ -67,44 +66,47 @@ func NewTallyMetricsHandler(cfg ClientConfig, scope tally.Scope) *tallyMetricsHa // Tags are merged with registered Tags from the source MetricsHandler func (tmp *tallyMetricsHandler) WithTags(tags ...Tag) MetricsHandler { return &tallyMetricsHandler{ - scope: tmp.scope, + scope: tmp.scope.Tagged(tagsToMap(tags, tmp.excludeTags)), perUnitBuckets: tmp.perUnitBuckets, - tags: append(tmp.tags, tags...), } } // Counter obtains a counter for the given name and MetricOptions. func (tmp *tallyMetricsHandler) Counter(counter string) CounterMetric { return CounterMetricFunc(func(i int64, t ...Tag) { - tmp.scope.Tagged(tagsToMap(tmp.tags, t, tmp.excludeTags)).Counter(counter).Inc(i) + tmp.scope.Tagged(tagsToMap(t, tmp.excludeTags)).Counter(counter).Inc(i) }) } // Gauge obtains a gauge for the given name and MetricOptions. func (tmp *tallyMetricsHandler) Gauge(gauge string) GaugeMetric { return GaugeMetricFunc(func(f float64, t ...Tag) { - tmp.scope.Tagged(tagsToMap(tmp.tags, t, tmp.excludeTags)).Gauge(gauge).Update(f) + tmp.scope.Tagged(tagsToMap(t, tmp.excludeTags)).Gauge(gauge).Update(f) }) } // Timer obtains a timer for the given name and MetricOptions. func (tmp *tallyMetricsHandler) Timer(timer string) TimerMetric { return TimerMetricFunc(func(d time.Duration, tag ...Tag) { - tmp.scope.Tagged(tagsToMap(tmp.tags, tag, tmp.excludeTags)).Timer(timer).Record(d) + tmp.scope.Tagged(tagsToMap(tag, tmp.excludeTags)).Timer(timer).Record(d) }) } // Histogram obtains a histogram for the given name and MetricOptions. func (tmp *tallyMetricsHandler) Histogram(histogram string, unit MetricUnit) HistogramMetric { return HistogramMetricFunc(func(i int64, t ...Tag) { - tmp.scope.Tagged(tagsToMap(tmp.tags, t, tmp.excludeTags)).Histogram(histogram, tmp.perUnitBuckets[unit]).RecordValue(float64(i)) + tmp.scope.Tagged(tagsToMap(t, tmp.excludeTags)).Histogram(histogram, tmp.perUnitBuckets[unit]).RecordValue(float64(i)) }) } func (*tallyMetricsHandler) Stop(log.Logger) {} -func tagsToMap(t1 []Tag, t2 []Tag, e excludeTags) map[string]string { - m := make(map[string]string, len(t1)+len(t2)) +func tagsToMap(t1 []Tag, e excludeTags) map[string]string { + if len(t1) == 0 { + return nil + } + + m := make(map[string]string, len(t1)) convert := func(tag Tag) { if vals, ok := e[tag.Key()]; ok { @@ -121,9 +123,5 @@ func tagsToMap(t1 []Tag, t2 []Tag, e excludeTags) map[string]string { convert(t1[i]) } - for i := range t2 { - convert(t2[i]) - } - return m } diff --git a/common/metrics/tally_metric_provider_test.go b/common/metrics/tally_metrics_handler_test.go similarity index 92% rename from common/metrics/tally_metric_provider_test.go rename to common/metrics/tally_metrics_handler_test.go index feb96da3251..c09a4908477 100644 --- a/common/metrics/tally_metric_provider_test.go +++ b/common/metrics/tally_metrics_handler_test.go @@ -33,6 +33,17 @@ import ( "github.com/uber-go/tally/v4" ) +var defaultConfig = ClientConfig{ + Tags: nil, + ExcludeTags: map[string][]string{ + "taskqueue": {"__sticky__"}, + "activityType": {}, + "workflowType": {}, + }, + Prefix: "", + PerUnitHistogramBoundaries: map[string][]float64{Dimensionless: {0, 10, 100}, Bytes: {1024, 2048}}, +} + func TestTallyScope(t *testing.T) { scope := tally.NewTestScope("test", map[string]string{}) mp := NewTallyMetricsHandler(defaultConfig, scope) diff --git a/common/metrics/userscope.go b/common/metrics/userscope.go deleted file mode 100644 index 7cf612eafbc..00000000000 --- a/common/metrics/userscope.go +++ /dev/null @@ -1,113 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package metrics - -import ( - "time" - - "golang.org/x/exp/maps" -) - -type ( - userScope struct { - provider MetricsHandler - tags map[string]string - } -) - -var _ UserScope = (*userScope)(nil) - -func newUserScope(provider MetricsHandler, tags map[string]string) *userScope { - return &userScope{ - provider: provider, - tags: tags, - } -} - -// IncCounter increments a counter metric -func (e *userScope) IncCounter(counter string) { - e.AddCounter(counter, 1) -} - -// AddCounter adds delta to the counter metric -func (e *userScope) AddCounter(counter string, delta int64) { - e.provider.Counter(counter).Record(delta, mapToTags(e.tags)...) -} - -// StartTimer starts a timer for the given metric name. -// Time will be recorded when stopwatch is stopped. -func (e *userScope) StartTimer(timer string) Stopwatch { - return &stopwatch{ - recordFunc: func(d time.Duration) { - e.provider.Timer(timer).Record(d, mapToTags(e.tags)...) - }, - start: time.Now(), - } -} - -// RecordTimer records a timer for the given metric name -func (e *userScope) RecordTimer(timer string, d time.Duration) { - e.provider.Timer(timer).Record(d, mapToTags(e.tags)...) -} - -// RecordDistribution records a distribution (wrapper on top of timer) for the given -// metric name -func (e *userScope) RecordDistribution(id string, unit MetricUnit, d int) { - e.provider.Histogram(id, unit).Record(int64(d), mapToTags(e.tags)...) -} - -// UpdateGauge reports Gauge type absolute value metric -func (e *userScope) UpdateGauge(gauge string, value float64) { - e.provider.Gauge(gauge).Record(value, mapToTags(e.tags)...) -} - -// Tagged returns a new scope with added and/or overriden tags values that can be used -// to provide additional information to metrics -func (e *userScope) Tagged(tags map[string]string) UserScope { - if len(tags) == 0 { - return newUserScope(e.provider, e.tags) - } - - if len(e.tags) == 0 { - return newUserScope(e.provider, tags) - } - - m := maps.Clone(e.tags) - maps.Copy(m, tags) - return newUserScope(e.provider, m) -} - -func mapToTags(m map[string]string) []Tag { - if len(m) == 0 { - return nil - } - - t := make([]Tag, 0, len(m)) - for _, k := range maps.Keys(m) { - t = append(t, StringTag(k, m[k])) - } - - return t -} diff --git a/common/metrics/userscope_test.go b/common/metrics/userscope_test.go deleted file mode 100644 index 72b36661033..00000000000 --- a/common/metrics/userscope_test.go +++ /dev/null @@ -1,77 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package metrics - -import ( - "testing" - "time" -) - -var defaultConfig = ClientConfig{ - Tags: nil, - ExcludeTags: map[string][]string{ - "taskqueue": {"__sticky__"}, - "activityType": {}, - "workflowType": {}, - }, - Prefix: "", - PerUnitHistogramBoundaries: map[string][]float64{Dimensionless: {0, 10, 100}, Bytes: {1024, 2048}}, -} - -func BenchmarkAllTheMetricsUserScope(b *testing.B) { - var emp MetricsHandler = NoopMetricsHandler.WithTags(OperationTag("everything-is-awesome-3")) - var us UserScope = newUserScope(emp, defaultConfig.Tags) - - b.ResetTimer() - b.ReportAllocs() - - b.RunParallel( - func(p *testing.PB) { - for p.Next() { - stp := us.StartTimer("stopwatch-1") - us.AddCounter("counter-1", 1) - us.IncCounter("counter-2") - us.RecordDistribution("dist-1", Bytes, 1024) - us.RecordTimer("timer-1", time.Hour*100) - us.UpdateGauge("gauge-1", 120.435) - stp.Stop() - stp = us.StartTimer("stopwatch-1") - us.AddCounter("counter-1", 1) - us.IncCounter("counter-2") - us.RecordDistribution("dist-1", Bytes, 1024) - us.RecordTimer("timer-1", time.Hour*100) - us.UpdateGauge("gauge-1", 120.435) - stp.Stop() - stp = us.StartTimer("stopwatch-1") - us.AddCounter("counter-1", 1) - us.IncCounter("counter-2") - us.RecordDistribution("dist-1", Bytes, 1024) - us.RecordTimer("timer-1", time.Hour*100) - us.UpdateGauge("gauge-1", 120.435) - stp.Stop() - } - }, - ) -} diff --git a/common/resource/fx.go b/common/resource/fx.go index ffdc778542f..8a9ae2003ed 100644 --- a/common/resource/fx.go +++ b/common/resource/fx.go @@ -116,8 +116,6 @@ var Module = fx.Options( membership.HostInfoProviderModule, fx.Invoke(RegisterBootstrapContainer), fx.Provide(PersistenceConfigProvider), - fx.Provide(func(r metrics.Reporter) metrics.MetricsHandler { return r.MetricsHandler() }), - fx.Provide(func(r metrics.Reporter) metrics.UserScope { return r.UserScope() }), fx.Provide(MetricsClientProvider), ) diff --git a/host/onebox.go b/host/onebox.go index d53d94842cf..a50425070f6 100644 --- a/host/onebox.go +++ b/host/onebox.go @@ -40,6 +40,7 @@ import ( "go.temporal.io/api/workflowservice/v1" otelsdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.temporal.io/server/api/adminservice/v1" "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/client" @@ -403,7 +404,6 @@ func (c *temporalImpl) startFrontend(hosts map[string][]string, startWG *sync.Wa stoppedCh, persistenceConfig, ), - fx.Provide(func() metrics.Reporter { return metrics.NoopReporter }), fx.Provide(func() resource.ServiceName { return resource.ServiceName(serviceName) }), fx.Provide(func() config.DCRedirectionPolicy { return config.DCRedirectionPolicy{} }), fx.Provide(func() resource.ThrottledLogger { return c.logger }), @@ -422,6 +422,7 @@ func (c *temporalImpl) startFrontend(hosts map[string][]string, startWG *sync.Wa sdk.NewMetricsHandler(metrics.NoopMetricsHandler), ) }), + fx.Provide(func() metrics.MetricsHandler { return metrics.NoopMetricsHandler }), fx.Provide(func() []grpc.UnaryServerInterceptor { return nil }), fx.Provide(func() authorization.Authorizer { return nil }), fx.Provide(func() authorization.ClaimMapper { return nil }), @@ -505,7 +506,7 @@ func (c *temporalImpl) startHistory( integrationClient, persistenceConfig, ), - fx.Provide(func() metrics.Reporter { return metrics.NoopReporter }), + fx.Provide(func() metrics.MetricsHandler { return metrics.NoopMetricsHandler }), fx.Provide(func() resource.ServiceName { return resource.ServiceName(serviceName) }), fx.Provide(func() config.DCRedirectionPolicy { return config.DCRedirectionPolicy{} }), fx.Provide(func() resource.ThrottledLogger { return c.logger }), @@ -595,7 +596,7 @@ func (c *temporalImpl) startMatching(hosts map[string][]string, startWG *sync.Wa stoppedCh, persistenceConfig, ), - fx.Provide(func() metrics.Reporter { return metrics.NoopReporter }), + fx.Provide(func() metrics.MetricsHandler { return metrics.NoopMetricsHandler }), fx.Provide(func() resource.ServiceName { return resource.ServiceName(serviceName) }), fx.Provide(func() resource.ThrottledLogger { return c.logger }), fx.Provide(func() common.RPCFactory { return rpcFactory }), @@ -680,7 +681,7 @@ func (c *temporalImpl) startWorker(hosts map[string][]string, startWG *sync.Wait stoppedCh, persistenceConfig, ), - fx.Provide(func() metrics.Reporter { return metrics.NoopReporter }), + fx.Provide(func() metrics.MetricsHandler { return metrics.NoopMetricsHandler }), fx.Provide(func() resource.ServiceName { return resource.ServiceName(serviceName) }), fx.Provide(func() config.DCRedirectionPolicy { return config.DCRedirectionPolicy{} }), fx.Provide(func() resource.ThrottledLogger { return c.logger }), diff --git a/service/frontend/fx.go b/service/frontend/fx.go index a7ea0f841eb..d93dd1064ea 100644 --- a/service/frontend/fx.go +++ b/service/frontend/fx.go @@ -106,7 +106,7 @@ func NewServiceProvider( visibilityMgr manager.VisibilityManager, logger resource.SnTaggedLogger, grpcListener net.Listener, - metricsScope metrics.UserScope, + metricsHandler metrics.MetricsHandler, faultInjectionDataStoreFactory *persistenceClient.FaultInjectionDataStoreFactory, ) *Service { return NewService( @@ -120,7 +120,7 @@ func NewServiceProvider( visibilityMgr, logger, grpcListener, - metricsScope, + metricsHandler, faultInjectionDataStoreFactory, ) } @@ -147,7 +147,7 @@ func GrpcServerOptionsProvider( MinTime: serviceConfig.KeepAliveMinTime(), PermitWithoutStream: serviceConfig.KeepAlivePermitWithoutStream(), } - var kp = keepalive.ServerParameters{ + kp := keepalive.ServerParameters{ MaxConnectionIdle: serviceConfig.KeepAliveMaxConnectionIdle(), MaxConnectionAge: serviceConfig.KeepAliveMaxConnectionAge(), MaxConnectionAgeGrace: serviceConfig.KeepAliveMaxConnectionAgeGrace(), diff --git a/service/frontend/service.go b/service/frontend/service.go index 6a01cf4930b..8b909388d4e 100644 --- a/service/frontend/service.go +++ b/service/frontend/service.go @@ -32,13 +32,14 @@ import ( "sync/atomic" "time" - "go.temporal.io/api/operatorservice/v1" - "go.temporal.io/api/workflowservice/v1" "google.golang.org/grpc" "google.golang.org/grpc/health" healthpb "google.golang.org/grpc/health/grpc_health_v1" "google.golang.org/grpc/reflection" + "go.temporal.io/api/operatorservice/v1" + "go.temporal.io/api/workflowservice/v1" + "go.temporal.io/server/api/adminservice/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/dynamicconfig" @@ -215,10 +216,9 @@ type Service struct { visibilityManager manager.VisibilityManager server *grpc.Server - serverMetricsReporter metrics.Reporter logger log.Logger grpcListener net.Listener - userMetricsScope metrics.UserScope + metricsHandler metrics.MetricsHandler faultInjectionDataStoreFactory *client.FaultInjectionDataStoreFactory } @@ -233,7 +233,7 @@ func NewService( visibilityMgr manager.VisibilityManager, logger log.Logger, grpcListener net.Listener, - userMetricsScope metrics.UserScope, + metricsHandler metrics.MetricsHandler, faultInjectionDataStoreFactory *client.FaultInjectionDataStoreFactory, ) *Service { return &Service{ @@ -248,7 +248,7 @@ func NewService( visibilityManager: visibilityMgr, logger: logger, grpcListener: grpcListener, - userMetricsScope: userMetricsScope, + metricsHandler: metricsHandler, faultInjectionDataStoreFactory: faultInjectionDataStoreFactory, } } @@ -270,7 +270,7 @@ func (s *Service) Start() { reflection.Register(s.server) // must start resource first - s.userMetricsScope.AddCounter(metrics.RestartCount, 1) + s.metricsHandler.Counter(metrics.RestartCount).Record(1) rand.Seed(time.Now().UnixNano()) s.versionChecker.Start() @@ -321,8 +321,8 @@ func (s *Service) Stop() { // TODO: Change this to GracefulStop when integration tests are refactored. s.server.Stop() - if s.serverMetricsReporter != nil { - s.serverMetricsReporter.Stop(logger) + if s.metricsHandler != nil { + s.metricsHandler.Stop(logger) } logger.Info("frontend stopped") @@ -345,7 +345,6 @@ func namespaceRPS( func numFrontendHosts( frontendResolver membership.ServiceResolver, ) int { - defaultHosts := 1 if frontendResolver == nil { return defaultHosts diff --git a/service/history/fx.go b/service/history/fx.go index c345286eb95..da018f0c1e5 100644 --- a/service/history/fx.go +++ b/service/history/fx.go @@ -89,7 +89,7 @@ func ServiceProvider( logger resource.SnTaggedLogger, grpcListener net.Listener, membershipMonitor membership.Monitor, - userScope metrics.UserScope, + metricsHandler metrics.MetricsHandler, faultInjectionDataStoreFactory *persistenceClient.FaultInjectionDataStoreFactory, ) *Service { return NewService( @@ -100,7 +100,7 @@ func ServiceProvider( logger, grpcListener, membershipMonitor, - userScope, + metricsHandler, faultInjectionDataStoreFactory, ) } diff --git a/service/history/service.go b/service/history/service.go index bd67a3efb3f..85fe85e1c86 100644 --- a/service/history/service.go +++ b/service/history/service.go @@ -57,7 +57,7 @@ type ( grpcListener net.Listener membershipMonitor membership.Monitor faultInjectionDataStoreFactory *client.FaultInjectionDataStoreFactory - userScope metrics.UserScope + metricsHandler metrics.MetricsHandler } ) @@ -69,7 +69,7 @@ func NewService( logger log.Logger, grpcListener net.Listener, membershipMonitor membership.Monitor, - userScope metrics.UserScope, + metricsHandler metrics.MetricsHandler, faultInjectionDataStoreFactory *client.FaultInjectionDataStoreFactory, ) *Service { return &Service{ @@ -81,7 +81,7 @@ func NewService( logger: logger, grpcListener: grpcListener, membershipMonitor: membershipMonitor, - userScope: userScope, + metricsHandler: metricsHandler, faultInjectionDataStoreFactory: faultInjectionDataStoreFactory, } } @@ -95,7 +95,7 @@ func (s *Service) Start() { logger := s.logger logger.Info("history starting") - s.userScope.AddCounter(metrics.RestartCount, 1) + s.metricsHandler.Counter(metrics.RestartCount).Record(1) rand.Seed(time.Now().UnixNano()) s.handler.Start() diff --git a/service/history/shard/context.go b/service/history/shard/context.go index 93492c6545a..9fa2f629362 100644 --- a/service/history/shard/context.go +++ b/service/history/shard/context.go @@ -62,7 +62,7 @@ type ( GetLogger() log.Logger GetThrottledLogger() log.Logger GetMetricsClient() metrics.Client - GetMetricsReporter() metrics.Reporter + GetMetricsHandler() metrics.MetricsHandler GetTimeSource() clock.TimeSource GetEngine() (Engine, error) diff --git a/service/history/shard/context_impl.go b/service/history/shard/context_impl.go index 2f8faf3f1a8..e35578f0d67 100644 --- a/service/history/shard/context_impl.go +++ b/service/history/shard/context_impl.go @@ -88,7 +88,7 @@ type ( shardID int32 executionManager persistence.ExecutionManager metricsClient metrics.Client - metricsReporter metrics.Reporter + metricsHandler metrics.MetricsHandler eventsCache events.Cache closeCallback func(*ContextImpl) config *configs.Config @@ -1811,7 +1811,7 @@ func newContext( clientBean client.Bean, historyClient historyservice.HistoryServiceClient, metricsClient metrics.Client, - metricsReporter metrics.Reporter, + metricsHandler metrics.MetricsHandler, payloadSerializer serialization.Serializer, timeSource clock.TimeSource, namespaceRegistry namespace.Registry, @@ -1830,7 +1830,7 @@ func newContext( shardID: shardID, executionManager: persistenceExecutionManager, metricsClient: metricsClient, - metricsReporter: metricsReporter, + metricsHandler: metricsHandler, closeCallback: closeCallback, config: config, contextTaggedLogger: log.With(logger, tag.ShardID(shardID), tag.Address(hostIdentity)), @@ -1925,8 +1925,8 @@ func (s *ContextImpl) GetMetricsClient() metrics.Client { return s.metricsClient } -func (s *ContextImpl) GetMetricsReporter() metrics.Reporter { - return s.metricsReporter +func (s *ContextImpl) GetMetricsHandler() metrics.MetricsHandler { + return s.metricsHandler } func (s *ContextImpl) GetTimeSource() clock.TimeSource { diff --git a/service/history/shard/context_mock.go b/service/history/shard/context_mock.go index f8b089d8e46..b78a1cd67d9 100644 --- a/service/history/shard/context_mock.go +++ b/service/history/shard/context_mock.go @@ -434,18 +434,18 @@ func (mr *MockContextMockRecorder) GetMetricsClient() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMetricsClient", reflect.TypeOf((*MockContext)(nil).GetMetricsClient)) } -// GetMetricsReporter mocks base method. -func (m *MockContext) GetMetricsReporter() metrics.Reporter { +// GetMetricsHandler mocks base method. +func (m *MockContext) GetMetricsHandler() metrics.MetricsHandler { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetMetricsReporter") - ret0, _ := ret[0].(metrics.Reporter) + ret := m.ctrl.Call(m, "GetMetricsHandler") + ret0, _ := ret[0].(metrics.MetricsHandler) return ret0 } -// GetMetricsReporter indicates an expected call of GetMetricsReporter. -func (mr *MockContextMockRecorder) GetMetricsReporter() *gomock.Call { +// GetMetricsHandler indicates an expected call of GetMetricsHandler. +func (mr *MockContextMockRecorder) GetMetricsHandler() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMetricsReporter", reflect.TypeOf((*MockContext)(nil).GetMetricsReporter)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMetricsHandler", reflect.TypeOf((*MockContext)(nil).GetMetricsHandler)) } // GetNamespaceNotificationVersion mocks base method. diff --git a/service/history/shard/controller_impl.go b/service/history/shard/controller_impl.go index 9cfb05f5633..8abaa84d1c1 100644 --- a/service/history/shard/controller_impl.go +++ b/service/history/shard/controller_impl.go @@ -32,6 +32,7 @@ import ( "time" "go.opentelemetry.io/otel/trace" + "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/client" "go.temporal.io/server/common" @@ -76,7 +77,7 @@ type ( historyClient historyservice.HistoryServiceClient historyServiceResolver membership.ServiceResolver metricsClient metrics.Client - metricsReporter metrics.Reporter + metricsHandler metrics.MetricsHandler payloadSerializer serialization.Serializer timeSource clock.TimeSource namespaceRegistry namespace.Registry @@ -245,7 +246,7 @@ func (c *ControllerImpl) getOrCreateShardContext(shardID int32) (*ContextImpl, e c.clientBean, c.historyClient, c.metricsClient, - c.metricsReporter, + c.metricsHandler, c.payloadSerializer, c.timeSource, c.namespaceRegistry, diff --git a/service/history/shard/fx.go b/service/history/shard/fx.go index 0223057f5cd..5e79142a39f 100644 --- a/service/history/shard/fx.go +++ b/service/history/shard/fx.go @@ -60,7 +60,7 @@ func ShardControllerProvider( historyClient historyservice.HistoryServiceClient, historyServiceResolver membership.ServiceResolver, metricsClient metrics.Client, - metricsReporter metrics.Reporter, + metricsHandler metrics.MetricsHandler, payloadSerializer serialization.Serializer, timeSource clock.TimeSource, namespaceRegistry namespace.Registry, @@ -88,7 +88,7 @@ func ShardControllerProvider( historyClient: historyClient, historyServiceResolver: historyServiceResolver, metricsClient: metricsClient, - metricsReporter: metricsReporter, + metricsHandler: metricsHandler, payloadSerializer: payloadSerializer, timeSource: timeSource, namespaceRegistry: namespaceRegistry, diff --git a/service/matching/service.go b/service/matching/service.go index a7bffb5e912..f1179bf6c47 100644 --- a/service/matching/service.go +++ b/service/matching/service.go @@ -53,7 +53,7 @@ type Service struct { membershipMonitor membership.Monitor grpcListener net.Listener runtimeMetricsReporter *metrics.RuntimeMetricsReporter - userMetricsScope metrics.UserScope + metricsHandler metrics.MetricsHandler faultInjectionDataStoreFactory *client.FaultInjectionDataStoreFactory } @@ -65,7 +65,7 @@ func NewService( grpcListener net.Listener, runtimeMetricsReporter *metrics.RuntimeMetricsReporter, handler *Handler, - userMetricsScope metrics.UserScope, + metricsHandler metrics.MetricsHandler, faultInjectionDataStoreFactory *client.FaultInjectionDataStoreFactory, ) *Service { return &Service{ @@ -77,7 +77,7 @@ func NewService( membershipMonitor: membershipMonitor, grpcListener: grpcListener, runtimeMetricsReporter: runtimeMetricsReporter, - userMetricsScope: userMetricsScope, + metricsHandler: metricsHandler, faultInjectionDataStoreFactory: faultInjectionDataStoreFactory, } } @@ -91,7 +91,7 @@ func (s *Service) Start() { s.logger.Info("matching starting") // must start base service first - s.userMetricsScope.AddCounter(metrics.RestartCount, 1) + s.metricsHandler.Counter(metrics.RestartCount).Record(1) rand.Seed(time.Now().UnixNano()) s.handler.Start() diff --git a/service/worker/archiver/replay_metrics_client.go b/service/worker/archiver/replay_metrics_client.go index 04134b99d1a..4d80cb79092 100644 --- a/service/worker/archiver/replay_metrics_client.go +++ b/service/worker/archiver/replay_metrics_client.go @@ -106,10 +106,6 @@ func (r *replayMetricsClient) Scope(scope int, tags ...metrics.Tag) metrics.Scop return NewReplayMetricsScope(r.client.Scope(scope, tags...), r.ctx) } -func (r *replayMetricsClient) UserScope() metrics.UserScope { - panic("Not supported") -} - // NewReplayMetricsScope creates a metrics scope which is aware of temporal's replay mode func NewReplayMetricsScope(scope metrics.Scope, ctx workflow.Context) metrics.Scope { return &replayMetricsScope{ diff --git a/service/worker/service.go b/service/worker/service.go index e013b8079a4..b0eedeb3fd1 100644 --- a/service/worker/service.go +++ b/service/worker/service.go @@ -86,7 +86,7 @@ type ( membershipMonitor membership.Monitor - userMetricsScope metrics.UserScope + metricsHandler metrics.MetricsHandler status int32 stopC chan struct{} @@ -135,7 +135,7 @@ func NewService( persistenceBean persistenceClient.Bean, membershipMonitor membership.Monitor, namespaceReplicationQueue persistence.NamespaceReplicationQueue, - metricsScope metrics.UserScope, + metricsHandler metrics.MetricsHandler, metadataManager persistence.MetadataManager, taskManager persistence.TaskManager, historyClient historyservice.HistoryServiceClient, @@ -167,7 +167,7 @@ func NewService( membershipMonitor: membershipMonitor, archiverProvider: archiverProvider, namespaceReplicationQueue: namespaceReplicationQueue, - userMetricsScope: metricsScope, + metricsHandler: metricsHandler, metadataManager: metadataManager, taskManager: taskManager, historyClient: historyClient, @@ -334,8 +334,7 @@ func (s *Service) Start() { tag.ComponentWorker, ) - // todo: introduce proper counter (same in resource.go) - s.userMetricsScope.AddCounter(metrics.RestartCount, 1) + s.metricsHandler.Counter(metrics.RestartCount).Record(1) s.clusterMetadata.Start() s.membershipMonitor.Start() diff --git a/temporal/fx.go b/temporal/fx.go index cc2e72a2445..1372b9040b7 100644 --- a/temporal/fx.go +++ b/temporal/fx.go @@ -125,7 +125,6 @@ type ( // below are things that could be over write by server options or may have default if not supplied by serverOptions. Logger log.Logger ClientFactoryProvider client.FactoryProvider - ServerReporter metrics.Reporter MetricsClient metrics.Client DynamicConfigClient dynamicconfig.Client DynamicConfigCollection *dynamicconfig.Collection @@ -198,12 +197,6 @@ func ServerOptionsProvider(opts []ServerOption) (serverOptionsProvider, error) { provider = metrics.MetricsHandlerFromConfig(logger, so.config.Global.Metrics) } - // ServerReporter - serverReporter := so.metricsReporter - if serverReporter == nil { - serverReporter = metrics.NewReporter(provider) - } - // MetricsClient var metricsClient metrics.Client = metrics.NewClient(provider, metrics.Server) @@ -280,7 +273,6 @@ func ServerOptionsProvider(opts []ServerOption) (serverOptionsProvider, error) { Logger: logger, ClientFactoryProvider: clientFactoryProvider, - ServerReporter: serverReporter, MetricsClient: metricsClient, DynamicConfigClient: dcClient, DynamicConfigCollection: dynamicconfig.NewCollection(dcClient, logger), @@ -324,7 +316,7 @@ type ( Logger log.Logger NamespaceLogger resource.NamespaceLogger DynamicConfigClient dynamicconfig.Client - ServerReporter metrics.Reporter + MetricsHandler metrics.MetricsHandler EsConfig *esclient.Config EsClient esclient.Client TlsConfigProvider encryption.TLSConfigProvider @@ -382,7 +374,7 @@ func HistoryServiceProvider( fx.Provide(func() dynamicconfig.Client { return params.DynamicConfigClient }), fx.Provide(func() resource.ServiceName { return resource.ServiceName(serviceName) }), fx.Provide(func() log.Logger { return params.Logger }), - fx.Provide(func() metrics.Reporter { return params.ServerReporter }), + fx.Provide(func() metrics.MetricsHandler { return params.MetricsHandler }), fx.Provide(func() esclient.Client { return params.EsClient }), fx.Provide(params.PersistenceFactoryProvider), fx.Provide(workflow.NewTaskGeneratorProvider), @@ -442,7 +434,7 @@ func MatchingServiceProvider( fx.Provide(func() dynamicconfig.Client { return params.DynamicConfigClient }), fx.Provide(func() resource.ServiceName { return resource.ServiceName(serviceName) }), fx.Provide(func() log.Logger { return params.Logger }), - fx.Provide(func() metrics.Reporter { return params.ServerReporter }), + fx.Provide(func() metrics.MetricsHandler { return params.MetricsHandler }), fx.Provide(func() esclient.Client { return params.EsClient }), fx.Provide(params.PersistenceFactoryProvider), fx.Supply(params.SpanExporters), @@ -499,7 +491,7 @@ func FrontendServiceProvider( fx.Provide(func() dynamicconfig.Client { return params.DynamicConfigClient }), fx.Provide(func() resource.ServiceName { return resource.ServiceName(serviceName) }), fx.Provide(func() log.Logger { return params.Logger }), - fx.Provide(func() metrics.Reporter { return params.ServerReporter }), + fx.Provide(func() metrics.MetricsHandler { return params.MetricsHandler }), fx.Provide(func() resource.NamespaceLogger { return params.NamespaceLogger }), fx.Provide(func() esclient.Client { return params.EsClient }), fx.Provide(params.PersistenceFactoryProvider), @@ -557,7 +549,7 @@ func WorkerServiceProvider( fx.Provide(func() dynamicconfig.Client { return params.DynamicConfigClient }), fx.Provide(func() resource.ServiceName { return resource.ServiceName(serviceName) }), fx.Provide(func() log.Logger { return params.Logger }), - fx.Provide(func() metrics.Reporter { return params.ServerReporter }), + fx.Provide(func() metrics.MetricsHandler { return params.MetricsHandler }), fx.Provide(func() esclient.Client { return params.EsClient }), fx.Provide(params.PersistenceFactoryProvider), fx.Supply(params.SpanExporters), diff --git a/temporal/server_impl.go b/temporal/server_impl.go index b76566da1a8..99559b1e24d 100644 --- a/temporal/server_impl.go +++ b/temporal/server_impl.go @@ -36,7 +36,6 @@ import ( "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" - "go.temporal.io/server/common/metrics" persistenceClient "go.temporal.io/server/common/persistence/client" "go.temporal.io/server/common/resolver" "go.temporal.io/server/common/resource" @@ -50,7 +49,6 @@ type ( stoppedCh chan interface{} logger log.Logger namespaceLogger resource.NamespaceLogger - serverReporter metrics.Reporter dcCollection *dynamicconfig.Collection @@ -72,7 +70,6 @@ func NewServerFxImpl( namespaceLogger resource.NamespaceLogger, stoppedCh chan interface{}, dcCollection *dynamicconfig.Collection, - serverReporter metrics.Reporter, servicesGroup ServicesGroupIn, persistenceConfig config.Persistence, clusterMetadata *cluster.Config, @@ -84,7 +81,6 @@ func NewServerFxImpl( stoppedCh: stoppedCh, logger: logger, namespaceLogger: namespaceLogger, - serverReporter: serverReporter, dcCollection: dcCollection, persistenceConfig: persistenceConfig, clusterMetadata: clusterMetadata, @@ -142,8 +138,8 @@ func (s *ServerImpl) Stop() { wg.Wait() - if s.serverReporter != nil { - s.serverReporter.Stop(s.logger) + if s.so.metricProvider != nil { + s.so.metricProvider.Stop(s.logger) } } diff --git a/temporal/server_option.go b/temporal/server_option.go index 22829c4eab6..faca6ec3815 100644 --- a/temporal/server_option.go +++ b/temporal/server_option.go @@ -121,21 +121,6 @@ func WithAudienceGetter(audienceGetter func(cfg *config.Config) authorization.JW }) } -// WithCustomMetricsReporter sets custom metric reporter -// Detailed examples can be found at https://github.com/temporalio/samples-server -// -// Sample usage: -// logger := log.NewCLILogger() -// Provider, err := NewCustomProviderImplementation(logger) -// reporter, err2 := metrics.NewEventsReporter(Provider) -// server := temporal.NewServer(temporal.WithCustomMetricsReporter(repoter)) -// Deprecated use WithCustomMetricsHandler -func WithCustomMetricsReporter(reporter metrics.Reporter) ServerOption { - return newApplyFuncContainer(func(s *serverOptions) { - s.metricsReporter = reporter - }) -} - // WithPersistenceServiceResolver sets a custom persistence service resolver which will convert service name or address value from config to another address func WithPersistenceServiceResolver(r resolver.ServiceResolver) ServerOption { return newApplyFuncContainer(func(s *serverOptions) { diff --git a/temporal/server_options.go b/temporal/server_options.go index a6cc785c21e..b51e9af1e9f 100644 --- a/temporal/server_options.go +++ b/temporal/server_options.go @@ -60,7 +60,6 @@ type ( tlsConfigProvider encryption.TLSConfigProvider claimMapper authorization.ClaimMapper audienceGetter authorization.JWTAudienceMapper - metricsReporter metrics.Reporter persistenceServiceResolver resolver.ServiceResolver elasticsearchHttpClient *http.Client dynamicConfigClient dynamicconfig.Client