Skip to content

Commit

Permalink
Emit action metrics for batch of markers (#4905)
Browse files Browse the repository at this point in the history
<!-- Describe what has changed in this PR -->
**What changed?**
Add action metric for batch of markers

<!-- Tell your future self why have you made these changes -->
**Why?**
Markers in one workflow task maybe counted as one action.

<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**


<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**


<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
  • Loading branch information
yiminc authored and rodrigozhou committed Oct 30, 2023
1 parent b2014cf commit 34f0fb3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions common/rpc/interceptor/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ func (ti *TelemetryInterceptor) emitActionMetric(
result interface{},
) {
if _, ok := grpcActions[methodName]; !ok || !strings.HasPrefix(fullName, api.WorkflowServicePrefix) {
// grpcActions checks that methodName is the one that we care about.
// ti.scopes verifies that the scope is the one we intended to emit action metrics.
// This is necessary because TelemetryInterceptor is used for all services. Different service could have same
// method name. But we only want to emit action metrics from frontend.
// grpcActions checks that methodName is the one that we care about, and we only care about WorkflowService.
return
}

Expand All @@ -217,11 +214,13 @@ func (ti *TelemetryInterceptor) emitActionMetric(
return
}

hasMarker := false
for _, command := range completedRequest.Commands {
if _, ok := commandActions[command.CommandType]; ok {
switch command.CommandType {
case enums.COMMAND_TYPE_RECORD_MARKER:
// handle RecordMarker command, they are used for localActivity, sideEffect, versioning etc.
hasMarker = true
markerName := command.GetRecordMarkerCommandAttributes().GetMarkerName()
metricsHandler.Counter(metrics.ActionCounter.GetMetricName()).Record(1, metrics.ActionType("command_RecordMarker_"+markerName))
default:
Expand All @@ -230,6 +229,13 @@ func (ti *TelemetryInterceptor) emitActionMetric(
}
}
}
if hasMarker {
// Emit separate action metric for batch of markers.
// One workflow task response may contain multiple marker commands. Each marker will emit one
// command_RecordMarker_Xxx action metric. Depending on pricing model, you may want to ignore all individual
// command_RecordMarker_Xxx and use command_BatchMarkers instead.
metricsHandler.Counter(metrics.ActionCounter.GetMetricName()).Record(1, metrics.ActionType("command_BatchMarkers"))
}

case pollActivityTaskQueue:
// handle activity retries
Expand Down

0 comments on commit 34f0fb3

Please sign in to comment.