Skip to content

Commit

Permalink
Merge branch 'main' into feature/historical-rules-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirFilonov authored Dec 16, 2024
2 parents b6bb671 + fca91d3 commit db60ab7
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 57 deletions.
30 changes: 22 additions & 8 deletions keep-ui/app/(keep)/alerts/alert-assign-ticket-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useState } from "react";
import Select, { components } from "react-select";
import { Button, TextInput, Text } from "@tremor/react";
import { Button, TextInput, Text, Icon } from "@tremor/react";
import { PlusIcon } from "@heroicons/react/20/solid";
import { useForm, Controller, SubmitHandler } from "react-hook-form";
import { Providers } from "../providers/providers";
import { AlertDto } from "./models";
import Modal from "@/components/ui/Modal";
import { useApi } from "@/shared/lib/hooks/useApi";
import { QuestionMarkCircleIcon } from "@heroicons/react/24/outline";

interface AlertAssignTicketModalProps {
handleClose: () => void;
Expand Down Expand Up @@ -41,12 +42,18 @@ const AlertAssignTicketModal = ({
const {
handleSubmit,
control,
reset,
formState: { errors, isSubmitting },
} = useForm<FormData>();

// if this modal should not be open, do nothing
if (!alert) return null;

const handleModalClose = () => {
reset();
handleClose();
};

const onSubmit: SubmitHandler<FormData> = async (data) => {
try {
// build the formData
Expand All @@ -60,7 +67,7 @@ const AlertAssignTicketModal = ({
};
const response = await api.post(`/alerts/enrich`, requestData);
alert.ticket_url = data.ticket_url;
handleClose();
handleModalClose();
} catch (error) {
// Handle unexpected error
console.error("An unexpected error occurred");
Expand Down Expand Up @@ -147,17 +154,24 @@ const AlertAssignTicketModal = ({
return (
<Modal
isOpen={isOpen}
onClose={handleClose}
onClose={handleModalClose}
title="Assign Ticket"
className="w-[400px]"
>
<div className="relative bg-white p-6 rounded-lg">
{ticketingProviders.length > 0 ? (
<form onSubmit={handleSubmit(onSubmit)} className="mt-4">
<div className="mt-4">
<label className="block text-sm font-medium text-gray-700">
Ticket Provider
</label>
<div className="flex flex-row items-center mb-2">
<label className="block text-sm font-medium text-gray-700">
Ticket Provider
</label>
<Icon
icon={QuestionMarkCircleIcon}
tooltip="Select a Ticketing provider from the list below, Keep will use the select provider and Ticket URL to enrich your alert."
className="w-2 h-2 ml-2 z-[60]"
/>
</div>
<Controller
name="provider"
control={control}
Expand Down Expand Up @@ -210,7 +224,7 @@ const AlertAssignTicketModal = ({
<Text>Assign Ticket</Text>
</Button>
<Button
onClick={handleClose}
onClick={handleModalClose}
variant="secondary"
className="border border-orange-500 text-orange-500"
>
Expand All @@ -234,7 +248,7 @@ const AlertAssignTicketModal = ({
<Text>Connect Ticketing Provider</Text>
</Button>
<Button
onClick={handleClose}
onClick={handleModalClose}
color="orange"
variant="secondary"
className="mt-4 border border-orange-500 text-orange-500"
Expand Down
22 changes: 11 additions & 11 deletions keep-ui/app/(keep)/alerts/alert-name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {
TicketIcon,
TrashIcon,
PencilSquareIcon,
Cog8ToothIcon,
// Cog8ToothIcon,
} from "@heroicons/react/24/outline";
import { Icon } from "@tremor/react";
import { AlertDto, AlertToWorkflowExecution } from "./models";
// import { useWorkflowExecutions } from "utils/hooks/useWorkflowExecutions";
import { useRouter } from "next/navigation";
import { useWorkflowExecutions } from "@/utils/hooks/useWorkflowExecutions";

interface Props {
alert: AlertDto;
Expand All @@ -22,8 +24,7 @@ export default function AlertName({
setTicketModalAlert,
}: Props) {
const router = useRouter();
// TODO: fix this so we can show which alert had workflow execution
// const { data: executions } = useWorkflowExecutions();
const { data: executions } = useWorkflowExecutions();

const handleNoteClick = () => {
if (setNoteModalAlert) {
Expand All @@ -39,9 +40,8 @@ export default function AlertName({
}
};

const relevantWorkflowExecution: AlertToWorkflowExecution | null = null;
// executions?.find((wf) => wf.alert_fingerprint === alert.fingerprint) ??
// null;
const relevantWorkflowExecution =
executions?.find((wf) => wf.event_id === alert.event_id) ?? null;

const {
name,
Expand Down Expand Up @@ -132,29 +132,29 @@ export default function AlertName({
variant="solid"
/>
)}
{/* {relevantWorkflowExecution && (
{relevantWorkflowExecution && (
<Icon
icon={Cog8ToothIcon}
size="xs"
color={`${
relevantWorkflowExecution.workflow_status === "success"
? "green"
: relevantWorkflowExecution.workflow_status === "error"
? "red"
: "gray"
? "red"
: "gray"
}`}
tooltip={`${
relevantWorkflowExecution.workflow_status === "success"
? "Last workflow executed successfully"
: relevantWorkflowExecution.workflow_status === "error"
? "Last workflow execution failed"
: undefined
? "Last workflow execution failed"
: undefined
}`}
onClick={() => handleWorkflowClick(relevantWorkflowExecution)}
className="ml-1 cursor-pointer"
variant="solid"
/>
)} */}
)}
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions keep-ui/app/(keep)/alerts/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export interface AlertToWorkflowExecution {
| "error"
| "providers_not_configured";
workflow_started: Date;
event_id: string;
}

export const AlertKnownKeys = [
Expand Down
8 changes: 4 additions & 4 deletions keep-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion keep-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"postcss-nested": "^6.0.1",
"postcss-selector-parser": "^6.0.12",
"postcss-value-parser": "^4.2.0",
"posthog-js": "^1.194.2",
"posthog-js": "^1.200.1",
"posthog-node": "^3.1.1",
"pusher-js": "^8.3.0",
"react": "^18.3.1",
Expand Down
14 changes: 7 additions & 7 deletions keep/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ def no_redirect_request(self, method, url, **kwargs):
async def check_pending_tasks(background_tasks: set):
while True:
events_in_queue = len(background_tasks)
if events_in_queue > 0:
logger.info(
f"{events_in_queue} background tasks pending",
extra={
"pending_tasks": events_in_queue,
},
)
logger.info(
f"{events_in_queue} background tasks pending",
extra={
"pending_tasks": events_in_queue,
},
)
await asyncio.sleep(1)


Expand Down Expand Up @@ -195,6 +194,7 @@ async def lifespan(app: FastAPI):
background_tasks = set()
# if debug tasks are enabled, create a task to check for pending tasks
if KEEP_DEBUG_TASKS:
logger.info("Starting background task to check for pending tasks")
asyncio.create_task(check_pending_tasks(background_tasks))

# Startup
Expand Down
1 change: 1 addition & 0 deletions keep/api/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class WorkflowToAlertExecutionDTO(BaseModel):
alert_fingerprint: str
workflow_status: str
workflow_started: datetime
event_id: str | None


class WorkflowExecutionDTO(BaseModel):
Expand Down
53 changes: 27 additions & 26 deletions keep/api/routes/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,33 @@ async def create_workflow(
)


@router.get("/executions", description="Get workflow executions by alert fingerprint")
def get_workflow_executions_by_alert_fingerprint(
authenticated_entity: AuthenticatedEntity = Depends(
IdentityManagerFactory.get_auth_verifier(["read:workflows"])
),
session: Session = Depends(get_session),
) -> list[WorkflowToAlertExecutionDTO]:
with tracer.start_as_current_span("get_workflow_executions_by_alert_fingerprint"):
latest_workflow_to_alert_executions = (
get_last_workflow_workflow_to_alert_executions(
session=session, tenant_id=authenticated_entity.tenant_id
)
)

return [
WorkflowToAlertExecutionDTO(
workflow_id=workflow_execution.workflow_execution.workflow_id,
workflow_execution_id=workflow_execution.workflow_execution_id,
alert_fingerprint=workflow_execution.alert_fingerprint,
workflow_status=workflow_execution.workflow_execution.status,
workflow_started=workflow_execution.workflow_execution.started,
event_id=workflow_execution.event_id,
)
for workflow_execution in latest_workflow_to_alert_executions
]


@router.post(
"/json",
description="Create or update a workflow",
Expand Down Expand Up @@ -540,32 +567,6 @@ def get_workflow_by_id(
raise HTTPException(status_code=500, detail="Error fetching workflow meta data")


@router.get("/executions", description="Get workflow executions by alert fingerprint")
def get_workflow_executions_by_alert_fingerprint(
authenticated_entity: AuthenticatedEntity = Depends(
IdentityManagerFactory.get_auth_verifier(["read:workflows"])
),
session: Session = Depends(get_session),
) -> list[WorkflowToAlertExecutionDTO]:
with tracer.start_as_current_span("get_workflow_executions_by_alert_fingerprint"):
latest_workflow_to_alert_executions = (
get_last_workflow_workflow_to_alert_executions(
session=session, tenant_id=authenticated_entity.tenant_id
)
)

return [
WorkflowToAlertExecutionDTO(
workflow_id=workflow_execution.workflow_execution.workflow_id,
workflow_execution_id=workflow_execution.workflow_execution_id,
alert_fingerprint=workflow_execution.alert_fingerprint,
workflow_status=workflow_execution.workflow_execution.status,
workflow_started=workflow_execution.workflow_execution.started,
)
for workflow_execution in latest_workflow_to_alert_executions
]


@router.get("/{workflow_id}/runs", description="Get workflow executions by ID")
def get_workflow_runs_by_id(
workflow_id: str,
Expand Down

0 comments on commit db60ab7

Please sign in to comment.