-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add dynamic config to toggle standalone activity functionality #8796
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,14 +10,15 @@ import ( | |
| "go.temporal.io/api/workflowservice/v1" | ||
| "go.temporal.io/server/chasm/lib/activity/gen/activitypb/v1" | ||
| "go.temporal.io/server/common" | ||
| "go.temporal.io/server/common/dynamicconfig" | ||
| "go.temporal.io/server/common/log" | ||
| "go.temporal.io/server/common/metrics" | ||
| "go.temporal.io/server/common/namespace" | ||
| "go.temporal.io/server/common/searchattribute" | ||
| "google.golang.org/protobuf/types/known/durationpb" | ||
| ) | ||
|
|
||
| const StandaloneActivityDisabledError = "Standalone activity is disabled" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I would just repeat the string instead of adding a layer of indirection. You're not getting much from this constant.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just keep the message in one place to keep it consistent. |
||
|
|
||
| type FrontendHandler interface { | ||
| StartActivityExecution(ctx context.Context, req *workflowservice.StartActivityExecutionRequest) (*workflowservice.StartActivityExecutionResponse, error) | ||
| DescribeActivityExecution(ctx context.Context, req *workflowservice.DescribeActivityExecutionRequest) (*workflowservice.DescribeActivityExecutionResponse, error) | ||
|
|
@@ -27,12 +28,13 @@ type FrontendHandler interface { | |
| ListActivityExecutions(context.Context, *workflowservice.ListActivityExecutionsRequest) (*workflowservice.ListActivityExecutionsResponse, error) | ||
| RequestCancelActivityExecution(context.Context, *workflowservice.RequestCancelActivityExecutionRequest) (*workflowservice.RequestCancelActivityExecutionResponse, error) | ||
| TerminateActivityExecution(context.Context, *workflowservice.TerminateActivityExecutionRequest) (*workflowservice.TerminateActivityExecutionResponse, error) | ||
| IsStandaloneActivityEnabled(namespaceName string) bool | ||
| } | ||
|
|
||
| type frontendHandler struct { | ||
| FrontendHandler | ||
| client activitypb.ActivityServiceClient | ||
| dc *dynamicconfig.Collection | ||
| config *Config | ||
| logger log.Logger | ||
| metricsHandler metrics.Handler | ||
| namespaceRegistry namespace.Registry | ||
|
|
@@ -43,7 +45,7 @@ type frontendHandler struct { | |
| // NewFrontendHandler creates a new FrontendHandler instance for processing activity frontend requests. | ||
| func NewFrontendHandler( | ||
| client activitypb.ActivityServiceClient, | ||
| dc *dynamicconfig.Collection, | ||
| config *Config, | ||
| logger log.Logger, | ||
| metricsHandler metrics.Handler, | ||
| namespaceRegistry namespace.Registry, | ||
|
|
@@ -52,7 +54,7 @@ func NewFrontendHandler( | |
| ) FrontendHandler { | ||
| return &frontendHandler{ | ||
| client: client, | ||
| dc: dc, | ||
| config: config, | ||
| logger: logger, | ||
| metricsHandler: metricsHandler, | ||
| namespaceRegistry: namespaceRegistry, | ||
|
|
@@ -61,6 +63,11 @@ func NewFrontendHandler( | |
| } | ||
| } | ||
|
|
||
| // IsStandaloneActivityEnabled checks if standalone activities are enabled for the given namespace | ||
| func (h *frontendHandler) IsStandaloneActivityEnabled(namespaceName string) bool { | ||
| return h.config.Enabled(namespaceName) | ||
| } | ||
|
|
||
| // StartActivityExecution initiates a standalone activity execution in the specified namespace. | ||
| // It validates the request, resolves the namespace ID, applies default configurations, | ||
| // and forwards the request to the activity service handler. | ||
|
|
@@ -71,6 +78,10 @@ func NewFrontendHandler( | |
| // before mutation to preserve the original for retries. | ||
| // 3. Sends the request to the history activity service. | ||
| func (h *frontendHandler) StartActivityExecution(ctx context.Context, req *workflowservice.StartActivityExecutionRequest) (*workflowservice.StartActivityExecutionResponse, error) { | ||
| if !h.config.Enabled(req.GetNamespace()) { | ||
fretz12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return nil, serviceerror.NewUnavailable(StandaloneActivityDisabledError) | ||
| } | ||
|
|
||
| namespaceID, err := h.namespaceRegistry.GetNamespaceID(namespace.Name(req.GetNamespace())) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -95,9 +106,13 @@ func (h *frontendHandler) DescribeActivityExecution( | |
| ctx context.Context, | ||
| req *workflowservice.DescribeActivityExecutionRequest, | ||
| ) (*workflowservice.DescribeActivityExecutionResponse, error) { | ||
| if !h.config.Enabled(req.GetNamespace()) { | ||
| return nil, serviceerror.NewUnavailable(StandaloneActivityDisabledError) | ||
| } | ||
|
|
||
| err := ValidateDescribeActivityExecutionRequest( | ||
| req, | ||
| dynamicconfig.MaxIDLengthLimit.Get(h.dc)(), | ||
| h.config.MaxIDLengthLimit(), | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -120,9 +135,13 @@ func (h *frontendHandler) GetActivityExecutionOutcome( | |
| ctx context.Context, | ||
| req *workflowservice.GetActivityExecutionOutcomeRequest, | ||
| ) (*workflowservice.GetActivityExecutionOutcomeResponse, error) { | ||
| if !h.config.Enabled(req.GetNamespace()) { | ||
| return nil, serviceerror.NewUnavailable(StandaloneActivityDisabledError) | ||
| } | ||
|
|
||
| err := ValidateGetActivityExecutionOutcomeRequest( | ||
| req, | ||
| dynamicconfig.MaxIDLengthLimit.Get(h.dc)(), | ||
| h.config.MaxIDLengthLimit(), | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -143,6 +162,10 @@ func (h *frontendHandler) TerminateActivityExecution( | |
| ctx context.Context, | ||
| req *workflowservice.TerminateActivityExecutionRequest, | ||
| ) (*workflowservice.TerminateActivityExecutionResponse, error) { | ||
| if !h.config.Enabled(req.GetNamespace()) { | ||
| return nil, serviceerror.NewUnavailable(StandaloneActivityDisabledError) | ||
| } | ||
|
|
||
| namespaceName := req.GetNamespace() | ||
| namespaceID, err := h.namespaceRegistry.GetNamespaceID(namespace.Name(namespaceName)) | ||
| if err != nil { | ||
|
|
@@ -152,8 +175,8 @@ func (h *frontendHandler) TerminateActivityExecution( | |
| if err := validateInputSize( | ||
| req.GetActivityId(), | ||
| "activity-termination", | ||
| dynamicconfig.BlobSizeLimitError.Get(h.dc), | ||
| dynamicconfig.BlobSizeLimitWarn.Get(h.dc), | ||
| h.config.BlobSizeLimitError, | ||
| h.config.BlobSizeLimitWarn, | ||
| len(req.GetReason()), | ||
| h.logger, | ||
| namespaceName); err != nil { | ||
|
|
@@ -177,6 +200,10 @@ func (h *frontendHandler) RequestCancelActivityExecution( | |
| ctx context.Context, | ||
| req *workflowservice.RequestCancelActivityExecutionRequest, | ||
| ) (*workflowservice.RequestCancelActivityExecutionResponse, error) { | ||
| if !h.config.Enabled(req.GetNamespace()) { | ||
| return nil, serviceerror.NewUnavailable(StandaloneActivityDisabledError) | ||
| } | ||
|
|
||
| namespaceID, err := h.namespaceRegistry.GetNamespaceID(namespace.Name(req.GetNamespace())) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -185,7 +212,7 @@ func (h *frontendHandler) RequestCancelActivityExecution( | |
| // Since validation potentially mutates the request, we clone it first so that any retries use the original request. | ||
| req = common.CloneProto(req) | ||
|
|
||
| maxIDLen := dynamicconfig.MaxIDLengthLimit.Get(h.dc)() | ||
| maxIDLen := h.config.MaxIDLengthLimit() | ||
|
|
||
| if len(req.GetRequestId()) > maxIDLen { | ||
| return nil, serviceerror.NewInvalidArgument("RequestID length exceeds limit.") | ||
|
|
@@ -226,8 +253,8 @@ func (h *frontendHandler) validateAndPopulateStartRequest( | |
| err := ValidateAndNormalizeActivityAttributes( | ||
| req.ActivityId, | ||
| activityType, | ||
| dynamicconfig.DefaultActivityRetryPolicy.Get(h.dc), | ||
| dynamicconfig.MaxIDLengthLimit.Get(h.dc)(), | ||
| h.config.DefaultActivityRetryPolicy, | ||
| h.config.MaxIDLengthLimit(), | ||
| namespaceID, | ||
| opts, | ||
| req.Priority, | ||
|
|
@@ -240,10 +267,10 @@ func (h *frontendHandler) validateAndPopulateStartRequest( | |
|
|
||
| err = validateAndNormalizeStartActivityExecutionRequest( | ||
| req, | ||
| dynamicconfig.BlobSizeLimitError.Get(h.dc), | ||
| dynamicconfig.BlobSizeLimitWarn.Get(h.dc), | ||
| h.config.BlobSizeLimitError, | ||
| h.config.BlobSizeLimitWarn, | ||
| h.logger, | ||
| dynamicconfig.MaxIDLengthLimit.Get(h.dc)(), | ||
| h.config.MaxIDLengthLimit(), | ||
| h.saValidator) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.