Skip to content

Commit

Permalink
refactor(Telemetry): Report installed docker version
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jun 2, 2023
1 parent 76454d3 commit 39806d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/utils/telemetry/generate-payload.js
Expand Up @@ -139,7 +139,7 @@ module.exports = ({
commandUsage,
variableSources,
isConsoleAuthenticated,
isDockerInstalled,
dockerVersion,
}) => {
let commandDurationMs;

Expand Down Expand Up @@ -198,7 +198,8 @@ module.exports = ({
const payload = {
ciName,
isTtyTerminal: process.stdin.isTTY && process.stdout.isTTY,
isDockerInstalled,
isDockerInstalled: dockerVersion === undefined ? undefined : Boolean(dockerVersion),
dockerVersion: dockerVersion || undefined,
cliName: 'serverless',
command,
commandOptionNames,
Expand Down
13 changes: 9 additions & 4 deletions scripts/serverless.js
Expand Up @@ -32,7 +32,7 @@ let serviceDir = null;
let configuration = null;
let serverless;
let isConsoleAuthenticated = false;
let isDockerInstalled;
let dockerVersion;
const commandUsage = {};
const variableSourcesInConfig = new Set();

Expand Down Expand Up @@ -82,7 +82,7 @@ const finalize = async ({ error, shouldBeSync, telemetryData, shouldSendTelemetr
commandUsage,
variableSources: variableSourcesInConfig,
isConsoleAuthenticated,
isDockerInstalled,
dockerVersion,
}),
...telemetryData,
});
Expand Down Expand Up @@ -819,8 +819,13 @@ processSpanPromise = (async () => {
if (commands.join(' ') === 'deploy') {
const spawn = require('child-process-ext/spawn');
spawn('docker', ['--version']).then(
() => (isDockerInstalled = true),
() => (isDockerInstalled = false)
({ stdoutBuffer }) => {
dockerVersion = null;
const matcher = String(stdoutBuffer).match(/(?<version>\d+\.\d+\.\d+),/);
if (!matcher) return;
dockerVersion = matcher.groups.version;
},
() => (dockerVersion = null)
);
}

Expand Down
5 changes: 5 additions & 0 deletions test/unit/lib/utils/telemetry/generate-payload.test.js
Expand Up @@ -168,6 +168,7 @@ describe('test/unit/lib/utils/telemetry/generate-payload.test.js', () => {
isAutoUpdateEnabled: false,
isUsingCompose: false,
isDockerInstalled: undefined,
dockerVersion: undefined,
notificationsMode: 'on',
npmDependencies: ['fooDep', 'barDep', 'fooOpt', 'someDev', 'otherDev'],
triggeredDeprecations: [],
Expand Down Expand Up @@ -234,6 +235,7 @@ describe('test/unit/lib/utils/telemetry/generate-payload.test.js', () => {
isAutoUpdateEnabled: false,
isUsingCompose: false,
isDockerInstalled: undefined,
dockerVersion: undefined,
notificationsMode: 'on',
npmDependencies: [],
triggeredDeprecations: [],
Expand Down Expand Up @@ -277,6 +279,7 @@ describe('test/unit/lib/utils/telemetry/generate-payload.test.js', () => {
isAutoUpdateEnabled: false,
isUsingCompose: false,
isDockerInstalled: undefined,
dockerVersion: undefined,
notificationsMode: 'on',
triggeredDeprecations: [],
installationType: 'global:other',
Expand Down Expand Up @@ -333,6 +336,7 @@ describe('test/unit/lib/utils/telemetry/generate-payload.test.js', () => {
isAutoUpdateEnabled: false,
isUsingCompose: false,
isDockerInstalled: undefined,
dockerVersion: undefined,
triggeredDeprecations: [],
installationType: 'global:other',
notificationsMode: 'on',
Expand Down Expand Up @@ -374,6 +378,7 @@ describe('test/unit/lib/utils/telemetry/generate-payload.test.js', () => {
isAutoUpdateEnabled: false,
isUsingCompose: false,
isDockerInstalled: undefined,
dockerVersion: undefined,
notificationsMode: 'on',
triggeredDeprecations: [],
installationType: 'global:other',
Expand Down

0 comments on commit 39806d6

Please sign in to comment.