Skip to content

Commit

Permalink
fix(topology): add more logs to process task (#1531)
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Aug 4, 2024
1 parent f3effde commit cee3757
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
28 changes: 19 additions & 9 deletions keep/api/tasks/process_topology_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
def process_topology(
tenant_id: str, topology_data: list[TopologyServiceInDto], provider_id: str
):
extra = {"provider_id": provider_id, "tenant_id": tenant_id}
if not topology_data:
logger.info(
"No topology data to process",
extra={"provider_id": provider_id, "tenant_id": tenant_id},
extra=extra,
)
return

logger.info("Processing topology data", extra=extra)
session = get_session_sync()

try:
logger.info(
"Deleting existing topology data",
extra={"provider_id": provider_id, "tenant_id": tenant_id},
extra=extra,
)
session.query(TopologyService).filter(
TopologyService.source_provider_id == provider_id,
Expand All @@ -37,14 +39,14 @@ def process_topology(
session.commit()
logger.info(
"Deleted existing topology data",
extra={"provider_id": provider_id, "tenant_id": tenant_id},
extra=extra,
)
except Exception as e:
except Exception:
logger.exception(
"Failed to delete TopologyService",
extra={"provider_id": provider_id, "error": str(e)},
"Failed to delete existing topology data",
extra=extra,
)
return
raise

logger.info(
"Creating new topology data",
Expand Down Expand Up @@ -72,11 +74,19 @@ def process_topology(
)

session.commit()

try:
session.close()
except Exception as e:
logger.warning(
"Failed to close session",
extra={**extra, "error": str(e)},
)

logger.info(
"Created new topology data",
extra={"provider_id": provider_id, "tenant_id": tenant_id},
extra=extra,
)
return True


async def async_process_topology(*args, **kwargs):
Expand Down
48 changes: 48 additions & 0 deletions keep/providers/grafana_provider/alerts_mock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
ALERTS = {
"database_connection_failure": {
"severity": "critical",
"title": "Database Connection Failure",
"alerts": [
{
"condition": "A",
"data": [
{
"datasourceUid": "datasource1",
"model": {
"conditions": [
{
"evaluator": {"params": [1], "type": "gt"},
"operator": {"type": "and"},
"query": {"params": ["A", "5m", "now"]},
"reducer": {"params": [], "type": "last"},
"type": "query",
}
],
"datasource": {"type": "grafana", "uid": "datasource1"},
"expression": "",
"hide": False,
"intervalMs": 1000,
"maxDataPoints": 100,
"refId": "A",
"type": "classic_conditions",
},
"queryType": "",
"refId": "A",
"relativeTimeRange": {"from": 300, "to": 0},
}
],
"execErrState": "Alerting",
"folderUID": "keep_alerts",
"for_": "5m",
"isPaused": False,
"labels": {"severity": "critical", "monitor": "database"},
"noDataState": "NoData",
"orgID": 1,
"ruleGroup": "keep_group_1",
"title": "Database Connection Failure",
"parameters": {
"labels.monitor": ["database1", "database2", "database3"],
"for_": ["5m", "10m", "15m"],
},
},
],
},
"high_memory_usage": {
"payload": {
"condition": "B",
Expand Down

0 comments on commit cee3757

Please sign in to comment.