Skip to content

Commit

Permalink
fix(api): maximum response size and linearb services (keephq#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Apr 10, 2024
1 parent 3b02914 commit 49ccf0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions keep/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uvicorn
from dotenv import find_dotenv, load_dotenv
from fastapi import FastAPI, HTTPException, Request, Response
from fastapi.middleware.gzip import GZipMiddleware
from fastapi.responses import JSONResponse
from opentelemetry import trace
from starlette.middleware.base import BaseHTTPMiddleware
Expand Down Expand Up @@ -134,6 +135,9 @@ def get_app(
version="0.1.0",
)
app.add_middleware(RawContextMiddleware, plugins=(plugins.RequestIdPlugin(),))
app.add_middleware(
GZipMiddleware, minimum_size=30 * 1024 * 1024
) # Approximately 30 MiB, https://cloud.google.com/run/quotas
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
Expand Down
2 changes: 2 additions & 0 deletions keep/providers/linearb_provider/linearb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def _notify(
if services:
if isinstance(services, str):
services = json.loads(services)
if len(services) > 0 and isinstance(services[0], dict):
services = [service["name"] for service in services]
payload["services"] = services
elif "services" in payload:
service_names = [service["name"] for service in payload["services"]]
Expand Down
21 changes: 14 additions & 7 deletions keep/step/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def _check_throttling(self, action_name):

throttling_type = throttling.get("type")
throttling_config = throttling.get("with")
throttle = ThrottleFactory.get_instance(self.context_manager, throttling_type, throttling_config)
throttle = ThrottleFactory.get_instance(
self.context_manager, throttling_type, throttling_config
)
alert_id = self.context_manager.get_workflow_id()
return throttle.check_throttling(action_name, alert_id)

Expand Down Expand Up @@ -201,19 +203,24 @@ def _run_single(self):
else:
evaluated_if_met = True

action_name = self.config.get("name")
if not evaluated_if_met:
self.logger.info(
"Action %s evaluated NOT to run, Reason: %s evaluated to false.",
self.config.get("name"),
if_met,
f"Action {action_name} evaluated NOT to run, Reason: {if_met} evaluated to false.",
extra={
"condition": if_conf,
"rendered": if_met,
},
)
return

if if_conf:
self.logger.info(
"Action %s evaluated to run! Reason: %s evaluated to true.",
self.config.get("name"),
if_met,
f"Action {action_name} evaluated to run! Reason: {if_met} evaluated to true.",
extra={
"condition": if_conf,
"rendered": if_met,
},
)
else:
self.logger.info(
Expand Down

0 comments on commit 49ccf0a

Please sign in to comment.