From 316d89486fe105198dde8123be4aa784b59db837 Mon Sep 17 00:00:00 2001 From: Magnus Melin Date: Wed, 26 Mar 2025 15:27:44 +0000 Subject: [PATCH] Bug 1942797 - Generate a serverknobs config for all uninteresting metrics. r=mkmelin a=pascalc In certain builds we pass a list of "interesting" metrics. Everything not on that list is marked as disabled. For tests however we want to keep all defined metrics enabled. We use serverknobs to control that. At build time we build a serverknobs config using all "uninteresting" metrics and enable them. This config would then need to be applied at runtime when in tests. Differential Revision: https://phabricator.services.mozilla.com/D242914 --- .../interesting_serverknobs.py | 54 +++++++++++++++++++ toolkit/components/glean/moz.build | 10 ++++ 2 files changed, 64 insertions(+) create mode 100644 toolkit/components/glean/build_scripts/glean_parser_ext/interesting_serverknobs.py diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/interesting_serverknobs.py b/toolkit/components/glean/build_scripts/glean_parser_ext/interesting_serverknobs.py new file mode 100644 index 000000000000..3dea700ff9e1 --- /dev/null +++ b/toolkit/components/glean/build_scripts/glean_parser_ext/interesting_serverknobs.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import json +import os +import sys + +import buildconfig +from buildconfig import topsrcdir +from run_glean_parser import parse + + +def main(serverknobs_fd, *args): + all_objs, options = parse(args) + + only_interesting = set() + interesting_yamls = buildconfig.substs.get("MOZ_GLEAN_INTERESTING_METRICS_FILES") + if interesting_yamls: + interesting = [os.path.join(topsrcdir, x) for x in interesting_yamls] + interesting.append( + os.path.join(topsrcdir, "toolkit/components/glean/tags.yaml") + ) + extra_tags_files = buildconfig.substs.get("MOZ_GLEAN_EXTRA_TAGS_FILES") + if extra_tags_files: + tag_files = [os.path.join(topsrcdir, x) for x in extra_tags_files] + interesting.extend(tag_files) + + interesting_metrics, _options = parse(interesting + list(args[1:])) + for category_name in interesting_metrics.keys(): + if category_name in ["pings", "tags"]: + continue + for name, metric in interesting_metrics[category_name].items(): + fullname = f"{category_name}.{name}" + only_interesting.add(fullname) + + only_uninteresting = {} + + for category_name in all_objs.keys(): + if category_name in ["pings", "tags"]: + continue + for name, metric in all_objs[category_name].items(): + fullname = f"{category_name}.{name}" + if fullname not in only_interesting: + only_uninteresting[fullname] = True + + config = {"metrics_enabled": only_uninteresting} + json.dump(config, serverknobs_fd, sort_keys=True, indent=2) + + +if __name__ == "__main__": + main(sys.stdout, *sys.argv[1:]) diff --git a/toolkit/components/glean/moz.build b/toolkit/components/glean/moz.build index cfee0be79dad..d48ce855b736 100644 --- a/toolkit/components/glean/moz.build +++ b/toolkit/components/glean/moz.build @@ -242,6 +242,16 @@ if CONFIG["MOZ_ARTIFACT_BUILDS"]: # Once generated, it needs to be placed in GreD so it can be found. FINAL_TARGET_FILES += ["!jogfile.json"] +if CONFIG["MOZ_GLEAN_INTERESTING_METRICS_FILES"]: + GeneratedFile( + "interesting_serverknobs.json", + script="build_scripts/glean_parser_ext/interesting_serverknobs.py", + flags=[CONFIG["MOZ_APP_VERSION"]], + inputs=["!metrics_yamls.cached"], + ) + # Once generated, it needs to be placed in GreD so it can be found. + FINAL_TARGET_FILES += ["!interesting_serverknobs.json"] + # OHTTP support requires the fog_control crate know which pings wish to be sent # using OHTTP. fog_control has no access to the firefox_on_glean crate, so it # needs its own codegen.