Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: feed counter #2587

Merged
merged 6 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions keep-ui/utils/hooks/usePresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useConfig } from "./useConfig";
import useSWRSubscription from "swr/subscription";
import { useWebsocket } from "./usePusher";
import { useSearchParams } from "next/navigation";
import { useRevalidateMultiple } from "../state";

export const usePresets = (type?: string, useFilters?: boolean) => {
const { data: session } = useSession();
Expand All @@ -31,6 +32,7 @@ export const usePresets = (type?: string, useFilters?: boolean) => {
const presetsOrderRef = useRef(presetsOrderFromLS);
const staticPresetsOrderRef = useRef(staticPresetsOrderFromLS);
const { bind, unbind } = useWebsocket();
const revalidateMultiple = useRevalidateMultiple();

useEffect(() => {
presetsOrderRef.current = presetsOrderFromLS;
Expand Down Expand Up @@ -88,6 +90,8 @@ export const usePresets = (type?: string, useFilters?: boolean) => {
(_, { next }) => {
const newPresets = (newPresets: Preset[]) => {
updateLocalPresets(newPresets);
const presetKeys = newPresets.map((preset) => `preset/${preset.id}`);
revalidateMultiple(presetKeys);
next(null, {
presets: newPresets,
isAsyncLoading: false,
Expand Down
7 changes: 6 additions & 1 deletion keep/api/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from sqlalchemy.sql import exists, expression
from sqlmodel import Session, SQLModel, col, or_, select, text

from keep.api.consts import STATIC_PRESETS
from keep.api.core.db_utils import create_db_engine, get_json_extract_field

# This import is required to create the tables
Expand Down Expand Up @@ -2624,7 +2625,6 @@ def get_preset_by_name(tenant_id: str, preset_name: str) -> Preset:
).first()
return preset


def get_all_presets(tenant_id: str) -> List[Preset]:
with Session(engine) as session:
presets = (
Expand All @@ -2634,6 +2634,11 @@ def get_all_presets(tenant_id: str) -> List[Preset]:
)
return presets

#
Kiryous marked this conversation as resolved.
Show resolved Hide resolved
def get_db_and_static_presets_dtos(tenant_id: str) -> List[PresetDto]:
Kiryous marked this conversation as resolved.
Show resolved Hide resolved
presets = get_all_presets(tenant_id)
static_presets_dtos = list(STATIC_PRESETS.values())
return [PresetDto(**preset.to_dict()) for preset in presets] + static_presets_dtos

def get_dashboards(tenant_id: str, email=None) -> List[Dict[str, Any]]:
with Session(engine) as session:
Expand Down
8 changes: 4 additions & 4 deletions keep/api/tasks/process_event_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
bulk_upsert_alert_fields,
get_alerts_by_fingerprint,
get_all_presets,
get_db_and_static_presets_dtos,
get_enrichment_with_session,
get_session_sync,
)
Expand Down Expand Up @@ -443,12 +444,11 @@ def __handle_formatted_events(
return

try:
presets = get_all_presets(tenant_id)
presets = get_db_and_static_presets_dtos(tenant_id)
rules_engine = RulesEngine(tenant_id=tenant_id)
presets_do_update = []
for preset in presets:
for preset_dto in presets:
# filter the alerts based on the search query
preset_dto = PresetDto(**preset.to_dict())
filtered_alerts = rules_engine.filter_alerts(
enriched_formatted_events, preset_dto.cel_query
)
Expand All @@ -458,7 +458,7 @@ def __handle_formatted_events(
presets_do_update.append(preset_dto)
preset_dto.alerts_count = len(filtered_alerts)
# update noisy
if preset.is_noisy:
if preset_dto.is_noisy:
firing_filtered_alerts = list(
filter(
lambda alert: alert.status == AlertStatus.FIRING.value,
Expand Down
Loading