Skip to content

Commit ebea1c2

Browse files
NO-JIRA: add stg overrides support validation (#2067)
1 parent 8070cdc commit ebea1c2

File tree

8 files changed

+35
-21
lines changed

8 files changed

+35
-21
lines changed

validator/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"version": "1.0.0",
55
"scripts": {
66
"test": "jest",
7-
"validate-definition": "ajv validate --errors=json -s schemas/entity-schema-v1.json -d '../entity-types/*/definition.yml' > /dev/null",
8-
"validate-summary-metrics": "ajv validate --errors=json -s schemas/summary-metrics-schema-v1.json -d '../entity-types/*/summary_metrics.yml' > /dev/null",
9-
"validate-golden-metrics": "ajv validate --errors=json -s schemas/golden-metrics-schema-v1.json -d '../entity-types/*/golden_metrics.yml' > /dev/null",
10-
"validate-dashboard": "ajv validate --errors=json -s schemas/dashboard-schema-v1.json -d '../entity-types/*/*dashboard.json' > /dev/null",
11-
"validate-relationship-synthesis": "ajv validate --errors=json -s schemas/relationship-synthesis-schema-v1.json -d '../relationships/synthesis/*.yml' > /dev/null",
7+
"validate-definition": "ajv validate --errors=json -s schemas/entity-schema-v1.json -d '../entity-types/*/definition{.stg,}.yml' > /dev/null",
8+
"validate-summary-metrics": "ajv validate --errors=json -s schemas/summary-metrics-schema-v1.json -d '../entity-types/*/summary_metrics{.stg,}.yml' > /dev/null",
9+
"validate-golden-metrics": "ajv validate --errors=json -s schemas/golden-metrics-schema-v1.json -d '../entity-types/*/golden_metrics{.stg,}.yml' > /dev/null",
10+
"validate-dashboard": "ajv validate --errors=json -s schemas/dashboard-schema-v1.json -d '../entity-types/*/*dashboard{.stg,}.json' > /dev/null",
11+
"validate-relationship-synthesis": "ajv validate --errors=json -s schemas/relationship-synthesis-schema-v1.json -d '../relationships/synthesis/*{.stg,}.yml' > /dev/null",
1212
"validate-folders": "node tools/validate_folders.js",
1313
"validate-rules": "node tools/validate_rules.js",
1414
"validate-relationship-synthesis-rules": "node tools/validate_relationship_synthesis_rules.js",
@@ -18,11 +18,11 @@
1818
"check": "npm run validate-schemas && npm run validate-rules && npm run validate-relationship-synthesis-rules && npm run approve-job",
1919
"sanitize-dashboards": "node tools/sanitize_dashboards.js",
2020
"check-pr": "npm run validate-schemas-pr && npm run validate-rules && npm run validate-relationship-synthesis-rules && npm run approve-job",
21-
"validate-definition-pr": "ajv validate --errors=json -s schemas/entity-schema-v1.json -d '../prcode/entity-types/*/definition.yml' > /dev/null",
22-
"validate-summary-metrics-pr": "ajv validate --errors=json -s schemas/summary-metrics-schema-v1.json -d '../prcode/entity-types/*/summary_metrics.yml' > /dev/null",
23-
"validate-golden-metrics-pr": "ajv validate --errors=json -s schemas/golden-metrics-schema-v1.json -d '../prcode/entity-types/*/golden_metrics.yml' > /dev/null",
24-
"validate-dashboard-pr": "ajv validate --errors=json -s schemas/dashboard-schema-v1.json -d '../prcode/entity-types/*/*dashboard.json' > /dev/null",
25-
"validate-relationship-synthesis-pr": "ajv validate --errors=json -s schemas/relationship-synthesis-schema-v1.json -d '../prcode/entity-types/synthesis/*.yml' > /dev/null",
21+
"validate-definition-pr": "ajv validate --errors=json -s schemas/entity-schema-v1.json -d '../prcode/entity-types/*/definition{.stg,}.yml' > /dev/null",
22+
"validate-summary-metrics-pr": "ajv validate --errors=json -s schemas/summary-metrics-schema-v1.json -d '../prcode/entity-types/*/summary_metrics{.stg,}.yml' > /dev/null",
23+
"validate-golden-metrics-pr": "ajv validate --errors=json -s schemas/golden-metrics-schema-v1.json -d '../prcode/entity-types/*/golden_metrics{.stg,}.yml' > /dev/null",
24+
"validate-dashboard-pr": "ajv validate --errors=json -s schemas/dashboard-schema-v1.json -d '../prcode/entity-types/*/*dashboard{.stg,}.json' > /dev/null",
25+
"validate-relationship-synthesis-pr": "ajv validate --errors=json -s schemas/relationship-synthesis-schema-v1.json -d '../prcode/entity-types/synthesis/*{.stg,}.yml' > /dev/null",
2626
"validate-schemas-pr": "npm run validate-definition-pr && npm run validate-summary-metrics-pr && npm run validate-golden-metrics-pr && npm run validate-dashboard-pr && npm run validate-relationship-synthesis-pr && npm run validate-folders && npm run validate-uninstrumented-definitions-exists",
2727
"lint:fix": "eslint --fix ./**/*.js"
2828
},

validator/schemas/entity-schema-v1.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,12 @@
356356
"template": {
357357
"$id": "#/properties/query/dashboardTemplates/template",
358358
"type": "string",
359-
"pattern": "^[0-9a-zA-Z_-]*dashboard.json$",
359+
"pattern": "^[0-9a-zA-Z_-]*dashboard(\\.stg)?\\.json$",
360360
"description": "The file where the dashboard is located.",
361361
"examples": [
362362
[
363-
"prometheus_dashboard.json"
363+
"prometheus_dashboard.json",
364+
"prometheus_dashboard.stg.json"
364365
]
365366
]
366367
},

validator/tools/props.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module.exports = {
33
RELATIONSHIPS_SYNTHESIS_DIR: process.env.RELATIONSHIPS_SYNTHESIS_DIR || '../relationships/synthesis/',
44
RELATIONSHIPS_CANDIDATES_DIR: process.env.RELATIONSHIPS_CANDIDATES_DIR || '../relationships/candidates/',
55
DEFINITION_FILE_NAME: 'definition.yml',
6+
DEFINITION_FILE_NAME_STG: 'definition.stg.yml',
67
DASHBOARD_FILE_NAME_SUFFIX: 'dashboard.json',
8+
DASHBOARD_FILE_NAME_SUFFIX_STG: 'dashboard.stg.json',
79
FILE_ENCODING: 'UTF-8'
810
};

validator/tools/sanitize_dashboards.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { DEFINITIONS_DIR, DASHBOARD_FILE_NAME_SUFFIX, FILE_ENCODING } = require('./props');
1+
const { DEFINITIONS_DIR, DASHBOARD_FILE_NAME_SUFFIX, DASHBOARD_FILE_NAME_SUFFIX_STG, FILE_ENCODING } = require('./props');
22
const fs = require('fs');
33
const { readdir } = fs.promises;
44
const path = require('path');
@@ -11,7 +11,7 @@ const utils = require('./utils');
1111
const folderName = folderDefinition.name;
1212
const files = await readdir(path.resolve(DEFINITIONS_DIR, folderDefinition.name), { withFileTypes: true });
1313
for (const file of files) {
14-
if (file.name.includes(DASHBOARD_FILE_NAME_SUFFIX)) {
14+
if (file.name.includes(DASHBOARD_FILE_NAME_SUFFIX) || file.name.includes(DASHBOARD_FILE_NAME_SUFFIX_STG)) {
1515
const filePath = path.resolve(DEFINITIONS_DIR, folderName, file.name);
1616
const fileContent = fs.readFileSync(filePath, FILE_ENCODING);
1717
const newFileContent = utils.sanitizeDashboard(fileContent);

validator/tools/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const githubHelper = require('./ghHelper');
55
const { readdir } = fs.promises;
66
const { DEFINITIONS_DIR } = require('./props');
77
const { RELATIONSHIPS_SYNTHESIS_DIR } = require('./props');
8-
const allowedFileNamesRegex = /^[A-Z0-9_]+(?:-[A-Z0-9_]+)?-to-[A-Z0-9_]+(?:-[A-Z0-9_]+)?\.yml$/;
8+
const allowedFileNamesRegex = /^[A-Z0-9_]+(?:-[A-Z0-9_]+)?-to-[A-Z0-9_]+(?:-[A-Z0-9_]+)?(\.stg)?\.yml$/;
99
const regex = new RegExp(allowedFileNamesRegex);
1010

1111
async function getFiles (dir) {

validator/tools/validate_folders.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { DEFINITIONS_DIR, DEFINITION_FILE_NAME } = require('./props');
1+
const { DEFINITIONS_DIR, DEFINITION_FILE_NAME, DEFINITION_FILE_NAME_STG } = require('./props');
22
const { readdir } = require('fs').promises;
33
const fs = require('fs');
44
const path = require('path');
@@ -8,7 +8,12 @@ const { FILE_ENCODING } = require('./props');
88
(async () => {
99
const folderDefinitions = await readdir(DEFINITIONS_DIR, { withFileTypes: true });
1010
for (const folderDefinition of folderDefinitions) {
11-
const definitionPath = path.resolve(DEFINITIONS_DIR, folderDefinition.name, DEFINITION_FILE_NAME);
11+
let definitionPath = path.resolve(DEFINITIONS_DIR, folderDefinition.name, DEFINITION_FILE_NAME);
12+
13+
if (!fs.existsSync(definitionPath)) {
14+
definitionPath = path.resolve(DEFINITIONS_DIR, folderDefinition.name, DEFINITION_FILE_NAME_STG);
15+
}
16+
1217
if (!fs.existsSync(definitionPath)) {
1318
console.error(`expected ${DEFINITION_FILE_NAME} in the definitions folder ${folderDefinition.name}`);
1419
process.exit(1);

validator/tools/validate_uninstrumented_definitions_exists.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const { RELATIONSHIPS_CANDIDATES_DIR, DEFINITIONS_DIR, DEFINITION_FILE_NAME, FILE_ENCODING } = require('./props');
1+
const { RELATIONSHIPS_CANDIDATES_DIR, DEFINITIONS_DIR, DEFINITION_FILE_NAME, DEFINITION_FILE_NAME_STG, FILE_ENCODING } = require('./props');
22
const fs = require('fs').promises;
33
const path = require('path');
44
const yaml = require('js-yaml');
55
const CREATE_UNINSTRUMENTED_DEF = 'CREATE_UNINSTRUMENTED';
66
const UNINSTRUMENTED_DEF = 'UNINSTRUMENTED';
77

8-
async function checkUninstrumentedDefExists (type) {
9-
const defPath = path.resolve(DEFINITIONS_DIR, `${UNINSTRUMENTED_DEF}-${type}`.toLowerCase(), DEFINITION_FILE_NAME);
8+
async function checkUninstrumentedDefExists (type, definitionFileName = DEFINITION_FILE_NAME) {
9+
const defPath = path.resolve(DEFINITIONS_DIR, `${UNINSTRUMENTED_DEF}-${type}`.toLowerCase(), definitionFileName);
1010
return await fs.access(defPath, fs.constants.F_OK | fs.constants.W_OK)
1111
.then(() => true)
1212
.catch(() => false);
@@ -20,7 +20,7 @@ async function checkUninstrumentedDefExists (type) {
2020
for (const lookup of object.lookups) {
2121
if (Object.hasOwn(lookup, 'onMiss') && lookup.onMiss.action === CREATE_UNINSTRUMENTED_DEF) {
2222
const type = lookup.onMiss.uninstrumented.type;
23-
if (!await checkUninstrumentedDefExists(type)) {
23+
if (!await checkUninstrumentedDefExists(type) && !await checkUninstrumentedDefExists(type, DEFINITION_FILE_NAME_STG)) {
2424
console.error(`Expected ${UNINSTRUMENTED_DEF} definition for ${type} in the Entity Definitions folder`);
2525
process.exit(1);
2626
}

validator/validator/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)