Skip to content

The agent that grows with you

fix(telemetry): name every gateway adapter platform from the Platform enum

teknium149aeaa15265f
diff --git a/hermes_cli/observability/shared_metrics_contract.py b/hermes_cli/observability/shared_metrics_contract.py
index 5e89cdff244..0c6603a026c 100644
--- a/hermes_cli/observability/shared_metrics_contract.py
+++ b/hermes_cli/observability/shared_metrics_contract.py
@@ -250,8 +250,23 @@ CRON_RUN_MARK = CRON_RUN_METRIC = "hermes.cron.run"
# plugin-catalog install (shared_metrics_catalog.platform_metric_name); every other one is ``plugin``.
_PLATFORM_CATALOGS = ("bundled_platform_names", "catalog_platform_names")
GATEWAY_PLATFORMS = _CatalogValues(*_PLATFORM_CATALOGS, extra=_CORE_GATEWAY_PLATFORMS)
-# The API server is an adapter the gateway connects and delivers through, but not a messaging surface.
-ADAPTER_PLATFORMS = _CatalogValues(*_PLATFORM_CATALOGS, extra=_CORE_GATEWAY_PLATFORMS | {"api_server"})
+
+
+def _gateway_adapter_platforms() -> frozenset[str]:
+ """The gateway's own adapter vocabulary: ``Platform``'s declared members (relay, msgraph_webhook
+ and api_server are adapters but not setup-wizard platforms; plugin pseudo-members are not
+ declared). Loaded on first use: gateway.config is too heavy for this module's import."""
+ from gateway.config import Platform
+
+ return frozenset(member.value for member in Platform)
+
+
+class _AdapterPlatforms(_CatalogValues):
+ def values(self) -> frozenset[str]:
+ return super().values() | _gateway_adapter_platforms()
+
+
+ADAPTER_PLATFORMS = _AdapterPlatforms(*_PLATFORM_CATALOGS, extra=_CORE_GATEWAY_PLATFORMS | {"api_server"})
PLATFORM_HEALTH_EVENTS = frozenset({"connect_ok", "connect_failed", "reconnect", "disconnect"})
PLATFORM_ERROR_CLASSES = frozenset({"none", "auth", "network", "rate_limited", "config", "other"})
DELIVERY_OUTCOMES = frozenset({"sent", "failed"})
@@ -885,7 +900,7 @@ def adapter_platform(value: Any) -> str:
"""Public name of a gateway adapter's platform (Platform enum or its value)."""
from .shared_metrics_catalog import platform_metric_name
- return platform_metric_name(value, _CORE_GATEWAY_PLATFORMS | {"api_server"})
+ return platform_metric_name(value, _CORE_GATEWAY_PLATFORMS | _gateway_adapter_platforms())
_SURFACE_ENTRYPOINTS = {
diff --git a/tests/hermes_cli/test_shared_metrics_gateway.py b/tests/hermes_cli/test_shared_metrics_gateway.py
index af796a524f1..1b4285a3365 100644
--- a/tests/hermes_cli/test_shared_metrics_gateway.py
+++ b/tests/hermes_cli/test_shared_metrics_gateway.py
@@ -93,3 +93,25 @@ def test_every_gateway_row_is_contract_valid_and_disabled_config_records_nothing
monkeypatch.setattr(rsm, "enabled", lambda: False)
smg.record_platform_disconnect(Adapter())
assert len(marks()) == 3
+
+
+def test_every_gateway_adapter_platform_is_named_and_accepted_by_contract_and_schema():
+ jsonschema = pytest.importorskip("jsonschema")
+ from pathlib import Path
+
+ from gateway.config import Platform
+
+ schema = json.loads((Path(contract.__file__).parent / "schemas/hermes.shared_metrics.v3.schema.json").read_text())
+ rows = {
+ "platform_health_counter": ("hermes.platform.health", {"error_class": "network", "event": "disconnect"}),
+ "platform_delivery_counter": ("hermes.platform.delivery", {"failure_class": "none", "outcome": "sent"}),
+ "reply_latency_counter": ("hermes.gateway.reply_latency", {"first_response_bucket": "lt_2s"}),
+ }
+ for member in Platform: # relay and msgraph_webhook are gateway adapters with no setup-wizard entry
+ name = contract.adapter_platform(member)
+ assert name == member.value
+ for definition, (metric, dims) in rows.items():
+ dims = {**dims, "platform": name}
+ assert contract.counter_dimensions_are_valid(metric, dims)
+ jsonschema.validate({"name": metric, "type": "counter", "dimensions": dims, "value": 1},
+ {"$defs": schema["$defs"], "$ref": f"#/$defs/{definition}"})