Skip to content

Commit d256620

Browse files
committed
Fully remove support for the old events API
1 parent 18bd599 commit d256620

24 files changed

+192
-175
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- BUGFIX: Remove internal-only fields from serialized metrics data ([#550](https://github.com/mozilla/glean_parser/pull/550))
66
- FEATURE: New subcommand: `dump` to dump the metrics data as JSON ([#550](https://github.com/mozilla/glean_parser/pull/550))
77
- BUGFIX: Kotlin: Generate enums with the right generic bound for ping reason codes ([#551](https://github.com/mozilla/glean_parser/pull/551)).
8+
- **BREAKING CHANGE:** Fully remove support for the old events API ([#549](https://github.com/mozilla/glean_parser/pull/549))
9+
Adds a new lint `OLD_EVENT_API` to warn about missing `type` attributes on event extra keys.
10+
Note that the Glean SDK already dropped support for the old events API.
811

912
## 6.4.0
1013

glean_parser/kotlin.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,20 @@ def type_name(obj: Union[metrics.Metric, pings.Ping]) -> str:
9292
"""
9393
generate_enums = getattr(obj, "_generate_enums", [])
9494
if len(generate_enums):
95-
template_args = []
95+
generic = None
9696
for member, suffix in generate_enums:
9797
if len(getattr(obj, member)):
98-
# Ugly hack to support the newer event extras API
99-
# along the deprecated API.
100-
# We need to specify both generic parameters,
101-
# but only for event metrics.
102-
# Plus `eventExtraKeys` use camelCase (lower),
103-
# whereas proper class names should use CamelCase.
104-
if suffix == "Extra":
105-
if isinstance(obj, metrics.Event):
106-
template_args.append("NoExtraKeys")
107-
template_args.append(util.Camelize(obj.name) + suffix)
98+
if isinstance(obj, metrics.Event):
99+
generic = util.Camelize(obj.name) + suffix
108100
else:
109-
template_args.append(util.camelize(obj.name) + suffix)
110-
if isinstance(obj, metrics.Event):
111-
template_args.append("NoExtras")
101+
generic = util.camelize(obj.name) + suffix
112102
else:
113-
if suffix == "Keys":
114-
template_args.append("NoExtraKeys")
115-
template_args.append("NoExtras")
103+
if isinstance(obj, metrics.Event):
104+
generic = "NoExtras"
116105
else:
117-
template_args.append("No" + suffix)
106+
generic = "No" + suffix
118107

119-
return "{}<{}>".format(class_name(obj.type), ", ".join(template_args))
108+
return "{}<{}>".format(class_name(obj.type), generic)
120109

121110
return class_name(obj.type)
122111

glean_parser/lint.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,21 @@ def check_expired_metric(
273273
yield ("Metric has expired. Please consider removing it.")
274274

275275

276+
def check_old_event_api(
277+
metric: metrics.Metric, parser_config: Dict[str, Any]
278+
) -> LintGenerator:
279+
# Glean v52.0.0 removed the old events API.
280+
# The metrics-2-0-0 schema still supports it.
281+
# We want to warn about it.
282+
# This can go when we introduce 3-0-0
283+
284+
if not isinstance(metric, metrics.Event):
285+
return
286+
287+
if not all("type" in x for x in metric.extra_keys.values()):
288+
yield ("The old event API is gone. Extra keys require a type.")
289+
290+
276291
def check_redundant_ping(
277292
pings: pings.Ping, parser_config: Dict[str, Any]
278293
) -> LintGenerator:
@@ -318,6 +333,7 @@ def check_redundant_ping(
318333
"EXPIRATION_DATE_TOO_FAR": (check_expired_date, CheckType.warning),
319334
"USER_LIFETIME_EXPIRATION": (check_user_lifetime_expiration, CheckType.warning),
320335
"EXPIRED": (check_expired_metric, CheckType.warning),
336+
"OLD_EVENT_API": (check_old_event_api, CheckType.warning),
321337
}
322338

323339

glean_parser/metrics.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,11 @@ class Event(Metric):
307307

308308
default_store_names = ["events"]
309309

310-
_generate_enums = [("allowed_extra_keys", "Keys")]
311-
312310
def __init__(self, *args, **kwargs):
313311
self.extra_keys = kwargs.pop("extra_keys", {})
314312
self.validate_extra_keys(self.extra_keys, kwargs.get("_config", {}))
315-
if self.has_extra_types:
316-
self._generate_enums = [("allowed_extra_keys_with_types", "Extra")]
317313
super().__init__(*args, **kwargs)
314+
self._generate_enums = [("allowed_extra_keys_with_types", "Extra")]
318315

319316
@property
320317
def allowed_extra_keys(self):
@@ -329,14 +326,6 @@ def allowed_extra_keys_with_types(self):
329326
key=lambda x: x[0],
330327
)
331328

332-
@property
333-
def has_extra_types(self):
334-
"""
335-
If any extra key has a `type` specified,
336-
we generate the new struct/object-based API.
337-
"""
338-
return any("type" in x for x in self.extra_keys.values())
339-
340329
@staticmethod
341330
def validate_extra_keys(extra_keys: Dict[str, str], config: Dict[str, Any]) -> None:
342331
if not config.get("allow_reserved") and any(

glean_parser/parser.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,6 @@ def _get_schema_for_content(
150150
return _get_schema(schema_url, filepath)
151151

152152

153-
def get_parameter_doc(key: str) -> str:
154-
"""
155-
Returns documentation about a specific metric parameter.
156-
"""
157-
schema, _ = _get_schema(METRICS_ID)
158-
return schema["definitions"]["metric"]["properties"][key]["description"]
159-
160-
161-
def get_ping_parameter_doc(key: str) -> str:
162-
"""
163-
Returns documentation about a specific ping parameter.
164-
"""
165-
schema, _ = _get_schema(PINGS_ID)
166-
return schema["additionalProperties"]["properties"][key]["description"]
167-
168-
169153
def validate(
170154
content: Dict[str, util.JSONType], filepath: Union[str, Path] = "<input>"
171155
) -> Generator[str, None, None]:

glean_parser/rust.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,18 @@ def type_name(obj):
103103
return "LabeledMetric<{}>".format(class_name(obj.type))
104104
generate_enums = getattr(obj, "_generate_enums", []) # Extra Keys? Reasons?
105105
if len(generate_enums):
106+
generic = None
106107
for name, suffix in generate_enums:
107-
if not len(getattr(obj, name)) and suffix == "Keys":
108-
return class_name(obj.type) + "<NoExtraKeys>"
108+
if len(getattr(obj, name)):
109+
generic = util.Camelize(obj.name) + suffix
109110
else:
110-
# we always use the `extra` suffix,
111-
# because we only expose the new event API
112-
suffix = "Extra"
113-
return "{}<{}>".format(
114-
class_name(obj.type), util.Camelize(obj.name) + suffix
115-
)
111+
if isinstance(obj, metrics.Event):
112+
generic = "NoExtra"
113+
else:
114+
generic = "No" + suffix
115+
116+
return "{}<{}>".format(class_name(obj.type), generic)
117+
116118
return class_name(obj.type)
117119

118120

glean_parser/swift.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,17 @@ def type_name(obj: Union[metrics.Metric, pings.Ping]) -> str:
9494
"""
9595
generate_enums = getattr(obj, "_generate_enums", [])
9696
if len(generate_enums):
97-
template_args = []
97+
generic = None
9898
for member, suffix in generate_enums:
9999
if len(getattr(obj, member)):
100-
# Ugly hack to support the newer event extras API
101-
# along the deprecated API.
102-
# We need to specify both generic parameters,
103-
# but only for event metrics.
104-
if suffix == "Extra":
105-
if isinstance(obj, metrics.Event):
106-
template_args.append("NoExtraKeys")
107-
template_args.append(util.Camelize(obj.name) + suffix)
108-
else:
109-
template_args.append(util.Camelize(obj.name) + suffix)
110-
if isinstance(obj, metrics.Event):
111-
template_args.append("NoExtras")
100+
generic = util.Camelize(obj.name) + suffix
112101
else:
113-
if suffix == "Keys":
114-
template_args.append("NoExtraKeys")
115-
template_args.append("NoExtras")
102+
if isinstance(obj, metrics.Event):
103+
generic = "NoExtras"
116104
else:
117-
template_args.append("No" + suffix)
105+
generic = "No" + suffix
118106

119-
return "{}<{}>".format(class_name(obj.type), ", ".join(template_args))
107+
return "{}<{}>".format(class_name(obj.type), generic)
120108

121109
return class_name(obj.type)
122110

glean_parser/templates/kotlin.jinja2

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ enum class {{ obj.name|camelize }}{{ suffix }} : ReasonCode {
4646
}
4747
{%- endmacro %}
4848

49-
{%- macro enum_decl(obj, name, suffix) -%}
50-
@Suppress("ClassNaming", "EnumNaming")
51-
enum class {{ obj.name|camelize }}{{ suffix }} : EventExtraKey {
52-
{% for key in obj|attr(name) %}
53-
{{ key|camelize }} {
54-
override fun keyName(): String = "{{ key }}"
55-
}{{ "," if not loop.last }}{{ ";" if loop.last }}
56-
57-
{% endfor %}
58-
}
59-
{%- endmacro %}
60-
6149
{%- macro struct_decl(obj, name, suffix) -%}
6250
@Suppress("ClassNaming", "EnumNaming")
6351
data class {{ obj.name|Camelize }}{{ suffix }}(
@@ -83,12 +71,10 @@ data class {{ obj.name|Camelize }}{{ suffix }}(
8371
package {{ namespace }}
8472

8573
import {{ glean_namespace }}.private.CommonMetricData // ktlint-disable import-ordering no-unused-imports
86-
import {{ glean_namespace }}.private.EventExtraKey // ktlint-disable import-ordering no-unused-imports
8774
import {{ glean_namespace }}.private.EventExtras // ktlint-disable import-ordering no-unused-imports
8875
import {{ glean_namespace }}.private.HistogramType // ktlint-disable import-ordering no-unused-imports
8976
import {{ glean_namespace }}.private.Lifetime // ktlint-disable import-ordering no-unused-imports
9077
import {{ glean_namespace }}.private.MemoryUnit // ktlint-disable import-ordering no-unused-imports
91-
import {{ glean_namespace }}.private.NoExtraKeys // ktlint-disable import-ordering no-unused-imports
9278
import {{ glean_namespace }}.private.NoExtras // ktlint-disable import-ordering no-unused-imports
9379
import {{ glean_namespace }}.private.ReasonCode // ktlint-disable import-ordering no-unused-imports
9480
import {{ glean_namespace }}.private.NoReasonCodes // ktlint-disable import-ordering no-unused-imports
@@ -114,11 +100,7 @@ internal object {{ category_name|Camelize }} {
114100
{% if obj|attr("_generate_enums") %}
115101
{% for name, suffix in obj["_generate_enums"] %}
116102
{% if obj|attr(name)|length %}
117-
{% if obj.has_extra_types %}
118103
{{ struct_decl(obj, name, suffix)|indent }}
119-
{% else %}
120-
{{ enum_decl(obj, name, suffix)|indent }}
121-
{% endif %}
122104
{% endif %}
123105
{% endfor %}
124106
{% endif %}

glean_parser/templates/rust.jinja2

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ Jinja2 template is not. Please file bugs! #}
1313
{# we always use the `extra` suffix, because we only expose the new event API #}
1414
{% set suffix = "Extra" %}
1515
{% if obj|attr(name)|length %}
16-
{% if obj.has_extra_types %}
1716
{{ extra_keys_with_types(obj, name, suffix)|indent }}
18-
{% else %}
19-
compile_error!("Untyped event extras not supported. Please annotate event extras with a type. See documentation for details. (Metric: {{obj.category}}.{{obj.name}}, defined in: {{obj.defined_in['filepath']}}:{{obj.defined_in['line']}})");
20-
{% endif %}
2117
{% endif %}
2218
{% endfor %}
2319
{% endmacro %}

glean_parser/templates/swift.jinja2

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ Jinja2 template is not. Please file bugs! #}
2424
)
2525
{% endmacro %}
2626

27-
{% macro enum_decl(obj, name, suffix) %}
28-
enum {{ obj.name|Camelize }}{{ suffix }}: Int32, ExtraKeys {
29-
{% for key in obj|attr(name) %}
30-
case {{ key|camelize|variable_name }} = {{ loop.index-1 }}
31-
{% endfor %}
32-
33-
public func index() -> Int32 {
34-
return self.rawValue
35-
}
36-
}
37-
{% endmacro %}
38-
3927
{% macro struct_decl(obj, name, suffix) %}
4028
struct {{ obj.name|Camelize }}{{ suffix }}: EventExtras {
4129
{% for item, typ in obj|attr(name) %}
@@ -119,11 +107,7 @@ extension {{ namespace }} {
119107
{% if obj|attr("_generate_enums") %}
120108
{% for name, suffix in obj["_generate_enums"] %}
121109
{% if obj|attr(name)|length %}
122-
{% if obj.has_extra_types %}
123110
{{ struct_decl(obj, name, suffix)|indent }}
124-
{% else %}
125-
{{ enum_decl(obj, name, suffix)|indent }}
126-
{% endif %}
127111
{% endif %}
128112
{% endfor %}
129113
{% endif %}

0 commit comments

Comments
 (0)