Skip to content

Commit a596e26

Browse files
committed
Add task category tag to history tasks metrics
1 parent ffee895 commit a596e26

File tree

6 files changed

+61
-20
lines changed

6 files changed

+61
-20
lines changed

common/metrics/tags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ func NamespaceTag(namespace string) Tag {
347347
return metricWithUnknown("namespace", namespace)
348348
}
349349

350+
func TaskCategoryTag(category string) Tag {
351+
return metricWithUnknown("task_category", category)
352+
}
353+
350354
// ReasonTag returns a new reason tag
351355
func ReasonTag(reason string) Tag {
352356
return metricWithUnknown("reason", reason)

common/persistence/data_manager_interfaces.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ const (
178178
type HistoryTaskCategory struct {
179179
categoryType int
180180
categoryID int
181+
categoryName string
181182
}
182183

183184
func (c *HistoryTaskCategory) Type() int {
@@ -188,6 +189,10 @@ func (c *HistoryTaskCategory) ID() int {
188189
return c.categoryID
189190
}
190191

192+
func (c *HistoryTaskCategory) Name() string {
193+
return c.categoryName
194+
}
195+
191196
const (
192197
HistoryTaskCategoryTypeImmediate = iota + 1
193198
HistoryTaskCategoryTypeScheduled
@@ -203,14 +208,17 @@ var (
203208
HistoryTaskCategoryTransfer = HistoryTaskCategory{
204209
categoryType: HistoryTaskCategoryTypeImmediate,
205210
categoryID: HistoryTaskCategoryIDTransfer,
211+
categoryName: "transfer",
206212
}
207213
HistoryTaskCategoryTimer = HistoryTaskCategory{
208214
categoryType: HistoryTaskCategoryTypeScheduled,
209215
categoryID: HistoryTaskCategoryIDTimer,
216+
categoryName: "timer",
210217
}
211218
HistoryTaskCategoryReplication = HistoryTaskCategory{
212219
categoryType: HistoryTaskCategoryTypeImmediate,
213220
categoryID: HistoryTaskCategoryIDReplication,
221+
categoryName: "replication",
214222
}
215223
)
216224

common/persistence/metered.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,15 @@ func (r GetCurrentExecutionRequest) GetDomainName() string {
438438
func (r GetCurrentExecutionRequest) GetExtraLogTags() []tag.Tag {
439439
return []tag.Tag{tag.WorkflowID(r.WorkflowID)}
440440
}
441+
442+
func (r GetHistoryTasksRequest) MetricTags() []metrics.Tag {
443+
return []metrics.Tag{metrics.TaskCategoryTag(r.TaskCategory.Name())}
444+
}
445+
446+
func (r RangeCompleteHistoryTaskRequest) MetricTags() []metrics.Tag {
447+
return []metrics.Tag{metrics.TaskCategoryTag(r.TaskCategory.Name())}
448+
}
449+
450+
func (r CompleteHistoryTaskRequest) MetricTags() []metrics.Tag {
451+
return []metrics.Tag{metrics.TaskCategoryTag(r.TaskCategory.Name())}
452+
}

common/persistence/wrappers/metered/base.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ func (p *base) call(scope int, op func() error, tags ...metrics.Tag) error {
143143
return err
144144
}
145145

146+
func (p *base) callWithoutDomainTag(scope int, op func() error, tags ...metrics.Tag) error {
147+
metricsScope := p.metricClient.Scope(scope, tags...)
148+
metricsScope.IncCounter(metrics.PersistenceRequests)
149+
before := time.Now()
150+
err := op()
151+
duration := time.Since(before)
152+
metricsScope.RecordTimer(metrics.PersistenceLatency, duration)
153+
154+
if p.enableLatencyHistogramMetrics {
155+
metricsScope.RecordHistogramDuration(metrics.PersistenceLatencyHistogram, duration)
156+
}
157+
if err != nil {
158+
p.updateErrorMetric(scope, err, metricsScope)
159+
}
160+
return err
161+
}
162+
146163
func (p *base) callWithDomainAndShardScope(scope int, op func() error, domainTag metrics.Tag, shardIDTag metrics.Tag) error {
147164
domainMetricsScope := p.metricClient.Scope(scope, domainTag)
148165
shardOperationsMetricsScope := p.metricClient.Scope(scope, shardIDTag)

common/persistence/wrappers/metered/execution_generated.go

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/persistence/wrappers/templates/metered_execution.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func New{{.Interface.Name}}(
7171
{{ $extraTags = printf ", getCustomMetricTags(%s)..." $reqName }}
7272
{{ end -}}
7373

74-
err = c.call({{$scopeName}}, op{{$extraTags}})
74+
err = c.callWithoutDomainTag({{$scopeName}}, op{{$extraTags}})
7575

7676
return
7777
}

0 commit comments

Comments
 (0)