Skip to content

Commit

Permalink
Add retain options to minireview
Browse files Browse the repository at this point in the history
- Fix Clippy error
  • Loading branch information
BLYKIM committed Jan 2, 2024
1 parent fec6a19 commit ed7ebca
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).
`Model`'s id. If not first fetch, generate iterator since the last fetched key.
- Stream through the `RankedOutlier` iterator, and repeat the behavior after a
period of time.
- Add retain options to minireview.

### Changed

Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ vinum = { git = "https://github.com/vinesystems/vinum.git", tag = "1.0.3" }
[dev-dependencies]
config = { version = "0.13", features = ["toml"], default-features = false }
futures = "0.3"
humantime = "2.1"
humantime-serde = "1"
tempfile = "3"
tokio = { version = "1", features = ["rt-multi-thread", "signal"] }
tracing-appender = "0.2"
Expand Down
38 changes: 37 additions & 1 deletion examples/minireview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::{
path::{Path, PathBuf},
process::exit,
sync::{Arc, Mutex},
time::Duration,
};
use tokio::{
signal::unix::{signal, SignalKind},
Expand Down Expand Up @@ -106,12 +107,18 @@ impl AgentManager for Manager {
const DEFAULT_DATABASE_URL: &str = "postgres://review@localhost/review";
const DEFAULT_SERVER: &str = "localhost";
const DEFAULT_LOG_PATH: &str = "/data/logs/apps";
const DEFAULT_EXPORT_PATH: &str = "/data/exports";
const DEFAULT_DB_RETENTION_PERIOD: &str = "6m";
const DEFAULT_STAT_RETENTION_PERIOD: &str = "10d";

pub struct Config {
data_dir: PathBuf,
backup_dir: PathBuf,
log_dir: PathBuf,
htdocs_dir: PathBuf,
export_dir: PathBuf,
db_retention: Duration,
stat_retention: Duration,
database_url: String,
graphql_srv_addr: SocketAddr,
cert: PathBuf,
Expand All @@ -127,6 +134,11 @@ struct ConfigParser {
backup_dir: PathBuf,
log_dir: PathBuf,
htdocs_dir: PathBuf,
export_dir: PathBuf,
#[serde(with = "humantime_serde")]
db_retention: Duration,
#[serde(with = "humantime_serde")]
stat_retention: Duration,
database_url: String,
graphql_srv_addr: String,
cert: PathBuf,
Expand Down Expand Up @@ -155,7 +167,13 @@ impl Config {
.set_default("log_dir", DEFAULT_LOG_PATH)
.context("cannot set the default log path")?
.set_default("htdocs_dir", env::current_dir()?.join("htdocs").to_str())
.context("cannot set the default web directory")?;
.context("cannot set the default web directory")?
.set_default("export_dir", DEFAULT_EXPORT_PATH)
.context("cannot set the default export directory")?
.set_default("db_retention", DEFAULT_DB_RETENTION_PERIOD)
.context("cannot set the default db retention")?
.set_default("stat_retention", DEFAULT_STAT_RETENTION_PERIOD)
.context("cannot set the default statistic retention")?;
let config: ConfigParser = if let Some(path) = path {
builder.add_source(File::with_name(path))
} else {
Expand All @@ -181,6 +199,9 @@ impl Config {
backup_dir: config.backup_dir,
log_dir: config.log_dir,
htdocs_dir: config.htdocs_dir,
export_dir: config.export_dir,
db_retention: config.db_retention,
stat_retention: config.stat_retention,
database_url: config.database_url,
graphql_srv_addr,
cert: config.cert,
Expand Down Expand Up @@ -211,6 +232,21 @@ impl Config {
self.htdocs_dir.as_ref()
}

#[must_use]
pub fn export_dir(&self) -> &Path {
self.export_dir.as_ref()
}

#[must_use]
pub fn db_retention(&self) -> Duration {
self.db_retention
}

#[must_use]
pub fn stat_retention(&self) -> Duration {
self.stat_retention
}

#[must_use]
pub fn database_url(&self) -> &str {
&self.database_url
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/event/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl MultiHostPortScan {
*self
.inner
.dst_addrs
.get(0)
.first()
.expect("has value with internal network"),
)
}
Expand Down Expand Up @@ -243,7 +243,7 @@ impl ExternalDdos {
*self
.inner
.src_addrs
.get(0)
.first()
.expect("has value with internal network"),
)
}
Expand Down
1 change: 1 addition & 0 deletions src/graphql/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ pub struct Setting {
review: Option<ServerPort>,
}

#[allow(clippy::struct_field_names)]
#[derive(Serialize)]
pub struct ServerAddress {
web_addr: Option<SocketAddr>,
Expand Down
10 changes: 3 additions & 7 deletions src/graphql/triage/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ use super::{
TriagePolicyMutation, TriagePolicyQuery,
};
use super::{Role, RoleGuard};
use anyhow::anyhow;
use async_graphql::{
connection::{query, Connection, EmptyFields},
Context, Object, Result, ID,
};
use bincode::Options;
use chrono::Utc;
use core::convert::TryInto;
use review_database::{
self as database, Indexed, IndexedMap, IndexedMapIterator, IndexedMapUpdate,
};
Expand Down Expand Up @@ -103,7 +101,7 @@ impl TriagePolicyMutation {
) -> Result<ID> {
let mut packet_attr_convert: Vec<database::PacketAttr> = Vec::new();
for p in &packet_attr {
packet_attr_convert.push(p.try_into()?);
packet_attr_convert.push(p.into());
}
packet_attr_convert.sort_unstable();
let mut ti_db = ti_db.iter().map(Into::into).collect::<Vec<database::Ti>>();
Expand Down Expand Up @@ -202,7 +200,7 @@ impl IndexedMapUpdate for TriagePolicyInput {
value.ti_db = ti_db;
let mut packet_attr: Vec<database::PacketAttr> = Vec::new();
for p in &self.packet_attr {
packet_attr.push(p.try_into().map_err(|e| anyhow!("{}", e))?);
packet_attr.push(p.into());
}
packet_attr.sort_unstable();
value.packet_attr = packet_attr;
Expand Down Expand Up @@ -239,9 +237,7 @@ impl IndexedMapUpdate for TriagePolicyInput {
}
let mut packet_attr: Vec<database::PacketAttr> = Vec::new();
for p in &self.packet_attr {
if let Ok(p) = p.try_into() {
packet_attr.push(p);
}
packet_attr.push(p.into());
}
packet_attr.sort_unstable();
if packet_attr != value.packet_attr {
Expand Down

0 comments on commit ed7ebca

Please sign in to comment.