-
Notifications
You must be signed in to change notification settings - Fork 4k
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
chore(cli): use CliIoHost as logger everywhere #32708
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #32708 +/- ##
==========================================
- Coverage 81.41% 81.40% -0.01%
==========================================
Files 223 223
Lines 13721 13727 +6
Branches 2416 2411 -5
==========================================
+ Hits 11171 11175 +4
- Misses 2271 2274 +3
+ Partials 279 278 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -108,105 +46,239 @@ export async function withCorkedLogging<T>(block: () => Promise<T>): Promise<T> | |||
} finally { | |||
CORK_COUNTER--; | |||
if (CORK_COUNTER === 0) { | |||
logBuffer.forEach(([stream, str]) => stream.write(str + '\n')); | |||
// Process each buffered message through notify | |||
for (const ioMessage of logBuffer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backlog item for Corking. Because Corking is global and we cannot have that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/aws-cdk/lib/os.ts
Outdated
@@ -23,7 +23,7 @@ export async function shell(command: string[]): Promise<string> { | |||
|
|||
// Both write to stdout and collect | |||
child.stdout.on('data', chunk => { | |||
process.stdout.write(chunk); | |||
data(chunk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this probably no good. This used to just print chunks and now we are formatting chunks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now revert and make backlog item to deal with this.
Only used in cdk init
apparently to do some setting up of Dotnet apps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this line indiscriminately wrote data chunks from the child process into the output stream. These chunks are probably strings, although technically they can be a buffer.
The chunk then gets passed through formatMessageAndLog
and log
, to end up on ioHost.notify
.
While this is probably safe, the logging helpers as written may or may not format chunks. Going forward, we should have a more explicit API for data chunks.
The problem is not with code calling data
but with the eventually called functions no explicitly being aware of the possibility of not to be formatted chunks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just to be defensive about unintentional changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | ||
* The current action being performed by the CLI. 'none' represents the absence of an action. | ||
*/ | ||
export type IoAction = 'synth' | 'list' | 'deploy' | 'destroy' | 'none'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export type IoAction = 'synth' | 'list' | 'deploy' | 'destroy' | 'none'; | |
export type ToolkitAction = 'synth' | 'list' | 'deploy' | 'destroy' | 'none'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { flatten } from '../../util'; | ||
import * as chalk from '../../util/cdk-chalk'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems we've previously made the decision to import from ../../util
(i.e. import from an index.ts
file in the util
folder). you are now doing something different for cdk-chalk. i am not opinionated on which way we do this, but i think it is important to be consistent, unless you have a compelling reason not to be.
maybe it means that cdk-chalk
doesn't belong in util
at all?
the resolution to this comment is either turning it into import { chalk, flatten} from '../../util'
, or moving chalk
out of util
, or providing a reason why it makes sense to import twice from ../../util
in this file.
import { flatten } from '../../util/arrays'; | ||
import * as chalk from '../../util/cdk-chalk'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh... it annoys me that we can import flatten
multiple ways, from ../../utill/arrays
and ../../util
. Maybe the solution is to remove util/index.ts
because that seems irrelevant. maybe i do this in a separate PR...
cd9d1ee
to
c9bc8ad
Compare
…ge-code-validation
### Reason for this change Instead of running regexp at runtime, we validate message codes at compile time ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
➡️ PR build request submitted to A maintainer must now check the pipeline and add the |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Related to #32346
Reason for this change
Capture all logs across the CLI as IoMessages so that when we allow customers to use the CDK Core functionality programmatically, these logs are delivered to the customers as messages and now just swallowed across the CLI.
Description of changes
Prevented access to
log()
andformatLogMessage()
. Now the only ways to log something properly are either through the exported log functions (which is how everyone was doing it anyway), or throughCliIoHost.notify()
directly.CliIoHost is now exposed as a global singleton which is currently only directly exclusively used in
logging.ts
but is effectively used everywhere as all logging functions inevitably callCliIoHost.notify()
All logging functions now optionally support the following input types
and everything is now translated into an
IoMessage
and callsCliIoHost.notify()
from these logging functions. Nothing currently specifies any message code so it's all the generic _0000, _1000, _2000Description of how you validated changes
added and updated unit tests
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license