Skip to content

Commit

Permalink
Waiting for API to get live
Browse files Browse the repository at this point in the history
  • Loading branch information
Matvey-Kuk committed Nov 18, 2024
1 parent 89faba0 commit 3fe4071
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions keep/api/core/demo_mode_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ async def simulate_alerts(
keep_api_url=None,
keep_api_key=None,
sleep_interval=5,
demo_correlation_rules=False,
demo_topology=False,
):
GENERATE_DEDUPLICATIONS = True

Expand All @@ -332,12 +334,29 @@ async def simulate_alerts(
for provider in providers
}

# Wait in the beginning because server may not be ready yet.
await asyncio.sleep(sleep_interval * 2)
while True:
try:
logger.info(f"Demo thread: Checking if server is up at {keep_api_url}...")
response = requests.get(keep_api_url)
response.raise_for_status()
break
except requests.exceptions.RequestException as e:
logger.info(f"Demo thread: API is not up yet. Waiting...")
await asyncio.sleep(5)

if demo_correlation_rules:
get_or_create_correlation_rules(keep_api_key, keep_api_url)
logger.info("Correlation rules created.")
if demo_topology:
get_or_create_topology(keep_api_key, keep_api_url)
logger.info("Topology created.")

logger.info(f"Waiting for server to start...")


while True:
logger.info("Looping to send alerts...")

remove_old_incidents(keep_api_key, keep_api_url)
logger.info("Old incidents removed.")

Expand Down Expand Up @@ -403,12 +422,6 @@ def launch_demo_mode():
system_description="Simulate Alerts API key",
)

logger.info(f"Creating correlation rules for the demo mode.")
get_or_create_correlation_rules(keep_api_key, keep_api_url)

logger.info(f"Creating topology for the demo mode.")
get_or_create_topology(keep_api_key, keep_api_url)

thread = threading.Thread(target=asyncio.run, args=(simulate_alerts(
keep_api_url,
keep_api_key,
Expand Down

0 comments on commit 3fe4071

Please sign in to comment.