Skip to content

Commit

Permalink
fix(api): workflowdb handler (#2988)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl authored Jan 6, 2025
1 parent 067df4a commit ee49e7c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
31 changes: 10 additions & 21 deletions keep/api/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import urllib3
from sqlmodel import Session

from keep.api.consts import RUNNING_IN_CLOUD_RUN
from keep.api.core.db import get_session, push_logs_to_db
from keep.api.models.db.provider import ProviderExecutionLog

Expand Down Expand Up @@ -140,26 +139,16 @@ def process(self, msg, kwargs):

def dump(self):
self.logger.info("Dumping workflow logs")
# TODO - this is a POC level code.
# TODO - we should:
# TODO - 1. find the right handler to push the logs to the DB
# TODO - 2. find a better way to push the logs async (maybe another service)
workflow_db_handler = next(
iter(
[
handler
for handler in (
# tb: for some reason, when running in cloud run, the handler is nested in another handler
# this needs to be handled in a better way
self.logger.parent.parent.handlers
if RUNNING_IN_CLOUD_RUN
else self.logger.parent.handlers
)
if isinstance(handler, WorkflowDBHandler)
]
),
None,
)
root_logger = logging.getLogger()
handlers = root_logger.handlers
workflow_db_handler = None

for handler in handlers:
# should be always the second
if isinstance(handler, WorkflowDBHandler):
workflow_db_handler = handler
break

if workflow_db_handler:
self.logger.info("Pushing logs to DB")
workflow_db_handler.push_logs_to_db()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "keep"
version = "0.33.9"
version = "0.34.0"
description = "Alerting. for developers, by developers."
authors = ["Keep Alerting LTD"]
packages = [{include = "keep"}]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_workflow_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ def test_workflow_execution_logs(
with patch(
"keep.contextmanager.contextmanager.WorkflowLoggerAdapter",
side_effect=fake_workflow_adapter,
), patch("keep.api.logging.RUNNING_IN_CLOUD_RUN", value=True):
):
base_time = datetime.now(tz=pytz.utc)

# Create alerts with specified statuses and timestamps
Expand Down Expand Up @@ -1009,7 +1009,7 @@ def test_workflow_execution_logs_log_level_debug_console_provider(
with patch(
"keep.contextmanager.contextmanager.WorkflowLoggerAdapter",
side_effect=fake_workflow_adapter,
), patch("keep.api.logging.RUNNING_IN_CLOUD_RUN", value=True):
):
base_time = datetime.now(tz=pytz.utc)

# Create alerts with specified statuses and timestamps
Expand Down

0 comments on commit ee49e7c

Please sign in to comment.