Skip to content
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

optional telemetry #1092

Merged
merged 41 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f6ed7bf
Telemetry
DavidGOrtega Jul 9, 2022
d97b0c1
appdirs
DavidGOrtega Jul 9, 2022
ec6b5e3
analytics tested
DavidGOrtega Jul 10, 2022
4e9ac5d
remove analytics
DavidGOrtega Jul 10, 2022
e569c3b
deterministic check
DavidGOrtega Jul 10, 2022
f53673e
remove fake code
DavidGOrtega Jul 10, 2022
e74eda2
fix isCI
DavidGOrtega Jul 10, 2022
e71fec8
cml
DavidGOrtega Jul 10, 2022
271fd5c
integrated
DavidGOrtega Jul 11, 2022
052f68d
endpoint
DavidGOrtega Jul 12, 2022
cef1830
defensive
DavidGOrtega Jul 12, 2022
0b8790c
json spec
DavidGOrtega Jul 12, 2022
e5d0657
Telemetry (#1092) suggestion: don't repeat ourselves (#1094)
0x2b3bfa0 Jul 13, 2022
d818b82
dryer cml
DavidGOrtega Jul 14, 2022
9e1a351
dryer cml
DavidGOrtega Jul 14, 2022
554d909
telemetrySend
DavidGOrtega Jul 14, 2022
41ec815
naming consistency
DavidGOrtega Jul 14, 2022
53f800b
read non json id
DavidGOrtega Jul 14, 2022
977ddd5
gh check repoOptions
DavidGOrtega Jul 15, 2022
dd9dfd5
one error handler
DavidGOrtega Jul 15, 2022
32edb2d
Merge branch 'master' of https://github.com/iterative/cml into telemetry
DavidGOrtega Jul 15, 2022
181ab44
fix tensorboard
DavidGOrtega Jul 18, 2022
34152a7
fix tensorboard and tests
DavidGOrtega Jul 18, 2022
e7b9d9b
cleanup yargs fail handler
DavidGOrtega Jul 21, 2022
1b2a618
unused
DavidGOrtega Jul 21, 2022
1a79b29
RUNNER_SHUTTING_DOWN
DavidGOrtega Jul 21, 2022
ef13e13
remove comments
DavidGOrtega Jul 21, 2022
6f1f931
golantic
DavidGOrtega Jul 21, 2022
2589efa
Merge branch 'master' of https://github.com/iterative/cml into telemetry
DavidGOrtega Jul 28, 2022
006e226
getDriver
DavidGOrtega Jul 28, 2022
17fc89f
fix telemetry
DavidGOrtega Jul 28, 2022
76cfc3d
fix getter
DavidGOrtega Jul 28, 2022
6160b89
merge master
DavidGOrtega Jul 31, 2022
c1349c7
Merge branch 'master' into telemetry
DavidGOrtega Aug 1, 2022
f806b05
merge master
DavidGOrtega Aug 1, 2022
39c6669
Merge branch 'telemetry' of https://github.com/iterative/cml into tel…
DavidGOrtega Aug 1, 2022
d144438
remove report
DavidGOrtega Aug 1, 2022
6271cb8
remove console
DavidGOrtega Aug 4, 2022
a7944f8
fix os release
DavidGOrtega Aug 10, 2022
3b8d1ea
windows release
DavidGOrtega Aug 10, 2022
7e74df6
Merge branch 'master' into telemetry
DavidGOrtega Aug 10, 2022
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
11 changes: 10 additions & 1 deletion bin/cml/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ const kebabcaseKeys = require('kebabcase-keys');

const { GIT_USER_NAME, GIT_USER_EMAIL } = require('../../src/cml');
const CML = require('../../src/cml').default;
const analytics = require('../../src/analytics');

exports.command = 'ci';
exports.description = 'Fixes specific CI setups';

exports.handler = async (opts) => {
const cml = new CML(opts);
console.log((await cml.ci(opts)) || '');
const event = await analytics.jitsuEventPayload({ action: 'ci', cml });

try {
console.log((await cml.ci(opts)) || '');
analytics.send({ event });
} catch (err) {
analytics.send({ ...event, error: err.message });
throw err;
}
};

exports.builder = (yargs) =>
Expand Down
12 changes: 10 additions & 2 deletions bin/cml/pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ const kebabcaseKeys = require('kebabcase-keys');

const { GIT_REMOTE, GIT_USER_NAME, GIT_USER_EMAIL } = require('../../src/cml');
const CML = require('../../src/cml').default;
const analytics = require('../../src/analytics');

exports.command = 'pr <glob path...>';
exports.description = 'Create a pull request with the specified files';

exports.handler = async (opts) => {
const cml = new CML(opts);
const link = await cml.prCreate({ ...opts, globs: opts.globpath });
if (link) console.log(link);
const event = await analytics.jitsuEventPayload({ action: 'pr', cml });
try {
const link = await cml.prCreate({ ...opts, globs: opts.globpath });
if (link) console.log(link);
analytics.send({ event });
} catch (err) {
analytics.send({ ...event, error: err.message });
throw err;
}
};

exports.builder = (yargs) =>
Expand Down
24 changes: 17 additions & 7 deletions bin/cml/publish.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require('fs').promises;
const kebabcaseKeys = require('kebabcase-keys');
const winston = require('winston');

const CML = require('../../src/cml').default;
const analytics = require('../../src/analytics');

exports.command = 'publish <asset>';
exports.description = 'Upload an image to build a report';
Expand All @@ -19,14 +19,24 @@ exports.handler = async (opts) => {

const path = opts.asset;
const cml = new CML({ ...opts, repo: native ? repo : 'cml' });

const output = await cml.publish({
...opts,
path
const event = await analytics.jitsuEventPayload({
action: 'publish',
cml: new CML(opts)
});

if (!file) console.log(output);
else await fs.writeFile(file, output);
try {
const output = await cml.publish({
...opts,
path
});

if (!file) console.log(output);
else await fs.writeFile(file, output);
analytics.send({ event });
} catch (err) {
analytics.send({ ...event, error: err.message });
throw err;
}
};

exports.builder = (yargs) =>
Expand Down
14 changes: 13 additions & 1 deletion bin/cml/rerun-workflow.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
const kebabcaseKeys = require('kebabcase-keys');

const CML = require('../../src/cml').default;
const analytics = require('../../src/analytics');

exports.command = 'rerun-workflow';
exports.description = 'Reruns a workflow given the jobId or workflow Id';

exports.handler = async (opts) => {
const cml = new CML(opts);
await cml.pipelineRerun(opts);
const event = await analytics.jitsuEventPayload({
action: 'rerun-workflow',
cml
});

try {
await cml.pipelineRerun(opts);
analytics.send({ event });
} catch (err) {
analytics.send({ ...event, error: err.message });
throw err;
}
};

exports.builder = (yargs) =>
Expand Down
16 changes: 12 additions & 4 deletions bin/cml/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ const timestring = require('timestring');
const winston = require('winston');

const CML = require('../../src/cml').default;
const analytics = require('../../src/analytics');
const { randid, sleep } = require('../../src/utils');
const tf = require('../../src/terraform');

let cml;
let event;
let RUNNER;
let RUNNER_SHUTTING_DOWN = false;
let RUNNER_TIMER = 0;
Expand Down Expand Up @@ -92,6 +94,7 @@ const shutdown = async (opts) => {

await destroyTerraform();

analytics.send({ ...event });
process.exit(error ? 1 : 0);
};

Expand Down Expand Up @@ -341,8 +344,6 @@ const run = async (opts) => {
opts.workdir = opts.workdir || `${homedir()}/.cml/${opts.name}`;
const {
driver,
repo,
token,
workdir,
cloud,
labels,
Expand All @@ -352,8 +353,6 @@ const run = async (opts) => {
dockerVolumes
} = opts;

cml = new CML({ driver, repo, token });

await cml.repoTokenCheck();

if (dockerVolumes.length && cml.driver !== 'gitlab')
Expand All @@ -368,6 +367,7 @@ const run = async (opts) => {
`Runner name ${name} is already in use. Please change the name or terminate the existing runner.`
);
winston.info(`Reusing existing runner named ${name}...`);
analytics.send({ ...event });
process.exit(0);
}

Expand All @@ -380,12 +380,14 @@ const run = async (opts) => {
winston.info(
`Reusing existing online runners with the ${labels} labels...`
);
analytics.send({ ...event });
process.exit(0);
}

if (reuseIdle) {
if (driver === 'bitbucket') {
winston.error('cml runner flag --reuse-idle is unsupported by bitbucket');
analytics.send({ ...event });
process.exit(1);
}
winston.info(
Expand All @@ -397,6 +399,7 @@ const run = async (opts) => {
);
if (availableRunner) {
winston.info('Found matching idle runner.', availableRunner);
analytics.send({ ...event });
process.exit(0);
}
}
Expand All @@ -419,6 +422,10 @@ exports.command = 'runner';
exports.description = 'Launch and register a self-hosted runner';

exports.handler = async (opts) => {
const { driver, repo, token } = opts;
cml = new CML({ driver, repo, token });
event = await analytics.jitsuEventPayload({ action: 'runner', cml });

if (process.env.RUNNER_NAME) {
winston.warn(
'ignoring RUNNER_NAME environment variable, use CML_RUNNER_NAME or --name instead'
Expand All @@ -428,6 +435,7 @@ exports.handler = async (opts) => {
await run(opts);
} catch (error) {
await shutdown({ ...opts, error });
analytics.send({ ...event, error: error.message });
}
};

Expand Down
15 changes: 14 additions & 1 deletion bin/cml/send-comment.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
const kebabcaseKeys = require('kebabcase-keys');

const CML = require('../../src/cml').default;
const analytics = require('../../src/analytics');

exports.command = 'send-comment <markdown file>';
exports.description = 'Comment on a commit';

exports.handler = async (opts) => {
opts.markdownFile = opts.markdownfile;

const cml = new CML(opts);
console.log(await cml.commentCreate(opts));
const event = await analytics.jitsuEventPayload({
action: 'send-comment',
cml
});

try {
console.log(await cml.commentCreate(opts));
analytics.send({ event });
} catch (err) {
analytics.send({ ...event, error: err.message });
throw err;
}
};

exports.builder = (yargs) =>
Expand Down
18 changes: 15 additions & 3 deletions bin/cml/send-github-check.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
const fs = require('fs').promises;
const kebabcaseKeys = require('kebabcase-keys');
const CML = require('../../src/cml').default;
const analytics = require('../../src/analytics');

exports.command = 'send-github-check <markdown file>';
exports.description = 'Create a check report';

exports.handler = async (opts) => {
const path = opts.markdownfile;
const report = await fs.readFile(path, 'utf-8');
const cml = new CML({ ...opts });
await cml.checkCreate({ ...opts, report });
const event = await analytics.jitsuEventPayload({
action: 'send-check',
cml
});

try {
const path = opts.markdownfile;
const report = await fs.readFile(path, 'utf-8');
await cml.checkCreate({ ...opts, report });
analytics.send({ ...event });
} catch (err) {
analytics.send({ ...event, error: err.message });
throw err;
}
};

exports.builder = (yargs) =>
Expand Down
104 changes: 60 additions & 44 deletions bin/cml/tensorboard-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const tempy = require('tempy');
const winston = require('winston');
const { exec, watermarkUri, sleep } = require('../../src/utils');

const CML = require('../../src/cml').default;
const analytics = require('../../src/analytics');

const closeFd = (fd) => {
try {
fd.close();
Expand Down Expand Up @@ -56,53 +59,66 @@ exports.handler = async (opts) => {
rmWatermark
} = opts;

// set credentials
const path = `${homedir()}/.config/tensorboard/credentials`;
await fs.mkdir(path, { recursive: true });
await fs.writeFile(`${path}/uploader-creds.json`, credentials);

// launch tensorboard on background
const help = await exec('tensorboard dev upload -h');
const extraParamsFound =
(name || description) && help.indexOf('--description') >= 0;
const extraParams = extraParamsFound
? `--name "${name}" --description "${description}"`
: '';
const command = `tensorboard dev upload --logdir ${logdir} ${extraParams}`;

const stdoutPath = tempy.file({ extension: 'log' });
const stdoutFd = await fs.open(stdoutPath, 'a');
const stderrPath = tempy.file({ extension: 'log' });
const stderrFd = await fs.open(stderrPath, 'a');

const proc = spawn(command, [], {
detached: true,
shell: true,
stdio: ['ignore', stdoutFd, stderrFd]
const cml = new CML({ ...opts });
const event = await analytics.jitsuEventPayload({
action: 'tensorboard-dev',
cml
});

proc.unref();
proc.on('exit', async (code) => {
if (code) {
try {
// set credentials
const path = `${homedir()}/.config/tensorboard/credentials`;
await fs.mkdir(path, { recursive: true });
await fs.writeFile(`${path}/uploader-creds.json`, credentials);

// launch tensorboard on background
const help = await exec('tensorboard dev upload -h');
const extraParamsFound =
(name || description) && help.indexOf('--description') >= 0;
const extraParams = extraParamsFound
? `--name "${name}" --description "${description}"`
: '';
const command = `tensorboard dev upload --logdir ${logdir} ${extraParams}`;

const stdoutPath = tempy.file({ extension: 'log' });
const stdoutFd = await fs.open(stdoutPath, 'a');
const stderrPath = tempy.file({ extension: 'log' });
const stderrFd = await fs.open(stderrPath, 'a');

const proc = spawn(command, [], {
detached: true,
shell: true,
stdio: ['ignore', stdoutFd, stderrFd]
});

proc.unref();
proc.on('exit', async (code) => {
const error = await fs.readFile(stderrPath, 'utf8');
winston.error(`Tensorboard failed with error: ${error}`);
}
process.exit(code);
});

const url = await exports.tbLink({
stdout: stdoutPath,
stderror: stderrPath,
title,
name,
rmWatermark,
md
});
if (!file) console.log(url);
else await fs.appendFile(file, url);

closeFd(stdoutFd) && closeFd(stderrFd);
process.exit(0);
if (code) {
winston.error(`Tensorboard failed with error: ${error}`);
}
analytics.send({ ...event, error });
process.exit(code);
});

const url = await exports.tbLink({
stdout: stdoutPath,
stderror: stderrPath,
title,
name,
rmWatermark,
md
});
if (!file) console.log(url);
else await fs.appendFile(file, url);

closeFd(stdoutFd) && closeFd(stderrFd);
analytics.send({ ...event });
process.exit(0);
} catch (err) {
analytics.send({ ...event, error: err.message });
throw err;
}
};

exports.builder = (yargs) =>
Expand Down
Loading