-
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 all 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
24 changes: 24 additions & 0 deletions
24
...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,24 @@ | ||
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 userContextFile = path.join(fixture.integTestDir, 'cdk.json'); | ||
try { | ||
// default status is enabled | ||
const output1 = await fixture.cdk(['cli-telemetry', '--status']); | ||
expect(output1).toContain('CLI Telemetry is enabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to disable.'); | ||
|
||
// disable status | ||
await fs.writeFile(userContextFile, JSON.stringify({ context: { 'cli-telemetry': false } })); | ||
const output2 = await fixture.cdk(['cli-telemetry', '--status']); | ||
expect(output2).toContain('CLI Telemetry is disabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to enable.'); | ||
} finally { | ||
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 { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Run code with additional environment variables | ||
*/ | ||
export async function withEnv(block: () => Promise<any>, env: Record<string, string | undefined> = {}) { | ||
const originalEnv = process.env; | ||
try { | ||
process.env = { | ||
...originalEnv, | ||
...env, | ||
}; | ||
|
||
return await block(); | ||
} finally { | ||
process.env = originalEnv; | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
import { Context } from '../../../lib/api/context'; | ||
import { canCollectTelemetry } from '../../../lib/cli/telemetry/collect-telemetry'; | ||
import { withEnv } from '../../_helpers/with-env'; | ||
|
||
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 () => { | ||
await withEnv(async () => { | ||
expect(canCollectTelemetry(context)).toBeTruthy(); | ||
}, { | ||
DISABLE_CLI_TELEMETRY: 'true', | ||
}); | ||
}); | ||
|
||
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
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.
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.
@iliapolo I pulled out this function from #631 and removed our own feature flag
CLI_TELEMETRY=true
because it misrepresents whether our users have enabled/disabled telemetry.