// Generate a timeline of simulated disruptions to seed
Generate a timeline of simulated disruptions to seed
Generate a timeline of simulated disruptions to seed
fn generate_disruptions(config: &Config, rng: &mut ThreadRng) -> HashMap<usize, (Disruption, usize)> {
    debug!("Generating disruptions...");
    let mut disruptions = HashMap::with_capacity(config.disruptions);
    for _ in 0..config.disruptions {
        // Disruptions start after the 48th hour, and can last 2-24 hours long
        let (start, length) = (rng.gen_range(48, config.hours - 24), rng.gen_range(2, 24));
        let disruption = match rng.gen_range(1,4) {
            // Node disruption: all (metric,queries) on the node are disrupted
            1 => {
                let id = rng.gen_range(0, config.nodes);
                debug!("Node Disruption: {}-{} [{:?}]", start, start+length, id);
                Disruption::Node(id)
            },
            // Query disruption: all (metric, node) with the query(ies) are disrupted
            2 => {
                // random number of queries from 1 to one-tenth of the total queries
                let num_queries = rng.gen_range(1,config.queries/10);
                let mut v: Vec<usize> = (0..num_queries).map(|_| rng.gen_range(0, config.queries)).collect();
                v.sort();
                v.dedup();
                debug!("Query Disruption: {}-{} [{:?}]", start, start+length, v);
                Disruption::Query(v)
            },
            // Metric disruption: all (node,query) with the metric are disrupted
            _ => {
                // one-to-all metrics disrupted
                let num_metrics = rng.gen_range(1,config.metrics);
                let mut v: Vec<usize> = (0..num_metrics).map(|_| rng.gen_range(0, config.metrics)).collect();
                v.sort();
                v.dedup();
                debug!("Metric Disruption: {}-{} [{:?}]", start, start+length, v);
                Disruption::Metric(v)
            }
        };
        disruptions.insert(start, (disruption, length));
    }
    disruptions
}
fn generate_disruptions ( config : & Config , rng : & mut ThreadRng ) -> HashMap < usize , ( Disruption , usize ) > { debug ! ( " " ) ; let mut disruptions = HashMap :: with_capacity ( config . disruptions ) ; for _ in 0 .. config . disruptions { // Disruptions start after the 48th hour, and can last 2-24 hours long let ( start , length ) = ( rng . gen_range ( 48 , config . hours - 24 ) , rng . gen_range ( 2 , 24 ) ) ; let disruption = match rng . gen_range ( 1 , 4 ) { // Node disruption: all (metric,queries) on the node are disrupted 1 => { let id = rng . gen_range ( 0 , config . nodes ) ; debug ! ( " " start start length id ) ; Disruption :: Node ( id ) } , // Query disruption: all (metric, node) with the query(ies) are disrupted 2 => { // random number of queries from 1 to one-tenth of the total queries let num_queries = rng . gen_range ( 1 , config . queries / 10 ) ; let mut v : Vec < usize > = ( 0 .. num_queries ) . map ( | _ | rng . gen_range ( 0 , config . queries ) ) . collect ( ) ; v . sort ( ) ; v . dedup ( ) ; debug ! ( " " start start length v ) ; Disruption :: Query ( v ) } , // Metric disruption: all (node,query) with the metric are disrupted _ => { // one-to-all metrics disrupted let num_metrics = rng . gen_range ( 1 , config . metrics ) ; let mut v : Vec < usize > = ( 0 .. num_metrics ) . map ( | _ | rng . gen_range ( 0 , config . metrics ) ) . collect ( ) ; v . sort ( ) ; v . dedup ( ) ; debug ! ( " " start start length v ) ; Disruption :: Metric ( v ) } } ; disruptions . insert ( start , ( disruption , length ) ) ; } disruptions }
Generate a timeline of simulated disruptions to seed
Generate a timeline of simulated disruptions to seed
config
&Config
rng
&mut ThreadRng