-
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
Open
kaizencc
wants to merge
14
commits into
main
Choose a base branch
from
conroy/telemetry-status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
09bfaf8
feat(cli): cli-telemetry status command
kaizencc dc20dcc
add readme for cli-telemetry command
kaizencc 4b7a6c2
add collect telemetry
kaizencc 0059d1b
add collect-tleemetry
kaizencc f959644
Update packages/aws-cdk/README.md
kaizencc db89333
chore: self mutation
invalid-email-address 750b548
Apply suggestions from code review
kaizencc e40dd08
Merge branch 'main' into conroy/telemetry-status
kaizencc 26561be
Merge branch 'main' into conroy/telemetry-status
kaizencc 106ce2d
fix from merge
kaizencc 60356b7
pr feedback
kaizencc 29cff30
update tests
kaizencc e63f3e0
Merge branch 'main' into conroy/telemetry-status
kaizencc 66a93ea
await
kaizencc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...i-integ/tests/cli-integ-tests/cli-telemetry/cdk-cli-telemetry-reports-status.integtest.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { promises as fs } from 'fs'; | ||
import * as path from 'path'; | ||
import { integTest, withDefaultFixture } from '../../../lib'; | ||
|
||
jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime | ||
|
||
integTest( | ||
'CLI Telemetry reports status', | ||
withDefaultFixture(async (fixture) => { | ||
const contextFile = path.join(fixture.integTestDir, 'cdk.context.json'); | ||
const userContextFile = path.join(fixture.integTestDir, 'cdk.json'); | ||
const context = { | ||
existedBefore: 'this was here', | ||
}; | ||
await fs.writeFile( | ||
contextFile, | ||
JSON.stringify(context), | ||
); | ||
try { | ||
// default status is enabled | ||
const output1 = await fixture.cdk(['cli-telemetry', '--status']); | ||
expect(output1).toContain('Telemetry is enabled. Run \'cdk cli-telemetry --disable\' to disable.'); | ||
kaizencc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// disable status | ||
await fs.writeFile(userContextFile, JSON.stringify({ context: { 'cli-telemetry': false }})); | ||
const output2 = await fixture.cdk(['cli-telemetry', '--status']); | ||
expect(output2).toContain('Telemetry is disabled. Run \'cdk cli-telemetry --enable\' to enable.'); | ||
kaizencc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} finally { | ||
await fs.unlink(contextFile); | ||
await fs.unlink(userContextFile); | ||
} | ||
}), | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { Context } from '../../api/context'; | ||
|
||
/** | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if ((['true', '1'].includes(process.env.CDK_CLI_DISABLE_TELEMETRY ?? '')) || ['false', false].includes(context.get('cli-telemetry'))) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/aws-cdk/test/cli/telemetry/collect-telemetry.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Context } from '../../../lib/api/context'; | ||
import { canCollectTelemetry } from '../../../lib/cli/telemetry/collect-telemetry'; | ||
|
||
describe(canCollectTelemetry, () => { | ||
let context: Context; | ||
|
||
beforeEach(() => { | ||
context = new Context(); | ||
}); | ||
|
||
test('returns true by default', async () => { | ||
expect(canCollectTelemetry(context)).toBeTruthy(); | ||
}); | ||
|
||
test('returns false if env variable is set', async () => { | ||
process.env.DISABLE_CLI_TELEMETRY = 'true'; | ||
kaizencc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(canCollectTelemetry(context)).toBeTruthy(); | ||
}); | ||
|
||
test('returns false if context is set to false', async () => { | ||
context.set('cli-telemetry', false); | ||
expect(canCollectTelemetry(context)).toBeFalsy(); | ||
|
||
context.set('cli-telemetry', 'false'); | ||
expect(canCollectTelemetry(context)).toBeFalsy(); | ||
}); | ||
|
||
test('returns true if context is set to true', async () => { | ||
context.set('cli-telemetry', true); | ||
expect(canCollectTelemetry(context)).toBeTruthy(); | ||
|
||
context.set('cli-telemetry', 'true'); | ||
expect(canCollectTelemetry(context)).toBeTruthy(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.