Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- BREAKING CHANGE: Generate labeled {custom|memory|timing} distribution for mobile ([#857](https://github.com/mozilla/glean_parser/pull/857))
- Allow categories to have subcategories longer than 29 characters ([bug 2062403](https://bugzilla.mozilla.org/show_bug.cgi?id=2062403))

## 20.2.0
- Allow renaming of fields when serializing metrics ([mozilla/glean-dictionary#2309](https://github.com/mozilla/glean-dictionary/issues/2309))
Expand Down
2 changes: 1 addition & 1 deletion glean_parser/schemas/metrics.2-0-0.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ definitions:

dotted_snake_case:
type: string
pattern: "^[a-z_][a-z0-9_]{0,29}(\\.[a-z_][a-z0-9_]{0,29})*$"
pattern: "^[a-z_][a-z0-9_]*(\\.[a-z_][a-z0-9_]*)*$"
maxLength: 40

event_extra_key:
Expand Down
22 changes: 22 additions & 0 deletions tests/data/categories.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Any copyright is dedicated to the Public Domain.
# https://creativecommons.org/publicdomain/zero/1.0/

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

we_used_to_have_subcategory_length:
Comment thread
chutten marked this conversation as resolved.
but_we_dont_any_more: &defaults
type: counter
expires: never
description: A test metric
bugs: [https://bugzil.la/2062403]
data_reviews: [https://www.example.com]
notification_emails: [glean-team@mozilla.com]
Comment thread
badboy marked this conversation as resolved.

it.may_matter_that_theres_a_dot_here:
so_we_will_test_that_too:
<<: *defaults

a.b:
really_short_categories_are_allowed:
<<: *defaults
5 changes: 4 additions & 1 deletion tests/data/schema-violation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ gleantest.lifetime:
expires: never
data_reviews: ['http://example.com']
gleantest.with.way.too.long.category.name:
test_event_inv_lt:
test_event_inv_lt: &valid_metric
description: A test metric
type: boolean
bugs:
- https://bugzilla.mozilla.org/1580707
notification_emails: ['nobody@example.com']
expires: never
data_reviews: ['http://example.com']
gleantest_with_way_too_long_category_name_and_no_subcategories:
test_metric:
<<: *valid_metric
gleantest.short.category:
very_long_metric_name_this_is_too_long_as_well_since_it_has_sooooo_many_characters:
description: A test metric
Expand Down
31 changes: 31 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,18 @@ def test_parser_schema_violation():
- `description`: **Required.** A description of the key.
Valid when `type`_ is `event`.
""",
"""
```
gleantest_with_way_too_long_category_name_and_no_subcategories
...
```

'gleantest_with_way_too_long_category_name_and_no_subcategories' is not valid under any of
the given schemas
'gleantest_with_way_too_long_category_name_and_no_subcategories' is too long
'gleantest_with_way_too_long_category_name_and_no_subcategories' is not one of
['$schema', '$tags']
""",
]

expected_errors = set(
Expand All @@ -371,6 +383,14 @@ def test_parser_schema_violation():
for found_error, expected_error in zip(found, expected):
assert found_error == expected_error

# If there are new errors and they're sorted after the expected list,
# the above checks won't find them. Log 'em, then assert 'em.
if len(found) > len(expected):
for i in range(len(expected), len(found)):
print(f"Unexpected error: {found[i]}")

assert len(found) == len(expected)


def test_parser_empty():
"""1507792: Get a good error message if the metrics.yaml file is empty."""
Expand Down Expand Up @@ -1593,3 +1613,14 @@ def test_overriden_expire_epoch_must_be_valid(invalid_epoch):
list(all_metrics)

del os.environ["SOURCE_DATE_EPOCH"]


def test_categories():
"""Test the basics of parsing oddly-named-or-structured categories."""
all_metrics = parser.parse_objects(
[ROOT / "data" / "categories.yaml"],
config={"allow_reserved": False},
)

errs = list(all_metrics)
assert len(errs) == 0