From ce1e57e67d4db9643c0199398529e33740cb1cc9 Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Wed, 27 Sep 2023 18:20:38 -0700 Subject: [PATCH] fix: re-enable slog's envlogger - add a test for autoendpoint's LogCheck (follow up for 392f4e1) - fix a bug in host_endpoint used for integration test's vapid headers SYNC-3933 --- Cargo.lock | 3 --- autoconnect/Cargo.toml | 3 +-- autoendpoint/Cargo.toml | 1 - autopush-common/src/logging.rs | 2 ++ autopush/Cargo.toml | 1 - tests/test_integration_all_rust.py | 39 ++++++++++++++++++++++-------- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82ddbe218..b0c0a602d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -556,7 +556,6 @@ dependencies = [ "serde_json", "slog", "slog-async", - "slog-envlogger", "slog-mozlog-json", "slog-scope", "slog-stdlog", @@ -721,7 +720,6 @@ dependencies = [ "serde_json", "slog", "slog-async", - "slog-envlogger", "slog-mozlog-json", "slog-scope", "slog-stdlog", @@ -774,7 +772,6 @@ dependencies = [ "signal-hook", "slog", "slog-async", - "slog-envlogger", "slog-mozlog-json", "slog-scope", "slog-stdlog", diff --git a/autoconnect/Cargo.toml b/autoconnect/Cargo.toml index 2af87bd26..fdb976b8a 100644 --- a/autoconnect/Cargo.toml +++ b/autoconnect/Cargo.toml @@ -36,7 +36,6 @@ serde_derive.workspace = true serde_json.workspace = true slog.workspace = true slog-async.workspace = true -slog-envlogger.workspace = true slog-mozlog-json.workspace = true slog-scope.workspace = true slog-stdlog.workspace = true @@ -53,4 +52,4 @@ docopt = "1.1" [features] emulator = ["bigtable"] -bigtable = ["autopush_common/bigtable", "autoconnect_settings/bigtable"] \ No newline at end of file +bigtable = ["autopush_common/bigtable", "autoconnect_settings/bigtable"] diff --git a/autoendpoint/Cargo.toml b/autoendpoint/Cargo.toml index 09d8bd2b6..5c66ad7de 100644 --- a/autoendpoint/Cargo.toml +++ b/autoendpoint/Cargo.toml @@ -35,7 +35,6 @@ serde_dynamodb.workspace = true serde_json.workspace = true slog.workspace = true slog-async.workspace = true -slog-envlogger.workspace = true slog-mozlog-json.workspace = true slog-scope.workspace = true slog-stdlog.workspace = true diff --git a/autopush-common/src/logging.rs b/autopush-common/src/logging.rs index 11f18719d..55af5e26a 100644 --- a/autopush-common/src/logging.rs +++ b/autopush-common/src/logging.rs @@ -24,11 +24,13 @@ pub fn init_logging(json: bool) -> Result<()> { .hostname(hostname) .build() .fuse(); + let drain = slog_envlogger::new(drain); let drain = slog_async::Async::new(drain).build().fuse(); slog::Logger::root(drain, slog_o!()) } else { let decorator = slog_term::TermDecorator::new().build(); let drain = slog_term::FullFormat::new(decorator).build().fuse(); + let drain = slog_envlogger::new(drain); let drain = slog_async::Async::new(drain).build().fuse(); slog::Logger::root(drain, slog_o!()) }; diff --git a/autopush/Cargo.toml b/autopush/Cargo.toml index b9d773724..7e9b80545 100644 --- a/autopush/Cargo.toml +++ b/autopush/Cargo.toml @@ -29,7 +29,6 @@ serde_derive.workspace = true serde_json.workspace = true slog.workspace = true slog-async.workspace = true -slog-envlogger.workspace = true slog-mozlog-json.workspace = true slog-scope.workspace = true slog-stdlog.workspace = true diff --git a/tests/test_integration_all_rust.py b/tests/test_integration_all_rust.py index 545f8e706..f6079730d 100644 --- a/tests/test_integration_all_rust.py +++ b/tests/test_integration_all_rust.py @@ -821,7 +821,7 @@ def tearDown(self): def host_endpoint(self, client): parsed = urlparse(list(client.channels.values())[0]) - "{}://{}".format(parsed.scheme, parsed.netloc) + return "{}://{}".format(parsed.scheme, parsed.netloc) @inlineCallbacks def quick_register(self): @@ -844,7 +844,7 @@ def _ws_url(self): @inlineCallbacks @max_logs(conn=4) - def test_sentry_output(self): + def test_sentry_output_autoconnect(self): if os.getenv("SKIP_SENTRY"): SkipTest("Skipping sentry test") return @@ -859,15 +859,34 @@ def test_sentry_output(self): requests.get( "http://localhost:{}/v1/err/crit".format(CONNECTION_PORT) ) + event1 = MOCK_SENTRY_QUEUE.get(timeout=5) + # new autoconnect emits 2 events try: - data = MOCK_SENTRY_QUEUE.get(timeout=5) - except ValueError as ex: - if not ex.contains("I/O operation on closed file"): - raise ex - # python2 on circleci will fail this test due to an IO error. - # Local testing shows that this test works. - # This may resolve by updating tests to python3 (see #334) - assert data["exception"]["values"][0]["value"] == "LogCheck" + maybe_event2 = MOCK_SENTRY_QUEUE.get(timeout=1) + except Empty: + pass + assert event1["exception"]["values"][0]["value"] == "LogCheck" + + @inlineCallbacks + @max_logs(endpoint=1) + def test_sentry_output_autoendpoint(self): + if os.getenv("SKIP_SENTRY"): + SkipTest("Skipping sentry test") + return + + client = yield self.quick_register() + endpoint = self.host_endpoint(client) + yield self.shut_down(client) + + requests.get("{}/__error__".format(endpoint)) + # 2 events excpted: 1 from a panic and 1 from a returned Error + event1 = MOCK_SENTRY_QUEUE.get(timeout=5) + event2 = MOCK_SENTRY_QUEUE.get(timeout=1) + values = ( + event1["exception"]["values"][0]["value"], + event2["exception"]["values"][0]["value"], + ) + assert sorted(values) == ["ERROR:Success", "LogCheck"] @max_logs(conn=4) def test_no_sentry_output(self):