Skip to content

Commit

Permalink
feat(cli): deployment progress shows stack name (#16604)
Browse files Browse the repository at this point in the history
Allows to filter logs based on stack name, gives more context
when looking at a log line in a log file.

Useful in CI when multiple stacks are deployed in a run.

(similar to lerna adding the package name)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jogold authored Oct 27, 2021
1 parent 354686b commit 322cf10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,9 @@ export class HistoryActivityPrinter extends ActivityPrinterBase {

this.stream.write(
util.format(
' %s%s | %s | %s | %s %s%s%s\n',
(progress !== false ? ` ${this.progress()} | ` : ''),
'%s | %s%s | %s | %s | %s %s%s%s\n',
e.StackName,
(progress !== false ? `${this.progress()} | ` : ''),
new Date(e.Timestamp).toLocaleTimeString(),
color(padRight(STATUS_WIDTH, (e.ResourceStatus || '').substr(0, STATUS_WIDTH))), // pad left and trim
padRight(this.props.resourceTypeColumnWidth, e.ResourceType || ''),
Expand Down
42 changes: 21 additions & 21 deletions packages/aws-cdk/test/api/stack-activity-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ test('prints 0/4 progress report, when addActivity is called with an "IN_PROGRES
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
});

expect(output[0].trim()).toStrictEqual(`0/4 | ${HUMAN_TIME} | ${reset('IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`);
expect(output[0].trim()).toStrictEqual(`stack-name | 0/4 | ${HUMAN_TIME} | ${reset('IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`);
});

test('prints 1/4 progress report, when addActivity is called with an "UPDATE_COMPLETE" ResourceStatus', () => {
Expand All @@ -51,12 +51,12 @@ test('prints 1/4 progress report, when addActivity is called with an "UPDATE_COM
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
});

expect(output[0].trim()).toStrictEqual(`1/4 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack1'))}`);
expect(output[0].trim()).toStrictEqual(`stack-name | 1/4 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack1'))}`);
});

test('prints 1/4 progress report, when addActivity is called with an "UPDATE_COMPLETE_CLEAN_IN_PROGRESS" ResourceStatus', () => {
Expand All @@ -75,12 +75,12 @@ test('prints 1/4 progress report, when addActivity is called with an "UPDATE_COM
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
});

expect(output[0].trim()).toStrictEqual(`1/4 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE_CLEA')} | AWS::CloudFormation::Stack | ${green(bold('stack1'))}`);
expect(output[0].trim()).toStrictEqual(`stack-name | 1/4 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE_CLEA')} | AWS::CloudFormation::Stack | ${green(bold('stack1'))}`);
});


Expand All @@ -100,12 +100,12 @@ test('prints 1/4 progress report, when addActivity is called with an "ROLLBACK_C
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
});

expect(output[0].trim()).toStrictEqual(`1/4 | ${HUMAN_TIME} | ${yellow('ROLLBACK_COMPLETE_CL')} | AWS::CloudFormation::Stack | ${yellow(bold('stack1'))}`);
expect(output[0].trim()).toStrictEqual(`stack-name | 1/4 | ${HUMAN_TIME} | ${yellow('ROLLBACK_COMPLETE_CL')} | AWS::CloudFormation::Stack | ${yellow(bold('stack1'))}`);
});

test('prints 0/4 progress report, when addActivity is called with an "UPDATE_FAILED" ResourceStatus', () => {
Expand All @@ -124,12 +124,12 @@ test('prints 0/4 progress report, when addActivity is called with an "UPDATE_FAI
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
});

expect(output[0].trim()).toStrictEqual(`0/4 | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))}`);
expect(output[0].trim()).toStrictEqual(`stack-name | 0/4 | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))}`);
});


Expand All @@ -149,7 +149,7 @@ test('does not print "Failed Resources:" list, when all deployments are successf
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
historyActivityPrinter.addActivity({
Expand All @@ -160,7 +160,7 @@ test('does not print "Failed Resources:" list, when all deployments are successf
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
historyActivityPrinter.addActivity({
Expand All @@ -171,16 +171,16 @@ test('does not print "Failed Resources:" list, when all deployments are successf
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
historyActivityPrinter.stop();
});

expect(output.length).toStrictEqual(3);
expect(output[0].trim()).toStrictEqual(`0/2 | ${HUMAN_TIME} | ${reset('IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`);
expect(output[1].trim()).toStrictEqual(`1/2 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack1'))}`);
expect(output[2].trim()).toStrictEqual(`2/2 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack2'))}`);
expect(output[0].trim()).toStrictEqual(`stack-name | 0/2 | ${HUMAN_TIME} | ${reset('IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`);
expect(output[1].trim()).toStrictEqual(`stack-name | 1/2 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack1'))}`);
expect(output[2].trim()).toStrictEqual(`stack-name | 2/2 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack2'))}`);
});

test('prints "Failed Resources:" list, when at least one deployment fails', () => {
Expand All @@ -199,7 +199,7 @@ test('prints "Failed Resources:" list, when at least one deployment fails', () =
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
historyActivityPrinter.addActivity({
Expand All @@ -210,15 +210,15 @@ test('prints "Failed Resources:" list, when at least one deployment fails', () =
ResourceType: 'AWS::CloudFormation::Stack',
StackId: '',
EventId: '',
StackName: '',
StackName: 'stack-name',
},
});
historyActivityPrinter.stop();
});

expect(output.length).toStrictEqual(4);
expect(output[0].trim()).toStrictEqual(`0/2 | ${HUMAN_TIME} | ${reset('IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`);
expect(output[1].trim()).toStrictEqual(`0/2 | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))}`);
expect(output[0].trim()).toStrictEqual(`stack-name | 0/2 | ${HUMAN_TIME} | ${reset('IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`);
expect(output[1].trim()).toStrictEqual(`stack-name | 0/2 | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))}`);
expect(output[2].trim()).toStrictEqual('Failed resources:');
expect(output[3].trim()).toStrictEqual(`${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))}`);
expect(output[3].trim()).toStrictEqual(`stack-name | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))}`);
});

0 comments on commit 322cf10

Please sign in to comment.