Skip to content

Commit 7ad6c46

Browse files
authored
fix: no workflows found for execution from alert or incident (#4858)
1 parent b261a3f commit 7ad6c46

File tree

7 files changed

+131
-10
lines changed

7 files changed

+131
-10
lines changed

keep-ui/components/ui/Modal.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import React from "react";
2-
import { DialogPanel, Dialog, Text, Badge, Button } from "@tremor/react";
2+
import {
3+
DialogPanel,
4+
Dialog,
5+
Text,
6+
Badge,
7+
Button,
8+
DialogProps,
9+
} from "@tremor/react";
310
import { XMarkIcon } from "@heroicons/react/24/outline";
411
import { PageTitle } from "@/shared/ui/PageTitle";
512

@@ -12,6 +19,7 @@ export default function Modal({
1219
className = "",
1320
beta = false,
1421
description,
22+
...props
1523
}: {
1624
children: React.ReactNode;
1725
isOpen: boolean;
@@ -21,9 +29,9 @@ export default function Modal({
2129
className?: string;
2230
beta?: boolean;
2331
description?: string;
24-
}) {
32+
} & Omit<DialogProps, "open" | "onClose" | "static" | "children">) {
2533
return (
26-
<Dialog open={isOpen} onClose={onClose}>
34+
<Dialog open={isOpen} onClose={onClose} {...props}>
2735
<DialogPanel
2836
className={`flex flex-col border-2 border-orange-300 rounded-lg ring-0 ${className}`}
2937
>
@@ -54,9 +62,7 @@ export default function Modal({
5462
)}
5563
</header>
5664
)}
57-
<div className="flex flex-col flex-1 min-h-0 overflow-auto">
58-
{children}
59-
</div>
65+
<div className="flex flex-col flex-1 min-h-0">{children}</div>
6066
</DialogPanel>
6167
</Dialog>
6268
);

keep-ui/features/workflows/manual-run-workflow/ui/manual-run-workflow-modal.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useApi } from "@/shared/lib/hooks/useApi";
99
import { showErrorToast, showSuccessToast } from "@/shared/ui";
1010
import { Select } from "@/shared/ui";
1111
import { Trigger, Workflow } from "@/shared/api/workflows";
12-
import { components, OptionProps } from "react-select";
12+
import { components, ControlProps, OptionProps } from "react-select";
1313
import { FilterOptionOption } from "react-select/dist/declarations/src/filters";
1414
import { WorkflowTriggerBadge } from "@/entities/workflows/ui/WorkflowTriggerBadge";
1515
import Link from "next/link";
@@ -51,7 +51,8 @@ export function ManualRunWorkflowModal({
5151
const { workflows } = useWorkflowsV2({
5252
...DEFAULT_WORKFLOWS_QUERY,
5353
limit: 100, // Fetch more workflows at once for the dropdown
54-
cel: "disabled == false", // Only show enabled workflows
54+
// FIXME: this is a temporary solution until 'disabled == false' query is fixed
55+
cel: "(disabled in ['0']) || (disabled == false)", // Only show enabled workflows
5556
});
5657
const filteredWorkflows = workflows?.filter((w) => w.canRun);
5758
const api = useApi();
@@ -196,6 +197,20 @@ export function ManualRunWorkflowModal({
196197
);
197198
};
198199

200+
const CustomControl = (props: ControlProps<Workflow>) => {
201+
return (
202+
<components.Control
203+
{...props}
204+
innerProps={
205+
{
206+
"data-testid": "manual-run-workflow-select-control",
207+
...props.innerProps,
208+
} as unknown as React.HTMLAttributes<HTMLDivElement>
209+
}
210+
/>
211+
);
212+
};
213+
199214
return (
200215
<Modal
201216
onClose={clearAndClose}
@@ -206,6 +221,7 @@ export function ManualRunWorkflowModal({
206221
(effectiveWorkflow?.name ? `Run: ${effectiveWorkflow.name}` : undefined)
207222
}
208223
title={workflow ? "Run Workflow with Inputs" : "Run Workflow"}
224+
data-testid="manual-run-workflow-modal"
209225
>
210226
{/* Only show workflow selector when no workflow is directly provided */}
211227
{!workflow && (
@@ -249,6 +265,7 @@ export function ManualRunWorkflowModal({
249265
}}
250266
components={{
251267
Option: CustomOption,
268+
Control: CustomControl,
252269
}}
253270
options={filteredWorkflows}
254271
/>

keep-ui/widgets/alerts-table/ui/alert-table-server-side.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,10 @@ export function AlertTableServerSide({
533533
}
534534
}
535535
return (
536-
<Table className="[&>table]:table-fixed [&>table]:w-full">
536+
<Table
537+
className="[&>table]:table-fixed [&>table]:w-full"
538+
data-testid="alerts-table"
539+
>
537540
<AlertsTableHeaders
538541
columns={columns}
539542
table={table}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "keep"
3-
version = "0.44.2"
3+
version = "0.44.3"
44
description = "Alerting. for developers, by developers."
55
authors = ["Keep Alerting LTD"]
66
packages = [{include = "keep"}]

tests/e2e_tests/test_end_to_end.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
from datetime import datetime
2828

2929
from playwright.sync_api import Page, expect
30+
import pytest
3031

32+
from tests.e2e_tests.incidents_alerts_tests.incidents_alerts_setup import (
33+
setup_incidents_alerts,
34+
)
3135
from tests.e2e_tests.utils import (
3236
assert_connected_provider_count,
3337
assert_scope_text_count,
@@ -725,3 +729,66 @@ def test_workflow_unsaved_changes(browser: Page):
725729
except Exception:
726730
save_failure_artifacts(page, log_entries)
727731
raise
732+
733+
734+
@pytest.fixture(scope="module")
735+
def setup_alerts_and_incidents():
736+
print("Setting up alerts and incidents...")
737+
test_data = setup_incidents_alerts()
738+
yield test_data
739+
740+
741+
def test_run_workflow_from_alert_and_incident(
742+
browser: Page, setup_alerts_and_incidents
743+
):
744+
page = browser
745+
log_entries = []
746+
setup_console_listener(browser, log_entries)
747+
try:
748+
init_e2e_test(browser, next_url="/signin")
749+
page.goto("http://localhost:3000/workflows")
750+
page.get_by_role("button", name="Upload Workflows").click()
751+
file_input = page.locator("#workflowFile")
752+
file_input.set_input_files(
753+
[
754+
"./tests/e2e_tests/workflow-alert-log.yaml",
755+
"./tests/e2e_tests/workflow-incident-log.yaml",
756+
]
757+
)
758+
page.get_by_role("button", name="Upload")
759+
expect(page.get_by_text("2 workflows uploaded successfully")).to_be_visible()
760+
# Run workflow from incident
761+
page.goto("http://localhost:3000/incidents")
762+
# wait for the incidents facets to load, so it doesn't interfere with the dropdown
763+
page.wait_for_selector("[data-testid='facet-value']")
764+
page.wait_for_timeout(500)
765+
page.get_by_test_id("incidents-table").get_by_test_id(
766+
"dropdown-menu-button"
767+
).first.click()
768+
page.get_by_test_id("dropdown-menu-list").get_by_role(
769+
"button", name="Run workflow"
770+
).click()
771+
modal = page.get_by_test_id("manual-run-workflow-modal")
772+
modal.get_by_test_id("manual-run-workflow-select-control").click()
773+
modal.get_by_role("option", name=re.compile(r"Log every incident")).click()
774+
modal.get_by_role("button", name="Run").click()
775+
expect(page.get_by_text("Workflow started successfully")).to_be_visible()
776+
# Run workflow from alert
777+
page.goto("http://localhost:3000/alerts/feed")
778+
# wait for the alerts facets to load, so it doesn't interfere with the dropdown
779+
page.wait_for_selector("[data-testid='facet-value']")
780+
page.wait_for_timeout(500)
781+
page.get_by_test_id("alerts-table").locator(
782+
"[data-column-id='alertMenu']"
783+
).first.get_by_test_id("dropdown-menu-button").click()
784+
page.get_by_test_id("dropdown-menu-list").get_by_role(
785+
"button", name="Run workflow"
786+
).click()
787+
modal = page.get_by_test_id("manual-run-workflow-modal")
788+
modal.get_by_test_id("manual-run-workflow-select-control").click()
789+
modal.get_by_role("option", name=re.compile(r"Log every alert")).click()
790+
modal.get_by_role("button", name="Run").click()
791+
expect(page.get_by_text("Workflow started successfully")).to_be_visible()
792+
except Exception:
793+
save_failure_artifacts(page, log_entries)
794+
raise
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
workflow:
2+
id: log-every-alert
3+
name: Log every alert
4+
description: Simple workflow demonstrating logging every alert
5+
triggers:
6+
- type: manual
7+
- type: alert
8+
actions:
9+
- name: log-alert
10+
provider:
11+
type: console
12+
with:
13+
message: "Alert name: {{alert.name}} - {{alert.message}}"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
workflow:
2+
id: log-every-incident
3+
name: Log every incident
4+
description: Simple workflow demonstrating logging every incident
5+
triggers:
6+
- type: manual
7+
- type: incident
8+
events:
9+
- created
10+
actions:
11+
- name: log-incident
12+
provider:
13+
type: console
14+
with:
15+
message: "Incident name: {{incident.user_generated_name}} - {{incident.severity}}"

0 commit comments

Comments
 (0)