Skip to content

Commit

Permalink
Make id length dynamic config per domain (cadence-workflow#3705)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjdawson2016 authored Oct 30, 2020
1 parent b9485f8 commit d47b0d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions service/frontend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
68 changes: 34 additions & 34 deletions service/frontend/workflowHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -1717,15 +1717,15 @@ 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)
}

if startRequest.GetWorkflowId() == "" {
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)
}

Expand All @@ -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
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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)...)
}

Expand All @@ -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)...)
}

Expand Down Expand Up @@ -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)...)
}

Expand All @@ -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)...)
}

Expand All @@ -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)...)
}

Expand All @@ -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)...)
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit d47b0d1

Please sign in to comment.