Skip to content

Commit

Permalink
Remove internal-only fields from data dump
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed Jan 24, 2023
1 parent cef4e43 commit 33c939f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

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

## 6.4.0
Expand Down
2 changes: 2 additions & 0 deletions glean_parser/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def serialize(self) -> Dict[str, util.JSONType]:
d[key] = [x.name for x in val]
del d["name"]
del d["category"]
d.pop("_config", None)
d.pop("_generate_enums", None)
return d

def _serialize_input(self) -> Dict[str, util.JSONType]:
Expand Down
64 changes: 64 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# http://creativecommons.org/publicdomain/zero/1.0/

from pathlib import Path
import json
import re
import sys
import textwrap
Expand Down Expand Up @@ -901,3 +902,66 @@ def test_no_lint_sorted():
assert all_objects.value["category"]["metric"].no_lint == ["lint1", "lint2"]
assert all_objects.value["pings"]["ping"].no_lint == ["lint1", "lint2"]
assert all_objects.value["tags"]["tag"].no_lint == ["lint1", "lint2"]


def test_no_internal_fields_exposed():
"""
We accidentally exposed fields like `_config` and `_generate_enums` before.
These ended up in probe-scraper output.
We replicate the code probe-scraper uses
and ensure we get the JSON we expect from it.
"""

results = parser.parse_objects(
[
util.add_required(
{
"category": {
"metric": {
"type": "event",
"extra_keys": {
"key_a": {"description": "desc-a", "type": "boolean"}
},
}
},
}
),
]
)
errs = list(results)
assert len(errs) == 0

metrics = {
metric.identifier(): metric.serialize()
for category, probes in results.value.items()
for probe_name, metric in probes.items()
}

expected = {
"category.metric": {
"bugs": ["http://bugzilla.mozilla.org/12345678"],
"data_reviews": ["https://example.com/review/"],
"defined_in": {"line": 3},
"description": "DESCRIPTION...",
"disabled": False,
"expires": "never",
"extra_keys": {"key_a": {"description": "desc-a", "type": "boolean"}},
"gecko_datapoint": "",
"lifetime": "ping",
"metadata": {},
"no_lint": [],
"notification_emails": ["[email protected]"],
"send_in_pings": ["events"],
"type": "event",
"version": 0,
}
}
expected_json = json.dumps(expected, sort_keys=True, indent=2)

out_json = json.dumps(
metrics,
sort_keys=True,
indent=2,
)
assert expected_json == out_json

0 comments on commit 33c939f

Please sign in to comment.