From c791912a3c3a20f7fec77afe3fb09c0f1317e695 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Tue, 23 Jan 2024 17:51:36 +0200 Subject: [PATCH 1/4] misc: Use fully-qualified secretmanager module --- kcidb/misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kcidb/misc.py b/kcidb/misc.py index 204f571f..945847bc 100644 --- a/kcidb/misc.py +++ b/kcidb/misc.py @@ -15,7 +15,7 @@ import dateutil import dateutil.relativedelta import dateutil.parser -from google.cloud import secretmanager +import google.cloud.secretmanager import jsonschema import jq import kcidb.io as io @@ -440,7 +440,7 @@ def get_secret(project_id, secret_id): """ assert isinstance(project_id, str) and project_id assert isinstance(secret_id, str) and secret_id - client = secretmanager.SecretManagerServiceClient() + client = google.cloud.secretmanager.SecretManagerServiceClient() path = client.secret_version_path(project_id, secret_id, "latest") return client.access_secret_version( request={"name": path} From 5e556593c32589d65521bb93eb00528e8f9fa4be Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Tue, 23 Jan 2024 18:38:40 +0200 Subject: [PATCH 2/4] misc: Add timestamps to all log messages --- kcidb/misc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kcidb/misc.py b/kcidb/misc.py index 945847bc..b0fab1c5 100644 --- a/kcidb/misc.py +++ b/kcidb/misc.py @@ -52,6 +52,10 @@ def logging_setup(level): """ assert isinstance(level, int) logging.getLogger().setLevel(level) + # Add timestamps to log messages + for handler in logging.getLogger().handlers: + handler.setFormatter(logging.Formatter( + '%(asctime)s:%(levelname)s:%(name)s:%(message)s')) # TODO Consider separate arguments for controlling the below logging.getLogger("urllib3").setLevel(LOGGING_LEVEL_MAP["NONE"]) logging.getLogger("google").setLevel(LOGGING_LEVEL_MAP["NONE"]) From 62420af557884a640a59bbd888c0a461464c7c03 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Tue, 23 Jan 2024 18:17:39 +0200 Subject: [PATCH 3/4] main: Setup Google Cloud logging to fix logging --- main.py | 6 ++++++ requirements.txt | 1 + setup.py | 1 + 3 files changed, 8 insertions(+) diff --git a/main.py b/main.py index fb7c667f..f0b2376c 100644 --- a/main.py +++ b/main.py @@ -10,14 +10,20 @@ import smtplib from urllib.parse import unquote import functions_framework +import google.cloud.logging import kcidb # Name of the Google Cloud project we're deployed in PROJECT_ID = os.environ["GCP_PROJECT"] +# Setup Google Cloud logging, unless testing +if PROJECT_ID != "TEST_PROJECT": + google.cloud.logging.Client().setup_logging() +# Setup KCIDB-specific logging kcidb.misc.logging_setup( kcidb.misc.LOGGING_LEVEL_MAP[os.environ.get("KCIDB_LOG_LEVEL", "NONE")] ) +# Get the module's logger LOGGER = logging.getLogger() # The subscriber object for the submission queue diff --git a/requirements.txt b/requirements.txt index b13dd20a..976e2cc6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ google-cloud-pubsub google-cloud-firestore google-cloud-storage google-cloud-secret-manager +google-cloud-logging psycopg2 functions-framework jsonschema[format] diff --git a/setup.py b/setup.py index 20fb38b1..eb678f6b 100644 --- a/setup.py +++ b/setup.py @@ -49,6 +49,7 @@ "functions-framework", "google-cloud-firestore", "google-cloud-secret-manager", + "google-cloud-logging", "psycopg2", "jsonschema[format]", "requests", From 29964d9a61815f42aa04f68975d19b1cc037be8a Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 25 Jan 2024 10:12:17 +0200 Subject: [PATCH 4/4] main: Give Cloud Logging some time to come up --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index f0b2376c..e2eea4e8 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ """Google Cloud Functions for Kernel CI reporting""" import os +import time import atexit import tempfile import base64 @@ -19,6 +20,8 @@ # Setup Google Cloud logging, unless testing if PROJECT_ID != "TEST_PROJECT": google.cloud.logging.Client().setup_logging() + # Give logging some time to avoid occasional deployment failures + time.sleep(5) # Setup KCIDB-specific logging kcidb.misc.logging_setup( kcidb.misc.LOGGING_LEVEL_MAP[os.environ.get("KCIDB_LOG_LEVEL", "NONE")]