Skip to content

Commit ed909df

Browse files
authored
Track Start Workflow actions correctly (temporalio#5603)
## What changed? <!-- Describe what has changed in this PR --> Adjust the Action metric for Start Workflow. This metric is used by OSS users to estimate their Cloud bill. ## Why? <!-- Tell your future self why have you made these changes --> After temporalio/api#359 was merged, a successful gRPC response from Start Workflow doesn't always result in an Action. ## How did you test it? <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> Added tests. ## Potential risks <!-- Assuming the worst case, what can be broken when deploying this change to production? --> Low. It's only an internal metric. ## Documentation <!-- Have you made sure this change doesn't falsify anything currently stated in `docs/`? If significant new behavior is added, have you described that in `docs/`? --> ## Is hotfix candidate? <!-- Is this PR a hotfix candidate or does it require a notification to be sent to the broader community? (Yes/No) -->
1 parent 72a19e7 commit ed909df

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

common/rpc/interceptor/telemetry.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,18 @@ var (
6666
var (
6767
respondWorkflowTaskCompleted = "RespondWorkflowTaskCompleted"
6868
pollActivityTaskQueue = "PollActivityTaskQueue"
69+
startWorkflowExecution = "StartWorkflowExecution"
6970

7071
grpcActions = map[string]struct{}{
72+
startWorkflowExecution: {},
73+
respondWorkflowTaskCompleted: {},
74+
pollActivityTaskQueue: {},
7175
"QueryWorkflow": {},
7276
"RecordActivityTaskHeartbeat": {},
7377
"RecordActivityTaskHeartbeatById": {},
7478
"ResetWorkflowExecution": {},
75-
"StartWorkflowExecution": {},
7679
"SignalWorkflowExecution": {},
7780
"SignalWithStartWorkflowExecution": {},
78-
"RespondWorkflowTaskCompleted": {},
79-
"PollActivityTaskQueue": {},
8081
"CreateSchedule": {},
8182
"UpdateSchedule": {},
8283
"DeleteSchedule": {},
@@ -214,6 +215,15 @@ func (ti *TelemetryInterceptor) emitActionMetric(
214215
}
215216

216217
switch methodName {
218+
case startWorkflowExecution:
219+
resp, ok := result.(*workflowservice.StartWorkflowExecutionResponse)
220+
if !ok {
221+
return
222+
}
223+
if resp.Started {
224+
metrics.ActionCounter.With(metricsHandler).Record(1, metrics.ActionType("grpc_"+methodName))
225+
}
226+
217227
case respondWorkflowTaskCompleted:
218228
// handle commands
219229
completedRequest, ok := req.(*workflowservice.RespondWorkflowTaskCompletedRequest)

common/rpc/interceptor/telemetry_test.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"github.com/golang/mock/gomock"
3131
"github.com/stretchr/testify/assert"
32+
"go.temporal.io/api/workflowservice/v1"
3233
"google.golang.org/grpc/codes"
3334
"google.golang.org/grpc/status"
3435

@@ -55,21 +56,31 @@ func TestEmitActionMetric(t *testing.T) {
5556
methodName string
5657
fullName string
5758
expectEmitMetrics bool
59+
resp any
5860
}{
5961
{
60-
queryWorkflow,
61-
api.WorkflowServicePrefix + queryWorkflow,
62-
true,
62+
methodName: startWorkflow,
63+
fullName: api.WorkflowServicePrefix + startWorkflow,
64+
resp: &workflowservice.StartWorkflowExecutionResponse{Started: false},
6365
},
6466
{
65-
queryWorkflow,
66-
api.AdminServicePrefix + queryWorkflow,
67-
false,
67+
methodName: startWorkflow,
68+
fullName: api.WorkflowServicePrefix + startWorkflow,
69+
resp: &workflowservice.StartWorkflowExecutionResponse{Started: true},
70+
expectEmitMetrics: true,
6871
},
6972
{
70-
metrics.MatchingClientAddWorkflowTaskScope,
71-
api.WorkflowServicePrefix + queryWorkflow,
72-
false,
73+
methodName: queryWorkflow,
74+
fullName: api.WorkflowServicePrefix + queryWorkflow,
75+
expectEmitMetrics: true,
76+
},
77+
{
78+
methodName: queryWorkflow,
79+
fullName: api.AdminServicePrefix + queryWorkflow,
80+
},
81+
{
82+
methodName: metrics.MatchingClientAddWorkflowTaskScope,
83+
fullName: api.WorkflowServicePrefix + queryWorkflow,
7384
},
7485
}
7586

@@ -80,7 +91,7 @@ func TestEmitActionMetric(t *testing.T) {
8091
} else {
8192
metricsHandler.EXPECT().Counter(gomock.Any()).Return(metrics.NoopCounterMetricFunc).Times(0)
8293
}
83-
telemetry.emitActionMetric(tt.methodName, tt.fullName, nil, metricsHandler, nil)
94+
telemetry.emitActionMetric(tt.methodName, tt.fullName, nil, metricsHandler, tt.resp)
8495
})
8596
}
8697
}

0 commit comments

Comments
 (0)