Skip to content

Commit

Permalink
Enforce a maximum limit of 10 extra_keys for events (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexterp37 committed May 21, 2020
1 parent 3c615ec commit d948a04
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Expand Up @@ -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)
-------------------
Expand Down
2 changes: 2 additions & 0 deletions glean_parser/schemas/metrics.1-0-0.schema.yaml
Expand Up @@ -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.
Expand All @@ -341,6 +342,7 @@ definitions:
type: string
required:
- description
maxProperties: 10
default: {}

gecko_datapoint:
Expand Down
32 changes: 32 additions & 0 deletions tests/data/schema-violation.yaml
Expand Up @@ -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
110 changes: 110 additions & 0 deletions tests/test_parser.py
Expand Up @@ -5,6 +5,7 @@

from pathlib import Path
import re
import sys
import textwrap

import pytest
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d948a04

Please sign in to comment.