Skip to content

Commit

Permalink
Enrich analytics with container information and options
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored Sep 20, 2022
1 parent 82af532 commit dd51390
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 6 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ WORKDIR ${CML_RUNNER_PATH}
# SET SPECIFIC ENVIRONMENT VARIABLES
ENV IN_DOCKER=1
ENV RUNNER_ALLOW_RUNASROOT=1
ENV _CML_CONTAINER_IMAGE=true

# DEFINE ENTRY POINT AND COMMAND
# Smart entrypoint understands commands like `bash` or `/bin/sh` but defaults to `cml`;
Expand Down
42 changes: 38 additions & 4 deletions bin/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { basename } = require('path');
const { pseudoexec } = require('pseudoexec');

const camelcaseKeys = require('camelcase-keys');
const which = require('which');
const winston = require('winston');
const yargs = require('yargs');
Expand Down Expand Up @@ -48,7 +49,6 @@ const setupOpts = (opts) => {

const { markdownfile } = opts;
opts.markdownFile = markdownfile;
opts.cmlCommand = opts._[0];
opts.cml = new CML(opts);
};

Expand Down Expand Up @@ -76,9 +76,42 @@ const setupLogger = (opts) => {
});
};

const setupTelemetry = async (opts) => {
const { cml, cmlCommand: action } = opts;
opts.telemetryEvent = await jitsuEventPayload({ action, cml });
const setupTelemetry = async (opts, { parsed: { defaulted } }) => {
const { cml, _: command } = opts;
const action = command.join(':');

const allowedTelemetryOptions = {
'runner:launch': {
cloud: 'plain',
cloudStartupScript: 'masked'
},
'comment:create': {
native: 'plain',
publishUrl: 'masked'
}
};

const options = Object.fromEntries(
Object.entries(opts)
.filter(
([key]) =>
Object.prototype.hasOwnProperty.call(
allowedTelemetryOptions[action] || {},
key
) &&
!Object.prototype.hasOwnProperty.call(camelcaseKeys(defaulted), key)
)
.map(([key, value]) => [
key,
(allowedTelemetryOptions[action] || {})[key] === 'plain' ? value : '***'
])
);

opts.telemetryEvent = await jitsuEventPayload({
action,
cml,
extra: { options }
});
};

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

(async () => {
setupLogger({ log: 'debug' });

try {
await yargs
.env('CML')
Expand Down
Loading

2 comments on commit dd51390

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

Please sign in to comment.