diff --git a/common/metrics/common.go b/common/metrics/common.go deleted file mode 100644 index d79e5fb313b..00000000000 --- a/common/metrics/common.go +++ /dev/null @@ -1,74 +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 ( - "fmt" - - "go.temporal.io/server/common/log" - "go.temporal.io/server/common/log/tag" - "go.temporal.io/server/common/primitives" -) - -// GetMetricsServiceIdx returns service id corresponding to serviceName -func GetMetricsServiceIdx(serviceName primitives.ServiceName, logger log.Logger) ServiceIdx { - switch serviceName { - case primitives.FrontendService: - return Frontend - case primitives.HistoryService: - return History - case primitives.MatchingService: - return Matching - case primitives.WorkerService: - return Worker - case primitives.ServerService: - return Server - case primitives.UnitTestService: - return UnitTestService - default: - logger.Fatal("Unknown service name for metrics!", tag.Service(serviceName)) - panic(fmt.Sprintf("Unknown service name for metrics: %s", serviceName)) - } -} - -// GetMetricsServiceIdx returns service id corresponding to serviceName -func MetricsServiceIdxToServiceName(serviceIdx ServiceIdx) (primitives.ServiceName, error) { - switch serviceIdx { - case Server: - return primitives.ServerService, nil - case Frontend: - return primitives.FrontendService, nil - case History: - return primitives.HistoryService, nil - case Matching: - return primitives.MatchingService, nil - case Worker: - return primitives.WorkerService, nil - case UnitTestService: - return primitives.UnitTestService, nil - default: - return "", fmt.Errorf(fmt.Sprintf("Unknown service idx for metrics: %d", serviceIdx)) - } -} diff --git a/common/metrics/defs.go b/common/metrics/defs.go index a7c41ed34fb..8a653a430d3 100644 --- a/common/metrics/defs.go +++ b/common/metrics/defs.go @@ -37,9 +37,6 @@ type ( metricName MetricName // metric name unit MetricUnit } - - // ServiceIdx is an index that uniquely identifies the service - ServiceIdx int ) // MetricUnit supported values diff --git a/common/metrics/metric_defs.go b/common/metrics/metric_defs.go index f8332546847..761c847a7f6 100644 --- a/common/metrics/metric_defs.go +++ b/common/metrics/metric_defs.go @@ -25,17 +25,6 @@ package metrics -// Service names for all services that emit metrics. -const ( - Common ServiceIdx = iota - Frontend - History - Matching - Worker - Server - UnitTestService -) - // Common tags for all services const ( OperationTagName = "operation" diff --git a/common/resourcetest/resourceTest.go b/common/resourcetest/resourceTest.go index f1ef360847b..0d56bcc67a9 100644 --- a/common/resourcetest/resourceTest.go +++ b/common/resourcetest/resourceTest.go @@ -120,10 +120,7 @@ const ( var testHostInfo = membership.NewHostInfoFromAddress(testHostName) // NewTest returns a new test resource instance -func NewTest( - controller *gomock.Controller, - serviceMetricsIndex metrics.ServiceIdx, -) *Test { +func NewTest(controller *gomock.Controller, serviceName primitives.ServiceName) *Test { logger := log.NewTestLogger() frontendClient := workflowservicemock.NewMockWorkflowServiceClient(controller) @@ -169,7 +166,6 @@ func NewTest( membershipMonitor.EXPECT().WaitUntilInitialized(gomock.Any()).Return(nil).AnyTimes() scope := tally.NewTestScope("test", nil) - serviceName, _ := metrics.MetricsServiceIdxToServiceName(serviceMetricsIndex) metricsHandler := metrics.NewTallyMetricsHandler(metrics.ClientConfig{}, scope).WithTags( metrics.ServiceNameTag(serviceName), ) diff --git a/service/frontend/adminHandler_test.go b/service/frontend/adminHandler_test.go index 8b8235d382a..5994fbfdb49 100644 --- a/service/frontend/adminHandler_test.go +++ b/service/frontend/adminHandler_test.go @@ -33,6 +33,7 @@ import ( "go.temporal.io/server/common/clock" "go.temporal.io/server/common/persistence/visibility/store/standard/cassandra" + "go.temporal.io/server/common/primitives" "go.temporal.io/server/common/resourcetest" "google.golang.org/grpc/health" @@ -62,7 +63,6 @@ import ( clientmocks "go.temporal.io/server/client" "go.temporal.io/server/common" "go.temporal.io/server/common/config" - "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/serialization" @@ -120,7 +120,7 @@ func (s *adminHandlerSuite) SetupTest() { ) s.controller = gomock.NewController(s.T()) - s.mockResource = resourcetest.NewTest(s.controller, metrics.Frontend) + s.mockResource = resourcetest.NewTest(s.controller, primitives.FrontendService) s.mockNamespaceCache = s.mockResource.NamespaceCache s.mockHistoryClient = s.mockResource.HistoryClient s.mockExecutionMgr = s.mockResource.ExecutionMgr diff --git a/service/frontend/operator_handler_test.go b/service/frontend/operator_handler_test.go index eb83b466c22..7b5bb5d1f03 100644 --- a/service/frontend/operator_handler_test.go +++ b/service/frontend/operator_handler_test.go @@ -41,13 +41,13 @@ import ( "go.temporal.io/api/operatorservice/v1" "go.temporal.io/api/serviceerror" "go.temporal.io/api/workflowservice/v1" + "go.temporal.io/server/common/primitives" "google.golang.org/grpc/health" "go.temporal.io/server/api/adminservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/dynamicconfig" - "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/visibility/store/elasticsearch" "go.temporal.io/server/common/resourcetest" @@ -83,7 +83,7 @@ func (s *operatorHandlerSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockResource = resourcetest.NewTest(s.controller, metrics.Frontend) + s.mockResource = resourcetest.NewTest(s.controller, primitives.FrontendService) s.mockResource.ClusterMetadata.EXPECT().GetCurrentClusterName().Return(uuid.New()).AnyTimes() args := NewOperatorHandlerImplArgs{ diff --git a/service/frontend/workflow_handler_test.go b/service/frontend/workflow_handler_test.go index 14ed361773d..e3c237c2225 100644 --- a/service/frontend/workflow_handler_test.go +++ b/service/frontend/workflow_handler_test.go @@ -141,7 +141,7 @@ func (s *workflowHandlerSuite) SetupTest() { s.testNamespaceID = "e4f90ec0-1313-45be-9877-8aa41f72a45a" s.controller = gomock.NewController(s.T()) - s.mockResource = resourcetest.NewTest(s.controller, metrics.Frontend) + s.mockResource = resourcetest.NewTest(s.controller, primitives.FrontendService) s.mockNamespaceCache = s.mockResource.NamespaceCache s.mockHistoryClient = s.mockResource.HistoryClient s.mockClusterMetadata = s.mockResource.ClusterMetadata diff --git a/service/history/replication/task_fetcher_test.go b/service/history/replication/task_fetcher_test.go index a6c0f51c29c..1c7e431dbb8 100644 --- a/service/history/replication/task_fetcher_test.go +++ b/service/history/replication/task_fetcher_test.go @@ -33,6 +33,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "go.temporal.io/server/common/primitives" "go.temporal.io/server/api/adminservice/v1" "go.temporal.io/server/api/adminservicemock/v1" @@ -40,7 +41,6 @@ import ( "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" - "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/resourcetest" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/tests" @@ -84,7 +84,7 @@ func (s *taskFetcherSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockResource = resourcetest.NewTest(s.controller, metrics.History) + s.mockResource = resourcetest.NewTest(s.controller, primitives.HistoryService) s.frontendClient = s.mockResource.RemoteAdminClient s.logger = log.NewNoopLogger() s.config = tests.NewDynamicConfig() diff --git a/service/history/shard/context_testutil.go b/service/history/shard/context_testutil.go index dcf2c0389ea..1ced55bd80c 100644 --- a/service/history/shard/context_testutil.go +++ b/service/history/shard/context_testutil.go @@ -29,13 +29,13 @@ import ( "fmt" "github.com/golang/mock/gomock" + "go.temporal.io/server/common/primitives" "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/future" "go.temporal.io/server/common/membership" - "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/resourcetest" "go.temporal.io/server/service/history/configs" @@ -70,7 +70,7 @@ func NewTestContext( shardInfo *persistencespb.ShardInfo, config *configs.Config, ) *ContextTest { - resourceTest := resourcetest.NewTest(ctrl, metrics.History) + resourceTest := resourcetest.NewTest(ctrl, primitives.HistoryService) eventsCache := events.NewMockCache(ctrl) hostInfoProvider := membership.NewMockHostInfoProvider(ctrl) lifecycleCtx, lifecycleCancel := context.WithCancel(context.Background()) diff --git a/service/history/shard/controller_test.go b/service/history/shard/controller_test.go index 334f8012f5b..f9eec144729 100644 --- a/service/history/shard/controller_test.go +++ b/service/history/shard/controller_test.go @@ -38,6 +38,7 @@ import ( "go.temporal.io/server/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/common/primitives" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" @@ -125,7 +126,7 @@ func (s *controllerSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockResource = resourcetest.NewTest(s.controller, metrics.History) + s.mockResource = resourcetest.NewTest(s.controller, primitives.HistoryService) s.mockHistoryEngine = NewMockEngine(s.controller) s.mockEngineFactory = NewMockEngineFactory(s.controller) diff --git a/service/worker/scanner/workflow_test.go b/service/worker/scanner/workflow_test.go index ff1d9c4aac3..d17c36cb0ad 100644 --- a/service/worker/scanner/workflow_test.go +++ b/service/worker/scanner/workflow_test.go @@ -34,11 +34,11 @@ import ( "github.com/stretchr/testify/suite" "go.temporal.io/sdk/activity" "go.temporal.io/sdk/workflow" + "go.temporal.io/server/common/primitives" "go.temporal.io/sdk/testsuite" "go.temporal.io/sdk/worker" - "go.temporal.io/server/common/metrics" p "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/resourcetest" ) @@ -77,7 +77,7 @@ func (s *scannerWorkflowTestSuite) TestScavengerActivity() { s.registerActivities(env) controller := gomock.NewController(s.T()) defer controller.Finish() - mockResource := resourcetest.NewTest(controller, metrics.Worker) + mockResource := resourcetest.NewTest(controller, primitives.WorkerService) mockResource.TaskMgr.EXPECT().ListTaskQueue(gomock.Any(), gomock.Any()).Return(&p.ListTaskQueueResponse{}, nil)