Skip to content

Commit ad86d60

Browse files
authored
Merge pull request #168 from mozilla/bhr-stack
Bug 1675103 - Set `payload.hangs[].stack` to string in telemetry.bhr.4
2 parents 96ed0f3 + c8e54e4 commit ad86d60

File tree

12 files changed

+95
-78
lines changed

12 files changed

+95
-78
lines changed

bin/generate_commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ function _generate_schemas() {
3838
--mps-branch "$mps_branch_source" \
3939
--out-dir ./telemetry
4040

41+
mozilla-schema-generator generate-bhr-ping \
42+
--mps-branch "$mps_branch_source" \
43+
--out-dir ./telemetry
44+
4145
mozilla-schema-generator generate-common-pings \
4246
--common-pings-config "$COMMON_PINGS_PATH" \
4347
--mps-branch "$mps_branch_source" \

mozilla_schema_generator/__main__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import click
1313
import yaml
1414

15+
from .bhr_ping import BhrPing
1516
from .common_ping import CommonPing
1617
from .config import Config
1718
from .glean_ping import GleanPing
@@ -88,6 +89,19 @@ def generate_main_ping(config, out_dir, split, pretty, mps_branch):
8889
config_data = yaml.safe_load(f)
8990

9091
config = Config("main", config_data)
92+
schemas = schema_generator.generate_schema(config, split=False)
93+
# schemas introduces an extra layer to the actual schema
94+
dump_schema(schemas, out_dir, pretty, version=4)
95+
96+
97+
@click.command()
98+
@common_options
99+
def generate_bhr_ping(out_dir, split, pretty, mps_branch):
100+
schema_generator = BhrPing(mps_branch=mps_branch)
101+
if out_dir:
102+
out_dir = Path(out_dir)
103+
104+
config = Config("bhr", {})
91105
schemas = schema_generator.generate_schema(config, split=split)
92106
dump_schema(schemas, out_dir, pretty, version=4)
93107

@@ -186,15 +200,7 @@ def generate_glean_pings(
186200
config = Config("glean", config_data)
187201

188202
for repo in repos:
189-
write_schema(
190-
repo,
191-
config,
192-
out_dir,
193-
split,
194-
pretty,
195-
generic_schema,
196-
mps_branch,
197-
)
203+
write_schema(repo, config, out_dir, split, pretty, generic_schema, mps_branch)
198204

199205

200206
def write_schema(repo, config, out_dir, split, pretty, generic_schema, mps_branch):
@@ -242,6 +248,7 @@ def main(args=None):
242248

243249

244250
main.add_command(generate_main_ping)
251+
main.add_command(generate_bhr_ping)
245252
main.add_command(generate_glean_pings)
246253
main.add_command(generate_common_pings)
247254

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
from .common_ping import CommonPing
8+
from .utils import prepend_properties
9+
10+
11+
class BhrPing(CommonPing):
12+
schema_url = (
13+
"https://raw.githubusercontent.com/mozilla-services/mozilla-pipeline-schemas"
14+
"/{branch}/schemas/telemetry/bhr/bhr.4.schema.json"
15+
)
16+
17+
def __init__(self, **kwargs):
18+
super().__init__(self.schema_url, **kwargs)
19+
20+
def _update_env(self, schema):
21+
# hangs is an array of objects
22+
stack = prepend_properties(("payload", "hangs")) + (
23+
"items",
24+
"properties",
25+
"stack",
26+
)
27+
schema.set_schema_elem(
28+
stack,
29+
{
30+
"type": "string",
31+
"description": (
32+
"JSON representation of the stack field."
33+
" Injected by mozilla-schema-generator."
34+
),
35+
},
36+
# this may otherwise overwrite the "items" fields
37+
propagate=False,
38+
)
39+
40+
return super()._update_env(schema)

mozilla_schema_generator/common_ping.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ def get_schema(self):
4141
def _update_env(self, schema):
4242
integer = {"type": "integer"}
4343
string = {"type": "string"}
44-
string_map = {
45-
"type": "object",
46-
"additionalProperties": string,
47-
}
44+
string_map = {"type": "object", "additionalProperties": string}
4845

4946
def with_description(dtype: dict, comment: str) -> dict:
5047
"""Add a description to the types defined above."""

mozilla_schema_generator/probes.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,11 @@ class MainProbe(Probe):
6868

6969
first_added_key = "first_added"
7070

71-
histogram_schema = {
72-
"type": "string",
73-
}
71+
histogram_schema = {"type": "string"}
7472

7573
parent_processes = {"main"}
7674

77-
child_processes = {
78-
"content",
79-
"gpu",
80-
"extension",
81-
"dynamic",
82-
"socket",
83-
}
75+
child_processes = {"content", "gpu", "extension", "dynamic", "socket"}
8476

8577
processes_map = {
8678
"all_childs": child_processes,

setup.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,10 @@
3333
"console_scripts": [
3434
"mozilla-schema-generator=mozilla_schema_generator.__main__:main",
3535
"validate-bigquery=mozilla_schema_generator.validate_bigquery:validate",
36-
],
36+
]
3737
},
3838
include_package_data=True,
39-
install_requires=[
40-
"click",
41-
"jsonschema",
42-
"pyyaml",
43-
"requests",
44-
"gitpython",
45-
],
39+
install_requires=["click", "jsonschema", "pyyaml", "requests", "gitpython"],
4640
license="MIT",
4741
zip_safe=False,
4842
keywords="mozilla-schema-generator",

tests/test_bhr.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
from mozilla_schema_generator.bhr_ping import BhrPing
8+
from mozilla_schema_generator.config import Config
9+
10+
11+
def test_schema_contains_hangs_stacks():
12+
schema = BhrPing().generate_schema(Config("bhr", {}))["bhr"][0].schema
13+
hangs = schema["properties"]["payload"]["properties"]["hangs"]
14+
assert hangs["items"]["properties"]["stack"]["type"] == "string"

tests/test_integration.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_split_representation(self, schema, env, probes): # noqa F811
102102
"properties": {"test_probe": MainProbe.histogram_schema},
103103
},
104104
},
105-
},
105+
}
106106
],
107107
"nested": [
108108
{
@@ -231,10 +231,7 @@ def test_max_size(self, schema, env, probes): # noqa F811
231231
{
232232
"second_level": False,
233233
"details": {"keyed": False},
234-
"versions": {
235-
"first": "50",
236-
"last": "60",
237-
},
234+
"versions": {"first": "50", "last": "60"},
238235
}
239236
]
240237
},

