Skip to content

Commit

Permalink
Merge branch 'main' into Matvey-Kuk/posthog-client-to-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Matvey-Kuk authored Jan 6, 2025
2 parents b612fb4 + ee49e7c commit de790b5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 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
12 changes: 10 additions & 2 deletions keep/providers/clickhouse_provider/clickhouse_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class ClickhouseProviderAuthConfig:
metadata={"required": False, "description": "Clickhouse database name"},
default=None,
)
protocol: str = dataclasses.field(
metadata={"required": True,
"description": "Protocol (Use clickhouses for SSL wrapped TCP socket connection, \
and clickhouse for plain TCP socket connection.)"},
default="clickhouse",
)


class ClickhouseProvider(BaseProvider):
Expand Down Expand Up @@ -107,8 +113,10 @@ def __generate_client(self):
host = self.authentication_config.host
database = self.authentication_config.database
port = self.authentication_config.port

dsn = f"clickhouse://{user}:{password}@{host}:{port}/{database}"
protocol = self.authentication_config.protocol
if protocol is None:
protocol = "clickhouse"
dsn = f"{protocol}://{user}:{password}@{host}:{port}/{database}"

return connect(dsn)

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 de790b5

Please sign in to comment.