Skip to content

Commit

Permalink
[ci-stats] Local metrics fixes (#113492) (#113710)
Browse files Browse the repository at this point in the history
* Rename `{ group: 'yarn start', id: 'started' }` to `{ group: 'scripts/kibana', id: 'dev server started' }` for consistency
* Rename `{ group: '@kbn/optimizer' }` to `{ group: 'scripts/build_kibana_platform_plugins' }` for consistency
* Include email for Elastic employees
* Standardize on Unix paths
* Set `subProcess: true` if the timing is already captured by a parent.
* Move nestedTiming to global and use normalize-path

Co-authored-by: Tyler Smalley <tyler.smalley@elastic.co>
  • Loading branch information
kibanamachine and Tyler Smalley authored Oct 3, 2021
1 parent 53fa6f5 commit 44b1a2e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 44 deletions.
6 changes: 3 additions & 3 deletions packages/kbn-cli-dev-mode/src/cli_dev_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ export class CliDevMode {
await reporter.timings({
timings: [
{
group: 'yarn start',
id: 'started',
group: 'scripts/kibana',
id: 'dev server started',
ms: Date.now() - this.startTime!,
meta: { success },
},
Expand All @@ -313,7 +313,7 @@ export class CliDevMode {
await reporter.timings({
timings: [
{
group: 'yarn start',
group: 'scripts/kibana',
id: 'dev server restart',
ms,
meta: {
Expand Down
20 changes: 12 additions & 8 deletions packages/kbn-dev-utils/src/ci_stats_reporter/ci_stats_reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,24 @@ export class CiStatsReporter {
this.log.debug(e.message);
}

const isElasticCommitter = email && email.endsWith('@elastic.co') ? true : false;

const defaultMetadata = {
osPlatform: Os.platform(),
osRelease: Os.release(),
osArch: Os.arch(),
committerHash: email
? crypto.createHash('sha256').update(email).digest('hex').substring(0, 20)
: undefined,
cpuCount: Os.cpus()?.length,
cpuModel: Os.cpus()[0]?.model,
cpuSpeed: Os.cpus()[0]?.speed,
email: isElasticCommitter ? email : undefined,
freeMem: Os.freemem(),
totalMem: Os.totalmem(),
committerHash: email
? crypto.createHash('sha256').update(email).digest('hex').substring(0, 20)
: undefined,
isElasticCommitter: email ? email.endsWith('@elastic.co') : undefined,
isElasticCommitter,
kibanaUuid,
nestedTiming: process.env.CI_STATS_NESTED_TIMING ? true : false,
osArch: Os.arch(),
osPlatform: Os.platform(),
osRelease: Os.release(),
totalMem: Os.totalmem(),
};

this.log.debug('CIStatsReporter committerHash: %s', defaultMetadata.committerHash);
Expand Down
49 changes: 25 additions & 24 deletions packages/kbn-dev-utils/src/run/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import path from 'path';
import { REPO_ROOT } from '@kbn/utils';
import normalizePath from 'normalize-path';
import { CiStatsReporter } from '../ci_stats_reporter';
import { ToolingLog } from '../tooling_log';

Expand All @@ -23,39 +24,39 @@ export class Metrics {
this.reporter = CiStatsReporter.fromEnv(log);
this.meta = new Map();
this.startTime = Date.now();
this.filePath = path.relative(REPO_ROOT, process.argv[1]).replace('.js', '');

// standardize to unix path
this.filePath = normalizePath(path.relative(REPO_ROOT, process.argv[1]).replace('.js', ''));
}

createTiming(meta: object, command?: string) {
return {
group: `${command ? `${this.filePath} ${command}` : this.filePath}`,
id: 'total',
ms: Date.now() - this.startTime,
meta: {
nestedTiming: process.env.CI_STATS_NESTED_TIMING,
...Object.fromEntries(this.meta),
...meta,
},
};
}

async reportCancelled(command?: string) {
return await this.reporter.timings({
timings: [this.createTiming({ cancelled: true }, command)],
});
}

async reportSuccess(command?: string) {
return await this.reporter.timings({
timings: [
{
group: `${command ? `${this.filePath} ${command}` : this.filePath}`,
id: 'total',
ms: Date.now() - this.startTime,
meta: {
success: true,
...Object.fromEntries(this.meta),
},
},
],
timings: [this.createTiming({ success: true }, command)],
});
}

async reportError(errorMessage?: string, command?: string) {
return await this.reporter.timings({
timings: [
{
group: `${command ? `${this.filePath} ${command}` : this.filePath}`,
id: 'total',
ms: Date.now() - this.startTime,
meta: {
success: false,
errorMessage,
...Object.fromEntries(this.meta),
},
},
],
timings: [this.createTiming({ success: false, errorMessage }, command)],
});
}
}
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/src/report_optimizer_timings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function reportOptimizerTimings(log: ToolingLog, config: OptimizerConfig)
await reporter.timings({
timings: [
{
group: '@kbn/optimizer',
group: 'scripts/build_kibana_platform_plugins',
id: 'total',
ms: time,
meta: {
Expand Down
18 changes: 11 additions & 7 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9108,18 +9108,21 @@ class CiStatsReporter {
this.log.debug(e.message);
}

const isElasticCommitter = email && email.endsWith('@elastic.co') ? true : false;
const defaultMetadata = {
osPlatform: _os.default.platform(),
osRelease: _os.default.release(),
osArch: _os.default.arch(),
committerHash: email ? _crypto.default.createHash('sha256').update(email).digest('hex').substring(0, 20) : undefined,
cpuCount: (_Os$cpus = _os.default.cpus()) === null || _Os$cpus === void 0 ? void 0 : _Os$cpus.length,
cpuModel: (_Os$cpus$ = _os.default.cpus()[0]) === null || _Os$cpus$ === void 0 ? void 0 : _Os$cpus$.model,
cpuSpeed: (_Os$cpus$2 = _os.default.cpus()[0]) === null || _Os$cpus$2 === void 0 ? void 0 : _Os$cpus$2.speed,
email: isElasticCommitter ? email : undefined,
freeMem: _os.default.freemem(),
totalMem: _os.default.totalmem(),
committerHash: email ? _crypto.default.createHash('sha256').update(email).digest('hex').substring(0, 20) : undefined,
isElasticCommitter: email ? email.endsWith('@elastic.co') : undefined,
kibanaUuid
isElasticCommitter,
kibanaUuid,
nestedTiming: process.env.CI_STATS_NESTED_TIMING ? true : false,
osArch: _os.default.arch(),
osPlatform: _os.default.platform(),
osRelease: _os.default.release(),
totalMem: _os.default.totalmem()
};
this.log.debug('CIStatsReporter committerHash: %s', defaultMetadata.committerHash);
return await this.req({
Expand Down Expand Up @@ -60705,6 +60708,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope



process.env.CI_STATS_NESTED_TIMING = 'true';
async function runCommand(command, config) {
const runStartTime = Date.now();
let kbn;
Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-pm/src/commands/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ export const BootstrapCommand: ICommand = {
upstreamBranch: kbn.kibanaProject.json.branch,
// prevent loading @kbn/utils by passing null
kibanaUuid: kbn.getUuid() || null,
timings: timings.map((t) => ({ group: 'scripts/kbn bootstrap', ...t })),
timings: timings.map((t) => ({
group: 'scripts/kbn bootstrap',
...t,
})),
});
},
};
2 changes: 2 additions & 0 deletions packages/kbn-pm/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { buildProjectGraph } from './utils/projects';
import { renderProjectsTree } from './utils/projects_tree';
import { Kibana } from './utils/kibana';

process.env.CI_STATS_NESTED_TIMING = 'true';

export async function runCommand(command: ICommand, config: Omit<ICommandConfig, 'kbn'>) {
const runStartTime = Date.now();
let kbn;
Expand Down

0 comments on commit 44b1a2e

Please sign in to comment.