-
Notifications
You must be signed in to change notification settings - Fork 35
feat(cli): cli-telemetry status command #697
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
base: main
Are you sure you want to change the base?
Conversation
/** | ||
* Whether or not we collect telemetry | ||
*/ | ||
export function canCollectTelemetry(context: Context): boolean { |
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.
Signed-off-by: github-actions <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #697 +/- ##
==========================================
- Coverage 80.13% 80.06% -0.07%
==========================================
Files 49 50 +1
Lines 7358 7383 +25
Branches 827 828 +1
==========================================
+ Hits 5896 5911 +15
- Misses 1439 1453 +14
+ Partials 23 19 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
.../cli-integ/tests/cli-integ-tests/cli-telemetry/cdk-cli-telemetry-reports-status.integtest.ts
Outdated
Show resolved
Hide resolved
.../cli-integ/tests/cli-integ-tests/cli-telemetry/cdk-cli-telemetry-reports-status.integtest.ts
Outdated
Show resolved
Hide resolved
integTest( | ||
'CLI Telemetry reports status', | ||
withDefaultFixture(async (fixture) => { | ||
const contextFile = path.join(fixture.integTestDir, 'cdk.context.json'); |
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.
What is the impact of this file on the test?
### `cdk cli-telemetry` | ||
|
||
Enables or disables cli telemetry collection for your local CDK App. Records your | ||
choice in `cdk.context.json`. |
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.
Can I also set it manually in the context
property of cdk.json
on the project level?
|
||
You can also check the current status on whether your CDK App is opted in or out of | ||
cli telemetry collection. Note that this takes into account all methods of disabling | ||
cli telemetry, including environment variables and preferences set globally in `~/.cdk.json`. |
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.
And context
in <app-root>/cdk.json
?
@@ -206,6 +207,15 @@ export class CdkToolkit { | |||
await this.props.configuration.saveContext(); | |||
} | |||
|
|||
public async cliTelemetryStatus() { | |||
const currentStatus = canCollectTelemetry(this.props.configuration.context); |
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.
const currentStatus = canCollectTelemetry(this.props.configuration.context); | |
const canCollect = canCollectTelemetry(this.props.configuration.context); |
Makes the next if
easier to read.
public async cliTelemetryStatus() { | ||
const currentStatus = canCollectTelemetry(this.props.configuration.context); | ||
if (currentStatus) { | ||
await this.ioHost.asIoHelper().defaults.info('CLI Telemetry is enabled. Run \'cdk cli-telemetry --disable\' to disable for this CDK App.'); |
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.
Maybe link to the README so that the user is also exposed to the other mechanisms?
}); | ||
|
||
test('returns false if env variable is set', async () => { | ||
process.env.DISABLE_CLI_TELEMETRY = 'true'; |
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.
Should be in a finally block that reverts back to the original value (see if we already have a withEnv
or something).
|
||
// THEN | ||
expect(info).toHaveBeenCalledWith('CLI Telemetry is disabled. Run \'cdk cli-telemetry --enable\' to enable for this CDK App.'); | ||
process.env.CDK_CLI_DISABLE_TELEMETRY = CDK_CLI_DISABLE_TELEMETRY; |
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.
Put in finally
cdk cli-telemetry --status
command that reports whether cli telemetry is enabled/disabled.canCollectTelemetry
command + tests out of feat(cli): send telemetry events to local file #631cli-telemetry
to the readmeBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license