-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add tags to metrics #414
Conversation
bbaf0dc
to
d5ee823
Compare
There was a problem hiding this 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?
internal/internal_logging_tags.go
Outdated
@@ -36,3 +36,7 @@ const ( | |||
tagSideEffectID = "SideEffectID" | |||
tagChildWorkflowID = "ChildWorkflowID" | |||
) | |||
|
|||
func newTag(tagName, tagValue string) map[string]string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use tagScope() helper method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
internal/internal_worker.go
Outdated
@@ -1020,6 +1020,7 @@ func newAggregatedWorker( | |||
|
|||
ensureRequiredParams(&workerParams) | |||
workerParams.MetricsScope = tagScope(workerParams.MetricsScope, tagDomain, domain) | |||
workerParams.MetricsScope = tagScope(workerParams.MetricsScope, tagTaskList, taskList) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
internal/internal_workflow_client.go
Outdated
@@ -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). |
There was a problem hiding this comment.
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.
internal/internal_workflow_client.go
Outdated
workflowService workflowserviceclient.Interface | ||
domain string | ||
metricsScope tally.Scope | ||
tagToMetricsScope map[string]tally.Scope // to avoid repeated creation of subScope |
There was a problem hiding this comment.
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.
internal/internal_task_handlers.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
internal/internal_task_handlers.go
Outdated
identity string | ||
service workflowserviceclient.Interface | ||
metricsScope tally.Scope | ||
tagToMetricsScope map[string]tally.Scope // to avoid repeated creation of subScope |
There was a problem hiding this comment.
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 {
//...
}
@yiminc all comments addressed. let me know if you have more concerns thanks. |
There was a problem hiding this 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 {
}
internal/internal_worker.go
Outdated
// 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) |
There was a problem hiding this comment.
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.
internal/client.go
Outdated
@@ -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{}}, |
There was a problem hiding this comment.
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{}}
}
internal/common/metrics/scope.go
Outdated
ts.Map = &sync.Map{} | ||
} | ||
|
||
key := tagName + tagValue // used to prevent collision of tagValue (map key) for different tagName |
There was a problem hiding this comment.
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.
internal/common/metrics/scope.go
Outdated
} | ||
|
||
// NewTaggedScope create a new TaggedScope | ||
func NewTaggedScope() *TaggedScope { |
There was a problem hiding this comment.
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
internal/internal_task_handlers.go
Outdated
@@ -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{}}, |
There was a problem hiding this comment.
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{}} |
There was a problem hiding this comment.
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{}} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
No description provided.