diff --git a/keep/api/core/demo_mode_runner.py b/keep/api/core/demo_mode_runner.py index 3f4b4f74e..084091004 100644 --- a/keep/api/core/demo_mode_runner.py +++ b/keep/api/core/demo_mode_runner.py @@ -7,6 +7,7 @@ import time import datetime from datetime import timezone +from requests.models import PreparedRequest from keep.api.core.db import get_session_sync from keep.api.core.dependencies import SINGLE_TENANT_UUID @@ -316,7 +317,17 @@ async def simulate_alerts( ): GENERATE_DEDUPLICATIONS = True - providers = ["prometheus", "grafana"] + providers = [ + "prometheus", + "grafana", + "cloudwatch", + "datadog", + ] + + providers_to_randomize_fingerprint_for = [ + "cloudwatch", + "datadog", + ] provider_classes = { provider: ProvidersFactory.get_provider_class(provider) @@ -333,8 +344,6 @@ async def simulate_alerts( get_or_create_topology(keep_api_key, keep_api_url) while True: - await asyncio.sleep(sleep_interval) - remove_old_incidents(keep_api_key, keep_api_url) # choose provider @@ -344,6 +353,12 @@ async def simulate_alerts( provider = provider_classes[provider_type] alert = provider.simulate_alert() + send_alert_url_params = {} + + if provider_type in providers_to_randomize_fingerprint_for: + send_alert_url_params['fingerprint'] = \ + ''.join(random.choices('abcdefghijklmnopqrstuvwxyz0123456789', k=10)) + # Determine number of times to send the same alert num_iterations = 1 if GENERATE_DEDUPLICATIONS: @@ -353,8 +368,11 @@ async def simulate_alerts( logger.info("Sending alert: {}".format(alert)) try: env = random.choice(["production", "staging", "development"]) + send_alert_url_params['provider_id'] = f"{provider_type}-{env}" + prepared_request = PreparedRequest() + prepared_request.prepare_url(send_alert_url, send_alert_url_params) response = requests.post( - send_alert_url + f"?provider_id={provider_type}-{env}", + prepared_request.url, headers={"x-api-key": keep_api_key}, json=alert, ) @@ -369,6 +387,9 @@ async def simulate_alerts( else: logger.info("Alert sent successfully") + await asyncio.sleep(sleep_interval) + + def launch_demo_mode(): """ Running async demo in the backgound. diff --git a/keep/providers/cloudwatch_provider/alerts_mock.py b/keep/providers/cloudwatch_provider/alerts_mock.py index 5fe2ec41e..1fc2377fe 100644 --- a/keep/providers/cloudwatch_provider/alerts_mock.py +++ b/keep/providers/cloudwatch_provider/alerts_mock.py @@ -11,7 +11,7 @@ } }, "parameters": { - "Message.AlarmName": ["HighCPUUsage-1", "HighCPUUsage-2", "HighCPUUsage-3"], + "Message.AlarmName": ["HighCPUUsage", "HighCPUUsageOnAPod", "PodRecycled"], }, }, } diff --git a/keep/providers/datadog_provider/alerts_mock.py b/keep/providers/datadog_provider/alerts_mock.py index 21205eab0..0ff032a3b 100644 --- a/keep/providers/datadog_provider/alerts_mock.py +++ b/keep/providers/datadog_provider/alerts_mock.py @@ -11,8 +11,8 @@ }, "parameters": { "tags": [ - "environment:production,team:backend,monitor", - "environment:staging,team:backend,monitor", + "environment:production,team:backend,monitor,service:api", + "environment:staging,team:backend,monitor,service:api", ], "priority": ["P2", "P3", "P4"], }, @@ -29,8 +29,8 @@ }, "parameters": { "tags": [ - "environment:production,team:analytics,monitor", - "environment:staging,team:database,monitor", + "environment:production,team:analytics,monitor,service:api", + "environment:staging,team:database,monitor,service:api", ], "priority": ["P1", "P3", "P4"], },