bug 1745283 Support file-level tags
This commit is contained in:
Родитель
89b02df07a
Коммит
8e2c38b977
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Support global file-level tags in metrics.yaml ([bug 1745283](https://bugzilla.mozilla.org/show_bug.cgi?id=1745283))
|
||||
|
||||
## 4.3.1
|
||||
|
||||
- BUGFIX: Skip tags for code generation ([#409](https://github.com/mozilla/glean_parser/pull/409))
|
||||
|
|
|
@ -195,6 +195,8 @@ def _instantiate_metrics(
|
|||
objects, and merge them into a single tree.
|
||||
"""
|
||||
global_no_lint = content.get("no_lint", [])
|
||||
global_tags = content.get("$tags", [])
|
||||
assert isinstance(global_tags, list)
|
||||
|
||||
for category_key, category_val in content.items():
|
||||
if category_key.startswith("$"):
|
||||
|
@ -243,6 +245,10 @@ def _instantiate_metrics(
|
|||
|
||||
if metric_obj is not None:
|
||||
metric_obj.no_lint = list(set(metric_obj.no_lint + global_no_lint))
|
||||
if len(global_tags):
|
||||
metric_obj.metadata["tags"] = list(
|
||||
set(metric_obj.metadata.get("tags", []) + global_tags)
|
||||
)
|
||||
|
||||
if isinstance(filepath, Path):
|
||||
metric_obj.defined_in["filepath"] = str(filepath)
|
||||
|
|
|
@ -538,7 +538,7 @@ propertyNames:
|
|||
- not:
|
||||
description: "'tags' is reserved as a category name."
|
||||
const: tags
|
||||
- enum: ['$schema']
|
||||
- enum: ['$schema', '$tags']
|
||||
|
||||
properties:
|
||||
$schema:
|
||||
|
@ -553,6 +553,14 @@ properties:
|
|||
items:
|
||||
type: string
|
||||
|
||||
$tags:
|
||||
title: Tags that apply to the whole file
|
||||
description: |
|
||||
This denotes the list of tags that apply to all metrics in this file.
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
|
||||
additionalProperties:
|
||||
type: object
|
||||
propertyNames:
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
---
|
||||
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
|
||||
|
||||
$tags:
|
||||
- global_tag
|
||||
|
||||
telemetry:
|
||||
client_id:
|
||||
type: uuid
|
||||
|
|
|
@ -13,3 +13,8 @@ apple:
|
|||
description: |
|
||||
A red fruit. Or green. Or a mix of it.
|
||||
Very good in pie.
|
||||
|
||||
global_tag:
|
||||
description: |
|
||||
A very uninteresting global tag.
|
||||
Alas, it has no colour.
|
||||
|
|
|
@ -110,7 +110,7 @@ def test_parser_schema_violation():
|
|||
the given schemas
|
||||
'gleantest.with.way.too.long.category.name' is too long
|
||||
'gleantest.with.way.too.long.category.name' is not one of
|
||||
['$schema']
|
||||
['$schema', '$tags']
|
||||
""",
|
||||
"""
|
||||
```
|
||||
|
@ -569,9 +569,12 @@ def test_tags():
|
|||
|
||||
assert errors == []
|
||||
assert len(all_metrics.value) == 1
|
||||
assert all_metrics.value["telemetry"]["client_id"].metadata == {
|
||||
"tags": ["banana", "apple"]
|
||||
}
|
||||
assert set(all_metrics.value["telemetry"]["client_id"].metadata.keys()) == set(
|
||||
["tags"]
|
||||
)
|
||||
assert set(all_metrics.value["telemetry"]["client_id"].metadata["tags"]) == set(
|
||||
["banana", "apple", "global_tag"]
|
||||
)
|
||||
|
||||
|
||||
def test_custom_expires():
|
||||
|
|
Загрузка…
Ссылка в новой задаче