From f0cc1b951c771c55d13ad7ebe0a2f4a4ab42c662 Mon Sep 17 00:00:00 2001 From: Antoine Tenart Date: Mon, 3 Jun 2024 16:26:41 +0200 Subject: [PATCH] tree: add common md event Signed-off-by: Antoine Tenart --- retis-events/src/common.rs | 11 +++++++++++ retis-events/src/events.rs | 14 +++++++++++--- retis/src/collect/collector.rs | 12 +++++++++++- tests/test_ovs.py | 5 +++-- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/retis-events/src/common.rs b/retis-events/src/common.rs index b6ee4c7db..f12361e99 100644 --- a/retis-events/src/common.rs +++ b/retis-events/src/common.rs @@ -2,6 +2,17 @@ use std::fmt; use crate::{event_section, event_type, *}; +#[event_section("md_common")] +pub struct CommonEventMd { + pub retis_version: String, +} + +impl EventFmt for CommonEventMd { + fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result { + write!(f, "Retis version {}", self.retis_version) + } +} + #[event_type] #[derive(Default)] pub struct TaskEvent { diff --git a/retis-events/src/events.rs b/retis-events/src/events.rs index 06c5cbaca..1845ee082 100644 --- a/retis-events/src/events.rs +++ b/retis-events/src/events.rs @@ -189,8 +189,9 @@ pub enum SectionId { Ovs = 8, Nft = 9, Ct = 10, + MdCommon = 11, // TODO: use std::mem::variant_count once in stable. - _MAX = 11, + _MAX = 12, } impl FromStr for SectionId { @@ -210,6 +211,7 @@ impl FromStr for SectionId { OvsEvent::SECTION_NAME => Ovs, NftEvent::SECTION_NAME => Nft, CtEvent::SECTION_NAME => Ct, + CommonEventMd::SECTION_NAME => MdCommon, x => bail!("Can't construct a SectionId from {}", x), }) } @@ -230,6 +232,7 @@ impl SectionId { 8 => Ovs, 9 => Nft, 10 => Ct, + 11 => MdCommon, x => bail!("Can't construct a SectionId from {}", x), }) } @@ -249,7 +252,8 @@ impl SectionId { Ovs => 8, Nft => 9, Ct => 10, - _MAX => 11, + MdCommon => 11, + _MAX => 12, } } @@ -267,13 +271,14 @@ impl SectionId { Ovs => OvsEvent::SECTION_NAME, Nft => NftEvent::SECTION_NAME, Ct => CtEvent::SECTION_NAME, + MdCommon => CommonEventMd::SECTION_NAME, _MAX => "_max", } } /// Is the section a metadata one? pub fn is_metadata(&self) -> bool { - false + matches!(self, SectionId::MdCommon) } } @@ -317,6 +322,9 @@ fn event_sections() -> Result<&'static EventSectionMap> { events.insert(CtEvent::SECTION_NAME.to_string(), |v| { Ok(Box::new(serde_json::from_value::(v)?)) }); + events.insert(CommonEventMd::SECTION_NAME.to_string(), |v| { + Ok(Box::new(serde_json::from_value::(v)?)) + }); Ok(events) }) } diff --git a/retis/src/collect/collector.rs b/retis/src/collect/collector.rs index 7961a37ad..b5bd0ec71 100644 --- a/retis/src/collect/collector.rs +++ b/retis/src/collect/collector.rs @@ -21,7 +21,7 @@ use crate::{ kernel::Symbol, probe::kernel::utils::parse_probe, }, - events::Event, + events::*, process::display::*, }; @@ -202,6 +202,16 @@ impl Collectors { bail!("Retis needs to be run as root when --allow-system-changes is used"); } + // Set common md event. + self.md_event.insert_section( + SectionId::MdCommon, + Box::new(CommonEventMd { + retis_version: option_env!("RELEASE_VERSION") + .unwrap_or("unspec") + .to_string(), + }), + )?; + // Try initializing all collectors. for name in &collect.args()?.collectors { let id = SectionId::from_str(name)?; diff --git a/tests/test_ovs.py b/tests/test_ovs.py index d2fe1ddce..5c445b74f 100644 --- a/tests/test_ovs.py +++ b/tests/test_ovs.py @@ -368,9 +368,10 @@ def test_ovs_tracking(two_port_ovs): series = retis.sort() # All events from the same direction must belong to the same packet (same # global tracking id). - assert len(series) == 2 - assert len(series[0]) == len(expected_events) / 2 + # 2 series + the initial md. + assert len(series) == 3 assert len(series[1]) == len(expected_events) / 2 + assert len(series[2]) == len(expected_events) / 2 @pytest.mark.ovs_track