Closed Bug 1921089 Opened 10 months ago Closed 3 months ago

glean_parser: forbid redefinition of categories, metrics, pings in definitions files

Categories

(Data Platform and Tools :: Glean: SDK, defect, P4)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: chutten, Unassigned)

Details

Attachments

(1 file)

YAML will allow you to write e.g.

category:
  metric:
    type: not_even_a_metric_type
    ...
  metric:
    type: counter
    ...
category:
  a_different_metric:
    type: timing_distribution

and happily overwrite category.metric with the second definition and then overwrite all of category.* with category.a_different_metric later.

This is a rather annoying thing to discover by accident. We should look into whether or not we can prevent this (while still permitting the time-saving spread operations like used to set test defaults in the SDK).

Actually, it's unclear whether YAML permits this or whether it's just our choice of YAML parser and parsing options that does. I shouldn't be so quick to tar the language with wrinkles it might not have.

PyYAML (the yaml library we use to load it) by default just uses ... the last seen key:

❯ python3
Python 3.12.6 (main, Sep  6 2024, 19:03:47) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> src = '''
... category:
...   metric:
...     type: not_even_a_metric_type
...   metric:
...     type: counter
... category:
...   a_different_metric:
...     type: timing_distribution
... '''
>>> yaml.safe_load(src)
{'category': {'a_different_metric': {'type': 'timing_distribution'}}}

It seems possible to overwrite that behavior: https://stackoverflow.com/questions/44904290/getting-duplicate-keys-in-yaml-using-python/48460700#48460700

We could use that to either error out, warn or merge things together.

Priority: -- → P4

chutten merged PR [mozilla/glean_parser]: bug 1921089 - Forbid redefinition of metrics in definitions files (#794) in 1289aef.

Needs to be released and vendored, but this ought to handle it.

Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: