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:
@@ -31,6 +31,7 @@ def test_ingest_fires_a_host_rule_from_a_backlog(app):
|
||||
from steward.alerts import service as alert_svc
|
||||
from steward.models.alerts import AlertEvent, AlertState, AlertStateEnum
|
||||
from steward.models.hosts import Host
|
||||
from steward.core.alerts import record_metrics
|
||||
from steward.models.metrics import PluginMetric
|
||||
from steward.models.users import User, UserRole
|
||||
|
||||
@@ -50,8 +51,8 @@ def test_ingest_fires_a_host_rule_from_a_backlog(app):
|
||||
"VALUES (:id, :host, :hash, now(), now(), now())"),
|
||||
{"id": str(uuid.uuid4()), "host": host.id,
|
||||
"hash": hashlib.sha256(token.encode()).hexdigest()})
|
||||
s.add(PluginMetric(source_module="host_agent", resource_name=hostname,
|
||||
metric_name="cpu_pct", value=5.0))
|
||||
await record_metrics(s, [PluginMetric(source_module="host_agent", resource_name=hostname,
|
||||
metric_name="cpu_pct", value=5.0)])
|
||||
await s.flush()
|
||||
fields = await alert_svc.rule_fields(
|
||||
s, name=f"cpu {tag}", source_module="host_agent", resource_name=hostname,
|
||||
|
||||
Reference in New Issue
Block a user