diff --git a/common/rpc/encryption/localStoreTlsProvider.go b/common/rpc/encryption/localStoreTlsProvider.go index 47b8d2adda7..c2840bd5e5c 100644 --- a/common/rpc/encryption/localStoreTlsProvider.go +++ b/common/rpc/encryption/localStoreTlsProvider.go @@ -435,10 +435,8 @@ func (s *localStoreTlsProvider) timerCallback() { } func (s *localStoreTlsProvider) checkCertExpiration() { - defer func() { - var retError error - log.CapturePanic(s.logger, &retError) - }() + var retError error + defer log.CapturePanic(s.logger, &retError) var errorTime time.Time if s.settings.ExpirationChecks.ErrorWindow != 0 { diff --git a/service/frontend/dcRedirectionHandler.go b/service/frontend/dcRedirectionHandler.go index 7f33a9bde03..49bc2d76162 100644 --- a/service/frontend/dcRedirectionHandler.go +++ b/service/frontend/dcRedirectionHandler.go @@ -115,9 +115,11 @@ func (handler *DCRedirectionHandlerImpl) DeprecateNamespace( scope, startTime := handler.beforeCall(metrics.DCRedirectionDeprecateNamespaceScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + return handler.frontendHandler.DeprecateNamespace(ctx, request) } @@ -131,9 +133,11 @@ func (handler *DCRedirectionHandlerImpl) DescribeNamespace( scope, startTime := handler.beforeCall(metrics.DCRedirectionDescribeNamespaceScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + return handler.frontendHandler.DescribeNamespace(ctx, request) } @@ -147,9 +151,11 @@ func (handler *DCRedirectionHandlerImpl) ListNamespaces( scope, startTime := handler.beforeCall(metrics.DCRedirectionListNamespacesScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + return handler.frontendHandler.ListNamespaces(ctx, request) } @@ -163,9 +169,11 @@ func (handler *DCRedirectionHandlerImpl) RegisterNamespace( scope, startTime := handler.beforeCall(metrics.DCRedirectionRegisterNamespaceScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + return handler.frontendHandler.RegisterNamespace(ctx, request) } @@ -179,9 +187,11 @@ func (handler *DCRedirectionHandlerImpl) UpdateNamespace( scope, startTime := handler.beforeCall(metrics.DCRedirectionUpdateNamespaceScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + return handler.frontendHandler.UpdateNamespace(ctx, request) } @@ -199,9 +209,11 @@ func (handler *DCRedirectionHandlerImpl) DescribeTaskQueue( scope, startTime := handler.beforeCall(metrics.DCRedirectionDescribeTaskQueueScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -233,9 +245,11 @@ func (handler *DCRedirectionHandlerImpl) DescribeWorkflowExecution( scope, startTime := handler.beforeCall(metrics.DCRedirectionDescribeWorkflowExecutionScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -267,9 +281,11 @@ func (handler *DCRedirectionHandlerImpl) GetWorkflowExecutionHistory( scope, startTime := handler.beforeCall(metrics.DCRedirectionGetWorkflowExecutionHistoryScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -301,9 +317,11 @@ func (handler *DCRedirectionHandlerImpl) GetWorkflowExecutionHistoryReverse( scope, startTime := handler.beforeCall(metrics.DCRedirectionGetWorkflowExecutionHistoryReverseScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -335,9 +353,11 @@ func (handler *DCRedirectionHandlerImpl) ListArchivedWorkflowExecutions( scope, startTime := handler.beforeCall(metrics.DCRedirectionListArchivedWorkflowExecutionsScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -369,9 +389,11 @@ func (handler *DCRedirectionHandlerImpl) ListClosedWorkflowExecutions( scope, startTime := handler.beforeCall(metrics.DCRedirectionListClosedWorkflowExecutionsScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -403,9 +425,11 @@ func (handler *DCRedirectionHandlerImpl) ListOpenWorkflowExecutions( scope, startTime := handler.beforeCall(metrics.DCRedirectionListOpenWorkflowExecutionsScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -437,9 +461,11 @@ func (handler *DCRedirectionHandlerImpl) ListWorkflowExecutions( scope, startTime := handler.beforeCall(metrics.DCRedirectionListWorkflowExecutionsScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -471,8 +497,10 @@ func (handler *DCRedirectionHandlerImpl) ScanWorkflowExecutions( scope, startTime := handler.beforeCall(metrics.DCRedirectionScanWorkflowExecutionsScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + + defer log.CapturePanic(handler.logger, &retError) err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -504,9 +532,11 @@ func (handler *DCRedirectionHandlerImpl) CountWorkflowExecutions( scope, startTime := handler.beforeCall(metrics.DCRedirectionCountWorkflowExecutionsScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -536,9 +566,11 @@ func (handler *DCRedirectionHandlerImpl) GetSearchAttributes( scope, startTime := handler.beforeCall(metrics.DCRedirectionGetSearchAttributesScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + return handler.frontendHandler.GetSearchAttributes(ctx, request) } @@ -554,9 +586,11 @@ func (handler *DCRedirectionHandlerImpl) PollActivityTaskQueue( scope, startTime := handler.beforeCall(metrics.DCRedirectionPollActivityTaskQueueScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -588,9 +622,11 @@ func (handler *DCRedirectionHandlerImpl) PollWorkflowTaskQueue( scope, startTime := handler.beforeCall(metrics.DCRedirectionPollWorkflowTaskQueueScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -621,9 +657,11 @@ func (handler *DCRedirectionHandlerImpl) QueryWorkflow( scope, startTime := handler.beforeCall(metrics.DCRedirectionQueryWorkflowScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -655,9 +693,11 @@ func (handler *DCRedirectionHandlerImpl) RecordActivityTaskHeartbeat( scope, startTime := handler.beforeCall(metrics.DCRedirectionRecordActivityTaskHeartbeatScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + token, err := handler.tokenSerializer.Deserialize(request.TaskToken) if err != nil { return nil, err @@ -694,9 +734,11 @@ func (handler *DCRedirectionHandlerImpl) RecordActivityTaskHeartbeatById( scope, startTime := handler.beforeCall(metrics.DCRedirectionRecordActivityTaskHeartbeatByIdScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -728,9 +770,11 @@ func (handler *DCRedirectionHandlerImpl) RequestCancelWorkflowExecution( scope, startTime := handler.beforeCall(metrics.DCRedirectionRequestCancelWorkflowExecutionScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -762,9 +806,11 @@ func (handler *DCRedirectionHandlerImpl) ResetStickyTaskQueue( scope, startTime := handler.beforeCall(metrics.DCRedirectionResetStickyTaskQueueScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -796,9 +842,11 @@ func (handler *DCRedirectionHandlerImpl) ResetWorkflowExecution( scope, startTime := handler.beforeCall(metrics.DCRedirectionResetWorkflowExecutionScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -830,9 +878,11 @@ func (handler *DCRedirectionHandlerImpl) RespondActivityTaskCanceled( scope, startTime := handler.beforeCall(metrics.DCRedirectionRespondActivityTaskCanceledScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + token, err := handler.tokenSerializer.Deserialize(request.TaskToken) if err != nil { return resp, err @@ -869,9 +919,11 @@ func (handler *DCRedirectionHandlerImpl) RespondActivityTaskCanceledById( scope, startTime := handler.beforeCall(metrics.DCRedirectionRespondActivityTaskCanceledByIdScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -903,9 +955,11 @@ func (handler *DCRedirectionHandlerImpl) RespondActivityTaskCompleted( scope, startTime := handler.beforeCall(metrics.DCRedirectionRespondActivityTaskCompletedScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + token, err := handler.tokenSerializer.Deserialize(request.TaskToken) if err != nil { return resp, err @@ -942,9 +996,11 @@ func (handler *DCRedirectionHandlerImpl) RespondActivityTaskCompletedById( scope, startTime := handler.beforeCall(metrics.DCRedirectionRespondActivityTaskCompletedByIdScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -976,9 +1032,11 @@ func (handler *DCRedirectionHandlerImpl) RespondActivityTaskFailed( scope, startTime := handler.beforeCall(metrics.DCRedirectionRespondActivityTaskFailedScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + token, err := handler.tokenSerializer.Deserialize(request.TaskToken) if err != nil { return resp, err @@ -1015,9 +1073,11 @@ func (handler *DCRedirectionHandlerImpl) RespondActivityTaskFailedById( scope, startTime := handler.beforeCall(metrics.DCRedirectionRespondActivityTaskFailedByIdScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1049,9 +1109,11 @@ func (handler *DCRedirectionHandlerImpl) RespondWorkflowTaskCompleted( scope, startTime := handler.beforeCall(metrics.DCRedirectionRespondWorkflowTaskCompletedScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + token, err := handler.tokenSerializer.Deserialize(request.TaskToken) if err != nil { return nil, err @@ -1088,9 +1150,11 @@ func (handler *DCRedirectionHandlerImpl) RespondWorkflowTaskFailed( scope, startTime := handler.beforeCall(metrics.DCRedirectionRespondWorkflowTaskFailedScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + token, err := handler.tokenSerializer.Deserialize(request.TaskToken) if err != nil { return resp, err @@ -1127,9 +1191,11 @@ func (handler *DCRedirectionHandlerImpl) RespondQueryTaskCompleted( scope, startTime := handler.beforeCall(metrics.DCRedirectionRespondQueryTaskCompletedScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + token, err := handler.tokenSerializer.DeserializeQueryTaskToken(request.TaskToken) if err != nil { return resp, err @@ -1166,9 +1232,11 @@ func (handler *DCRedirectionHandlerImpl) SignalWithStartWorkflowExecution( scope, startTime := handler.beforeCall(metrics.DCRedirectionSignalWithStartWorkflowExecutionScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1200,9 +1268,11 @@ func (handler *DCRedirectionHandlerImpl) SignalWorkflowExecution( scope, startTime := handler.beforeCall(metrics.DCRedirectionSignalWorkflowExecutionScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1233,9 +1303,11 @@ func (handler *DCRedirectionHandlerImpl) StartWorkflowExecution( scope, startTime := handler.beforeCall(metrics.DCRedirectionStartWorkflowExecutionScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1267,9 +1339,11 @@ func (handler *DCRedirectionHandlerImpl) TerminateWorkflowExecution( scope, startTime := handler.beforeCall(metrics.DCRedirectionTerminateWorkflowExecutionScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1301,9 +1375,11 @@ func (handler *DCRedirectionHandlerImpl) DeleteWorkflowExecution( scope, startTime := handler.beforeCall(metrics.DCRedirectionDeleteWorkflowExecutionScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1335,9 +1411,11 @@ func (handler *DCRedirectionHandlerImpl) ListTaskQueuePartitions( scope, startTime := handler.beforeCall(metrics.DCRedirectionListTaskQueuePartitionsScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1384,9 +1462,11 @@ func (handler *DCRedirectionHandlerImpl) CreateSchedule( scope, startTime := handler.beforeCall(metrics.DCRedirectionCreateScheduleScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1417,9 +1497,11 @@ func (handler *DCRedirectionHandlerImpl) DescribeSchedule( scope, startTime := handler.beforeCall(metrics.DCRedirectionDescribeScheduleScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1450,9 +1532,11 @@ func (handler *DCRedirectionHandlerImpl) UpdateSchedule( scope, startTime := handler.beforeCall(metrics.DCRedirectionUpdateScheduleScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1483,9 +1567,11 @@ func (handler *DCRedirectionHandlerImpl) PatchSchedule( scope, startTime := handler.beforeCall(metrics.DCRedirectionPatchScheduleScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1516,9 +1602,11 @@ func (handler *DCRedirectionHandlerImpl) ListScheduleMatchingTimes( scope, startTime := handler.beforeCall(metrics.DCRedirectionListScheduleMatchingTimesScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1549,9 +1637,11 @@ func (handler *DCRedirectionHandlerImpl) DeleteSchedule( scope, startTime := handler.beforeCall(metrics.DCRedirectionDeleteScheduleScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1582,9 +1672,11 @@ func (handler *DCRedirectionHandlerImpl) ListSchedules( scope, startTime := handler.beforeCall(metrics.DCRedirectionListSchedulesScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1615,9 +1707,11 @@ func (handler *DCRedirectionHandlerImpl) UpdateWorkerBuildIdOrdering( scope, startTime := handler.beforeCall(metrics.DCRedirectionUpdateWorkerBuildIdOrderingScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC @@ -1648,9 +1742,11 @@ func (handler *DCRedirectionHandlerImpl) GetWorkerBuildIdOrdering( scope, startTime := handler.beforeCall(metrics.DCRedirectionGetWorkerBuildIdOrderingScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1682,9 +1778,11 @@ func (handler *DCRedirectionHandlerImpl) UpdateWorkflow( scope, startTime := handler.beforeCall(metrics.DCRedirectionUpdateWorkflowScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), "UpdateWorkflow", func(targetDC string) error { cluster = targetDC switch { @@ -1714,9 +1812,11 @@ func (handler *DCRedirectionHandlerImpl) StartBatchOperation( scope, startTime := handler.beforeCall(metrics.DCRedirectionStartBatchOperationScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1746,9 +1846,11 @@ func (handler *DCRedirectionHandlerImpl) StopBatchOperation( scope, startTime := handler.beforeCall(metrics.DCRedirectionStopBatchOperationScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1778,9 +1880,11 @@ func (handler *DCRedirectionHandlerImpl) DescribeBatchOperation( scope, startTime := handler.beforeCall(metrics.DCRedirectionDescribeBatchOperationScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1810,9 +1914,11 @@ func (handler *DCRedirectionHandlerImpl) ListBatchOperations( scope, startTime := handler.beforeCall(metrics.DCRedirectionListBatchOperationsScope) defer func() { - handler.afterCall(scope, startTime, cluster, &retError) + handler.afterCall(scope, startTime, cluster, retError) }() + defer log.CapturePanic(handler.logger, &retError) + err = handler.redirectionPolicy.WithNamespaceRedirect(ctx, namespace.Name(request.GetNamespace()), apiName, func(targetDC string) error { cluster = targetDC switch { @@ -1843,15 +1949,12 @@ func (handler *DCRedirectionHandlerImpl) afterCall( metricsHandler metrics.MetricsHandler, startTime time.Time, cluster string, - retError *error, + retError error, ) { - - log.CapturePanic(handler.logger, retError) - metricsHandler = metricsHandler.WithTags(metrics.TargetClusterTag(cluster)) metricsHandler.Counter(metrics.ClientRedirectionRequests.GetMetricName()).Record(1) metricsHandler.Timer(metrics.ClientRedirectionLatency.GetMetricName()).Record(handler.timeSource.Now().Sub(startTime)) - if *retError != nil { + if retError != nil { metricsHandler.Counter(metrics.ClientRedirectionFailures.GetMetricName()).Record(1) } }