Skip to content

Commit

Permalink
allow to limit time range for records considered in priority plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-k committed Jul 19, 2022
1 parent d580e51 commit 88b787a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 9 deletions.
94 changes: 86 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ actix-web = "4.1.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde = { version = "1", features = ["derive"] }
serde-aux = "3"
serde_with = { version = "2", features = ["chrono_0_4"] }
config = "0.13"
uuid = { version = "1.1", features = ["v4"] }
chrono = { version = "0.4.19", features = ["serde"] }
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/priority/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use chrono::Duration;
use serde_aux::field_attributes::deserialize_number_from_string;
use std::collections::HashMap;

#[serde_with::serde_as]
#[derive(serde::Deserialize, Debug, Clone)]
pub struct Settings {
#[serde(default = "default_addr")]
Expand All @@ -25,6 +27,8 @@ pub struct Settings {
pub group_mapping: HashMap<String, Vec<String>>,
#[serde(default = "default_command")]
pub commands: Vec<String>,
#[serde_as(as = "Option<serde_with::DurationSeconds<i64>>")]
pub duration: Option<Duration>,
}

fn default_addr() -> String {
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/priority/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use anyhow::Error;
use auditor::client::AuditorClient;
use auditor::domain::Record;
use auditor::telemetry::{get_subscriber, init_subscriber};
use chrono::Utc;
use configuration::Settings;
use num_traits::cast::FromPrimitive;
use std::collections::HashMap;
Expand Down Expand Up @@ -211,8 +212,13 @@ async fn main() -> Result<(), Error> {

let client = AuditorClient::new(&config.addr, config.port)?;

let records = match config.duration {
Some(duration) => client.get_stopped_since(Utc::now() - duration).await?,
None => client.get().await?,
};

set_priorities(
compute_priorities(extract(client.get().await?, &config), &config),
compute_priorities(extract(records, &config), &config),
&config,
)?;

Expand All @@ -238,6 +244,7 @@ mod tests {
max_priority: 10,
group_mapping: HashMap::new(),
commands: vec!["whatever".to_string()],
duration: None,
};

let prios = compute_priorities(resources, &config);
Expand Down

0 comments on commit 88b787a

Please sign in to comment.