1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# This Source Code Form is subject to the terms of Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
import unittest
from os import path
import mozunit
TELEMETRY_ROOT_PATH = path.abspath(
path.join(path.dirname(__file__), path.pardir, path.pardir)
)
sys.path.append(TELEMETRY_ROOT_PATH)
# The parsers live in a subdirectory of "build_scripts", account for that.
# NOTE: if the parsers are moved, this logic will need to be updated.
sys.path.append(path.join(TELEMETRY_ROOT_PATH, "build_scripts"))
from mozparsers import parse_events, parse_histograms, parse_scalars
def is_expired(app_version_major, probe_expiration):
if probe_expiration in ["never", "default"]:
return False
if int(app_version_major) < int(probe_expiration.split(".", 1)[0]):
return False
return True
class TestNoExpiredProbes(unittest.TestCase):
def test_no_expired_probes(self):
"""Ensure there are no expired histograms, events, or scalars
in Histograms.json, Events.yaml, or Scalars.yaml, respectively."""
with open("browser/config/version.txt") as version_file:
app_version = version_file.read().strip()
app_version_major = app_version.split(".", 1)[0]
hgrams = parse_histograms.from_files(
[path.join(TELEMETRY_ROOT_PATH, "Histograms.json")]
)
for hgram in hgrams:
if hgram.name().startswith("TELEMETRY_TEST_"):
# We ignore test histograms which are permitted to be expired.
continue
self.assertFalse(
is_expired(app_version_major, hgram.expiration()),
f"Histogram {hgram.name()} is expired (expiration: {hgram.expiration()}).",
)
scalars = parse_scalars.load_scalars(
path.join(TELEMETRY_ROOT_PATH, "Scalars.yaml")
)
for scalar in scalars:
if scalar.category == "telemetry.test":
# We ignore test scalars which are permitted to be expired.
continue
self.assertFalse(
is_expired(app_version_major, scalar.expires),
f"Scalar {scalar.label} is expired (expires: {scalar.expires}).",
)
events = parse_events.load_events(
path.join(TELEMETRY_ROOT_PATH, "Events.yaml"), True
)
for event in events:
if event.category == "telemetry.test":
# We ignore test events which are permitted to be expired.
continue
self.assertFalse(
is_expired(app_version_major, event.expiry_version),
f"Event definition {event.identifier} is expired (expiry_version: {event.expiry_version}).",
)
if __name__ == "__main__":
mozunit.main()
|