Skip to content

Commit 188cde1

Browse files
0x2b3bfa0Domas Monkus
andauthored
Enhance telemetry data and exclude tensorboard tracebacks (#1172)
* Enrich analytics with container information and options * Add reminder * Avoid stack trace leak on Tensorboard * Make the code self-mindblowing * Pin `is-docker` in `package.json` 🙀 * Update tests * Fix double `.options` * Simplify container * Fix tests, again * Simplify telemetry options * Fix tests, again * Restore name/full differentiation * Revert telemetryData * Fix legacy commands * Surely not meant to be here * Apply suggestions from code review Co-authored-by: Domas Monkus <domas@iterative.ai> * Unpack yargs in function body * fixup! Unpack yargs in function body * Add a Helpful Comment™ * Fix merge * Apply suggestions from code review Co-authored-by: Domas Monkus <domas@iterative.ai>
1 parent c1ec211 commit 188cde1

File tree

17 files changed

+124
-31
lines changed

17 files changed

+124
-31
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ WORKDIR ${CML_RUNNER_PATH}
116116
# SET SPECIFIC ENVIRONMENT VARIABLES
117117
ENV IN_DOCKER=1
118118
ENV RUNNER_ALLOW_RUNASROOT=1
119+
# Environment variable used by cml to detect it's been installed using the docker image.
120+
ENV _CML_CONTAINER_IMAGE=true
119121

120122
# DEFINE ENTRY POINT AND COMMAND
121123
# Smart entrypoint understands commands like `bash` or `/bin/sh` but defaults to `cml`;

bin/cml.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const setupOpts = (opts) => {
4848

4949
const { markdownfile } = opts;
5050
opts.markdownFile = markdownfile;
51-
opts.cmlCommand = opts._[0];
5251
opts.cml = new CML(opts);
5352
};
5453

@@ -76,9 +75,29 @@ const setupLogger = (opts) => {
7675
});
7776
};
7877

