Skip to content

Commit

Permalink
Made clippy happy
Browse files Browse the repository at this point in the history
Signed-off-by: Benedikt Zinn <[email protected]>
  • Loading branch information
BenediktZinn committed Jan 20, 2025
1 parent 43baf06 commit dcd8abc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
45 changes: 30 additions & 15 deletions rust/backend/daemon/src/collector/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ use ractor::{cast, Actor, ActorProcessingErr, ActorRef};
use shared::ziofa::event::EventType;
use shared::ziofa::log_event::EventData;
use shared::ziofa::time_series_event::EventTypeEnum;
use shared::ziofa::{Event, TimeSeriesEvent as ZioTimeSeries};
use shared::ziofa::time_series_event::TimeSeries as ZioTimeSeries;
use shared::ziofa::{Event, TimeSeriesEvent as ZioTimeSeriesEvent};
use std::collections::HashMap;
use tokio::time;

pub struct Aggregator;
impl Aggregator {
fn convert_map_to_prototype(
time_series_map: HashMap<u32, TimeSeries>,
) -> HashMap<u32, ZioTimeSeries> {
let mut map = HashMap::<u32, ZioTimeSeries>::with_capacity(time_series_map.len());
for (id, time_series) in time_series_map {
map.insert(id, time_series.into());
}
map
}
}

impl Default for Aggregator {
fn default() -> Self {
Expand Down Expand Up @@ -105,12 +117,15 @@ impl Actor for Aggregator {
) -> Result<(), ActorProcessingErr> {
match msg.event_type {
Some(EventType::Log(event)) => {
let pid = match event.clone() {
EventData::VfsWrite(item) => item.pid,
EventData::SysSendmsg(item) => item.pid,
EventData::JniReferences(item) => item.pid,
EventData::SysSigquit(item) => item.pid,
EventData::Gc(item) => item.pid,
let pid = match event.event_data.clone() {
Some(EventData::VfsWrite(item)) => item.pid,
Some(EventData::SysSendmsg(item)) => item.pid,
Some(EventData::JniReferences(item)) => item.pid,
Some(EventData::SysSigquit(item)) => item.pid,
Some(EventData::Gc(item)) => item.pid,
_ => {
panic!("unexpected event type");
}
};

let msg_event_type = EventTypeEnum::from(event);
Expand All @@ -121,9 +136,7 @@ impl Actor for Aggregator {
state.event_type, msg_event_type
);
}
if !state.event_count_map.contains_key(&pid) {
state.event_count_map.insert(pid, 1);
}
state.event_count_map.entry(pid).or_insert(1);
}
_ => {
// event type is none -> timer was triggered -> send the metric
Expand All @@ -137,10 +150,13 @@ impl Actor for Aggregator {
}
}

let time_series = ZioTimeSeries {
//convert type for sending
//ziofa::time_series_event::TimeSeries

let time_series = ZioTimeSeriesEvent {
event_type_enum: state.event_type.into(),
timeframe_ms: state.timeframe.as_millis() as u32,
time_series_map: state.timeseries.clone().into(),
time_series_map: Self::convert_map_to_prototype(state.timeseries.clone()),
};

cast!(
Expand All @@ -150,9 +166,8 @@ impl Actor for Aggregator {
}
)
.map_err(|_| ActorProcessingErr::from("Failed to send metric to event actor"))?;
for key in state.event_count_map.keys() {
let mut count = state.event_count_map.get_mut(key).unwrap();
*count = 0;
for (_, value) in state.event_count_map.iter_mut() {
*value = 0;
}
}
}
Expand Down
15 changes: 5 additions & 10 deletions rust/backend/daemon/src/collector/time_series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: MIT

#[derive(Clone)]
pub struct TimeSeries {
internal_time_series: Vec<u64>,
internal_head_pointer: usize,
Expand Down Expand Up @@ -39,20 +40,14 @@ impl TimeSeries {
}
}


impl Into<shared::ziofa::time_series_event::TimeSeries> for TimeSeries {
fn into(self) -> shared::ziofa::time_series_event::TimeSeries {
shared::ziofa::time_series_event::TimeSeries{
list: self.as_array(),
impl From<TimeSeries> for shared::ziofa::time_series_event::TimeSeries {
fn from(series: TimeSeries) -> Self {
shared::ziofa::time_series_event::TimeSeries {
list: series.as_array(),
}
}
}






#[test]
fn some_test() {
let mut ts = TimeSeries::new(5);
Expand Down

0 comments on commit dcd8abc

Please sign in to comment.