From e944a19a8d27fd52b766a45ca594ce4d47f6be4c Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Tue, 13 Oct 2026 17:52:24 +0200 Subject: [PATCH] Bug 2076540 - Add a skip_schema_validation option to bypass schema validation Firefox parses all of its metrics.yaml/pings.yaml files at the start of every build, and validating them against the JSON schema accounts for most of that time (5.2s -> 2.8s in CI, 2.5s -> 0.7s locally when skipped). Firefox already validates these files in a separate lint job (bug 2076535), so builds don't need to do it again. The new `skip_schema_validation` parser option skips the jsonschema validation step in `_load_file`, including the check that `$schema` is a known schema; the Python-level checks still run. It is only safe when the input has been validated elsewhere, since invalid input may raise exceptions rather than produce errors. The default is unchanged. --- CHANGELOG.md | 1 + glean_parser/parser.py | 11 ++++++++--- tests/test_parser.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5209fe57e..ea81fcee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - JS/TS server: Add support for `server-deletion-request` ping. Server apps can now add `server-deletion-request` to `send_in_pings` on identifier metrics (e.g. user IDs) ([DENG-4079](https://mozilla-hub.atlassian.net/browse/DENG-4079)) - JS: Ensure imports are sorted ([#865](https://github.com/mozilla/glean_parser/pull/865)) - BREAKING CHANGE: Require pings defined requiring an "ohttp" uploader capability to have `metadata.include_info_sections: false` ([bug 2074263](https://bugzilla.mozilla.org/show_bug.cgi?id=2074263)) +- Add a `skip_schema_validation` option to `parse_objects` to skip schema validation of input files ([bug 2076540](https://bugzilla.mozilla.org/show_bug.cgi?id=2076540)) ## 21.0.1 diff --git a/glean_parser/parser.py b/glean_parser/parser.py index 98489e3e9..7df2d0c9b 100644 --- a/glean_parser/parser.py +++ b/glean_parser/parser.py @@ -95,9 +95,10 @@ def _load_file( if filetype not in ("metrics", "pings", "tags"): filetype = None - for error in validate(content, filepath): - content = {} - yield error + if not parser_config.get("skip_schema_validation", False): + for error in validate(content, filepath): + content = {} + yield error return content, filetype @@ -486,6 +487,10 @@ def parse_objects( the input `filepaths` do not exist. - `interesting`: Contains an array of interesting metrics/ping files. Probes not included in these files will be marked as disabled. + - `skip_schema_validation`: Don't validate the input files against the + schema, including checking that `$schema` is a known schema. This is + only safe when they have been validated elsewhere: invalid input may + raise exceptions rather than produce errors. """ if config is None: config = {} diff --git a/tests/test_parser.py b/tests/test_parser.py index 9801add29..040a741c6 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -727,6 +727,21 @@ def test_do_not_disable_expired(): assert metrics["category"]["metric"].disabled is False +def test_skip_schema_validation(): + contents = [{"category": {"metric": {"type": "boolean", "description": 42}}}] + contents = [util.add_required(x) for x in contents] + + all_metrics = parser.parse_objects(contents) + errors = list(all_metrics) + assert len(errors) == 1 + assert "description" in errors[0] + + all_metrics = parser.parse_objects(contents, {"skip_schema_validation": True}) + errors = list(all_metrics) + assert len(errors) == 0 + assert all_metrics.value["category"]["metric"].description == 42 + + def test_interesting_disables_others(): # Test that if we get an "interesting" config param, only the metrics in # the provided config files are enabled.