Skip to content

fix(topology): raise incidents for standalone services with no application - #6737

Open
Prabal864 wants to merge 1 commit into
keephq:mainfrom
Prabal864:fix-6702-standalone-service-incidents
Open

fix(topology): raise incidents for standalone services with no application#6737
Prabal864 wants to merge 1 commit into
keephq:mainfrom
Prabal864:fix-6702-standalone-service-incidents

Conversation

@Prabal864

Copy link
Copy Markdown
Contributor

What's changed?

_process_tenant returned immediately whenever a tenant had no topology applications at all (if not applications: return), so a service with an active alert never got an incident unless it happened to belong to an application. Separately, _get_topology_data called get_all_topology_data without include_empty_deps=True, so a service with zero dependency edges - the literal "standalone service" from the issue title - was filtered out of the topology data before the processor ever saw it, even once the early-return above is removed.

Fixed both:

  • _get_topology_data now passes include_empty_deps=True.
  • The application loop no longer gates the rest of the function. After it runs, any service that has an alert but isn't part of any application gets its own topology incident via new _get_service_based_incident / _create_service_based_incident / _update_service_based_incident methods - keyed by service name with incident_application left None, instead of an application id. These are additive; the existing application-based methods and their callers are untouched.

Closes #6702

How was this patch tested?

  • Added tests to tests/test_topology.py following its existing style (real TopologyProcessor() against the sqlite db_session fixture, not mocks): incident-creation defaults for the new service-based path, the same deleted-incident-is-skipped guard the application path already has, a check that the service-based lookup never picks up an application-based incident, and two _process_tenant-level tests (a standalone service alone, and an application + an unrelated standalone service together) proving the actual bug is fixed end to end.
  • Couldn't run these locally - same poetry install/Windows blocker as my other PRs in this repo, this time compounded by keep.api.core.db unconditionally importing most of the optional integrations (GCP/AWS/Azure SDKs, several message queues, etc.) at module scope, which pip's resolver couldn't reconcile in one shot on this platform. So instead I extracted the two actual pieces of changed control flow (the include_empty_deps gate and the application-vs-standalone routing in _process_tenant) into a standalone script using plain Python objects and confirmed old-vs-new behavior objectively - happy to paste it here if useful.
  • python -m py_compile and black --check pass on both changed files.

…ation

_process_tenant returned immediately whenever a tenant had no topology
applications at all, so a service with an active alert never got an
incident unless it happened to belong to one. Separately,
_get_topology_data called get_all_topology_data without
include_empty_deps, so a service with zero dependency edges (the
literal 'standalone service' case) was filtered out before the
processor ever saw it.

Fixes both: the application loop no longer gates the rest of the
function, and services with alerts that aren't part of any application
now get their own topology incident via new
_get/_create/_update_service_based_incident methods, keyed by service
name (incident_application left null) instead of an application id.
Application-based incidents are untouched.

Closes keephq#6702
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. Bug Something isn't working labels Aug 27, 2026
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 30.46%. Comparing base (ce302f6) to head (37a8a0c).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #6737       +/-   ##
===========================================
- Coverage   46.42%   30.46%   -15.96%     
===========================================
  Files         178      101       -77     
  Lines       18694    11773     -6921     
===========================================
- Hits         8679     3587     -5092     
+ Misses      10015     8186     -1829     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Topology processor does not create an incident for standalone services without dependencies

1 participant