-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci-stats] move shipper to a package, validate limits in on-merge job (…
…#149474) We just had an issue where two PRs were merged and it caused the limit of the `triggerActionsUi` bundle to be exceeded, breaking PR builds. The issue is that we didn't see any indication of this in the on-merge jobs because we don't produce the PR report for on-merge jobs or ask ci-stats if we should fail the job. Instead, we just ship the metrics for baseline purposes. This fixes that problem by adding a `--validate` flag to `node scripts/ship_ci_stats`, which takes care of sending at least some ci-stats and will verify that the bundle limits are not exceeded. Since we didn't catch this issue in the on-merge job the limits were incorrect for over an hour and merged into many PRs, wasting engineering and CI time. Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
179b36f
commit 4e7560f
Showing
15 changed files
with
149 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @kbn/ci-stats-shipper-cli | ||
|
||
Simple CLI that runs in CI to ship the metrics produced by the build process. We used to ship these metrics as part of the build, but in order to enable distributed caching of optimizer bundles (which we still don't do) we broke the metrics out of the build and write them to disk instead, to be shipped at a later time. | ||
|
||
Run `node scripts/ship_ci_stats --help` for usage information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_node', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-ci-stats-shipper-cli'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/ci-stats-shipper-cli", | ||
"owner": "@elastic/kibana-operations", | ||
"devOnly": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "@kbn/ci-stats-shipper-cli", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "SSPL-1.0 OR Elastic License 2.0", | ||
"main": "./ship_ci_stats_cli" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import Path from 'path'; | ||
import Fs from 'fs'; | ||
|
||
import { CiStatsReporter, CiStatsMetric } from '@kbn/ci-stats-reporter'; | ||
|
||
import { createFailError } from '@kbn/dev-cli-errors'; | ||
import { run } from '@kbn/dev-cli-runner'; | ||
|
||
run( | ||
async ({ log, flagsReader }) => { | ||
const validate = flagsReader.boolean('validate'); | ||
const metricPaths = flagsReader.arrayOfStrings('metrics') ?? []; | ||
|
||
const maybeFail = (message: string) => { | ||
const error = createFailError(message); | ||
if (process.env.IGNORE_SHIP_CI_STATS_ERROR === 'true') { | ||
error.exitCode = 0; | ||
} | ||
return error; | ||
}; | ||
|
||
const reporter = CiStatsReporter.fromEnv(log); | ||
|
||
if (!reporter.isEnabled()) { | ||
throw maybeFail('unable to initilize the CI Stats reporter'); | ||
} | ||
|
||
const overLimit: string[] = []; | ||
|
||
for (const path of metricPaths) { | ||
// resolve path from CLI relative to CWD | ||
const abs = Path.resolve(path); | ||
const json = Fs.readFileSync(abs, 'utf8'); | ||
const metrics: CiStatsMetric[] = JSON.parse(json); | ||
if (await reporter.metrics(metrics)) { | ||
log.success('shipped metrics from', path); | ||
} else { | ||
throw maybeFail('failed to ship metrics'); | ||
} | ||
|
||
for (const metric of metrics) { | ||
if (metric.limit !== undefined && metric.limit < metric.value) { | ||
overLimit.push( | ||
`${metric.group} > ${metric.id} with value of ${metric.value} is greater than the limit of ${metric.limit}` | ||
); | ||
} | ||
} | ||
} | ||
|
||
if (validate && overLimit.length) { | ||
throw maybeFail(`Metric overages:\n${overLimit.map((l) => ` ${l}`).join('\n')}`); | ||
} | ||
}, | ||
{ | ||
description: 'ship ci-stats which have been written to files', | ||
usage: `node scripts/ship_ci_stats`, | ||
log: { | ||
defaultLevel: 'debug', | ||
}, | ||
flags: { | ||
string: ['metrics'], | ||
boolean: ['validate'], | ||
help: ` | ||
--metrics [path] A path to a JSON file that includes metrics which should be sent. Multiple instances supported | ||
--validate When passed, the process will exit with an error message and a non-zero exit status if any of the bundle limits are exceeded. | ||
`, | ||
}, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target/types", | ||
"types": [ | ||
"jest", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [ | ||
"@kbn/ci-stats-reporter", | ||
"@kbn/dev-cli-errors", | ||
"@kbn/dev-cli-runner", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters