Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report GetWFExecutionHistory long poll under custom operation tag #1404

Merged
merged 6 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 46 additions & 43 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,10 @@ const (
FrontendRespondActivityTaskFailedByIdScope
// FrontendRespondActivityTaskCanceledScope is the metric scope for frontend.RespondActivityTaskCanceledById
FrontendRespondActivityTaskCanceledByIdScope
// FrontendGetWorkflowExecutionHistoryScope is the metric scope for frontend.GetWorkflowExecutionHistory
// FrontendGetWorkflowExecutionHistoryScope is the metric scope for non-long-poll frontend.GetWorkflowExecutionHistory
FrontendGetWorkflowExecutionHistoryScope
// FrontendGetWorkflowExecutionHistoryScope is the metric scope for long poll case of frontend.GetWorkflowExecutionHistory
FrontendLongPollGetWorkflowExecutionHistoryScope
Ardagan marked this conversation as resolved.
Show resolved Hide resolved
// FrontendGetWorkflowExecutionRawHistoryScope is the metric scope for frontend.GetWorkflowExecutionRawHistory
FrontendGetWorkflowExecutionRawHistoryScope
// FrontendPollForWorkflowExecutionRawHistoryScope is the metric scope for frontend.GetWorkflowExecutionRawHistory
Expand Down Expand Up @@ -1396,48 +1398,49 @@ var ScopeDefs = map[ServiceIdx]map[int]scopeDefinition{
AdminRefreshWorkflowTasksScope: {operation: "RefreshWorkflowTasks"},
AdminResendReplicationTasksScope: {operation: "ResendReplicationTasks"},

FrontendStartWorkflowExecutionScope: {operation: "StartWorkflowExecution"},
FrontendPollWorkflowTaskQueueScope: {operation: "PollWorkflowTaskQueue"},
FrontendPollActivityTaskQueueScope: {operation: "PollActivityTaskQueue"},
FrontendRecordActivityTaskHeartbeatScope: {operation: "RecordActivityTaskHeartbeat"},
FrontendRecordActivityTaskHeartbeatByIdScope: {operation: "RecordActivityTaskHeartbeatById"},
FrontendRespondWorkflowTaskCompletedScope: {operation: "RespondWorkflowTaskCompleted"},
FrontendRespondWorkflowTaskFailedScope: {operation: "RespondWorkflowTaskFailed"},
FrontendRespondQueryTaskCompletedScope: {operation: "RespondQueryTaskCompleted"},
FrontendRespondActivityTaskCompletedScope: {operation: "RespondActivityTaskCompleted"},
FrontendRespondActivityTaskFailedScope: {operation: "RespondActivityTaskFailed"},
FrontendRespondActivityTaskCanceledScope: {operation: "RespondActivityTaskCanceled"},
FrontendRespondActivityTaskCompletedByIdScope: {operation: "RespondActivityTaskCompletedById"},
FrontendRespondActivityTaskFailedByIdScope: {operation: "RespondActivityTaskFailedById"},
FrontendRespondActivityTaskCanceledByIdScope: {operation: "RespondActivityTaskCanceledById"},
FrontendGetWorkflowExecutionHistoryScope: {operation: "GetWorkflowExecutionHistory"},
FrontendGetWorkflowExecutionRawHistoryScope: {operation: "GetWorkflowExecutionRawHistory"},
FrontendPollForWorkflowExecutionRawHistoryScope: {operation: "PollForWorkflowExecutionRawHistory"},
FrontendSignalWorkflowExecutionScope: {operation: "SignalWorkflowExecution"},
FrontendSignalWithStartWorkflowExecutionScope: {operation: "SignalWithStartWorkflowExecution"},
FrontendTerminateWorkflowExecutionScope: {operation: "TerminateWorkflowExecution"},
FrontendResetWorkflowExecutionScope: {operation: "ResetWorkflowExecution"},
FrontendRequestCancelWorkflowExecutionScope: {operation: "RequestCancelWorkflowExecution"},
FrontendListArchivedWorkflowExecutionsScope: {operation: "ListArchivedWorkflowExecutions"},
FrontendListOpenWorkflowExecutionsScope: {operation: "ListOpenWorkflowExecutions"},
FrontendListClosedWorkflowExecutionsScope: {operation: "ListClosedWorkflowExecutions"},
FrontendListWorkflowExecutionsScope: {operation: "ListWorkflowExecutions"},
FrontendScanWorkflowExecutionsScope: {operation: "ScanWorkflowExecutions"},
FrontendCountWorkflowExecutionsScope: {operation: "CountWorkflowExecutions"},
FrontendRegisterNamespaceScope: {operation: "RegisterNamespace"},
FrontendDescribeNamespaceScope: {operation: "DescribeNamespace"},
FrontendListNamespacesScope: {operation: "ListNamespaces"},
FrontendUpdateNamespaceScope: {operation: "UpdateNamespace"},
FrontendDeprecateNamespaceScope: {operation: "DeprecateNamespace"},
FrontendQueryWorkflowScope: {operation: "QueryWorkflow"},
FrontendDescribeWorkflowExecutionScope: {operation: "DescribeWorkflowExecution"},
FrontendListTaskQueuePartitionsScope: {operation: "ListTaskQueuePartitions"},
FrontendDescribeTaskQueueScope: {operation: "DescribeTaskQueue"},
FrontendResetStickyTaskQueueScope: {operation: "ResetStickyTaskQueue"},
FrontendGetSearchAttributesScope: {operation: "GetSearchAttributes"},
FrontendGetClusterInfoScope: {operation: "GetClusterInfo"},
VersionCheckScope: {operation: "VersionCheck"},
AuthorizationScope: {operation: "Authorization"},
FrontendStartWorkflowExecutionScope: {operation: "StartWorkflowExecution"},
FrontendPollWorkflowTaskQueueScope: {operation: "PollWorkflowTaskQueue"},
FrontendPollActivityTaskQueueScope: {operation: "PollActivityTaskQueue"},
FrontendRecordActivityTaskHeartbeatScope: {operation: "RecordActivityTaskHeartbeat"},
FrontendRecordActivityTaskHeartbeatByIdScope: {operation: "RecordActivityTaskHeartbeatById"},
FrontendRespondWorkflowTaskCompletedScope: {operation: "RespondWorkflowTaskCompleted"},
FrontendRespondWorkflowTaskFailedScope: {operation: "RespondWorkflowTaskFailed"},
FrontendRespondQueryTaskCompletedScope: {operation: "RespondQueryTaskCompleted"},
FrontendRespondActivityTaskCompletedScope: {operation: "RespondActivityTaskCompleted"},
FrontendRespondActivityTaskFailedScope: {operation: "RespondActivityTaskFailed"},
FrontendRespondActivityTaskCanceledScope: {operation: "RespondActivityTaskCanceled"},
FrontendRespondActivityTaskCompletedByIdScope: {operation: "RespondActivityTaskCompletedById"},
FrontendRespondActivityTaskFailedByIdScope: {operation: "RespondActivityTaskFailedById"},
FrontendRespondActivityTaskCanceledByIdScope: {operation: "RespondActivityTaskCanceledById"},
FrontendGetWorkflowExecutionHistoryScope: {operation: "GetWorkflowExecutionHistory"},
FrontendLongPollGetWorkflowExecutionHistoryScope: {operation: "LongPollGetWorkflowExecutionHistory"},
FrontendGetWorkflowExecutionRawHistoryScope: {operation: "GetWorkflowExecutionRawHistory"},
FrontendPollForWorkflowExecutionRawHistoryScope: {operation: "PollForWorkflowExecutionRawHistory"},
FrontendSignalWorkflowExecutionScope: {operation: "SignalWorkflowExecution"},
FrontendSignalWithStartWorkflowExecutionScope: {operation: "SignalWithStartWorkflowExecution"},
FrontendTerminateWorkflowExecutionScope: {operation: "TerminateWorkflowExecution"},
FrontendResetWorkflowExecutionScope: {operation: "ResetWorkflowExecution"},
FrontendRequestCancelWorkflowExecutionScope: {operation: "RequestCancelWorkflowExecution"},
FrontendListArchivedWorkflowExecutionsScope: {operation: "ListArchivedWorkflowExecutions"},
FrontendListOpenWorkflowExecutionsScope: {operation: "ListOpenWorkflowExecutions"},
FrontendListClosedWorkflowExecutionsScope: {operation: "ListClosedWorkflowExecutions"},
FrontendListWorkflowExecutionsScope: {operation: "ListWorkflowExecutions"},
FrontendScanWorkflowExecutionsScope: {operation: "ScanWorkflowExecutions"},
FrontendCountWorkflowExecutionsScope: {operation: "CountWorkflowExecutions"},
FrontendRegisterNamespaceScope: {operation: "RegisterNamespace"},
FrontendDescribeNamespaceScope: {operation: "DescribeNamespace"},
FrontendListNamespacesScope: {operation: "ListNamespaces"},
FrontendUpdateNamespaceScope: {operation: "UpdateNamespace"},
FrontendDeprecateNamespaceScope: {operation: "DeprecateNamespace"},
FrontendQueryWorkflowScope: {operation: "QueryWorkflow"},
FrontendDescribeWorkflowExecutionScope: {operation: "DescribeWorkflowExecution"},
FrontendListTaskQueuePartitionsScope: {operation: "ListTaskQueuePartitions"},
FrontendDescribeTaskQueueScope: {operation: "DescribeTaskQueue"},
FrontendResetStickyTaskQueueScope: {operation: "ResetStickyTaskQueue"},
FrontendGetSearchAttributesScope: {operation: "GetSearchAttributes"},
FrontendGetClusterInfoScope: {operation: "GetClusterInfo"},
VersionCheckScope: {operation: "VersionCheck"},
AuthorizationScope: {operation: "Authorization"},
},
// History Scope Names
History: {
Expand Down
18 changes: 18 additions & 0 deletions common/rpc/interceptor/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"context"

"go.temporal.io/api/serviceerror"
"go.temporal.io/api/workflowservice/v1"
"google.golang.org/grpc"

"go.temporal.io/server/common"
Expand Down Expand Up @@ -67,6 +68,21 @@ func NewTelemetryInterceptor(
}
}

// Use this method to override scope used for reporting a metric.
// Ideally this method should never be used.
func (ti *TelemetryInterceptor) overrideScope(scope int, methodName string, req interface{}) int {
// GetWorkflowExecutionHistory method handles both long poll and regular calls.
// Current plan is to eventually split GetWorkflowExecutionHistory into two APIs,
// remove this if case when that is done.
if scope == metrics.FrontendGetWorkflowExecutionHistoryScope {
request := req.(*workflowservice.GetWorkflowExecutionHistoryRequest)
if request.GetWaitNewEvent() {
return metrics.FrontendLongPollGetWorkflowExecutionHistoryScope
}
}
return scope
}

func (ti *TelemetryInterceptor) Intercept(
ctx context.Context,
req interface{},
Expand All @@ -77,6 +93,7 @@ func (ti *TelemetryInterceptor) Intercept(
// if the method name is not defined, will default to
// unknown scope, which carries value 0
scope, _ := ti.scopes[methodName]
scope = ti.overrideScope(scope, methodName, req)
var metricsScope metrics.Scope
if namespace := GetNamespace(req); namespace != "" {
metricsScope = ti.metricsClient.Scope(scope).Tagged(metrics.NamespaceTag(namespace))
Expand All @@ -85,6 +102,7 @@ func (ti *TelemetryInterceptor) Intercept(
}
ctx = context.WithValue(ctx, metricsCtxKey, metricsScope)
metricsScope.IncCounter(metrics.ServiceRequests)

timer := metricsScope.StartTimer(metrics.ServiceLatency)
defer timer.Stop()

Expand Down