Skip to content

Commit

Permalink
instant -> random
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbayer committed Jul 2, 2024
1 parent 34836a6 commit 173a8da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion relay-metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fnv = { workspace = true }
hash32 = { workspace = true }
hashbrown = { workspace = true }
itertools = { workspace = true }
rand = { workspace = true }
relay-base-schema = { workspace = true }
relay-cardinality = { workspace = true }
relay-cogs = { workspace = true }
Expand All @@ -40,7 +41,6 @@ unescaper = { workspace = true }
[dev-dependencies]
criterion = { workspace = true }
insta = { workspace = true }
rand = { workspace = true }
relay-statsd = { workspace = true, features = ["test"] }
relay-test = { workspace = true }
similar-asserts = { workspace = true }
Expand Down
34 changes: 17 additions & 17 deletions relay-metrics/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct BucketKey {
metric_name: MetricName,
tags: BTreeMap<String, String>,
extracted_from_indexed: bool,
randomness: Option<Instant>,
randomness: u16,
}

impl BucketKey {
Expand Down Expand Up @@ -717,8 +717,8 @@ impl Aggregator {
tags: bucket.tags,
extracted_from_indexed: bucket.metadata.extracted_from_indexed,
randomness: match self.config.aggregate {
true => None,
false => Some(Instant::now()),
true => 0,
false => rand::random(),
},
};
let key = validate_bucket_key(key, &self.config)?;
Expand Down Expand Up @@ -973,7 +973,7 @@ mod tests {
),
tags: {},
extracted_from_indexed: false,
randomness: None,
randomness: 0,
},
Counter(
85.0,
Expand Down Expand Up @@ -1024,11 +1024,11 @@ mod tests {
("answer".to_owned(), "42".to_owned()),
]),
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};
assert_eq!(
bucket_key.cost(),
104 + // BucketKey
88 + // BucketKey
5 + // name
(5 + 5 + 6 + 2), // tags
);
Expand Down Expand Up @@ -1072,7 +1072,7 @@ mod tests {
),
tags: {},
extracted_from_indexed: false,
randomness: None,
randomness: 0,
},
Counter(
84.0,
Expand All @@ -1087,7 +1087,7 @@ mod tests {
),
tags: {},
extracted_from_indexed: false,
randomness: None,
randomness: 0,
},
Counter(
42.0,
Expand Down Expand Up @@ -1211,7 +1211,7 @@ mod tests {
metric_name: "c:transactions/foo@none".into(),
tags: BTreeMap::new(),
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};
let fixed_cost = bucket_key.cost() + mem::size_of::<BucketValue>();
for (metric_name, metric_value, expected_added_cost) in [
Expand Down Expand Up @@ -1369,7 +1369,7 @@ mod tests {
tags
},
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};

let mut bucket_key = validate_bucket_key(bucket_key, &test_config()).unwrap();
Expand All @@ -1396,7 +1396,7 @@ mod tests {
metric_name: "c:transactions/a_short_metric".into(),
tags: BTreeMap::new(),
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};
assert!(validate_bucket_key(short_metric, &test_config()).is_ok());

Expand All @@ -1406,7 +1406,7 @@ mod tests {
metric_name: "c:transactions/long_name_a_very_long_name_its_super_long_really_but_like_super_long_probably_the_longest_name_youve_seen_and_even_the_longest_name_ever_its_extremly_long_i_cant_tell_how_long_it_is_because_i_dont_have_that_many_fingers_thus_i_cant_count_the_many_characters_this_long_name_is".into(),
tags: BTreeMap::new(),
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};
let validation = validate_bucket_key(long_metric, &test_config());

Expand All @@ -1423,7 +1423,7 @@ mod tests {
metric_name: "c:transactions/a_short_metric_with_long_tag_key".into(),
tags: BTreeMap::from([("i_run_out_of_creativity_so_here_we_go_Lorem_Ipsum_is_simply_dummy_text_of_the_printing_and_typesetting_industry_Lorem_Ipsum_has_been_the_industrys_standard_dummy_text_ever_since_the_1500s_when_an_unknown_printer_took_a_galley_of_type_and_scrambled_it_to_make_a_type_specimen_book".into(), "tag_value".into())]),
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};
let validation = validate_bucket_key(short_metric_long_tag_key, &test_config()).unwrap();
assert_eq!(validation.tags.len(), 0);
Expand All @@ -1434,7 +1434,7 @@ mod tests {
metric_name: "c:transactions/a_short_metric_with_long_tag_value".into(),
tags: BTreeMap::from([("tag_key".into(), "i_run_out_of_creativity_so_here_we_go_Lorem_Ipsum_is_simply_dummy_text_of_the_printing_and_typesetting_industry_Lorem_Ipsum_has_been_the_industrys_standard_dummy_text_ever_since_the_1500s_when_an_unknown_printer_took_a_galley_of_type_and_scrambled_it_to_make_a_type_specimen_book".into())]),
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};
let validation = validate_bucket_key(short_metric_long_tag_value, &test_config()).unwrap();
assert_eq!(validation.tags.len(), 0);
Expand All @@ -1453,7 +1453,7 @@ mod tests {
metric_name: "c:transactions/a_short_metric".into(),
tags: BTreeMap::from([("foo".into(), tag_value.clone())]),
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};
let validated_bucket = validate_metric_tags(short_metric, &test_config());
assert_eq!(validated_bucket.tags["foo"], tag_value);
Expand Down Expand Up @@ -1588,7 +1588,7 @@ mod tests {
metric_name: "c:transactions/foo".into(),
tags: BTreeMap::new(),
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};

// Second bucket has a timestamp in this hour.
Expand All @@ -1599,7 +1599,7 @@ mod tests {
metric_name: "c:transactions/foo".into(),
tags: BTreeMap::new(),
extracted_from_indexed: false,
randomness: None,
randomness: 0,
};

let flush_time_1 = get_flush_time(&config, reference_time, &bucket_key_1);
Expand Down

0 comments on commit 173a8da

Please sign in to comment.