Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add tags to metrics #414

Merged
merged 8 commits into from
Mar 16, 2018
Merged

Add tags to metrics #414

merged 8 commits into from
Mar 16, 2018

Conversation

vancexu
Copy link
Contributor

@vancexu vancexu commented Mar 6, 2018

No description provided.

@vancexu vancexu requested a review from yiminc-zz March 6, 2018 18:56
@vancexu vancexu force-pushed the metric branch 2 times, most recently from bbaf0dc to d5ee823 Compare March 6, 2018 19:27
Copy link
Contributor

@yiminc-zz yiminc-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is tasklist something we want to add as well?

@@ -36,3 +36,7 @@ const (
tagSideEffectID = "SideEffectID"
tagChildWorkflowID = "ChildWorkflowID"
)

func newTag(tagName, tagValue string) map[string]string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tagScope() helper method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1020,6 +1020,7 @@ func newAggregatedWorker(

ensureRequiredParams(&workerParams)
workerParams.MetricsScope = tagScope(workerParams.MetricsScope, tagDomain, domain)
workerParams.MetricsScope = tagScope(workerParams.MetricsScope, tagTaskList, taskList)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you update tagScope to take variable inputs so we only call tagScope once and only create one map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -190,7 +190,8 @@ func (wc *workflowClient) StartWorkflow(
}

if wc.metricsScope != nil {
wc.metricsScope.Counter(metrics.WorkflowStartCounter).Inc(1)
tagScope(wc.metricsScope, tagWorkflowType, workflowType.Name).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will only include that tag for this specific metric. We want to include those tags for all metrics. But if you do the same thing for every metric, you are going to create a log of tagged subscope, which is not a cheap operation.

workflowService workflowserviceclient.Interface
domain string
metricsScope tally.Scope
tagToMetricsScope map[string]tally.Scope // to avoid repeated creation of subScope
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this need to handle multi-thread concurrent access issue.

@@ -1247,7 +1249,11 @@ func (ath *activityTaskHandlerImpl) Execute(taskList string, t *s.PollForActivit
ath.logger.Error("Activity panic.",
zap.String("PanicError", fmt.Sprintf("%v", p)),
zap.String("PanicStack", st))
ath.metricsScope.Counter(metrics.ActivityTaskPanicCounter).Inc(1)
activityTypeName := t.ActivityType.GetName()
if _, ok := ath.tagToMetricsScope[activityTypeName]; !ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract these code so we don't have to dup this logic in 3 places.

identity string
service workflowserviceclient.Interface
metricsScope tally.Scope
tagToMetricsScope map[string]tally.Scope // to avoid repeated creation of subScope
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type scopeFactory struct {
tagToScopes map[string]tally.Scope
}

func (f *scopeFactory) getScope(tag string) Scope {
//...
}

@vancexu
Copy link
Contributor Author

vancexu commented Mar 15, 2018

@yiminc all comments addressed. let me know if you have more concerns thanks.

@coveralls
Copy link

coveralls commented Mar 15, 2018

Coverage Status

Coverage decreased (-0.05%) to 65.145% when pulling d39a0d0 on metric into 8e121e2 on master.

Copy link
Contributor

@yiminc-zz yiminc-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create a new type that encapsulate this logic
type taggedScope struct {
Tally.scope
syncMap sync.Map
}

func (ts *taggedScope) getTaggedScope(tagName, tagvalue) scope {

}

// otherwise retrieved subScope will be corrupted. e.g you cannot getOrCreateTaggedScope(m, scope, "domain", "A name")
// and then getOrCreateTaggedScope(m, scope, "workflow-type", "A name")
func getOrCreateTaggedScope(m sync.Map, scope tally.Scope, tagName, tagValue string) tally.Scope {
taggedScope, ok := m.Load(tagValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make the key be tagName+tagValue, then you don't have to worry about the case you put in your comment.

@@ -326,7 +327,7 @@ func NewClient(service workflowserviceclient.Interface, domain string, options *
return &workflowClient{
workflowService: metrics.NewWorkflowServiceWrapper(service, metricScope),
domain: domain,
metricsScope: metricScope,
metricsScope: &metrics.TaggedScope{Scope: metricScope, Map: &sync.Map{}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a func to create this because who using this taggedScope should not need to know that it needs a sync.Map internally:
func newTaggedScope(scope tally.Scope) *TaggedScope {
return &metrics.TaggedScope{Scope: scope, Map: &sync.Map{}}
}

ts.Map = &sync.Map{}
}

key := tagName + tagValue // used to prevent collision of tagValue (map key) for different tagName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a separater here: key := tagName + ":" + tagValue.

}

// NewTaggedScope create a new TaggedScope
func NewTaggedScope() *TaggedScope {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let this function take a scope as input parameter

@@ -1089,7 +1089,7 @@ func newActivityTaskHandlerWithCustomProvider(
identity: params.Identity,
service: service,
logger: params.Logger,
metricsScope: params.MetricsScope,
metricsScope: &metrics.TaggedScope{Scope: params.MetricsScope, Map: &sync.Map{}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use that newTaggedScope(scope) method

@@ -212,7 +213,7 @@ func newTestWorkflowEnvironmentImpl(s *WorkflowTestSuite) *testWorkflowEnvironme
env.logger = logger
}
if env.metricsScope == nil {
env.metricsScope = tally.NoopScope
env.metricsScope = &metrics.TaggedScope{Scope: s.scope, Map: &sync.Map{}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use that newTaggedScope(scope) method

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

metricsScope := tally.NoopScope
metricsScope := &metrics.TaggedScope{Scope: tally.NoopScope, Map: &sync.Map{}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the newTaggedScope(scope) function

Copy link
Contributor

@yiminc-zz yiminc-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@vancexu vancexu merged commit a31deb5 into master Mar 16, 2018
@vancexu vancexu deleted the metric branch March 16, 2018 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants