ServiceMap: update dependencies and backend/app (+5 areas)

Public changes compared with the previous published export:
16 files changed.

Affected areas:
- backend/app: 3 files
- dependencies: 5 files
- deployment and CI: 2 files
- documentation: 2 files
- frontend/src: 1 file
- project files: 1 file
- tests: 2 files

Changed files:
- Updated: ".env.example"
- Updated: "Dockerfile.unraid"
- Updated: "README.md"
- Updated: "backend/app/incidents.py"
- Updated: "backend/app/main.py"
- Updated: "backend/app/store.py"
- Updated: "backend/pyproject.toml"
- Updated: "backend/tests/test_docker_provider.py"
- Updated: "backend/tests/test_v163_health_performance.py"
- Updated: "docker-compose.broker.yml"
- Updated: "docs/ARCHITECTURE.md"
- Updated: "frontend/package-lock.json"
- Updated: "frontend/package.json"
- Updated: "frontend/src/App.tsx"
- Updated: "package-lock.json"
- Updated: "package.json"

Export provenance/manifests refreshed; excluded from the change summary.

Publish curated ServiceMap source from 8c297f756ff84aaa917ae9c48535e835f8c09ec7
This commit is contained in:
NuklearRabbit committed 2026-11-20 16:01:36 +01:00
1 parent d4c351ce73
commit 41a8eee259
18 files changed
+167 -92

No files matched your search

