Skip to content

Commit

Permalink
support data dump type filtering in search filters
Browse files Browse the repository at this point in the history
- added `DumpType` enum with options for updates, rib, and both
- added `dump_type` field with `updates` as default
- updated broker query to filter by selected dump type
  • Loading branch information
digizeph committed Dec 30, 2024
1 parent 94b6a96 commit 07cace2
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/filters/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::filters::MrtParserFilters;
use anyhow::Result;
use bgpkit_broker::BrokerItem;
use bgpkit_parser::BgpkitParser;
use clap::Args;
use clap::{Args, ValueEnum};
use serde::Serialize;
use std::io::Read;

#[derive(Args, Debug, Clone)]
Expand All @@ -18,6 +19,21 @@ pub struct SearchFilters {
/// Filter by route collection project, i.e., riperis or routeviews
#[clap(short = 'P', long)]
pub project: Option<String>,

/// Specify data dump type to search (updates or RIB dump)
#[clap(short = 'D', long, default_value_t, value_enum)]
pub dump_type: DumpType,
}

#[derive(ValueEnum, Clone, Debug, Default, Serialize)]
pub enum DumpType {
/// BGP updates only
#[default]
Updates,
/// BGP RIB dump only
Rib,
/// BGP RIB dump and BGP updates
RibUpdates,
}

impl SearchFilters {
Expand All @@ -28,7 +44,6 @@ impl SearchFilters {
let mut broker = bgpkit_broker::BgpkitBroker::new()
.ts_start(ts_start)
.ts_end(ts_end)
.data_type("update")
.page_size(1000);

if let Some(project) = &self.project {
Expand All @@ -38,6 +53,18 @@ impl SearchFilters {
broker = broker.collector_id(collector.as_str());
}

match self.dump_type {
DumpType::Updates => {
broker = broker.data_type("updates");
}
DumpType::Rib => {
broker = broker.data_type("rib");
}
DumpType::RibUpdates => {
// do nothing here -> getting all RIB and updates
}
}

broker
.query()
.map_err(|_| anyhow::anyhow!("broker query error: please check filters are valid"))
Expand Down

0 comments on commit 07cace2

Please sign in to comment.