test(alerts): seed metrics the way ingest does, through record_metrics (#5473)
#5473 "Opening an alert rule takes up to 15 s". With the rule pickers now reading plugin_metric_latest, nine integration tests failed on rule_fields: "host_agent has no resource 'box-…'". They seeded a resource by adding a raw PluginMetric row, which no production path does: host-agent ingest and record_metric both go through record_metrics, which keeps the latest-value table. The seeds now go through record_metrics too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -124,6 +124,7 @@ def test_a_renamed_host_carries_agent_and_container_metrics_and_their_rules(app)
|
||||
from sqlalchemy import select
|
||||
from steward.alerts import service as alert_svc
|
||||
from steward.models.alerts import AlertRule
|
||||
from steward.core.alerts import record_metrics
|
||||
from steward.models.hosts import Host
|
||||
from steward.models.metrics import PluginMetric
|
||||
|
||||
@@ -140,8 +141,9 @@ def test_a_renamed_host_carries_agent_and_container_metrics_and_their_rules(app)
|
||||
async with s.begin():
|
||||
s.add(Host(id=hid, name=old, address="10.8.8.8"))
|
||||
s.add(Host(id=str(uuid.uuid4()), name=f"{old}x", address="10.8.8.9"))
|
||||
for src, res in rows:
|
||||
s.add(PluginMetric(source_module=src, resource_name=res, metric_name="disk_used_pct", value=1))
|
||||
await record_metrics(s, [PluginMetric(source_module=src, resource_name=res,
|
||||
metric_name="disk_used_pct", value=1)
|
||||
for src, res in rows])
|
||||
await s.flush()
|
||||
fields = await alert_svc.rule_fields(
|
||||
s, name=f"disk {tag}", source_module="host_agent", resource_name=f"{old}:/",
|
||||
|
||||
Reference in New Issue
Block a user