Skip to content

Commit

Permalink
Merge branch 'main' into feat-add-event-id-to-alert-dto
Browse files Browse the repository at this point in the history
  • Loading branch information
pehlicd authored Apr 11, 2024
2 parents fbd3b18 + a2cc359 commit 6f74cf1
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 82 deletions.
2 changes: 1 addition & 1 deletion keep-ui/app/workflows/[workflow_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function WorkflowDetailPage({
<TableBody>
{workflowExecutions.map((execution) => (
<TableRow key={execution.id}>
<TableCell>{execution.started}</TableCell>
<TableCell>{new Date(execution.started + "Z").toLocaleString()}</TableCell>
<TableCell>{execution.id}</TableCell>
<TableCell>{execution.triggered_by}</TableCell>
<TableCell>{execution.status}</TableCell>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ export default function WorkflowExecutionPage({
<TableCell className="w-1/4 break-words whitespace-normal">
{stepId}
</TableCell>
<TableCell className="w-3/4 break-words whitespace-normal">
<TableCell className="w-3/4 break-words whitespace-normal max-w-xl">
<Accordion>
<AccordionHeader>Value</AccordionHeader>
<AccordionBody>
<pre className="overflow-scroll max-w-lg">
<pre className="overflow-scroll">
{JSON.stringify(stepResults, null, 2)}
</pre>
</AccordionBody>
Expand All @@ -140,43 +140,61 @@ export default function WorkflowExecutionPage({
)}
<div className={Object.keys(results).length > 0 ? "mt-8" : ""}>
{executionStatus === "success" ? (
<Card>
<Title>Workflow Logs</Title>
<Table className="w-full">
<TableHead>
<TableRow>
<TableCell className="w-1/3 break-words whitespace-normal">
Timestamp
</TableCell>
<TableCell className="w-1/3 break-words whitespace-normal">
Message
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{logs.map((log, index) => (
<TableRow
className={`${
log.message?.includes("NOT to run")
? "bg-red-100"
: log.message?.includes("evaluated to run")
? "bg-green-100"
: ""
}`}
key={index}
>
<>
{error && (
<Callout
className="mt-4"
title="Error during workflow execution"
icon={ExclamationCircleIcon}
color="rose"
>
{error
? error.split("\n").map((line, index) => (
// Render each line as a separate paragraph or div.
// The key is index, which is sufficient for simple lists like this.
<p key={index}>{line}</p>
))
: "An unknown error occurred during execution."}
</Callout>
)}
<Card>
<Title>Workflow Logs</Title>
<Table className="w-full">
<TableHead>
<TableRow>
<TableCell className="w-1/3 break-words whitespace-normal">
{log.timestamp}
Timestamp
</TableCell>
<TableCell className="w-1/3 break-words whitespace-normal">
{log.message}
Message
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Card>
) : executionStatus === "in_progress" ? (
</TableHead>
<TableBody>
{logs.map((log, index) => (
<TableRow
className={`${
log.message?.includes("NOT to run")
? "bg-red-100"
: log.message?.includes("evaluated to run")
? "bg-green-100"
: ""
}`}
key={index}
>
<TableCell className="w-1/3 break-words whitespace-normal">
{log.timestamp}
</TableCell>
<TableCell className="w-1/3 break-words whitespace-normal">
{log.message}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Card>
</>
) : (
<div>
<div className="flex items-center justify-center">
<p>
Expand All @@ -186,22 +204,6 @@ export default function WorkflowExecutionPage({
</div>
<Loading></Loading>
</div>
) : (
<Callout
className="mt-4"
title="Error during workflow execution"
icon={ExclamationCircleIcon}
color="rose"
>
{error
? error.split('\n').map((line, index) => (
// Render each line as a separate paragraph or div.
// The key is index, which is sufficient for simple lists like this.
<p key={index}>{line}</p>
))
: "An unknown error occurred during execution."
}
</Callout>
)}
</div>
</div>
Expand Down
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
10 changes: 9 additions & 1 deletion keep/api/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,15 @@ def finish_workflow_execution(tenant_id, workflow_id, execution_id, status, erro
def get_workflow_executions(tenant_id, workflow_id, limit=50):
with Session(engine) as session:
workflow_executions = session.exec(
select(WorkflowExecution)
select(
WorkflowExecution.id,
WorkflowExecution.workflow_id,
WorkflowExecution.started,
WorkflowExecution.status,
WorkflowExecution.triggered_by,
WorkflowExecution.execution_time,
WorkflowExecution.error,
)
.where(WorkflowExecution.tenant_id == tenant_id)
.where(WorkflowExecution.workflow_id == workflow_id)
.where(
Expand Down
21 changes: 10 additions & 11 deletions keep/api/routes/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,18 @@ def get_workflow_by_id(
workflow_executions_dtos = []
with tracer.start_as_current_span("create_workflow_dtos"):
for workflow_execution in workflow_executions:
workflow_execution_dto = WorkflowExecutionDTO(
id=workflow_execution.id,
workflow_id=workflow_execution.workflow_id,
status=workflow_execution.status,
started=workflow_execution.started,
triggered_by=workflow_execution.triggered_by,
error=workflow_execution.error,
execution_time=workflow_execution.execution_time,
results=workflow_execution.results,
)
workflow_execution_dto = {
"id": workflow_execution.id,
"workflow_id": workflow_execution.workflow_id,
"status": workflow_execution.status,
"started": workflow_execution.started.isoformat(),
"triggered_by": workflow_execution.triggered_by,
"error": workflow_execution.error,
"execution_time": workflow_execution.execution_time,
}
workflow_executions_dtos.append(workflow_execution_dto)

return workflow_executions_dtos
return JSONResponse(content=workflow_executions_dtos)


@router.delete("/{workflow_id}", description="Delete workflow")
Expand Down
5 changes: 4 additions & 1 deletion keep/providers/linearb_provider/linearb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _notify(
ended_at="",
git_ref="",
should_delete="",
issued_at="",
**kwargs: dict,
):
"""
Expand Down Expand Up @@ -134,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 Expand Up @@ -165,7 +168,7 @@ def _notify(
"At least 1 team is required for creating an incident"
)

issued_at = datetime.datetime.now().isoformat()
issued_at = issued_at or datetime.datetime.now().isoformat()

payload = {
"provider_id": incident_id,
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 6f74cf1

Please sign in to comment.