Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { integTest, withDefaultFixture } from '../../../lib';

jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime

integTest(
'sending cli telemetry to file fails if not invoked with --unstable',
withDefaultFixture(async (fixture) => {
const telemetryFile = path.join(fixture.integTestDir, `telemetry-${Date.now()}.json`);
try {
await fixture.cdk(['list', `--telemetry-file=${telemetryFile}`]);
throw new Error('Expected command to fail');
} catch (error) {
expect(fs.existsSync(telemetryFile)).toBeFalsy();
expect(fixture.output.toString()).toContain('Unstable feature use');
}
}),
);
8 changes: 4 additions & 4 deletions packages/aws-cdk/lib/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
caBundlePath: configuration.settings.get(['caBundlePath']),
});

if (argv['telemetry-file'] && !configuration.settings.get(['unstable']).includes('telemetry')) {
throw new ToolkitError('Unstable feature use: \'telemetry-file\' is unstable. It must be opted in via \'--unstable\', e.g. \'cdk deploy --unstable=telemetry --telemetry-file=my/file/path\'');
}

try {
await ioHost.startTelemetry(argv, configuration.context);
} catch (e: any) {
Expand Down Expand Up @@ -209,10 +213,6 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
throw new ToolkitError('You must either specify a list of Stacks or the `--all` argument');
}

if (args['telemetry-file'] && !configuration.settings.get(['unstable']).includes('telemetry')) {
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 too late in the process because telemetry has already been initialized, and the error thrown is then considered as a telemetry event.

We should really structure the unstable protection mechanism better.

throw new ToolkitError('Unstable feature use: \'telemetry-file\' is unstable. It must be opted in via \'--unstable\', e.g. \'cdk deploy --unstable=telemetry --telemetry-file=my/file/path\'');
}

args.STACKS = args.STACKS ?? (args.STACK ? [args.STACK] : []);
args.ENVIRONMENTS = args.ENVIRONMENTS ?? [];

Expand Down
Loading