Skip to content

Commit

Permalink
tree: add common md event
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Tenart <[email protected]>
  • Loading branch information
atenart committed Jun 5, 2024
1 parent 5454960 commit f0cc1b9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
11 changes: 11 additions & 0 deletions retis-events/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions retis-events/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
})
}
Expand All @@ -230,6 +232,7 @@ impl SectionId {
8 => Ovs,
9 => Nft,
10 => Ct,
11 => MdCommon,
x => bail!("Can't construct a SectionId from {}", x),
})
}
Expand All @@ -249,7 +252,8 @@ impl SectionId {
Ovs => 8,
Nft => 9,
Ct => 10,
_MAX => 11,
MdCommon => 11,
_MAX => 12,
}
}

Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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::<CtEvent>(v)?))
});
events.insert(CommonEventMd::SECTION_NAME.to_string(), |v| {
Ok(Box::new(serde_json::from_value::<CommonEventMd>(v)?))
});
Ok(events)
})
}
Expand Down
12 changes: 11 additions & 1 deletion retis/src/collect/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
kernel::Symbol,
probe::kernel::utils::parse_probe,
},
events::Event,
events::*,
process::display::*,
};

Expand Down Expand Up @@ -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)?;
Expand Down
5 changes: 3 additions & 2 deletions tests/test_ovs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f0cc1b9

Please sign in to comment.