79-
const setupTelemetry = async (opts) => {
80-
const { cml, cmlCommand: action } = opts;
81-
opts.telemetryEvent = await jitsuEventPayload({ action, cml });
78+
const setupTelemetry = async (opts, yargs) => {
79+
const { cml, _: command } = opts;
80+
81+
const options = {};
82+
for (const [name, option] of Object.entries(opts.options)) {
83+
// Skip options with default values (i.e. not explicitly set by users)
84+
if (opts[name] && !yargs.parsed.defaulted[name]) {
85+
switch (option.telemetryData) {
86+
case 'name':
87+
options[name] = null;
88+
break;
89+
case 'full':
90+
options[name] = opts[name];
91+
break;
92+
}
93+
}
94+
}
95+
96+
opts.telemetryEvent = await jitsuEventPayload({
97+
action: command.join(':'),
98+
extra: { options },
99+
cml
100+
});
82101
};
83102

84103
const runPlugin = async ({ $0: executable, command }) => {
@@ -99,6 +118,7 @@ const handleError = (message, error) => {
99118

100119
(async () => {
101120
setupLogger({ log: 'debug' });
121+
102122
try {
103123
await yargs
104124
.env('CML')

bin/cml/asset/publish.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ exports.handler = async (opts) => {
2323
else await fs.writeFile(file, output);
2424
};
2525

26-
exports.builder = (yargs) => yargs.env('CML_ASSET').options(exports.options);
26+
exports.builder = (yargs) =>
27+
yargs
28+
.env('CML_ASSET')
29+
.option('options', { default: exports.options, hidden: true })
30+
.options(exports.options);
2731

2832
exports.options = kebabcaseKeys({
2933
url: {
@@ -51,7 +55,8 @@ exports.options = kebabcaseKeys({
5155
},
5256
rmWatermark: {
5357
type: 'boolean',
54-
description: 'Avoid CML watermark.'
58+
description: 'Avoid CML watermark.',
59+
telemetryData: 'name'
5560
},
5661
mimeType: {
5762
type: 'string',

bin/cml/check/create.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ exports.handler = async (opts) => {
1010
await cml.checkCreate({ ...opts, report });
1111
};
1212

13-
exports.builder = (yargs) => yargs.env('CML_CHECK').options(exports.options);
13+
exports.builder = (yargs) =>
14+
yargs
15+
.env('CML_CHECK')
16+
.option('options', { default: exports.options, hidden: true })
17+
.options(exports.options);
1418

1519
exports.options = kebabcaseKeys({
1620
token: {

bin/cml/comment/create.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ exports.handler = async (opts) => {
88
console.log(await cml.commentCreate(opts));
99
};
1010

11-
exports.builder = (yargs) => yargs.env('CML_COMMENT').options(exports.options);
11+
exports.builder = (yargs) =>
12+
yargs
13+
.env('CML_COMMENT')
14+
.option('options', { default: exports.options, hidden: true })
15+
.options(exports.options);
1216

1317
exports.options = kebabcaseKeys({
1418
pr: {
@@ -30,7 +34,8 @@ exports.options = kebabcaseKeys({
3034
publishUrl: {
3135
type: 'string',
3236
default: 'https://asset.cml.dev',
33-
description: 'Self-hosted image server URL'
37+
description: 'Self-hosted image server URL',
38+
telemetryData: 'name'
3439
},
3540
watch: {
3641
type: 'boolean',
@@ -44,7 +49,8 @@ exports.options = kebabcaseKeys({
4449
native: {
4550
type: 'boolean',
4651
description:
47-
"Uses driver's native capabilities to upload assets instead of CML's storage; not available on GitHub"
52+
"Uses driver's native capabilities to upload assets instead of CML's storage; not available on GitHub",
53+
telemetryData: 'name'
4854
},
4955
update: {
5056
type: 'boolean',
@@ -55,6 +61,7 @@ exports.options = kebabcaseKeys({
5561
rmWatermark: {
5662
type: 'boolean',
5763
description:
58-
'Avoid watermark; CML needs a watermark to be able to distinguish CML comments from others'
64+
'Avoid watermark; CML needs a watermark to be able to distinguish CML comments from others',
65+
telemetryData: 'name'
5966
}
6067
});

bin/cml/pr.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ exports.builder = (yargs) =>
1616
])
1717
)
1818
)
19+
.option('options', { default: options, hidden: true })
1920
.check(({ globpath }) => globpath)
2021
.strict();

bin/cml/pr/create.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ exports.handler = async (opts) => {
1515
console.log(link);
1616
};
1717

18-
exports.builder = (yargs) => yargs.env('CML_PR').options(exports.options);
18+
exports.builder = (yargs) =>
19+
yargs
20+
.env('CML_PR')
21+
.option('options', { default: exports.options, hidden: true })
22+
.options(exports.options);
1923

2024
exports.options = kebabcaseKeys({
2125
md: {

bin/cml/repo/prepare.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ exports.handler = async (opts) => {
1010
await cml.ci(opts);
1111
};
1212

13-
exports.builder = (yargs) => yargs.env('CML_REPO').options(exports.options);
13+
exports.builder = (yargs) =>
14+
yargs
15+
.env('CML_REPO')
16+
.option('options', { default: exports.options, hidden: true })
17+
.options(exports.options);
1418

1519
exports.options = kebabcaseKeys({
1620
unshallow: {

bin/cml/runner.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ exports.builder = (yargs) =>
1616
])
1717
)
1818
)
19+
.option('options', { default: options, hidden: true })
1920
.check(() => process.argv.some((arg) => arg.startsWith('-')))
2021
.strict();

bin/cml/runner/launch.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,11 @@ exports.handler = async (opts) => {
418418
}
419419
};
420420

421-
exports.builder = (yargs) => yargs.env('CML_RUNNER').options(exports.options);
421+
exports.builder = (yargs) =>
422+
yargs
423+
.env('CML_RUNNER')
424+
.option('options', { default: exports.options, hidden: true })
425+
.options(exports.options);
422426

423427
exports.options = kebabcaseKeys({
424428
labels: {
@@ -454,13 +458,15 @@ exports.options = kebabcaseKeys({
454458
type: 'boolean',
455459
conflicts: ['single', 'reuseIdle'],
456460
description:
457-
"Don't launch a new runner if an existing one has the same name or overlapping labels"
461+
"Don't launch a new runner if an existing one has the same name or overlapping labels",
462+
telemetryData: 'name'
458463
},
459464
reuseIdle: {
460465
type: 'boolean',
461466
conflicts: ['reuse', 'single'],
462467
description:
463-
"Creates a new runner only if the matching labels don't exist or are already busy"
468+
"Creates a new runner only if the matching labels don't exist or are already busy",
469+
telemetryData: 'name'
464470
},
465471
workdir: {
466472
type: 'string',
@@ -476,7 +482,8 @@ exports.options = kebabcaseKeys({
476482
cloud: {
477483
type: 'string',
478484
choices: ['aws', 'azure', 'gcp', 'kubernetes'],
479-
description: 'Cloud to deploy the runner'
485+
description: 'Cloud to deploy the runner',
486+
telemetryData: 'full'
480487
},
481488
cloudRegion: {
482489
type: 'string',
@@ -529,12 +536,14 @@ exports.options = kebabcaseKeys({
529536
type: 'number',
530537
default: -1,
531538
description:
532-
'Maximum spot instance bidding price in USD. Defaults to the current spot bidding price'
539+
'Maximum spot instance bidding price in USD. Defaults to the current spot bidding price',
540+
telemetryData: 'name'
533541
},
534542
cloudStartupScript: {
535543
type: 'string',
536544
description:
537-
'Run the provided Base64-encoded Linux shell script during the instance initialization'
545+
'Run the provided Base64-encoded Linux shell script during the instance initialization',
546+
telemetryData: 'name'
538547
},
539548
cloudAwsSecurityGroup: {
540549
type: 'string',

0 commit comments

Comments
 (0)