def test_set_application_id_and_version(safe_httpserver): safe_httpserver.serve_content(b"", code=200) Glean._reset() Glean._initialize_with_tempdir_for_testing( application_id="my-id", application_version="my-version", upload_enabled=True, configuration=Configuration(server_endpoint=safe_httpserver.url), ) assert ( "my-version" == _builtins.metrics.glean.internal.metrics.app_display_version.test_get_value() ) Glean._configuration.server_endpoint = safe_httpserver.url _builtins.pings.baseline.submit() assert 1 == len(safe_httpserver.requests) request = safe_httpserver.requests[0] assert "baseline" in request.url assert "my-id" in request.url
def test_flush_queued_events_on_startup(safe_httpserver): safe_httpserver.serve_content(b"", code=200) Glean._configuration.server_endpoint = safe_httpserver.url class EventKeys(enum.Enum): SOME_EXTRA = 0 event = metrics.EventMetricType( disabled=False, category="telemetry", lifetime=Lifetime.PING, name="test_event", send_in_pings=["events"], allowed_extra_keys=["some_extra"], ) event.record(extra={EventKeys.SOME_EXTRA: "bar"}) assert 1 == len(event.test_get_value()) testing.reset_glean( application_id="glean-python-test", application_version=glean_version, clear_stores=False, configuration=Configuration(server_endpoint=safe_httpserver.url), ) assert 1 == len(safe_httpserver.requests) request = safe_httpserver.requests[0] assert "events" in request.url
def test_no_sending_deletion_ping_if_unchanged_outside_of_run(safe_httpserver, tmpdir): safe_httpserver.serve_content(b"", code=200) Glean._reset() config = Configuration(server_endpoint=safe_httpserver.url) Glean.initialize( application_id=GLEAN_APP_ID, application_version=glean_version, upload_enabled=False, data_dir=Path(str(tmpdir)), configuration=config, ) assert 0 == len(safe_httpserver.requests) Glean._reset() Glean.initialize( application_id=GLEAN_APP_ID, application_version=glean_version, upload_enabled=False, data_dir=Path(str(tmpdir)), configuration=config, ) assert 0 == len(safe_httpserver.requests)
def test_sending_deletion_ping_if_disabled_outside_of_run( tmpdir, ping_schema_url): info_path = Path(str(tmpdir)) / "info.txt" data_dir = Path(str(tmpdir)) / "glean" Glean._reset() Glean.initialize( application_id=GLEAN_APP_ID, application_version=glean_version, upload_enabled=True, data_dir=data_dir, configuration=Configuration( ping_uploader=_RecordingUploader(info_path)), ) Glean._reset() Glean.initialize( application_id=GLEAN_APP_ID, application_version=glean_version, upload_enabled=False, data_dir=data_dir, configuration=Configuration( ping_uploader=_RecordingUploader(info_path)), ) while not info_path.exists(): time.sleep(0.1) with info_path.open("r") as fd: url_path = fd.readline() serialized_ping = fd.readline() assert "deletion-request" == url_path.split("/")[3] json_content = json.loads(serialized_ping) assert 0 == validate_ping.validate_ping( io.StringIO(serialized_ping), sys.stdout, schema_url=ping_schema_url, ) assert not json_content["client_info"]["client_id"].startswith("c0ffee")
def test_the_app_channel_must_be_correctly_set(): Glean.reset() Glean.initialize( application_id=GLEAN_APP_ID, application_version=glean_version, configuration=Configuration(channel="my-test-channel"), ) assert ("my-test-channel" == _builtins.metrics.glean.internal.metrics. app_channel.test_get_value())
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 test_the_app_channel_must_be_correctly_set(): Glean._reset() Glean._initialize_with_tempdir_for_testing( application_id=GLEAN_APP_ID, application_version=glean_version, upload_enabled=True, configuration=Configuration(channel="my-test-channel"), ) assert ("my-test-channel" == _builtins.metrics.glean.internal.metrics. app_channel.test_get_value())
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_flush_queued_events_on_startup_and_correctly_handle_preinit_events( safe_httpserver, ): safe_httpserver.serve_content(b"", code=200) Glean._configuration.server_endpoint = safe_httpserver.url Glean._configuration.log_pings = True class EventKeys(enum.Enum): SOME_EXTRA = 0 event = metrics.EventMetricType( disabled=False, category="telemetry", lifetime=Lifetime.PING, name="test_event", send_in_pings=["events"], allowed_extra_keys=["some_extra"], ) event.record(extra={EventKeys.SOME_EXTRA: "run1"}) assert 1 == len(event.test_get_value()) Dispatcher.set_task_queueing(True) event.record(extra={EventKeys.SOME_EXTRA: "pre-init"}) testing.reset_glean( application_id="glean-python-test", application_version=glean_version, clear_stores=False, configuration=Configuration(server_endpoint=safe_httpserver.url, log_pings=True), ) event.record(extra={EventKeys.SOME_EXTRA: "post-init"}) assert 1 == len(safe_httpserver.requests) request = safe_httpserver.requests[0] assert "events" in request.url assert 1 == len(event.test_get_value()) Glean._submit_ping_by_name("events") assert 2 == len(safe_httpserver.requests) request = safe_httpserver.requests[1] assert "events" in request.url