def metrics(self, metrics_path): if metrics_path not in self._metrics_cache: from glean import load_metrics metrics = load_metrics(metrics_path) self._metrics_cache[metrics_path] = metrics return self._metrics_cache[metrics_path]
def test_event_extra_does_typechecks(): metrics = load_metrics( ROOT.parent / "data" / "events_with_types.yaml", config={"allow_reserved": False} ) # Valid combinations of extras. # These do not throw. metrics.core.PreferenceToggledExtra(preference="value1") metrics.core.PreferenceToggledExtra(enabled=True) metrics.core.PreferenceToggledExtra(swapped=1) extras = metrics.core.PreferenceToggledExtra(preference="value1", enabled=True, swapped=1) # Check conversion to FFI types, extras are sorted by name ffi = extras.to_ffi_extra() expected = ([0, 1, 2], ["true", "value1", "1"]) assert expected == ffi with pytest.raises(TypeError): metrics.core.PreferenceToggledExtra(preference=True) with pytest.raises(TypeError): metrics.core.PreferenceToggledExtra(enabled=1) with pytest.raises(TypeError): metrics.core.PreferenceToggledExtra(swapped="string") # Modifying an attribute only checks on conversion to FFI extras = metrics.core.PreferenceToggledExtra(preference="string") extras.preference = True with pytest.raises(TypeError): extras.to_ffi_extra()
def test_unknown_metric_type(): metrics = load_metrics(ROOT / "data" / "core.yaml", config={"allow_reserved": True}) assert isinstance(metrics.environment.profile_date, UnsupportedMetricType) with pytest.raises(TypeError): metrics.environment.profile_date.set("foo")
def test_working_metric(): metrics = load_metrics(ROOT / "data" / "core.yaml", config={"allow_reserved": True}) assert metrics.core_ping.flash_usage.__doc__.startswith( "The number of times the flash plugin" ) metrics.core_ping.flash_usage.add(1) assert 1 == metrics.core_ping.flash_usage.test_get_value()
def test_event_extra_is_generated_correctly(): metrics = load_metrics( ROOT.parent / "data" / "events_with_types.yaml", config={"allow_reserved": False} ) metrics.core.preference_toggled.record( metrics.core.PreferenceToggledExtra(preference="value1", enabled=True) ) assert { "preference": "value1", "enabled": "true", } == metrics.core.preference_toggled.test_get_value()[0].extra
def __init__(self): """Initiate Glean, load pings and metrics.""" logger.debug("Initializing Glean...") Glean.initialize( application_id="MozPhab", application_version=MOZPHAB_VERSION, upload_enabled=config.telemetry_enabled, configuration=Configuration(), data_dir=Path(environment.MOZBUILD_PATH) / "telemetry-data", ) self.pings = load_pings(environment.MOZPHAB_MAIN_DIR / "pings.yaml") self.metrics = load_metrics(environment.MOZPHAB_MAIN_DIR / "metrics.yaml")
def test_event_enum_is_generated_correctly(): metrics = load_metrics(ROOT.parent / "data" / "core.yaml", config={"allow_reserved": True}) print(dir(metrics.environment)) metrics.environment.event_example.record({ metrics.environment.event_example_keys.KEY1: "value1", metrics.environment.event_example_keys.KEY2: "value2", }) assert { "key1": "value1", "key2": "value2", } == metrics.environment.event_example.test_get_value()[0].extra
def __init__(self): """Initiate Glean, load pings and metrics.""" import glean logging.getLogger("glean").setLevel(logging.DEBUG) logger.debug("Initializing Glean...") glean.Glean.initialize( application_id="MozPhab", application_version=MOZPHAB_VERSION, upload_enabled=True, configuration=glean.Configuration(), data_dir=Path(environment.MOZBUILD_PATH) / "telemetry-data", ) self._pings = glean.load_pings(environment.MOZPHAB_MAIN_DIR / "pings.yaml") self._metrics = glean.load_metrics(environment.MOZPHAB_MAIN_DIR / "metrics.yaml")
def test_clear_application_lifetime_metrics(tmpdir): Glean._reset() Glean.initialize( application_id=GLEAN_APP_ID, application_version=glean_version, upload_enabled=True, data_dir=Path(str(tmpdir)), ) counter_metric = CounterMetricType( disabled=False, category="test.telemetry", lifetime=Lifetime.APPLICATION, name="lifetime_reset", send_in_pings=["store1"], ) # Additionally get metrics using the loader. metrics = load_metrics(ROOT / "data" / "core.yaml", config={"allow_reserved": True}) counter_metric.add(10) metrics.core_ping.seq.add(10) assert counter_metric.test_has_value() assert counter_metric.test_get_value() == 10 assert metrics.core_ping.seq.test_has_value() assert metrics.core_ping.seq.test_get_value() == 10 Glean._reset() Glean.initialize( application_id=GLEAN_APP_ID, application_version=glean_version, upload_enabled=True, data_dir=Path(str(tmpdir)), ) assert not counter_metric.test_has_value() assert not metrics.core_ping.seq.test_has_value()
# This Source Code Form is subject to the terms of the 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/. __version__ = "20.2.0" __title__ = "burnham" __description__ = "Application for end-to-end testing Mozilla's Glean telemetry. 👩🚀" __url__ = "https://github.com/mozilla/burnham" __author__ = "Raphael Pierzina" __email__ = "*****@*****.**" __license__ = "MPL 2.0" __copyright__ = "Copyright (c) 2019 Raphael Pierzina" from pkg_resources import resource_filename from glean import load_metrics, load_pings metrics = load_metrics(resource_filename(__name__, "config/metrics.yaml")) pings = load_pings(resource_filename(__name__, "config/pings.yaml"))
def test_glinter_no_error(capsys): load_metrics(ROOT / "data" / "core.yaml", config={"allow_reserved": True}) captured = capsys.readouterr() assert "" == captured.err
def test_glinter_error(capsys): load_metrics(ROOT / "data" / "glinter.yaml") captured = capsys.readouterr() assert "BUG_NUMBER" in captured.err
import time from multiprocessing import Process from pathlib import Path from glean import Configuration, Glean, load_metrics, load_pings from mozlog import get_proxy_logger from pkg_resources import resource_filename from mozregression import __version__ LOG = get_proxy_logger("telemetry") PINGS = load_pings(resource_filename(__name__, "pings.yaml")) METRICS = load_metrics(resource_filename(__name__, "metrics.yaml")) def initialize_telemetry(upload_enabled): mozregression_path = Path.home() / ".mozilla" / "mozregression" Glean.initialize( application_id="org.mozilla.mozregression", application_version=__version__, upload_enabled=upload_enabled, configuration=Configuration(allow_multiprocessing=False), data_dir=mozregression_path / "data", ) def _send_telemetry_ping(variant, appname): METRICS.usage.variant.set(variant) METRICS.usage.app.set(appname) PINGS.usage.submit()