Skip to content

Commit 84f08ad

Browse files
committed
Support custom buffer len for trace stats concentrator
1 parent b9320a3 commit 84f08ad

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

libdd-trace-stats/benches/span_concentrator_bench.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
4747
now,
4848
vec![],
4949
vec!["db_name".into(), "bucket_s3".into()],
50+
2,
5051
);
5152
let mut spans = vec![];
5253
for trace_id in 1..100 {

libdd-trace-stats/src/span_concentrator/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl SpanConcentrator {
7979
now: SystemTime,
8080
span_kinds_stats_computed: Vec<String>,
8181
peer_tag_keys: Vec<String>,
82+
buffer_len: usize,
8283
) -> SpanConcentrator {
8384
SpanConcentrator {
8485
bucket_size: bucket_size.as_nanos() as u64,
@@ -87,7 +88,7 @@ impl SpanConcentrator {
8788
system_time_to_unix_duration(now).as_nanos() as u64,
8889
bucket_size.as_nanos() as u64,
8990
),
90-
buffer_len: 2,
91+
buffer_len,
9192
span_kinds_stats_computed,
9293
peer_tag_keys,
9394
}

libdd-trace-stats/src/span_concentrator/tests.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn assert_counts_equal(expected: Vec<pb::ClientGroupedStats>, actual: Vec<pb::Cl
100100
fn test_concentrator_oldest_timestamp_cold() {
101101
let now = SystemTime::now();
102102
let mut concentrator =
103-
SpanConcentrator::new(Duration::from_nanos(BUCKET_SIZE), now, vec![], vec![]);
103+
SpanConcentrator::new(Duration::from_nanos(BUCKET_SIZE), now, vec![], vec![], 2);
104104
let mut spans = vec![
105105
get_test_span(now, 1, 0, 50, 5, "A1", "resource1", 0),
106106
get_test_span(now, 1, 0, 40, 4, "A1", "resource1", 0),
@@ -150,7 +150,7 @@ fn test_concentrator_oldest_timestamp_cold() {
150150
fn test_concentrator_oldest_timestamp_hot() {
151151
let now = SystemTime::now();
152152
let mut concentrator =
153-
SpanConcentrator::new(Duration::from_nanos(BUCKET_SIZE), now, vec![], vec![]);
153+
SpanConcentrator::new(Duration::from_nanos(BUCKET_SIZE), now, vec![], vec![], 2);
154154
let mut spans = vec![
155155
get_test_span(now, 1, 0, 50, 5, "A1", "resource1", 0),
156156
get_test_span(now, 1, 0, 40, 4, "A1", "resource1", 0),
@@ -223,7 +223,7 @@ fn test_concentrator_oldest_timestamp_hot() {
223223
fn test_concentrator_stats_totals() {
224224
let now = SystemTime::now();
225225
let mut concentrator =
226-
SpanConcentrator::new(Duration::from_nanos(BUCKET_SIZE), now, vec![], vec![]);
226+
SpanConcentrator::new(Duration::from_nanos(BUCKET_SIZE), now, vec![], vec![], 2);
227227
let aligned_now = align_timestamp(
228228
system_time_to_unix_duration(now).as_nanos() as u64,
229229
concentrator.bucket_size,
@@ -283,7 +283,7 @@ fn test_concentrator_stats_totals() {
283283
fn test_concentrator_stats_counts() {
284284
let now = SystemTime::now();
285285
let mut concentrator =
286-
SpanConcentrator::new(Duration::from_nanos(BUCKET_SIZE), now, vec![], vec![]);
286+
SpanConcentrator::new(Duration::from_nanos(BUCKET_SIZE), now, vec![], vec![], 2);
287287
let aligned_now = align_timestamp(
288288
system_time_to_unix_duration(now).as_nanos() as u64,
289289
concentrator.bucket_size,
@@ -578,6 +578,7 @@ fn test_span_should_be_included_in_stats() {
578578
now,
579579
get_span_kinds(),
580580
vec![],
581+
2,
581582
);
582583
for span in &spans {
583584
concentrator.add_span(span);
@@ -656,6 +657,7 @@ fn test_ignore_partial_spans() {
656657
now,
657658
get_span_kinds(),
658659
vec![],
660+
2,
659661
);
660662
for span in &spans {
661663
concentrator.add_span(span);
@@ -679,6 +681,7 @@ fn test_force_flush() {
679681
now,
680682
get_span_kinds(),
681683
vec![],
684+
2,
682685
);
683686
for span in &spans {
684687
concentrator.add_span(span);
@@ -760,12 +763,14 @@ fn test_peer_tags_aggregation() {
760763
now,
761764
get_span_kinds(),
762765
vec![],
766+
2,
763767
);
764768
let mut concentrator_with_peer_tags = SpanConcentrator::new(
765769
Duration::from_nanos(BUCKET_SIZE),
766770
now,
767771
get_span_kinds(),
768772
vec!["db.instance".to_string(), "db.system".to_string()],
773+
2,
769774
);
770775
for span in &spans {
771776
concentrator_without_peer_tags.add_span(span);
@@ -1014,6 +1019,7 @@ fn test_pb_span() {
10141019
now,
10151020
get_span_kinds(),
10161021
vec!["db.instance".to_string(), "db.system".to_string()],
1022+
2,
10171023
);
10181024
let aligned_now = align_timestamp(
10191025
system_time_to_unix_duration(now).as_nanos() as u64,

0 commit comments

Comments
 (0)