Skip to content

Commit

Permalink
Bug 1648696 - Look for metrics in send_if_empty pings (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Beatriz Rizental authored Jun 30, 2020
1 parent 14e65c8 commit 3c8de75
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ History
Unreleased
----------

* BUGFIX: look for metrics in send_if_empty pings. Metrics for these kinds of pings were being ignored.

1.23.0 (2020-06-27)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ clean-build: ## remove build artifacts
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.egg' -exec rm -fr {} +

clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
Expand Down
14 changes: 8 additions & 6 deletions glean_parser/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ def output_markdown(
# the description
if isinstance(obj, pings.Ping):
custom_pings_cache[obj.name] = obj
if obj.send_if_empty:
# Pings that have `send_if_empty` set to true,
# might not have any metrics. They need to at least have an
# empty array of metrics to show up on the template.
if obj.send_if_empty and not metrics_by_pings[obj.name]:
metrics_by_pings[obj.name] = []
elif obj.is_internal_metric():
# This is an internal Glean metric, and we don't
# want docs for it.
continue
else:

# If this is an internal Glean metric, and we don't
# want docs for it.
if isinstance(obj, metrics.Metric) and not obj.is_internal_metric():
# If we get here, obj is definitely a metric we want
# docs for.
for ping_name in obj.send_in_pings:
Expand Down
21 changes: 21 additions & 0 deletions tests/data/send_if_empty_with_metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Any copyright is dedicated to the Public Domain.
# https://creativecommons.org/publicdomain/zero/1.0/

---
$schema: moz://mozilla.org/schemas/glean/metrics/1-0-0

telemetry:
some_metric:
type: uuid
lifetime: ping
description: >
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
bugs:
- https://bugzilla.mozilla.org/1137353
data_reviews:
- http://example.com/reviews
notification_emails:
- CHANGE-ME@example.com
send_in_pings:
- custom-ping-might-be-empty
expires: 2100-01-01
21 changes: 21 additions & 0 deletions tests/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,24 @@ def test_event_extra_keys_in_correct_order(tmpdir):
r"<li>bob: three</li>"
r"<li>charlie: one</li></ul>" in content
)


def test_send_if_empty_metrics(tmpdir):
tmpdir = Path(str(tmpdir))

translate.translate(
[
ROOT / "data" / "send_if_empty_with_metrics.yaml",
ROOT / "data" / "pings.yaml",
],
"markdown",
tmpdir,
{"namespace": "Foo"},
)

assert set(x.name for x in tmpdir.iterdir()) == set(["metrics.md"])

# Make sure descriptions made it in
with (tmpdir / "metrics.md").open("r", encoding="utf-8") as fd:
content = fd.read()
assert "Lorem ipsum dolor sit amet, consectetur adipiscing elit." in content

0 comments on commit 3c8de75

Please sign in to comment.