From 22e627b686160181b70dada6e10fd3b40478b1fb Mon Sep 17 00:00:00 2001 From: Tom Tankilevitch <59158507+Tankilevitch@users.noreply.github.com> Date: Sun, 9 Jun 2024 10:48:19 +0300 Subject: [PATCH] increase verbosity for jira syncer (#19) --- config.py | 1 + core/base_handler.py | 1 - core/github_handler.py | 1 - core/jira_handler.py | 6 +++--- core/slack_handler.py | 1 - main.py | 17 ++++++++++++++--- targets/github.py | 1 - targets/jira.py | 3 +-- targets/slack.py | 1 - 9 files changed, 19 insertions(+), 13 deletions(-) diff --git a/config.py b/config.py index 711f84e..188bf80 100644 --- a/config.py +++ b/config.py @@ -43,6 +43,7 @@ class Settings(BaseSettings): filter_rule: Union[FilterRule, str, None] = Field(default=None) operation_kind: OperationKind = OperationKind.scorecard_reminder target_kind: TargetKind = TargetKind.slack + log_level: str = "INFO" class Config: env_prefix = "INPUT_" diff --git a/core/base_handler.py b/core/base_handler.py index e3e138f..7bd6abf 100644 --- a/core/base_handler.py +++ b/core/base_handler.py @@ -3,7 +3,6 @@ from config import settings from port.client import PortClient -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) diff --git a/core/github_handler.py b/core/github_handler.py index d312d72..b316322 100644 --- a/core/github_handler.py +++ b/core/github_handler.py @@ -5,7 +5,6 @@ from generators.github import GithubIssueGenerator from targets.github import Github -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) diff --git a/core/jira_handler.py b/core/jira_handler.py index 3c72c81..ac4b60e 100644 --- a/core/jira_handler.py +++ b/core/jira_handler.py @@ -5,7 +5,6 @@ from generators.jira import JiraIssueGenerator from targets.jira import Jira -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -86,9 +85,10 @@ def ticket_handler(self): elif not rule_successful and subtask["fields"]["resolution"]: Jira().reopen_issue(subtask) elif not rule_successful: + logger.debug( + f"Creating subtask for {rule.get('title')} in {parent_key} for {entity.get('name')}") Jira().create_issue(generated_subtask) if (scorecard_level_completed and - task_exists and - not task["fields"]["resolution"]): + task_exists and not task["fields"]["resolution"]): Jira().resolve_issue(task) diff --git a/core/slack_handler.py b/core/slack_handler.py index 37d2455..beb2fc7 100644 --- a/core/slack_handler.py +++ b/core/slack_handler.py @@ -5,7 +5,6 @@ from generators.slack import SlackMessageGenerator from targets.slack import Slack -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) diff --git a/main.py b/main.py index eae1467..55ab0b5 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ from typing import Dict, Type +import logging from config import settings from core.base_handler import BaseHandler @@ -7,11 +8,21 @@ from core.slack_handler import SlackHandler HANDLERS: Dict[str, Type[BaseHandler]] = { - "jira": JiraHandler, - "slack": SlackHandler, - "github": GithubHandler + "jira": JiraHandler, + "slack": SlackHandler, + "github": GithubHandler } +if len(logging.getLogger().handlers) > 0: + # The Lambda environment pre-configures a handler logging to stderr. + # If a handler is already configured, `.basicConfig` does not execute. + # Thus we set the level directly. + # https://stackoverflow.com/a/56579088 + logging.getLogger().setLevel(settings.log_level) +else: + logging.basicConfig(level=settings.log_level) +logger = logging.getLogger(__name__) + if __name__ == '__main__': operation_kind = settings.operation_kind handler = HANDLERS.get(settings.target_kind, SlackHandler)() diff --git a/targets/github.py b/targets/github.py index 6437d6f..4cee465 100644 --- a/targets/github.py +++ b/targets/github.py @@ -5,7 +5,6 @@ import requests from config import settings -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) REQUESTS_BACKOFF_FACTOR = 60 diff --git a/targets/jira.py b/targets/jira.py index 80feb73..4f30f5f 100644 --- a/targets/jira.py +++ b/targets/jira.py @@ -8,7 +8,6 @@ from config import settings -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -30,7 +29,7 @@ def __init__(self) -> None: def create_issue(self, params: dict[str, Any]) -> dict[str, Any]: logger.info(f"Creating new issue: {params['fields']['summary']}") - + logger.debug(f"Creating new issue with params: {params}") create_issue_response = requests.request( "POST", f"{self.api_url}/issue", json=params, headers=self.headers ) diff --git a/targets/slack.py b/targets/slack.py index 5beebf8..231cb32 100644 --- a/targets/slack.py +++ b/targets/slack.py @@ -5,7 +5,6 @@ from config import settings -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__)