Skip to content

Commit 2b21b25

Browse files
trentmPeterEinberger
authored andcommitted
chore: add 'npm run lint:tav' (elastic#3340)
This checks that .ci/tav.json is correct: both that it covers all the modules in all the .tav.yml files in the repo, and that it never results in a TAV test matrix greater than the GH Actions 256 limit. This is part of `npm run lint` which is run by the lint CI workflow. This also drops the body-parser TAV tests: we don't instrument it, just use it in some tests. Refs: elastic#3227 (item 3)
1 parent ea271d6 commit 2b21b25

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

.tav.yml

-5
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,6 @@ memcached:
493493
versions: '>=2.2.0'
494494
commands: node test/instrumentation/modules/memcached.test.js
495495

496-
body-parser:
497-
versions: '>=1.19.0'
498-
commands:
499-
- node test/sanitize-field-names/express.test.js
500-
501496
aws-sdk:
502497
# We want this version range:
503498
# versions: '>=2.858 <3'

dev-utils/lint-tav-json.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
* Copyright Elasticsearch B.V. and other contributors where applicable.
5+
* Licensed under the BSD 2-Clause License; you may not use this file except in
6+
* compliance with the BSD 2-Clause License.
7+
*/
8+
9+
'use strict'
10+
11+
// Check that the ".ci/tav.json" file includes all the modules defined in
12+
// the various ".tav.yml" files. If not, then CI "TAV" runs are not testing
13+
// all modules.
14+
//
15+
// Also check that the product of "versions" and "modules" in tav.json does
16+
// not exceed the 256 GH Actions limit.
17+
// https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#usage-limits
18+
19+
const fs = require('fs')
20+
const path = require('path')
21+
22+
const glob = require('glob')
23+
const yaml = require('js-yaml')
24+
25+
const TOP = path.resolve(path.join(__dirname, '..'))
26+
const TAV_JSON_PATH = path.join('.ci', 'tav.json')
27+
28+
// ---- mainline
29+
30+
function main (argv) {
31+
let numErrors = 0
32+
33+
// Find all module names in ".tav.yml" files.
34+
const moduleNamesFromYaml = new Set()
35+
const tavYmlPaths = glob.sync(
36+
'**/.tav.yml',
37+
{ ignore: ['**/node_modules/**'] }
38+
)
39+
// console.log('tavYmlPaths:', tavYmlPaths)
40+
tavYmlPaths.forEach(p => {
41+
const tavCfg = yaml.load(fs.readFileSync(p, 'utf8'))
42+
Object.keys(tavCfg).forEach(k => {
43+
const v = tavCfg[k]
44+
moduleNamesFromYaml.add(v.name || k)
45+
})
46+
})
47+
// console.log('moduleNamesFromYaml: ', moduleNamesFromYaml)
48+
49+
// Find module names in ".ci/tav.json".
50+
const moduleNamesFromJson = new Set()
51+
const tavJson = JSON.parse(fs.readFileSync(path.join(TOP, TAV_JSON_PATH)))
52+
tavJson.modules.forEach(m => {
53+
m.split(',').forEach(moduleName => {
54+
moduleNamesFromJson.add(moduleName)
55+
})
56+
})
57+
// console.log('moduleNamesFromJson: ', moduleNamesFromJson)
58+
59+
// Matrix 256 limit.
60+
const matrixSize = tavJson.versions.length * tavJson.modules.length
61+
if (matrixSize > 256) {
62+
console.error('lint-tav-json: #versions * #modules from "%s" is >256, which exceeds the GH Actions workflow matrix limit: %d',
63+
TAV_JSON_PATH, matrixSize)
64+
numErrors += 1
65+
}
66+
67+
// Error out if any discrepancies.
68+
const missingFromYaml = new Set([...moduleNamesFromJson].filter((x) => !moduleNamesFromYaml.has(x)))
69+
if (missingFromYaml.size > 0) {
70+
console.error('lint-tav-json: the following %d module name(s) are in "%s" but not in the "**/.tav.yml" files: %s',
71+
missingFromYaml.size, TAV_JSON_PATH, missingFromYaml)
72+
numErrors += 1
73+
}
74+
const missingFromJson = new Set([...moduleNamesFromYaml].filter((x) => !moduleNamesFromJson.has(x)))
75+
if (missingFromJson.size > 0) {
76+
console.error('lint-tav-json: the following %d module name(s) are in the "**/.tav.yml" files but not in "%s": %s',
77+
missingFromJson.size, TAV_JSON_PATH, missingFromJson)
78+
numErrors += 1
79+
}
80+
81+
if (numErrors > 0) {
82+
process.exitCode = 1
83+
}
84+
}
85+
86+
if (require.main === module) {
87+
main(process.argv)
88+
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
"backport": "backport",
99
"docs:open": "PREVIEW=1 npm run docs:build",
1010
"docs:build": "./docs/scripts/build_docs.sh apm-agent-nodejs ./docs ./build",
11-
"lint": "npm run lint:eslint && npm run lint:license-files && npm run lint:yaml-files",
11+
"lint": "npm run lint:eslint && npm run lint:license-files && npm run lint:yaml-files && npm run lint:tav",
1212
"lint:eslint": "eslint . # requires node >=8.10",
1313
"lint:fix": "eslint --fix . # requires node >=8.10",
1414
"lint:license-files": "./dev-utils/gen-notice.sh --lint . # requires node >=16",
1515
"lint:yaml-files": "./dev-utils/lint-yaml-files.sh # requires node >=10",
16+
"lint:tav": "./dev-utils/lint-tav-json.js",
1617
"coverage": "COVERAGE=true ./test/script/run_tests.sh",
1718
"test": "./test/script/run_tests.sh",
1819
"test:deps": "dependency-check index.js start.js start-next.js 'lib/**/*.js' 'test/**/*.js' '!test/activation-method/fixtures' '!test/instrumentation/azure-functions/fixtures' '!test/instrumentation/modules/next/a-nextjs-app' '!test/opentelemetry-bridge' '!test/opentelemetry-metrics/fixtures' --no-dev -i async_hooks -i perf_hooks -i node:http -i @azure/functions-core",

0 commit comments

Comments
 (0)