From cb4e06ec36f5c9e885e660dc02718b2f45807312 Mon Sep 17 00:00:00 2001 From: Sayan Samanta Date: Wed, 9 Oct 2019 19:11:55 -0700 Subject: [PATCH 1/2] 0.11.1 Allow adding an ID suffix for embedded workflow-manager Currently we re-use the state machine name, which doesn't give us very descriptive underlying execution names. For example: https://us-west-1.console.aws.amazon.com/states/home?region=us-west-1#/statemachines/view/arn:aws:states:us-west-1:589690932525:stateMachine:production--pod-canary-confirm-deploy---1--Start Instead, let's allow the client to add a human readable suffix --- embedded/embedded.go | 26 +++++++++++++++++++------- swagger.yml | 5 ++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/embedded/embedded.go b/embedded/embedded.go index 47b38700..0fa76bc7 100644 --- a/embedded/embedded.go +++ b/embedded/embedded.go @@ -394,7 +394,7 @@ New state machine: } workflow := &models.Workflow{ WorkflowSummary: models.WorkflowSummary{ - ID: workflowID(stateMachineName), + ID: workflowID(stateMachineName, i.IDSuffix), CreatedAt: strfmt.DateTime(time.Now()), LastUpdated: strfmt.DateTime(time.Now()), WorkflowDefinition: wd, @@ -507,13 +507,25 @@ func (e *Embedded) NewWorkflowDefinition(ctx context.Context, i *models.NewWorkf // The workflow ID will contain the state machine name. // This is to support the implementation of `GetWorkflowByID`, which requires // the state machine name in order to call `DescribeExecution` in the SFN API. -func workflowID(smName string) string { - return fmt.Sprintf("%s--%s", smName, shortUUID()) +// It will append a suffix, trimming the length to abide the 80 character step functions limit +// https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html +// If a suffix isn't provided the generated ID will include the first 8 characters of a UUID +func workflowID(smName, suffix string) string { + if suffix == "" { + suffix = shortUUID() + } + id := fmt.Sprintf("%s--%s", smName, suffix) + + // ensure the generated ID is within the 80 character limit + if len(id) > 80 { + return id[:80] + } + return id } type workflowIDParts struct { - SMName string - ShortUUID string + SMName string + Suffix string } func parseWorkflowID(wid string) (*workflowIDParts, error) { @@ -522,8 +534,8 @@ func parseWorkflowID(wid string) (*workflowIDParts, error) { return nil, errors.Errorf("expected workflowID two contain at least two parts: %s", wid) } return &workflowIDParts{ - SMName: strings.Join(s[0:len(s)-1], "--"), - ShortUUID: s[len(s)-1], + SMName: strings.Join(s[0:len(s)-1], "--"), + Suffix: s[len(s)-1], }, nil } diff --git a/swagger.yml b/swagger.yml index 903743fe..773fc9a0 100644 --- a/swagger.yml +++ b/swagger.yml @@ -4,7 +4,7 @@ info: description: Orchestrator for AWS Step Functions # when changing the version here, make sure to # re-run `make generate` to generate clients and server - version: 0.11.0 + version: 0.11.1 x-npm-package: workflow-manager schemes: - http @@ -592,6 +592,9 @@ definitions: description: "tags: object with key-value pairs; keys and values should be strings" additionalProperties: type: object + idSuffix: + description: "idSuffix is exclusively used for embedded workflow-manager to append human readable information to the newly created workflow's ID. Workflow IDs are truncated to 80 characters, so some or all of the suffix may be lost" + type: string WorkflowDefinitionRef: type: object From 921176b1579a5637035b2e0a754d14cab0e0a7bb Mon Sep 17 00:00:00 2001 From: Sayan Samanta Date: Wed, 9 Oct 2019 19:43:16 -0700 Subject: [PATCH 2/2] 0.11.1 - gen files --- docs/definitions.md | 13 +++++++------ docs/overview.md | 2 +- gen-go/models/start_workflow_request.go | 3 +++ gen-go/server/router.go | 1 + gen-js/index.d.ts | 2 ++ gen-js/index.js | 8 ++++---- gen-js/package.json | 2 +- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/definitions.md b/docs/definitions.md index 79bca9fb..41fb3c54 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -219,12 +219,13 @@ ### StartWorkflowRequest -|Name|Schema| -|---|---| -|**input**
*optional*|string| -|**namespace**
*optional*|string| -|**queue**
*optional*|string| -|**workflowDefinition**
*optional*|[WorkflowDefinitionRef](#workflowdefinitionref)| +|Name|Description|Schema| +|---|---|---| +|**idSuffix**
*optional*|idSuffix is exclusively used for embedded workflow-manager to append human readable information to the newly created workflow's ID. Workflow IDs are truncated to 80 characters, so some or all of the suffix may be lost|string| +|**input**
*optional*||string| +|**namespace**
*optional*||string| +|**queue**
*optional*||string| +|**workflowDefinition**
*optional*||[WorkflowDefinitionRef](#workflowdefinitionref)| diff --git a/docs/overview.md b/docs/overview.md index 192f8645..2be10d76 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -7,7 +7,7 @@ Orchestrator for AWS Step Functions ### Version information -*Version* : 0.11.0 +*Version* : 0.11.1 ### URI scheme diff --git a/gen-go/models/start_workflow_request.go b/gen-go/models/start_workflow_request.go index a0843d4a..106574f9 100644 --- a/gen-go/models/start_workflow_request.go +++ b/gen-go/models/start_workflow_request.go @@ -16,6 +16,9 @@ import ( // swagger:model StartWorkflowRequest type StartWorkflowRequest struct { + // idSuffix is exclusively used for embedded workflow-manager to append human readable information to the newly created workflow's ID. Workflow IDs are truncated to 80 characters, so some or all of the suffix may be lost + IDSuffix string `json:"idSuffix,omitempty"` + // input Input string `json:"input,omitempty"` diff --git a/gen-go/server/router.go b/gen-go/server/router.go index 3922b2ad..63c4dd2d 100644 --- a/gen-go/server/router.go +++ b/gen-go/server/router.go @@ -97,6 +97,7 @@ func (s *Server) Serve() error { opentracing.Tag{Key: "deploy_env", Value: os.Getenv("_DEPLOY_ENV")}, opentracing.Tag{Key: "team_owner", Value: os.Getenv("_TEAM_OWNER")}, opentracing.Tag{Key: "pod_id", Value: os.Getenv("_POD_ID")}, + opentracing.Tag{Key: "pod_shortname", Value: os.Getenv("_POD_SHORTNAME")}, opentracing.Tag{Key: "pod_account", Value: os.Getenv("_POD_ACCOUNT")}, opentracing.Tag{Key: "pod_region", Value: os.Getenv("_POD_REGION")}, }, diff --git a/gen-js/index.d.ts b/gen-js/index.d.ts index a5defbd1..867cf110 100644 --- a/gen-js/index.d.ts +++ b/gen-js/index.d.ts @@ -36,6 +36,7 @@ interface GenericOptions { logger?: Logger; tracer?: Tracer; circuit?: CircuitOptions; + serviceName?: string; } interface DiscoveryOptions { @@ -232,6 +233,7 @@ type SLStateMachine = { type SLStateType = ("Pass" | "Task" | "Choice" | "Wait" | "Succeed" | "Fail" | "Parallel"); type StartWorkflowRequest = { + idSuffix?: string; input?: string; namespace?: string; queue?: string; diff --git a/gen-js/index.js b/gen-js/index.js index 58410a8d..84e9432d 100644 --- a/gen-js/index.js +++ b/gen-js/index.js @@ -168,9 +168,9 @@ class WorkflowManager { if (options.discovery) { try { - this.address = discovery("workflow-manager", "http").url(); + this.address = discovery(options.serviceName || "workflow-manager", "http").url(); } catch (e) { - this.address = discovery("workflow-manager", "default").url(); + this.address = discovery(options.serviceName || "workflow-manager", "default").url(); } } else if (options.address) { this.address = options.address; @@ -193,7 +193,7 @@ class WorkflowManager { if (options.logger) { this.logger = options.logger; } else { - this.logger = new kayvee.logger("workflow-manager-wagclient"); + this.logger = new kayvee.logger((options.serviceName || "workflow-manager") + "-wagclient"); } if (options.tracer) { this.tracer = options.tracer; @@ -202,7 +202,7 @@ class WorkflowManager { } const circuitOptions = Object.assign({}, defaultCircuitOptions, options.circuit); - this._hystrixCommand = commandFactory.getOrCreate("workflow-manager"). + this._hystrixCommand = commandFactory.getOrCreate(options.serviceName || "workflow-manager"). errorHandler(this._hystrixCommandErrorHandler). circuitBreakerForceClosed(circuitOptions.forceClosed). requestVolumeRejectionThreshold(circuitOptions.maxConcurrentRequests). diff --git a/gen-js/package.json b/gen-js/package.json index b8253b15..bd67ad46 100644 --- a/gen-js/package.json +++ b/gen-js/package.json @@ -1,6 +1,6 @@ { "name": "workflow-manager", - "version": "0.11.0", + "version": "0.11.1", "description": "Orchestrator for AWS Step Functions", "main": "index.js", "dependencies": {