Skip to content

Commit 342cbf8

Browse files
committed
Remove internal-only fields from data dump
1 parent b688430 commit 342cbf8

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- BUGFIX: Remove internal-only fields from serialized metrics data ([#550](https://github.com/mozilla/glean_parser/pull/550))
56
- FEATURE: New subcommand: `dump` to dump the metrics data as JSON ([#550](https://github.com/mozilla/glean_parser/pull/550))
67

78
## 6.4.0

glean_parser/metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def serialize(self) -> Dict[str, util.JSONType]:
177177
d[key] = [x.name for x in val]
178178
del d["name"]
179179
del d["category"]
180+
d.pop("_config", None)
181+
d.pop("_generate_enums", None)
180182
return d
181183

182184
def _serialize_input(self) -> Dict[str, util.JSONType]:

tests/test_parser.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# http://creativecommons.org/publicdomain/zero/1.0/
55

66
from pathlib import Path
7+
import json
78
import re
89
import sys
910
import textwrap
@@ -901,3 +902,66 @@ def test_no_lint_sorted():
901902
assert all_objects.value["category"]["metric"].no_lint == ["lint1", "lint2"]
902903
assert all_objects.value["pings"]["ping"].no_lint == ["lint1", "lint2"]
903904
assert all_objects.value["tags"]["tag"].no_lint == ["lint1", "lint2"]
905+
906+
907+
def test_no_internal_fields_exposed():
908+
"""
909+
We accidentally exposed fields like `_config` and `_generate_enums` before.
910+
These ended up in probe-scraper output.
911+
912+
We replicate the code probe-scraper uses
913+
and ensure we get the JSON we expect from it.
914+
"""
915+
916+
results = parser.parse_objects(
917+
[
918+
util.add_required(
919+
{
920+
"category": {
921+
"metric": {
922+
"type": "event",
923+
"extra_keys": {
924+
"key_a": {"description": "desc-a", "type": "boolean"}
925+
},
926+
}
927+
},
928+
}
929+
),
930+
]
931+
)
932+
errs = list(results)
933+
assert len(errs) == 0
934+
935+
metrics = {
936+
metric.identifier(): metric.serialize()
937+
for category, probes in results.value.items()
938+
for probe_name, metric in probes.items()
939+
}
940+
941+
expected = {
942+
"category.metric": {
943+
"bugs": ["http://bugzilla.mozilla.org/12345678"],
944+
"data_reviews": ["https://example.com/review/"],
945+
"defined_in": {"line": 3},
946+
"description": "DESCRIPTION...",
947+
"disabled": False,
948+
"expires": "never",
949+
"extra_keys": {"key_a": {"description": "desc-a", "type": "boolean"}},
950+
"gecko_datapoint": "",
951+
"lifetime": "ping",
952+
"metadata": {},
953+
"no_lint": [],
954+
"notification_emails": ["nobody@example.com"],
955+
"send_in_pings": ["events"],
956+
"type": "event",
957+
"version": 0,
958+
}
959+
}
960+
expected_json = json.dumps(expected, sort_keys=True, indent=2)
961+
962+
out_json = json.dumps(
963+
metrics,
964+
sort_keys=True,
965+
indent=2,
966+
)
967+
assert expected_json == out_json

0 commit comments

Comments
 (0)