tests/test_matcher.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
class TestMatcher(object):
1212
def test_matches(self):
1313
match_obj = {
14-
"details": {
15-
"record_in_processes": {"contains": "main"},
16-
"keyed": True,
17-
},
14+
"details": {"record_in_processes": {"contains": "main"}, "keyed": True},
1815
"table_group": "keyed_scalars",
1916
"type": "scalar",
2017
}

tests/test_probes.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@ def glean_probe_defn():
1919
"first": "2019-04-12 13:44:13",
2020
"last": "2019-08-08 15:34:03",
2121
},
22-
"send_in_pings": [
23-
"metrics",
24-
],
22+
"send_in_pings": ["metrics"],
2523
},
2624
{
2725
"description": "Glean test description",
2826
"dates": {
2927
"first": "2019-08-08 15:34:14",
3028
"last": "2019-08-08 15:45:14",
3129
},
32-
"send_in_pings": [
33-
"all-pings",
34-
],
30+
"send_in_pings": ["all-pings"],
3531
},
3632
],
3733
"name": "glean.error.invalid_value",
@@ -48,18 +44,14 @@ def glean_probe_defn_subset_pings():
4844
"first": "2019-04-12 13:44:13",
4945
"last": "2019-08-08 15:34:03",
5046
},
51-
"send_in_pings": [
52-
"metrics",
53-
],
47+
"send_in_pings": ["metrics"],
5448
},
5549
{
5650
"dates": {
5751
"first": "2019-08-08 15:34:14",
5852
"last": "2019-08-08 15:45:14",
5953
},
60-
"send_in_pings": [
61-
"baseline",
62-
],
54+
"send_in_pings": ["baseline"],
6355
},
6456
],
6557
"name": "glean.error.invalid_value",
@@ -138,17 +130,11 @@ def main_probe_defn():
138130
"versions": {"first": "65", "last": "68"},
139131
},
140132
{
141-
"details": {
142-
"keyed": False,
143-
"kind": "string",
144-
},
133+
"details": {"keyed": False, "kind": "string"},
145134
"versions": {"first": "61", "last": "64"},
146135
},
147136
{
148-
"details": {
149-
"keyed": False,
150-
"kind": "string",
151-
},
137+
"details": {"keyed": False, "kind": "string"},
152138
"versions": {"first": "55", "last": "60"},
153139
},
154140
],
@@ -172,7 +158,7 @@ def main_probe_all_childs_defn():
172158
},
173159
"versions": {"first": "67", "last": "70"},
174160
}
175-
],
161+
]
176162
},
177163
"name": "a11y.instantiators",
178164
"type": "scalar",
@@ -201,7 +187,7 @@ def main_probe_all_childs_and_main_defn():
201187
},
202188
"versions": {"first": "62", "last": "66"},
203189
},
204-
],
190+
]
205191
},
206192
"name": "a11y.instantiators",
207193
"type": "scalar",
@@ -223,7 +209,7 @@ def main_probe_all_defn():
223209
},
224210
"versions": {"first": "67", "last": "70"},
225211
}
226-
],
212+
]
227213
},
228214
"name": "a11y.instantiators",
229215
"type": "scalar",
@@ -245,7 +231,7 @@ def main_probe_max_description_length():
245231
},
246232
"versions": {"first": "67", "last": "70"},
247233
}
248-
],
234+
]
249235
},
250236
"name": "a11y.instantiators",
251237
"type": "scalar",

0 commit comments

Comments
 (0)