Skip to content

Commit cf9e84a

Browse files
authored
Overwrite operation for admin and operator APIs (#3890)
1 parent 19d36fb commit cf9e84a

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

common/rpc/interceptor/telemetry.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ var (
6363
respondWorkflowTaskCompleted = "RespondWorkflowTaskCompleted"
6464
pollActivityTaskQueue = "PollActivityTaskQueue"
6565
frontendPackagePrefix = "/temporal.api.workflowservice.v1.WorkflowService/"
66+
operatorServicePrefix = "/temporal.api.operatorservice.v1.OperatorService/"
67+
adminServicePrefix = "/temporal.server.api.adminservice.v1.AdminService/"
6668

6769
grpcActions = map[string]struct{}{
6870
metrics.FrontendQueryWorkflowScope: {},
@@ -102,16 +104,29 @@ func NewTelemetryInterceptor(
102104

103105
// Use this method to override scope used for reporting a metric.
104106
// Ideally this method should never be used.
105-
func (ti *TelemetryInterceptor) overrideOperationTag(operation string, req interface{}) string {
106-
// GetWorkflowExecutionHistory method handles both long poll and regular calls.
107-
// Current plan is to eventually split GetWorkflowExecutionHistory into two APIs,
108-
// remove this "if" case when that is done.
109-
if operation == metrics.FrontendGetWorkflowExecutionHistoryScope {
110-
request := req.(*workflowservice.GetWorkflowExecutionHistoryRequest)
111-
if request.GetWaitNewEvent() {
112-
return metrics.FrontendPollWorkflowExecutionHistoryScope
107+
func (ti *TelemetryInterceptor) overrideOperationTag(fullName, operation string, req interface{}) string {
108+
if strings.HasPrefix(fullName, frontendPackagePrefix) {
109+
// GetWorkflowExecutionHistory method handles both long poll and regular calls.
110+
// Current plan is to eventually split GetWorkflowExecutionHistory into two APIs,
111+
// remove this "if" case when that is done.
112+
if operation == metrics.FrontendGetWorkflowExecutionHistoryScope {
113+
request := req.(*workflowservice.GetWorkflowExecutionHistoryRequest)
114+
if request.GetWaitNewEvent() {
115+
return metrics.FrontendPollWorkflowExecutionHistoryScope
116+
}
113117
}
118+
return operation
119+
}
120+
121+
// prepend Operator prefix to Operator APIs
122+
if strings.HasPrefix(fullName, operatorServicePrefix) {
123+
return "Operator" + operation
114124
}
125+
// prepend Admin prefix to Admin APIs
126+
if strings.HasPrefix(fullName, adminServicePrefix) {
127+
return "Admin" + operation
128+
}
129+
115130
return operation
116131
}
117132

@@ -221,7 +236,7 @@ func (ti *TelemetryInterceptor) metricsHandlerLogTags(
221236
methodName string,
222237
) (metrics.Handler, []tag.Tag) {
223238

224-
overridedMethodName := ti.overrideOperationTag(methodName, req)
239+
overridedMethodName := ti.overrideOperationTag(fullMethod, methodName, req)
225240

226241
nsName := GetNamespace(ti.namespaceRegistry, req)
227242
if nsName == "" {

common/rpc/interceptor/telemetry_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"testing"
2929

3030
"github.com/golang/mock/gomock"
31+
"github.com/stretchr/testify/assert"
3132

3233
"go.temporal.io/server/common/log"
3334
"go.temporal.io/server/common/metrics"
@@ -73,3 +74,40 @@ func TestEmitActionMetric(t *testing.T) {
7374
})
7475
}
7576
}
77+
78+
func TestOperationOverwrite(t *testing.T) {
79+
controller := gomock.NewController(t)
80+
register := namespace.NewMockRegistry(controller)
81+
metricsHandler := metrics.NewMockHandler(controller)
82+
telemetry := NewTelemetryInterceptor(register, metricsHandler, log.NewNoopLogger())
83+
84+
testCases := []struct {
85+
methodName string
86+
fullName string
87+
expectedOperation string
88+
}{
89+
{
90+
"DeleteWorkflowExecution",
91+
adminServicePrefix + "DeleteWorkflowExecution",
92+
"AdminDeleteWorkflowExecution",
93+
},
94+
{
95+
"DeleteNamespace",
96+
operatorServicePrefix + "DeleteNamespace",
97+
"OperatorDeleteNamespace",
98+
},
99+
{
100+
metrics.FrontendStartWorkflowExecutionScope,
101+
frontendPackagePrefix + metrics.FrontendStartWorkflowExecutionScope,
102+
metrics.FrontendStartWorkflowExecutionScope,
103+
},
104+
}
105+
106+
for _, tt := range testCases {
107+
t.Run(tt.methodName, func(t *testing.T) {
108+
operation := telemetry.overrideOperationTag(tt.fullName, tt.methodName, nil)
109+
assert.Equal(t, tt.expectedOperation, operation)
110+
})
111+
}
112+
113+
}

0 commit comments

Comments
 (0)