Skip to content

Commit

Permalink
change NewTaggedScope()
Browse files Browse the repository at this point in the history
  • Loading branch information
vancexu committed Mar 16, 2018
1 parent ed72e73 commit d39a0d0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
3 changes: 1 addition & 2 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package internal
import (
"context"
"fmt"
"sync"
"time"

"go.uber.org/cadence/encoded"
Expand Down Expand Up @@ -327,7 +326,7 @@ func NewClient(service workflowserviceclient.Interface, domain string, options *
return &workflowClient{
workflowService: metrics.NewWorkflowServiceWrapper(service, metricScope),
domain: domain,
metricsScope: &metrics.TaggedScope{Scope: metricScope, Map: &sync.Map{}},
metricsScope: metrics.NewTaggedScope(metricScope),
identity: identity,
}
}
Expand Down
9 changes: 6 additions & 3 deletions internal/common/metrics/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (ts *TaggedScope) GetTaggedScope(tagName, tagValue string) tally.Scope {
ts.Map = &sync.Map{}
}

key := tagName + tagValue // used to prevent collision of tagValue (map key) for different tagName
key := tagName + ":" + tagValue // used to prevent collision of tagValue (map key) for different tagName
taggedScope, ok := ts.Load(key)
if !ok {
ts.Store(key, ts.Scope.Tagged(map[string]string{tagName: tagValue}))
Expand All @@ -214,6 +214,9 @@ func (ts *TaggedScope) GetTaggedScope(tagName, tagValue string) tally.Scope {
}

// NewTaggedScope create a new TaggedScope
func NewTaggedScope() *TaggedScope {
return &TaggedScope{Scope: tally.NoopScope, Map: &sync.Map{}}
func NewTaggedScope(scope tally.Scope) *TaggedScope {
if scope == nil {
scope = tally.NoopScope
}
return &TaggedScope{Scope: scope, Map: &sync.Map{}}
}
2 changes: 1 addition & 1 deletion internal/internal_task_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ func newActivityTaskHandlerWithCustomProvider(
identity: params.Identity,
service: service,
logger: params.Logger,
metricsScope: &metrics.TaggedScope{Scope: params.MetricsScope, Map: &sync.Map{}},
metricsScope: metrics.NewTaggedScope(params.MetricsScope),
userContext: params.UserContext,
hostEnv: env,
activityProvider: activityProvider,
Expand Down
4 changes: 1 addition & 3 deletions internal/internal_workflow_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"errors"
"log"
"os"
"sync"
"testing"
"time"

Expand All @@ -34,7 +33,6 @@ import (

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"
"github.com/uber-go/tally"
"go.uber.org/cadence/internal/common/metrics"
)

Expand Down Expand Up @@ -192,7 +190,7 @@ func (s *workflowRunSuite) SetupTest() {
mockCtrl := gomock.NewController(s.T())
s.workflowServiceClient = workflowservicetest.NewMockClient(mockCtrl)

metricsScope := &metrics.TaggedScope{Scope: tally.NoopScope, Map: &sync.Map{}}
metricsScope := metrics.NewTaggedScope(nil)
s.workflowClient = &workflowClient{
workflowService: s.workflowServiceClient,
domain: domain,
Expand Down
4 changes: 2 additions & 2 deletions internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func newTestWorkflowEnvironmentImpl(s *WorkflowTestSuite) *testWorkflowEnvironme
taskListSpecificActivities: make(map[string]*taskListSpecificActivity),

logger: s.logger,
metricsScope: metrics.NewTaggedScope(),
metricsScope: metrics.NewTaggedScope(nil),
mockClock: clock.NewMock(),
wallClock: clock.New(),
timers: make(map[string]*testTimerHandle),
Expand Down Expand Up @@ -213,7 +213,7 @@ func newTestWorkflowEnvironmentImpl(s *WorkflowTestSuite) *testWorkflowEnvironme
env.logger = logger
}
if env.metricsScope == nil {
env.metricsScope = &metrics.TaggedScope{Scope: s.scope, Map: &sync.Map{}}
env.metricsScope = metrics.NewTaggedScope(s.scope)
}

// setup mock service
Expand Down

0 comments on commit d39a0d0

Please sign in to comment.