From d47b0d18e3aece8babbc3350de76ad39370f1ca4 Mon Sep 17 00:00:00 2001 From: Andrew Dawson Date: Fri, 30 Oct 2020 11:16:40 -0700 Subject: [PATCH] Make id length dynamic config per domain (#3705) --- service/frontend/service.go | 4 +- service/frontend/workflowHandler.go | 68 ++++++++++++++--------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/service/frontend/service.go b/service/frontend/service.go index 19786fa3e84..a0925298cc3 100644 --- a/service/frontend/service.go +++ b/service/frontend/service.go @@ -56,7 +56,7 @@ type Config struct { RPS dynamicconfig.IntPropertyFn MaxDomainRPSPerInstance dynamicconfig.IntPropertyFnWithDomainFilter GlobalDomainRPS dynamicconfig.IntPropertyFnWithDomainFilter - MaxIDLengthLimit dynamicconfig.IntPropertyFn + MaxIDLengthLimit dynamicconfig.IntPropertyFnWithDomainFilter MaxIDLengthWarnLimit dynamicconfig.IntPropertyFn EnableClientVersionCheck dynamicconfig.BoolPropertyFn DisallowQuery dynamicconfig.BoolPropertyFnWithDomainFilter @@ -111,7 +111,7 @@ func NewConfig(dc *dynamicconfig.Collection, numHistoryShards int, enableReadFro RPS: dc.GetIntProperty(dynamicconfig.FrontendRPS, 1200), MaxDomainRPSPerInstance: dc.GetIntPropertyFilteredByDomain(dynamicconfig.FrontendMaxDomainRPSPerInstance, 1200), GlobalDomainRPS: dc.GetIntPropertyFilteredByDomain(dynamicconfig.FrontendGlobalDomainRPS, 0), - MaxIDLengthLimit: dc.GetIntProperty(dynamicconfig.MaxIDLengthLimit, 1000), + MaxIDLengthLimit: dc.GetIntPropertyFilteredByDomain(dynamicconfig.MaxIDLengthLimit, 1000), MaxIDLengthWarnLimit: dc.GetIntProperty(dynamicconfig.MaxIDLengthWarnLimit, 150), HistoryMgrNumConns: dc.GetIntProperty(dynamicconfig.FrontendHistoryMgrNumConns, 10), EnableAdminProtection: dc.GetBoolProperty(dynamicconfig.EnableAdminProtection, false), diff --git a/service/frontend/workflowHandler.go b/service/frontend/workflowHandler.go index 89903714457..3db8db8e762 100644 --- a/service/frontend/workflowHandler.go +++ b/service/frontend/workflowHandler.go @@ -447,14 +447,14 @@ func (wh *WorkflowHandler) PollForActivityTask( return nil, wh.error(errDomainNotSet, scope) } - if !wh.validIDLength(pollRequest.GetDomain(), scope) { + if !wh.validIDLength(pollRequest.GetDomain(), scope, pollRequest.GetDomain()) { return nil, wh.error(errDomainTooLong, scope) } - if err := wh.validateTaskList(pollRequest.TaskList, scope); err != nil { + if err := wh.validateTaskList(pollRequest.TaskList, scope, pollRequest.GetDomain()); err != nil { return nil, err } - if !wh.validIDLength(pollRequest.GetIdentity(), scope) { + if !wh.validIDLength(pollRequest.GetIdentity(), scope, pollRequest.GetDomain()) { return nil, wh.error(errIdentityTooLong, scope) } @@ -531,15 +531,15 @@ func (wh *WorkflowHandler) PollForDecisionTask( if pollRequest.Domain == nil || pollRequest.GetDomain() == "" { return nil, wh.error(errDomainNotSet, scope, tagsForErrorLog...) } - if !wh.validIDLength(pollRequest.GetDomain(), scope) { + if !wh.validIDLength(pollRequest.GetDomain(), scope, pollRequest.GetDomain()) { return nil, wh.error(errDomainTooLong, scope, tagsForErrorLog...) } - if !wh.validIDLength(pollRequest.GetIdentity(), scope) { + if !wh.validIDLength(pollRequest.GetIdentity(), scope, pollRequest.GetDomain()) { return nil, wh.error(errIdentityTooLong, scope, tagsForErrorLog...) } - if err := wh.validateTaskList(pollRequest.TaskList, scope); err != nil { + if err := wh.validateTaskList(pollRequest.TaskList, scope, pollRequest.GetDomain()); err != nil { return nil, err } @@ -874,7 +874,7 @@ func (wh *WorkflowHandler) RespondActivityTaskCompleted( if err != nil { return wh.error(err, scope) } - if !wh.validIDLength(completeRequest.GetIdentity(), scope) { + if !wh.validIDLength(completeRequest.GetIdentity(), scope, domainEntry.GetInfo().Name) { return wh.error(errIdentityTooLong, scope) } @@ -974,7 +974,7 @@ func (wh *WorkflowHandler) RespondActivityTaskCompletedByID( return wh.error(errActivityIDNotSet, scope) } - if !wh.validIDLength(completeRequest.GetIdentity(), scope) { + if !wh.validIDLength(completeRequest.GetIdentity(), scope, completeRequest.GetDomain()) { return wh.error(errIdentityTooLong, scope) } @@ -1092,7 +1092,7 @@ func (wh *WorkflowHandler) RespondActivityTaskFailed( return errShuttingDown } - if !wh.validIDLength(failedRequest.GetIdentity(), scope) { + if !wh.validIDLength(failedRequest.GetIdentity(), scope, domainEntry.GetInfo().Name) { return wh.error(errIdentityTooLong, scope) } @@ -1167,7 +1167,7 @@ func (wh *WorkflowHandler) RespondActivityTaskFailedByID( if activityID == "" { return wh.error(errActivityIDNotSet, scope) } - if !wh.validIDLength(failedRequest.GetIdentity(), scope) { + if !wh.validIDLength(failedRequest.GetIdentity(), scope, failedRequest.GetDomain()) { return wh.error(errIdentityTooLong, scope) } @@ -1274,7 +1274,7 @@ func (wh *WorkflowHandler) RespondActivityTaskCanceled( return errShuttingDown } - if !wh.validIDLength(cancelRequest.GetIdentity(), scope) { + if !wh.validIDLength(cancelRequest.GetIdentity(), scope, domainEntry.GetInfo().Name) { return wh.error(errIdentityTooLong, scope) } @@ -1361,7 +1361,7 @@ func (wh *WorkflowHandler) RespondActivityTaskCanceledByID( if activityID == "" { return wh.error(errActivityIDNotSet, scope) } - if !wh.validIDLength(cancelRequest.GetIdentity(), scope) { + if !wh.validIDLength(cancelRequest.GetIdentity(), scope, cancelRequest.GetDomain()) { return wh.error(errIdentityTooLong, scope) } @@ -1487,7 +1487,7 @@ func (wh *WorkflowHandler) RespondDecisionTaskCompleted( return nil, wh.error(err, scope) } - if !wh.validIDLength(completeRequest.GetIdentity(), scope) { + if !wh.validIDLength(completeRequest.GetIdentity(), scope, domainEntry.GetInfo().Name) { return nil, wh.error(errIdentityTooLong, scope) } @@ -1565,7 +1565,7 @@ func (wh *WorkflowHandler) RespondDecisionTaskFailed( return errShuttingDown } - if !wh.validIDLength(failedRequest.GetIdentity(), scope) { + if !wh.validIDLength(failedRequest.GetIdentity(), scope, domainEntry.GetInfo().Name) { return wh.error(errIdentityTooLong, scope) } @@ -1717,7 +1717,7 @@ func (wh *WorkflowHandler) StartWorkflowExecution( return nil, wh.error(errDomainNotSet, scope) } - if !wh.validIDLength(domainName, scope) { + if !wh.validIDLength(domainName, scope, domainName) { return nil, wh.error(errDomainTooLong, scope) } @@ -1725,7 +1725,7 @@ func (wh *WorkflowHandler) StartWorkflowExecution( return nil, wh.error(errWorkflowIDNotSet, scope) } - if !wh.validIDLength(startRequest.GetWorkflowId(), scope) { + if !wh.validIDLength(startRequest.GetWorkflowId(), scope, domainName) { return nil, wh.error(errWorkflowIDTooLong, scope) } @@ -1745,11 +1745,11 @@ func (wh *WorkflowHandler) StartWorkflowExecution( return nil, wh.error(errWorkflowTypeNotSet, scope) } - if !wh.validIDLength(startRequest.WorkflowType.GetName(), scope) { + if !wh.validIDLength(startRequest.WorkflowType.GetName(), scope, domainName) { return nil, wh.error(errWorkflowTypeTooLong, scope) } - if err := wh.validateTaskList(startRequest.TaskList, scope); err != nil { + if err := wh.validateTaskList(startRequest.TaskList, scope, domainName); err != nil { return nil, err } @@ -1765,7 +1765,7 @@ func (wh *WorkflowHandler) StartWorkflowExecution( return nil, wh.error(errRequestIDNotSet, scope) } - if !wh.validIDLength(startRequest.GetRequestId(), scope) { + if !wh.validIDLength(startRequest.GetRequestId(), scope, domainName) { return nil, wh.error(errRequestIDTooLong, scope) } @@ -2087,7 +2087,7 @@ func (wh *WorkflowHandler) SignalWorkflowExecution( return wh.error(errDomainNotSet, scope, getWfIDRunIDTags(wfExecution)...) } - if !wh.validIDLength(signalRequest.GetDomain(), scope) { + if !wh.validIDLength(signalRequest.GetDomain(), scope, signalRequest.GetDomain()) { return wh.error(errDomainTooLong, scope, getWfIDRunIDTags(wfExecution)...) } @@ -2100,11 +2100,11 @@ func (wh *WorkflowHandler) SignalWorkflowExecution( scope, getWfIDRunIDTags(wfExecution)...) } - if !wh.validIDLength(signalRequest.GetSignalName(), scope) { + if !wh.validIDLength(signalRequest.GetSignalName(), scope, signalRequest.GetDomain()) { return wh.error(errSignalNameTooLong, scope, getWfIDRunIDTags(wfExecution)...) } - if !wh.validIDLength(signalRequest.GetRequestId(), scope) { + if !wh.validIDLength(signalRequest.GetRequestId(), scope, signalRequest.GetDomain()) { return wh.error(errRequestIDTooLong, scope, getWfIDRunIDTags(wfExecution)...) } @@ -2179,7 +2179,7 @@ func (wh *WorkflowHandler) SignalWithStartWorkflowExecution( return nil, wh.error(errDomainNotSet, scope, getWfIDRunIDTags(wfExecution)...) } - if !wh.validIDLength(domainName, scope) { + if !wh.validIDLength(domainName, scope, domainName) { return nil, wh.error(errDomainTooLong, scope, getWfIDRunIDTags(wfExecution)...) } @@ -2188,7 +2188,7 @@ func (wh *WorkflowHandler) SignalWithStartWorkflowExecution( scope, getWfIDRunIDTags(wfExecution)...) } - if !wh.validIDLength(signalWithStartRequest.GetWorkflowId(), scope) { + if !wh.validIDLength(signalWithStartRequest.GetWorkflowId(), scope, domainName) { return nil, wh.error(errWorkflowIDTooLong, scope, getWfIDRunIDTags(wfExecution)...) } @@ -2197,7 +2197,7 @@ func (wh *WorkflowHandler) SignalWithStartWorkflowExecution( scope, getWfIDRunIDTags(wfExecution)...) } - if !wh.validIDLength(signalWithStartRequest.GetSignalName(), scope) { + if !wh.validIDLength(signalWithStartRequest.GetSignalName(), scope, domainName) { return nil, wh.error(errSignalNameTooLong, scope, getWfIDRunIDTags(wfExecution)...) } @@ -2206,15 +2206,15 @@ func (wh *WorkflowHandler) SignalWithStartWorkflowExecution( scope, getWfIDRunIDTags(wfExecution)...) } - if !wh.validIDLength(signalWithStartRequest.WorkflowType.GetName(), scope) { + if !wh.validIDLength(signalWithStartRequest.WorkflowType.GetName(), scope, domainName) { return nil, wh.error(errWorkflowTypeTooLong, scope, getWfIDRunIDTags(wfExecution)...) } - if err := wh.validateTaskList(signalWithStartRequest.TaskList, scope); err != nil { + if err := wh.validateTaskList(signalWithStartRequest.TaskList, scope, domainName); err != nil { return nil, err } - if !wh.validIDLength(signalWithStartRequest.GetRequestId(), scope) { + if !wh.validIDLength(signalWithStartRequest.GetRequestId(), scope, domainName) { return nil, wh.error(errRequestIDTooLong, scope, getWfIDRunIDTags(wfExecution)...) } @@ -3215,7 +3215,7 @@ func (wh *WorkflowHandler) DescribeTaskList( return nil, wh.error(err, scope) } - if err := wh.validateTaskList(request.TaskList, scope); err != nil { + if err := wh.validateTaskList(request.TaskList, scope, request.GetDomain()); err != nil { return nil, err } @@ -3260,7 +3260,7 @@ func (wh *WorkflowHandler) ListTaskListPartitions( return nil, wh.error(errDomainNotSet, scope) } - if err := wh.validateTaskList(request.TaskList, scope); err != nil { + if err := wh.validateTaskList(request.TaskList, scope, request.GetDomain()); err != nil { return nil, err } @@ -3510,11 +3510,11 @@ func (wh *WorkflowHandler) validateTaskListType(t *gen.TaskListType, scope metri return nil } -func (wh *WorkflowHandler) validateTaskList(t *gen.TaskList, scope metrics.Scope) error { +func (wh *WorkflowHandler) validateTaskList(t *gen.TaskList, scope metrics.Scope, domain string) error { if t == nil || t.Name == nil || t.GetName() == "" { return wh.error(errTaskListNotSet, scope) } - if !wh.validIDLength(t.GetName(), scope) { + if !wh.validIDLength(t.GetName(), scope, domain) { return wh.error(errTaskListTooLong, scope) } return nil @@ -3858,8 +3858,8 @@ func (wh *WorkflowHandler) getArchivedHistory( }, nil } -func (wh *WorkflowHandler) validIDLength(id string, scope metrics.Scope) bool { - valid := len(id) <= wh.config.MaxIDLengthLimit() +func (wh *WorkflowHandler) validIDLength(id string, scope metrics.Scope, domain string) bool { + valid := len(id) <= wh.config.MaxIDLengthLimit(domain) if len(id) > wh.config.MaxIDLengthWarnLimit() { scope.IncCounter(metrics.CadenceErrIDLengthExceededWarnLimit) }