Commit a9745c5
committed
feat: pluggable TemplateStore for horizontal parser scale-out
Add a TemplateStore trait so V9 and IPFIX templates can be persisted to
and re-read from an external backend (Redis, NATS KV, etc.). With a
store configured, the parser writes through every learned template,
consults the store on every cache miss, and propagates LRU evictions,
RFC 7011 §8.1 withdrawals, and explicit clear_*_templates calls. This
unblocks running multiple stateless parser replicas behind a UDP load
balancer without source-IP-affinity routing.
AutoScopedParser auto-derives a per-source scope so exporters using the
same template ID with different layouts do not collide in the store.
The trait sees opaque Vec<u8> payloads encoded with a small versioned
custom binary wire format — no serde_json or other runtime serializer
is added to the dependency tree. An InMemoryTemplateStore reference
impl is provided for tests.
New public API:
- TemplateStore, TemplateStoreKey, TemplateKind, TemplateStoreError
- InMemoryTemplateStore
- NetflowParserBuilder::with_template_store / with_template_store_scope
- NetflowParser::set_template_store_scope
Eight integration tests in tests/template_store.rs cover write-through,
cross-replica read-through, baseline (no-store) unchanged, clear_*
propagation, IPFIX withdrawal eviction, and per-source scoping. README
gains a "Pluggable Template Storage" section under the Template
Management Guide; RELEASES.md notes the feature under 1.0.3.
fix: address TemplateStore code-review feedback
Apply all blocking and high-value items from the independent review of
the TemplateStore branch.
Must-fix:
- Codec errors no longer collapse into silent cache misses. fetch_*_from_store
now distinguishes Ok(None) vs Err vs codec rejection: backend errors are
counted in metrics, codec errors are counted AND remove the corrupted key
so a fresh template announce can repopulate cleanly.
- README's "RedisTemplateStore" example dropped rustdoc hidden-line `#`
markers (only stripped in `rust` doctests, not `rust,ignore`) so readers
see valid Rust.
Should-fix:
- Read-through LRU push now captures the eviction return and propagates
evict-from-store + record_eviction(), keeping primary and secondary
tiers consistent.
- V9-in-IPFIX validation extracted into Template::is_valid_with_limits and
OptionsTemplate::is_valid_with_limits. Three copies of the rule in
parse_templates and the IPFIX read-through helpers collapse into one.
- New TemplateEvent::Restored variant fires when a template is pulled in
via read-through; observability tools that count Learned can now also
count Restored after a parser restart. Hooks fire from parse_bytes via
per-parser drain_restored_templates(), driven by a small Vec buffer that
is cleared at the top of each V9::parse / IPFix::parse.
- Pending-flow replay now also runs against templates restored via the
secondary store, not just templates announced in the current packet.
- decode_v9_options_template rejects payloads where options_scope_length
or options_length is not a multiple of 4, matching the live parse path.
- TemplateStoreKey.scope is now Arc<str> (was String). Internal scope
fields on Config / V9Parser / IPFixParser / NetflowParserBuilder follow.
Per-key clones become refcount bumps. NetflowParserBuilder::with_template_store_scope
and NetflowParser::set_template_store_scope take impl Into<Arc<str>>.
- Three new metric counters: template_store_restored,
template_store_codec_errors, template_store_backend_errors.
Tests:
- Nine new tests cover backend Err returns (FaultStore fault injection),
corrupted-payload codec rejection + cleanup, LRU eviction propagating
to store on a full cache, IPFIX options-template read-through,
Restored event firing, pending-flow replay after read-through,
duplicate-ID write-through, and set_template_store_scope retrofit.
Docs:
- WIRE_VERSION migration story added to template_store module docs
(drain-before-upgrade or version-namespaced scope).
- InMemoryTemplateStore documents its mutex-poison panic behavior.
All 216 lib tests + 17 integration tests + 66 doctests pass.1 parent 80678db commit a9745c5
13 files changed
Lines changed: 2395 additions & 23 deletions
File tree
- src
- variable_versions
- ipfix
- v9
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
789 | 789 | | |
790 | 790 | | |
791 | 791 | | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
792 | 864 | | |
793 | 865 | | |
794 | 866 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
3 | 36 | | |
4 | 37 | | |
5 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
274 | 278 | | |
275 | 279 | | |
276 | 280 | | |
| 281 | + | |
| 282 | + | |
277 | 283 | | |
278 | 284 | | |
279 | 285 | | |
| |||
304 | 310 | | |
305 | 311 | | |
306 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
307 | 322 | | |
308 | 323 | | |
309 | 324 | | |
| |||
317 | 332 | | |
318 | 333 | | |
319 | 334 | | |
| 335 | + | |
| 336 | + | |
320 | 337 | | |
321 | 338 | | |
322 | 339 | | |
| |||
776 | 793 | | |
777 | 794 | | |
778 | 795 | | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
779 | 842 | | |
780 | 843 | | |
781 | 844 | | |
| |||
822 | 885 | | |
823 | 886 | | |
824 | 887 | | |
825 | | - | |
826 | | - | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
827 | 896 | | |
828 | 897 | | |
829 | 898 | | |
| |||
1092 | 1161 | | |
1093 | 1162 | | |
1094 | 1163 | | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
1095 | 1179 | | |
1096 | 1180 | | |
1097 | 1181 | | |
| |||
1340 | 1424 | | |
1341 | 1425 | | |
1342 | 1426 | | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
1343 | 1447 | | |
1344 | 1448 | | |
1345 | 1449 | | |
| |||
1358 | 1462 | | |
1359 | 1463 | | |
1360 | 1464 | | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
1361 | 1496 | | |
1362 | 1497 | | |
1363 | 1498 | | |
| |||
1581 | 1716 | | |
1582 | 1717 | | |
1583 | 1718 | | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
1584 | 1735 | | |
1585 | 1736 | | |
1586 | 1737 | | |
| |||
1592 | 1743 | | |
1593 | 1744 | | |
1594 | 1745 | | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
1595 | 1751 | | |
1596 | 1752 | | |
1597 | 1753 | | |
| |||
0 commit comments