Exemplo n.º 1
0
def test_500_error_submit_concurrent_writing(slow_httpserver, monkeypatch):
    # This tests that concurrently writing to the database from the main process
    # and the ping uploading subprocess.
    slow_httpserver.serve_content(b"", code=500)

    counter = metrics.CounterMetricType(
        disabled=False,
        category="test",
        name="counter",
        send_in_pings=["metrics"],
        lifetime=metrics.Lifetime.PING,
    )

    # Force the ping upload worker into a separate process
    monkeypatch.setattr(PingUploadWorker, "process", PingUploadWorker._process)
    Glean._configuration._server_endpoint = slow_httpserver.url
    Glean._submit_ping_by_name("baseline")

    # While the uploader is running, increment the counter as fast as we can
    times = 0
    last_process = ProcessDispatcher._last_process
    while last_process.poll() is None:
        counter.add()
        times += 1

    # This kind of recoverable error will be tried 3 times
    # The number of retries is defined on glean-core
    assert 3 == len(slow_httpserver.requests)

    metric = get_upload_failure_metric()
    assert not metric["status_code_4xx"].test_has_value()
    assert 3 == metric["status_code_5xx"].test_get_value()

    assert times > 0
    assert times == counter.test_get_value()
Exemplo n.º 2
0
def test_recording_upload_errors_doesnt_clobber_database(
        tmpdir, safe_httpserver, monkeypatch):
    """
    Test that running the ping uploader subprocess doesn't clobber the
    database. If, under some bug, the subprocess had "upload_enabled" set to
    True, it could record upload errors in the database, clobbering any metrics
    that might have meanwhile been recorded in the main process.

    This test is known to fail if "upload_enabled" is set to `True` in the
    subprocess.
    """
    tmpdir = Path(tmpdir)

    Glean._reset()
    Glean.initialize(
        application_id=GLEAN_APP_ID,
        application_version=glean_version,
        upload_enabled=True,
        data_dir=tmpdir,
    )

    counter_metric = CounterMetricType(
        disabled=False,
        category="telemetry",
        lifetime=Lifetime.PING,
        name="counter_metric",
        send_in_pings=["baseline"],
    )
    counter_metric.add(10)

    safe_httpserver.serve_content(b"", code=400)

    # Force the ping upload worker into a separate process
    monkeypatch.setattr(PingUploadWorker, "process", PingUploadWorker._process)
    Glean._configuration._server_endpoint = safe_httpserver.url
    Glean._submit_ping_by_name("baseline")
    ProcessDispatcher._wait_for_last_process()

    assert 1 == len(safe_httpserver.requests)

    # Force a reload of the database from disk
    Glean._reset()
    Glean.initialize(
        application_id=GLEAN_APP_ID,
        application_version=glean_version,
        upload_enabled=True,
        data_dir=tmpdir,
    )

    metric = get_upload_failure_metric()
    assert not metric["status_code_4xx"].test_has_value()
Exemplo n.º 3
0
def test_400_error_submit(safe_httpserver, monkeypatch):
    safe_httpserver.serve_content(b"", code=400)

    # Force the ping upload worker into a separate process
    monkeypatch.setattr(PingUploadWorker, "process", PingUploadWorker._process)
    Glean._configuration._server_endpoint = safe_httpserver.url
    Glean._submit_ping_by_name("baseline")
    ProcessDispatcher._wait_for_last_process()

    assert 1 == len(safe_httpserver.requests)

    metric = get_upload_failure_metric()
    assert 1 == metric["status_code_4xx"].test_get_value()
    assert not metric["status_code_5xx"].test_has_value()
Exemplo n.º 4
0
def test_500_error_submit(safe_httpserver, monkeypatch):
    safe_httpserver.serve_content(b"", code=500)

    # Force the ping upload worker into a separate process
    monkeypatch.setattr(PingUploadWorker, "process", PingUploadWorker._process)
    Glean._configuration._server_endpoint = safe_httpserver.url
    Glean._submit_ping_by_name("baseline")
    ProcessDispatcher._wait_for_last_process()

    # This kind of recoverable error will be tried 10 times
    # The number of retries is defined on glean-core
    assert 3 == len(safe_httpserver.requests)

    metric = get_upload_failure_metric()
    assert not metric["status_code_4xx"].test_has_value()
    assert 3 == metric["status_code_5xx"].test_get_value()
Exemplo n.º 5
0
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
Exemplo n.º 6
0
def test_submiting_an_empty_ping_doesnt_queue_work(safe_httpserver):
    safe_httpserver.serve_content(b"", code=200)

    Glean._submit_ping_by_name("metrics")
    assert 0 == len(safe_httpserver.requests)