в backend каноническим полем остался только target. В выходной сериализации убраны плоские алиасы target_kind и target_value

This commit is contained in:
Ilgiz Kamelyev 2026-05-05 09:31:41 +05:00
parent f21746993f
commit eb0cb514a1
6 changed files with 1965 additions and 11 deletions

View File

@ -128,8 +128,6 @@ class NormalizedEvent:
"correlation_id": self.correlation_id,
"causation_id": self.causation_id,
"target": json_safe(self.target),
"target_kind": self.target.kind,
"target_value": self.target.value,
"data_kind": self.data_kind,
"payload": json_safe(self.payload),
}

View File

@ -43,10 +43,10 @@ def _matches_rule(match: Mapping[str, Any], event: Mapping[str, Any]) -> bool:
continue
if key.endswith("_in"):
actual_key = key[:-3]
if not _match_value(event.get(actual_key), candidate):
if not _match_value(_lookup_path(event, actual_key), candidate):
return False
continue
if event.get(key) != candidate:
if _lookup_path(event, key) != candidate:
return False
return True

View File

@ -63,7 +63,7 @@ def _config(tmp_path: Path) -> Path:
match:
source_type: dbus
event_kind: properties_changed
target_kind: bss
target.kind: bss
metrics:
- key: wifi.bss.signal
host_path: target.value
@ -131,6 +131,9 @@ def test_backend_accepts_canonical_batch_and_maps_multiple_metrics(
assert len(sender.sent_batches) == 1
assert len(sender.sent_batches[0]) == 2
assert sender.sent_batches[0][0]["client"]["ip_address"] == "192.0.2.10"
assert sender.sent_batches[0][0]["target"]["kind"] == "bss"
assert "target_kind" not in sender.sent_batches[0][0]
assert "target_value" not in sender.sent_batches[0][0]
lines = [
json.loads(line) for line in stdout.getvalue().splitlines() if line.strip()
]
@ -140,7 +143,10 @@ def test_backend_accepts_canonical_batch_and_maps_multiple_metrics(
assert len(lines[0]["batch"]["items"]) == 1
assert lines[0]["batch"]["items"][0]["event_kind"] == "properties_changed"
assert lines[0]["batch"]["items"][0]["payload"]["changed"]["Signal"] == -41
assert lines[0]["batch"]["items"][0]["target"]["kind"] == "bss"
assert lines[0]["batch"]["items"][0]["client"]["ip_address"] == "192.0.2.10"
assert "target_kind" not in lines[0]["batch"]["items"][0]
assert "target_value" not in lines[0]["batch"]["items"][0]
def test_backend_rejects_unsupported_message_shapes(

View File

@ -37,7 +37,7 @@ mapping:
match:
source_type: dbus
event_kind: properties_changed
target_kind: bss
target.kind: bss
metrics:
- key: wifi.bss.signal
host_path: target.value

View File

@ -560,8 +560,7 @@ class NormalizedEvent:
robot_id: str | None
message_id: str
item_kind: str
target_kind: str
target_value: str
target: dict
data_kind: str
event_kind: str
observed_at_unix_ms: int
@ -643,8 +642,7 @@ The mapper should be able to emit multiple metric intents per event before the q
```python
class MetricIntent:
target_kind: str
target_value: str
target: dict
metric_key: str
value: str | int | float
clock_unix: int | None
@ -656,7 +654,7 @@ Rules:
- one normalized event may produce zero or more metric intents;
- one metric intent maps to one Zabbix metric record;
- the backend routing layer should use `target_kind` + `target_value` to determine the Zabbix host or host group.
- the backend routing layer should use `target.kind` + `target.value` to determine the Zabbix host or host group.
---

1952
tmp/3.json Normal file

File diff suppressed because it is too large Load Diff