Skip to content

Commit

Permalink
Merge pull request #365 from Clever/INFRANG-5595
Browse files Browse the repository at this point in the history
add tags for state machines created by embedded wfm
  • Loading branch information
tnsardesai authored Sep 18, 2023
2 parents 6ebeed7 + d1fb14d commit ca8abfd
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 36 deletions.
2 changes: 1 addition & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Orchestrator for AWS Step Functions


### Version information
*Version* : 0.16.0
*Version* : 0.16.1


### URI scheme
Expand Down
10 changes: 10 additions & 0 deletions embedded/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/Clever/workflow-manager/gen-go/client"
"github.com/Clever/workflow-manager/gen-go/models"
"github.com/Clever/workflow-manager/resources"
"github.com/Clever/workflow-manager/util"
)

// Embedded ...
Expand Down Expand Up @@ -395,6 +396,8 @@ func (e *Embedded) StartWorkflow(ctx context.Context, i *models.StartWorkflowReq
return nil, errors.Errorf("json marshal: %s", err.Error())
}

tags := sfnconventions.StateMachineTags(i.Namespace, wd.Name, wd.Version, wd.StateMachine.StartAt, util.ToTagMap(wd.DefaultTags))

// find or create the state machine in AWS
stateMachineName := sfnconventions.StateMachineName(wd.Name, wd.Version, i.Namespace, wd.StateMachine.StartAt)
stateMachineArn := sfnconventions.StateMachineArn(e.sfnRegion, e.sfnAccountID, wd.Name, wd.Version, i.Namespace, wd.StateMachine.StartAt)
Expand All @@ -408,6 +411,7 @@ func (e *Embedded) StartWorkflow(ctx context.Context, i *models.StartWorkflowReq
Name: aws.String(stateMachineName),
Definition: aws.String(string(stateMachineDefBytes)),
RoleArn: aws.String(e.sfnRoleArn),
Tags: util.ToSFNTags(tags),
}); err != nil {
return nil, errors.Errorf("CreateStateMachine error: %s", err.Error())
}
Expand All @@ -425,6 +429,12 @@ func (e *Embedded) StartWorkflow(ctx context.Context, i *models.StartWorkflowReq
// Control for "Executions started immediately after calling UpdateStateMachine might use the previous state machine definition and roleArn."
// https://docs.aws.amazon.com/step-functions/latest/dg/concepts-read-consistency.html
time.Sleep(5 * time.Second)
if _, err := e.sfnAPI.TagResource(&sfn.TagResourceInput{
ResourceArn: out.StateMachineArn,
Tags: util.ToSFNTags(tags),
}); err != nil {
return nil, errors.Errorf("TagResource: %s", err.Error())
}
} else {
// if it exists, verify they're the same--if not, it's user error:
// state machines are immutable, user should create a workflow def with
Expand Down
27 changes: 3 additions & 24 deletions executor/workflow_manager_sfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/Clever/workflow-manager/gen-go/models"
"github.com/Clever/workflow-manager/resources"
"github.com/Clever/workflow-manager/store"
"github.com/Clever/workflow-manager/util"
"github.com/Clever/workflow-manager/wfupdater"
)

Expand Down Expand Up @@ -158,17 +159,6 @@ func stateMachineWithDefaultRetriers(oldSM models.SLStateMachine) *models.SLStat
return &sm
}

func toTagMap(wdTags map[string]interface{}) map[string]string {
tags := map[string]string{}
for k, v := range wdTags {
vs, ok := v.(string)
if ok {
tags[k] = vs
}
}
return tags
}

func toCWLogGroupTags(tags map[string]string) map[string]*string {
cwlogsTags := map[string]*string{}
for k, v := range tags {
Expand All @@ -177,17 +167,6 @@ func toCWLogGroupTags(tags map[string]string) map[string]*string {
return cwlogsTags
}

func toSFNTags(tags map[string]string) []*sfn.Tag {
sfnTags := []*sfn.Tag{}
for k, v := range tags {
sfnTags = append(sfnTags, &sfn.Tag{
Key: aws.String(k),
Value: aws.String(v),
})
}
return sfnTags
}

func loggingConfiguration(logGroupARN string) *sfn.LoggingConfiguration {
return &sfn.LoggingConfiguration{
Destinations: []*sfn.LogDestination{{
Expand Down Expand Up @@ -260,7 +239,7 @@ func (wm *SFNWorkflowManager) describeOrCreateStateMachine(ctx context.Context,
// the name must be unique. Use workflow definition name + version + namespace + queue to uniquely identify a state machine
// this effectively creates a new workflow definition in each namespace we deploy into
awsStateMachineName := sfnconventions.StateMachineName(wd.Name, wd.Version, namespace, wd.StateMachine.StartAt)
tags := sfnconventions.StateMachineTags(namespace, wd.Name, wd.Version, wd.StateMachine.StartAt, toTagMap(wd.DefaultTags))
tags := sfnconventions.StateMachineTags(namespace, wd.Name, wd.Version, wd.StateMachine.StartAt, util.ToTagMap(wd.DefaultTags))
describeOutput, err := wm.sfnapi.DescribeStateMachineWithContext(ctx,
&sfn.DescribeStateMachineInput{
StateMachineArn: aws.String(sfnconventions.StateMachineArn(wm.region, wm.accountID, wd.Name, wd.Version, namespace, wd.StateMachine.StartAt)),
Expand Down Expand Up @@ -319,7 +298,7 @@ func (wm *SFNWorkflowManager) describeOrCreateStateMachine(ctx context.Context,
Definition: aws.String(awsStateMachineDef),
RoleArn: aws.String(wm.roleARN),
LoggingConfiguration: lc,
Tags: toSFNTags(tags),
Tags: util.ToSFNTags(tags),
})
if err != nil {
return nil, fmt.Errorf("CreateStateMachine error: %s", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion gen-go/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = strconv.FormatInt
var _ = bytes.Compare

// Version of the client.
const Version = "0.16.0"
const Version = "0.16.1"

// VersionHeader is sent with every request.
const VersionHeader = "X-Client-Version"
Expand Down
2 changes: 1 addition & 1 deletion gen-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2288,7 +2288,7 @@ module.exports.Errors = Errors;

module.exports.DefaultCircuitOptions = defaultCircuitOptions;

const version = "0.16.0";
const version = "0.16.1";
const versionHeader = "X-Client-Version";
module.exports.Version = version;
module.exports.VersionHeader = versionHeader;
2 changes: 1 addition & 1 deletion gen-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workflow-manager",
"version": "0.16.0",
"version": "0.16.1",
"description": "Orchestrator for AWS Step Functions",
"main": "index.js",
"dependencies": {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.16.0
version: 0.16.1
x-npm-package: workflow-manager
schemes:
- http
Expand Down
28 changes: 28 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package util

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sfn"
)

func ToTagMap(wdTags map[string]interface{}) map[string]string {
tags := map[string]string{}
for k, v := range wdTags {
vs, ok := v.(string)
if ok {
tags[k] = vs
}
}
return tags
}

func ToSFNTags(tags map[string]string) []*sfn.Tag {
sfnTags := []*sfn.Tag{}
for k, v := range tags {
sfnTags = append(sfnTags, &sfn.Tag{
Key: aws.String(k),
Value: aws.String(v),
})
}
return sfnTags
}

0 comments on commit ca8abfd

Please sign in to comment.