Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): workflowdb handler #2988

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading