Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): stack monitor uses io-host #150

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

mrgrain
Copy link
Contributor

@mrgrain mrgrain commented Feb 25, 2025

Provides stack events to the IoHost in a structured way.

The main change here is that StackActivityMonitor does not directly talk to the ActivityPrinter anymore. Instead messages are emitted to the IoHost. This caused two related changes:

  • Progress tracking has been split into a more generic StackProgressMonitor and progress information is now provided directly by the StackActivityMonitor
  • Originally we only had a single timer that covered polling events and printing them. With the split, we now have two separate timers: one for polling events and a separate one for updating the view

Removed low-level options:

  • progress -> now a CliIoHost property
  • ci -> use value from CliIoHost directly instead of passing through all the layers
  • quiet -> surprisingly this was unused by CLI. We should have something like this again, but can be implemented in a follow up PR.

Manually tested the changes in addition to integ tests.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@mrgrain mrgrain force-pushed the mrgrain/refactor/io-host-stack-monitor branch from f4fecad to e8b93d8 Compare February 26, 2025 14:43
@codecov-commenter
Copy link

codecov-commenter commented Feb 26, 2025

Codecov Report

Attention: Patch coverage is 73.03719% with 261 lines in your changes missing coverage. Please review.

Project coverage is 84.46%. Comparing base (97d02a8) to head (79285c2).

Files with missing lines Patch % Lines
...ckages/aws-cdk/lib/cli/activity-printer/current.ts 27.43% 119 Missing ⚠️
...ckages/aws-cdk/lib/cli/activity-printer/history.ts 66.20% 47 Missing and 2 partials ⚠️
packages/aws-cdk/lib/toolkit/cli-io-host.ts 74.19% 24 Missing ⚠️
...cdk/lib/api/stack-events/stack-activity-monitor.ts 87.22% 22 Missing and 1 partial ⚠️
packages/aws-cdk/lib/cli/activity-printer/base.ts 86.36% 21 Missing ⚠️
...ckages/aws-cdk/lib/api/deployments/deploy-stack.ts 59.09% 9 Missing ⚠️
packages/aws-cdk/lib/cli/cdk-toolkit.ts 11.11% 8 Missing ⚠️
...cdk/lib/api/stack-events/stack-progress-monitor.ts 95.34% 6 Missing ⚠️
...ackages/aws-cdk/lib/api/deployments/deployments.ts 91.66% 1 Missing ⚠️
packages/aws-cdk/lib/util/cloudformation.ts 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #150      +/-   ##
==========================================
- Coverage   84.79%   84.46%   -0.34%     
==========================================
  Files         198      204       +6     
  Lines       35400    35646     +246     
  Branches     4573     4563      -10     
==========================================
+ Hits        30019    30108      +89     
- Misses       5235     5393     +158     
+ Partials      146      145       -1     
Flag Coverage Δ
suite.unit 84.46% <73.03%> (-0.34%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mrgrain mrgrain force-pushed the mrgrain/refactor/io-host-stack-monitor branch from e8b93d8 to 97a7ca5 Compare February 26, 2025 15:02
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to stack-activity-monitor.test.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had multiple versions of this. Consolidating to one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulling these out into a shared file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now only a CLI concern (not toolkit anymore)

@mrgrain mrgrain force-pushed the mrgrain/refactor/io-host-stack-monitor branch from aaf99a7 to a0fcbbd Compare February 27, 2025 11:24
Comment on lines -286 to -295
function padRight(n: number, x: string): string {
return x + ' '.repeat(Math.max(0, n - x.length));
}

/**
* Infamous padLeft()
*/
function padLeft(n: number, x: string): string {
return ' '.repeat(Math.max(0, n - x.length)) + x;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to util/string-manipulation.ts

Comment on lines -297 to -307
function calcMaxResourceTypeLength(template: any) {
const resources = (template && template.Resources) || {};
let maxWidth = 0;
for (const id of Object.keys(resources)) {
const type = resources[id].Type || '';
if (type.length > maxWidth) {
maxWidth = type.length;
}
}
return maxWidth;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to util/cloudformation.ts

return maxWidth;
}

interface PrinterProps {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest of this file moved to various files in cli/activity-printer but also got refactored a lot

@mrgrain mrgrain marked this pull request as ready for review February 27, 2025 11:47
@mrgrain mrgrain disabled auto-merge February 27, 2025 11:48
@mrgrain mrgrain force-pushed the mrgrain/refactor/io-host-stack-monitor branch from a0fcbbd to 1b28383 Compare February 27, 2025 12:34
code: 'CDK_TOOLKIT_I5502',
description: 'Stack Monitoring Activity event',
level: 'info',
interface: 'StackActivity',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have our own copy of this type? I'm not comfortable exposing other people's types as part of our API.

Also if we make our own copy of the type, we'll have the ability to add fields if we feel that's convenient, and we can simplify and omit fields that aren't necessary for our current implementation.

Copy link
Contributor Author

@mrgrain mrgrain Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is our own copy of StackActivity.

However its event property is typed as @aws-sdk/client-cloudformation.StackEvent. I'm inclined to pass this on as is, since the CFN API is well defined und unlikely to change badly or even at all.

@mrgrain mrgrain force-pushed the mrgrain/refactor/io-host-stack-monitor branch from 1b28383 to 56a8ee3 Compare February 27, 2025 13:47
@mrgrain mrgrain force-pushed the mrgrain/refactor/io-host-stack-monitor branch from 94f39a2 to 1a42d87 Compare February 27, 2025 14:31
@mrgrain mrgrain force-pushed the mrgrain/refactor/io-host-stack-monitor branch from 1a42d87 to 79285c2 Compare February 27, 2025 15:54
@mrgrain mrgrain enabled auto-merge February 27, 2025 15:54
@mrgrain mrgrain added this pull request to the merge queue Feb 27, 2025
Merged via the queue into main with commit 0d9912f Feb 27, 2025
20 checks passed
@mrgrain mrgrain deleted the mrgrain/refactor/io-host-stack-monitor branch February 27, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants