Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1648696 - Look for metrics in send_if_empty pings #197

Merged
merged 3 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {} +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated. I ran into issues while running make clean


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] = []
brizental marked this conversation as resolved.
Show resolved Hide resolved
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The designer part of you is now surfacing :)

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