refactor(observability): drop file-SD writer for http_sd_configs
Slice 4 of observability-service-registry. Removes the shared-file Prometheus bridge; external Prometheus now consumes node-exporter targets via http_sd_configs against GET /api/monitoring/prometheus-targets. - services/targets.py: removed write_prometheus_targets() (the file writer) and its json/Path/get_settings imports; updated module docstring. build_node_exporter_targets() is unchanged and still powers the HTTP endpoint. - main.py: removed the startup write_prometheus_targets call. - routers/settings.py: removed the _write_prometheus_targets helper and its three post machine create/update/delete call sites + the now-unused targets import. - config.py: removed the prometheus_file_sd_dir field. - docker-compose.yml / docker-compose.dev.yml: removed the PROMETHEUS_FILE_SD_DIR backend env var. - tests: removed TestWritePrometheusTargets + the write_prometheus_targets import in test_targets.py; rewrote the two TestSettingsMachines tests to assert machines appear/disappear from /api/monitoring/prometheus-targets (the surviving HTTP path) instead of the removed file-writer side effect. ruff clean; 239 backend tests pass.
This commit is contained in:
+24
-23
@@ -702,27 +702,26 @@ class TestResolveServiceRecord:
|
||||
|
||||
|
||||
class TestSettingsMachines:
|
||||
def test_post_machine_rewrites_prometheus_targets(self, test_client):
|
||||
with patch("media_library_viewer_api.routers.settings.write_prometheus_targets") as write_targets:
|
||||
with patch("media_library_viewer_api.routers.settings._validate_saved_machine_ssh"):
|
||||
response = test_client.post(
|
||||
"/api/settings/machines",
|
||||
json={
|
||||
"name": "remote1",
|
||||
"mode": "ssh",
|
||||
"enabled": True,
|
||||
"services": ["monitoring"],
|
||||
"host": "10.0.0.5",
|
||||
"username": "u",
|
||||
"node_exporter_enabled": True,
|
||||
"node_exporter_port": 9200,
|
||||
"node_exporter_scrape_host": "1.2.3.4",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 201
|
||||
write_targets.assert_called_once()
|
||||
def test_machine_appears_in_prometheus_targets(self, test_client):
|
||||
store = app.dependency_overrides[get_settings_store]()
|
||||
store.upsert_machine(
|
||||
{
|
||||
"name": "remote1",
|
||||
"mode": "ssh",
|
||||
"enabled": True,
|
||||
"services": ["monitoring"],
|
||||
"host": "10.0.0.5",
|
||||
"username": "u",
|
||||
"node_exporter_enabled": True,
|
||||
"node_exporter_port": 9200,
|
||||
"node_exporter_scrape_host": "1.2.3.4",
|
||||
}
|
||||
)
|
||||
targets = test_client.get("/api/monitoring/prometheus-targets").json()
|
||||
assert len(targets) == 1
|
||||
assert targets[0]["targets"] == ["1.2.3.4:9200"]
|
||||
|
||||
def test_delete_machine_rewrites_prometheus_targets(self, test_client):
|
||||
def test_delete_machine_removed_from_prometheus_targets(self, test_client):
|
||||
store = app.dependency_overrides[get_settings_store]()
|
||||
machine = store.upsert_machine(
|
||||
{
|
||||
@@ -732,12 +731,14 @@ class TestSettingsMachines:
|
||||
"services": ["monitoring"],
|
||||
"host": "10.0.0.5",
|
||||
"username": "u",
|
||||
"node_exporter_enabled": True,
|
||||
"node_exporter_port": 9200,
|
||||
"node_exporter_scrape_host": "1.2.3.4",
|
||||
}
|
||||
)
|
||||
with patch("media_library_viewer_api.routers.settings.write_prometheus_targets") as write_targets:
|
||||
response = test_client.delete(f"/api/settings/machines/{machine['id']}")
|
||||
response = test_client.delete(f"/api/settings/machines/{machine['id']}")
|
||||
assert response.status_code == 200
|
||||
write_targets.assert_called_once()
|
||||
assert test_client.get("/api/monitoring/prometheus-targets").json() == []
|
||||
|
||||
|
||||
def _am_service(name="Alertmanager", **config):
|
||||
|
||||
Reference in New Issue
Block a user