Skip to content

Commit 59825ac

Browse files
pauloh-temporalxwduan
authored andcommitted
excluding workflow metadata query types from actions history (#6663)
## What changed? We are excluding `__temporal_workflow_metadata` actions from metrics emission. ## Why? The pricing committee has decided to not charge for [`__temporal_workflow_metadata`](https://www.notion.so/temporalio/Do-not-charge-for-built-in-metadata-query-10c8fc5677388033845ffb1aa504e4d4?pvs=4) for billable actions. ## How did you test it? unit tests ## Potential risks Potential to expose a workaround for query types to be supplied at the client level to bypass metrics for billing purposes.
1 parent 5f04874 commit 59825ac

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

common/rpc/interceptor/telemetry.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ var (
8080
respondWorkflowTaskCompleted = "RespondWorkflowTaskCompleted"
8181
pollActivityTaskQueue = "PollActivityTaskQueue"
8282
startWorkflowExecution = "StartWorkflowExecution"
83+
queryWorkflow = "QueryWorkflow"
8384

8485
grpcActions = map[string]struct{}{
8586
startWorkflowExecution: {},
8687
respondWorkflowTaskCompleted: {},
8788
pollActivityTaskQueue: {},
88-
"QueryWorkflow": {},
89+
queryWorkflow: {},
8990
"RecordActivityTaskHeartbeat": {},
9091
"RecordActivityTaskHeartbeatById": {},
9192
"ResetWorkflowExecution": {},
@@ -258,7 +259,6 @@ func (ti *TelemetryInterceptor) emitActionMetric(
258259
if resp.Started {
259260
metrics.ActionCounter.With(metricsHandler).Record(1, metrics.ActionType("grpc_"+methodName))
260261
}
261-
262262
case respondWorkflowTaskCompleted:
263263
// handle commands
264264
completedRequest, ok := req.(*workflowservice.RespondWorkflowTaskCompletedRequest)
@@ -321,7 +321,18 @@ func (ti *TelemetryInterceptor) emitActionMetric(
321321
if activityPollResponse.Attempt > 1 {
322322
metrics.ActionCounter.With(metricsHandler).Record(1, metrics.ActionType("activity_retry"))
323323
}
324-
324+
case queryWorkflow:
325+
queryWorkflowReq, ok := req.(*workflowservice.QueryWorkflowRequest)
326+
if !ok {
327+
return
328+
}
329+
queryType := queryWorkflowReq.GetQuery().GetQueryType()
330+
switch queryType {
331+
case "__temporal_workflow_metadata":
332+
return
333+
default:
334+
metrics.ActionCounter.With(metricsHandler).Record(1, metrics.ActionType("grpc_"+methodName))
335+
}
325336
default:
326337
// grpc action
327338
metrics.ActionCounter.With(metricsHandler).Record(1, metrics.ActionType("grpc_"+methodName))

common/rpc/interceptor/telemetry_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
commonpb "go.temporal.io/api/common/v1"
3333
enumspb "go.temporal.io/api/enums/v1"
3434
protocolpb "go.temporal.io/api/protocol/v1"
35+
"go.temporal.io/api/query/v1"
3536
"go.temporal.io/api/serviceerror"
3637
"go.temporal.io/api/workflowservice/v1"
3738
"go.temporal.io/server/api/historyservice/v1"
@@ -48,7 +49,6 @@ import (
4849

4950
const (
5051
startWorkflow = "StartWorkflowExecution"
51-
queryWorkflow = "QueryWorkflow"
5252
)
5353

5454
func TestEmitActionMetric(t *testing.T) {
@@ -78,11 +78,6 @@ func TestEmitActionMetric(t *testing.T) {
7878
resp: &workflowservice.StartWorkflowExecutionResponse{Started: true},
7979
expectEmitMetrics: true,
8080
},
81-
{
82-
methodName: queryWorkflow,
83-
fullName: api.WorkflowServicePrefix + queryWorkflow,
84-
expectEmitMetrics: true,
85-
},
8681
{
8782
methodName: queryWorkflow,
8883
fullName: api.AdminServicePrefix + queryWorkflow,
@@ -144,6 +139,25 @@ func TestEmitActionMetric(t *testing.T) {
144139
},
145140
},
146141
},
142+
{
143+
methodName: queryWorkflow,
144+
fullName: api.WorkflowServicePrefix + queryWorkflow,
145+
req: &workflowservice.QueryWorkflowRequest{
146+
Query: &query.WorkflowQuery{
147+
QueryType: "some_type",
148+
},
149+
},
150+
expectEmitMetrics: true,
151+
},
152+
{
153+
methodName: queryWorkflow,
154+
fullName: api.WorkflowServicePrefix + queryWorkflow,
155+
req: &workflowservice.QueryWorkflowRequest{
156+
Query: &query.WorkflowQuery{
157+
QueryType: "__temporal_workflow_metadata",
158+
},
159+
},
160+
},
147161
}
148162

149163
for _, tt := range testCases {

0 commit comments

Comments
 (0)