+14 -5
View File
@@ -97,14 +97,23 @@ def _severity(service: Service) -> Criticality:
# concurrent passes could both see "no active incident" for a root and each
# open one (the later duplicate cleanup then left two journal entries).
_SYNC_LOCK = threading.RLock()
_DEFAULT_RESOLUTION_REASON = "Hoofdoorzaak hersteld; incident opgelost"
def sync_incidents(store: Store, *, resolution_reason: str = "Hoofdoorzaak hersteld; incident opgelost") -> list[IncidentRecord]:
def sync_incidents(store: Store, *, resolution_reason: str = _DEFAULT_RESOLUTION_REASON) -> list[IncidentRecord]:
with _SYNC_LOCK:
return _sync_incidents_locked(store, resolution_reason=resolution_reason)
_sync_incidents_locked(store, resolution_reason=resolution_reason)
return store.list_incidents(active_only=False)
def _sync_incidents_locked(store: Store, *, resolution_reason: str) -> list[IncidentRecord]:
def reconcile_incidents(store: Store) -> tuple[TopologyHealth, IncidentOverview]:
with _SYNC_LOCK:
return _sync_incidents_locked(store, resolution_reason=_DEFAULT_RESOLUTION_REASON)
def _sync_incidents_locked(
store: Store, *, resolution_reason: str
) -> tuple[TopologyHealth, IncidentOverview]:
"""Reconcile the current graph with the durable incident journal.
A root service has at most one active incident. Repeated probe cycles only
@@ -117,7 +126,7 @@ def _sync_incidents_locked(store: Store, *, resolution_reason: str) -> list[Inci
now = datetime.now(UTC)
active: dict[str, IncidentRecord] = {}
for incident in sorted(
store.list_incidents(active_only=True),
store.list_incidents(active_only=True, services=services),
key=lambda item: (item.detected_at, item.id),
):
if incident.root_service_id in active:
@@ -191,4 +200,4 @@ def _sync_incidents_locked(store: Store, *, resolution_reason: str) -> list[Inci
)
store.upsert_incident(resolved)
store.append_incident_event(incident.id, "incident.resolved", resolution_reason, root_id)
return store.list_incidents(active_only=False)
return health, overview
+42 -40
View File
@@ -22,8 +22,8 @@ from .discovery_store import DiscoveryStore
from .docker_discovery import discover_containers
from .docker_provider import docker_provider_mode
from .events import SSE_RETRY_MS, event_bus, next_event, sse_payload
from .health import status_maps, topology_health, validate_dependencies
from .incidents import incident_overview, sync_incidents
from .health import TopologyHealth, status_maps, topology_health, validate_dependencies
from .incidents import incident_overview, reconcile_incidents, sync_incidents
from .loops import loop_registry, run_periodic
from .models import (
AvailabilitySummary,
@@ -288,7 +288,7 @@ async def lifespan(_: FastAPI):
await background_task
app = FastAPI(title="ServiceMap API", version="1.6.3", lifespan=lifespan)
app = FastAPI(title="ServiceMap API", version="1.6.4", lifespan=lifespan)
# Bounded request bodies: the largest legitimate payload is a config import.
@@ -404,7 +404,7 @@ def meta() -> dict[str, str | int | float | bool]:
auth_mode = "misconfigured"
return {
"name": "ServiceMap",
"version": "1.6.3",
"version": "1.6.4",
"stage": "v1",
"scheduled_probing": PROBE_INTERVAL > 0,
"probe_interval_seconds": PROBE_INTERVAL,
@@ -488,21 +488,21 @@ def verify_write_access() -> dict[str, bool]:
return {"ok": True}
def _visible_services(services: list[Service]) -> list[Service]:
return [
service for service in services
if service.visibility.value == "visible" and service.lifecycle.value not in {"retired", "ignored"}
]
def _service_snapshots(
*, include_hidden: bool = False, include_context: bool = True
) -> list[ServiceSnapshot]:
*, include_hidden: bool = False, include_details: bool = True
) -> tuple[list[ServiceSnapshot], TopologyHealth]:
all_services = store.list_services()
services = (
all_services
if include_hidden
else [
service
for service in all_services
if service.visibility.value == "visible" and service.lifecycle.value not in {"retired", "ignored"}
]
)
latest = store.latest_probes([service.id for service in services])
availability = store.availability_summaries([service.id for service in services], 24)
services = all_services if include_hidden else _visible_services(all_services)
visible_ids = [service.id for service in services]
latest = store.latest_probes(visible_ids)
availability = store.availability_summaries(visible_ids, 24) if include_details else {}
evidence_by_service = store.health_evidence_for_services([service.id for service in all_services])
# Calculate propagation over the complete canonical graph first. Hidden
# infrastructure nodes may still sit between a visible service and its
@@ -512,15 +512,15 @@ def _service_snapshots(
[service.id for service in all_services], evidence_by_service=evidence_by_service
)
effective_all, dependency_all = status_maps(all_services, direct_statuses=direct_all)
dependent_names = {
service.id: [item.name for item in services if service.id in item.depends_on]
for service in services
}
visible_ids = [service.id for service in services]
windows = store.maintenance_windows()
sources_by_service = discovery_store.sources_for_services(visible_ids) if include_context else {}
relations_by_service = discovery_store.evidence_for_services(visible_ids) if include_context else {}
return [
dependent_names: dict[str, list[str]] = {}
if include_details:
for service in services:
for dependency_id in set(service.depends_on):
dependent_names.setdefault(dependency_id, []).append(service.name)
windows = store.maintenance_windows() if include_details else {}
sources_by_service = discovery_store.sources_for_services(visible_ids) if include_details else {}
relations_by_service = discovery_store.evidence_for_services(visible_ids) if include_details else {}
snapshots = [
ServiceSnapshot(
service=service,
latest_probe=latest.get(service.id),
@@ -539,16 +539,18 @@ def _service_snapshots(
sources=sources_by_service.get(service.id, []),
evidence=relations_by_service.get(service.id, []),
health_evidence=evidence_by_service.get(service.id, []),
health_resolution=resolutions.get(service.id, HealthResolution()),
health_resolution=resolutions.get(service.id) or HealthResolution(),
maintenance_until=windows.get(service.id),
)
for service in services
]
return snapshots, TopologyHealth(all_services, direct_all, effective_all, dependency_all)
@app.get("/api/v1/services", response_model=list[ServiceSnapshot])
def list_services(include_hidden: bool = Query(default=False)) -> list[ServiceSnapshot]:
return _service_snapshots(include_hidden=include_hidden)
snapshots, _ = _service_snapshots(include_hidden=include_hidden)
return snapshots
@app.post("/api/v1/services", response_model=Service, status_code=status.HTTP_201_CREATED)
@@ -768,23 +770,23 @@ async def event_stream() -> StreamingResponse:
@app.get("/api/v1/overview", response_model=OverviewSummary)
def overview() -> OverviewSummary:
sync_incidents(store)
# Only status and coverage are counted; discovery context is not needed.
snapshots = _service_snapshots(include_hidden=False, include_context=False)
overview_state = incident_overview(store)
health, overview_state = reconcile_incidents(store)
services = _visible_services(health.services)
counts: dict[str, int] = {}
coverage: dict[str, int] = {}
for snapshot in snapshots:
counts[snapshot.effective_status.value] = counts.get(snapshot.effective_status.value, 0) + 1
state = snapshot.service.monitoring_state.value
for service in services:
status = health.effective[service.id].value
counts[status] = counts.get(status, 0) + 1
state = service.monitoring_state.value
coverage[state] = coverage.get(state, 0) + 1
services_by_id = {service.id: service for service in health.services}
return OverviewSummary(
generated_at=overview_state.generated_at,
total_services=len(snapshots),
total_services=len(services),
health_counts=counts,
active_incidents=len(store.list_incidents(active_only=True)),
active_incidents=len(store.list_incidents(active_only=True, services=services_by_id)),
likely_root_causes=[candidate.service_name for candidate in overview_state.candidates],
flapping_services=[snapshot.service.name for snapshot in snapshots if snapshot.flapping],
flapping_services=[service.name for service in services if service.flapping],
recent_events=store.list_events(limit=10),
monitoring_coverage=coverage,
)
@@ -982,8 +984,8 @@ def _semantic_representation(include_hidden: bool) -> CachedRepresentation:
cached = semantic_cache.get(cache_key, revision)
if cached is not None:
return cached
snapshots = _service_snapshots(include_hidden=include_hidden, include_context=False)
incident_state = incident_overview(store)
snapshots, health = _service_snapshots(include_hidden=include_hidden, include_details=False)
incident_state = incident_overview(store, health=health)
root_ids = {candidate.service_id for candidate in incident_state.candidates}
affected_ids = {
service_id
+7 -2
View File
@@ -2134,8 +2134,9 @@ class Store:
event_bus.publish({"event_type": "topology.changed", "message": "Synthetische demo afgesloten"})
return True
def list_incidents(self, active_only: bool = False, limit: int = 100) -> list[IncidentRecord]:
services = {service.id: service for service in self.list_services()}
def list_incidents(
self, active_only: bool = False, limit: int = 100, *, services: dict[str, Service] | None = None
) -> list[IncidentRecord]:
with self._connect() as db:
query = "SELECT * FROM incidents"
params: tuple[Any, ...] = ()
@@ -2144,6 +2145,10 @@ class Store:
query += " ORDER BY detected_at DESC LIMIT ?"
params += (limit,)
rows = db.execute(query, params).fetchall()
if not rows:
return []
if services is None:
services = {service.id: service for service in self.list_services()}
return [self._row_to_incident(row, services) for row in rows]
def get_incident(self, incident_id: str) -> IncidentRecord | None:
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "servicemap-backend"
version = "1.6.3"
version = "1.6.4"
description = "ServiceMap API, topology intelligence and probe engine"
requires-python = ">=3.12"
dependencies = [
+35
View File
@@ -53,6 +53,41 @@ def _mocked_broker_client(
return client, options
def test_reopened_inventory_client_reads_atomically_rotated_broker_token(tmp_path, monkeypatch) -> None:
token_file = tmp_path / "servicemap-docker-broker.token"
token_file.write_text("initial-token", encoding="utf-8")
monkeypatch.setenv("SERVICEMAP_DOCKER_PROVIDER", "broker")
monkeypatch.setenv("SERVICEMAP_DOCKER_BROKER_URL", "https://broker.internal")
monkeypatch.setenv("SERVICEMAP_DOCKER_BROKER_TOKEN_FILE", str(token_file))
seen = []
def inventory(request):
seen.append(request.headers["authorization"])
return httpx.Response(200, json={"items": []})
original_client = httpx.Client
monkeypatch.setattr(
docker_provider.httpx, "Client",
lambda **kwargs: original_client(transport=httpx.MockTransport(inventory), **kwargs),
)
client = docker_provider.docker_client_for_inventory("")
try:
assert client.containers.list() == []
finally:
client.close()
replacement = tmp_path / "next-token"
replacement.write_text("rotated-token", encoding="utf-8")
replacement.replace(token_file)
client = docker_provider.docker_client_for_inventory("")
try:
assert client.containers.list() == []
finally:
client.close()
assert seen == ["Bearer initial-token", "Bearer rotated-token"]
def test_inventory_uses_authenticated_fixed_get_and_health_check_has_no_token(monkeypatch) -> None:
requests = []
@@ -353,12 +353,35 @@ def test_topology_request_budget_at_300_services(tmp_path: Path, monkeypatch) ->
return original()
monkeypatch.setattr(store, "_connect", counting_connect)
evidence_reads = 0
read_evidence = store.health_evidence_for_services
def counting_evidence(service_ids, **kwargs):
nonlocal evidence_reads
evidence_reads += 1
return read_evidence(service_ids, **kwargs)
monkeypatch.setattr(store, "health_evidence_for_services", counting_evidence)
topology_reads = 0
list_services = store.list_services
def counting_services():
nonlocal topology_reads
topology_reads += 1
return list_services()
monkeypatch.setattr(store, "list_services", counting_services)
client = TestClient(main_module.app)
budget_ms = os.environ.get("SERVICEMAP_API_P95_BUDGET_MS")
for endpoint in ("/api/v1/topology/semantic", "/api/v1/overview"):
connections = 0
evidence_reads = 0
topology_reads = 0
main_module.semantic_cache.clear()
assert client.get(endpoint).status_code == 200
assert evidence_reads == 1, (endpoint, evidence_reads)
assert topology_reads == 1, (endpoint, topology_reads)
assert connections <= 30, (endpoint, connections)
elapsed_ms = []
for _ in range(20):