diff --git a/HISTORY.rst b/HISTORY.rst index aed166d9..e1083d79 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,7 @@ Unreleased * `glinter` messages have been improved with more details and to be more actionable. +* A maximum of 10 `extra_keys` is now enforced for `event` metric types. 1.20.4 (2020-05-07) ------------------- diff --git a/glean_parser/schemas/metrics.1-0-0.schema.yaml b/glean_parser/schemas/metrics.1-0-0.schema.yaml index 0b63a4f2..d9d2c08e 100644 --- a/glean_parser/schemas/metrics.1-0-0.schema.yaml +++ b/glean_parser/schemas/metrics.1-0-0.schema.yaml @@ -326,6 +326,7 @@ definitions: description: | The acceptable keys on the "extra" object sent with events. This is an object mapping the key to an object containing metadata about the key. + A maximum of 10 extra keys is allowed. This metadata object has the following keys: - `description`: **Required.** A description of the key. @@ -341,6 +342,7 @@ definitions: type: string required: - description + maxProperties: 10 default: {} gecko_datapoint: diff --git a/tests/data/schema-violation.yaml b/tests/data/schema-violation.yaml index 10845cee..0f298c38 100644 --- a/tests/data/schema-violation.yaml +++ b/tests/data/schema-violation.yaml @@ -36,3 +36,35 @@ gleantest.short.category: notification_emails: ['nobody@example.com'] expires: never data_reviews: ['http://example.com'] +gleantest.event: + event_too_many_extras: + description: A test event with too many extra keys + type: event + bugs: + - https://bugzilla.mozilla.org/1580707 + notification_emails: ['nobody@example.com'] + expires: never + data_reviews: ['http://example.com'] + extra_keys: + key_1: + description: Sample extra key + key_2: + description: Sample extra key + key_3: + description: Sample extra key + key_4: + description: Sample extra key + key_5: + description: Sample extra key + key_6: + description: Sample extra key + key_7: + description: Sample extra key + key_8: + description: Sample extra key + key_9: + description: Sample extra key + key_10: + description: Sample extra key + key_11: + description: Sample extra key diff --git a/tests/test_parser.py b/tests/test_parser.py index b3289cc1..77524170 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -5,6 +5,7 @@ from pathlib import Path import re +import sys import textwrap import pytest @@ -134,6 +135,115 @@ def test_parser_schema_violation(): """, ] + # The validator reports a different error based on the python version, so + # we need to provide two copies for this to work. + if sys.version_info < (3, 7): + expected_errors.append( + """ + ``` + gleantest.event: + event_too_many_extras: + extra_keys: + key_1: + description: Sample extra key + key_2: + description: Sample extra key + key_3: + description: Sample extra key + key_4: + description: Sample extra key + key_5: + description: Sample extra key + key_6: + description: Sample extra key + key_7: + description: Sample extra key + key_8: + description: Sample extra key + key_9: + description: Sample extra key + key_10: + description: Sample extra key + key_11: + description: Sample extra key + ``` + + OrderedDict([('key_1', OrderedDict([('description', 'Sample extra + key')])), ('key_2', OrderedDict([('description', 'Sample extra + key')])), ('key_3', OrderedDict([('description', 'Sample extra + key')])), ('key_4', OrderedDict([('description', 'Sample extra + key')])), ('key_5', OrderedDict([('description', 'Sample extra + key')])), ('key_6', OrderedDict([('description', 'Sample extra + key')])), ('key_7', OrderedDict([('description', 'Sample extra + key')])), ('key_8', OrderedDict([('description', 'Sample extra + key')])), ('key_9', OrderedDict([('description', 'Sample extra + key')])), ('key_10', OrderedDict([('description', 'Sample extra + key')])), ('key_11', OrderedDict([('description', 'Sample extra + key')]))]) has too many properties + + Documentation for this node: + The acceptable keys on the "extra" object sent with events. This is an + object mapping the key to an object containing metadata about the key. + A maximum of 10 extra keys is allowed. + This metadata object has the following keys: + + - `description`: **Required.** A description of the key. + + Valid when `type`_ is `event`. + """ + ) + else: + expected_errors.append( + """ + ``` + gleantest.event: + event_too_many_extras: + extra_keys: + key_1: + description: Sample extra key + key_10: + description: Sample extra key + key_11: + description: Sample extra key + key_2: + description: Sample extra key + key_3: + description: Sample extra key + key_4: + description: Sample extra key + key_5: + description: Sample extra key + key_6: + description: Sample extra key + key_7: + description: Sample extra key + key_8: + description: Sample extra key + key_9: + description: Sample extra key + ``` + + {'key_1': {'description': 'Sample extra key'}, 'key_2': + {'description': 'Sample extra key'}, 'key_3': {'description': 'Sample + extra key'}, 'key_4': {'description': 'Sample extra key'}, 'key_5': + {'description': 'Sample extra key'}, 'key_6': {'description': 'Sample + extra key'}, 'key_7': {'description': 'Sample extra key'}, 'key_8': + {'description': 'Sample extra key'}, 'key_9': {'description': 'Sample + extra key'}, 'key_10': {'description': 'Sample extra key'}, 'key_11': + {'description': 'Sample extra key'}} has too many properties + + Documentation for this node: + The acceptable keys on the "extra" object sent with events. This is an + object mapping the key to an object containing metadata about the key. + A maximum of 10 extra keys is allowed. + This metadata object has the following keys: + + - `description`: **Required.** A description of the key. + + Valid when `type`_ is `event`. + """ + ) + expected_errors = set( re.sub(r"\s", "", _utils.indent(textwrap.dedent(x)).strip()) for x in expected_errors