Skip to content

Commit 99ba7f5

Browse files
authored
Merge branch 'main' into utpilla/Add-counter-multithreaded-tests
2 parents 56865f4 + 3825edc commit 99ba7f5

File tree

1 file changed

+25
-22
lines changed
  • opentelemetry-sdk/src/metrics

1 file changed

+25
-22
lines changed

opentelemetry-sdk/src/metrics/mod.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,25 @@ mod tests {
218218
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
219219
async fn updown_counter_aggregation_cumulative() {
220220
// Run this test with stdout enabled to see output.
221-
// cargo test counter_aggregation_cumulative --features=metrics,testing -- --nocapture
221+
// cargo test updown_counter_aggregation_cumulative --features=metrics,testing -- --nocapture
222222
updown_counter_aggregation_helper(Temporality::Cumulative);
223223
}
224224

225225
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
226226
async fn updown_counter_aggregation_delta() {
227227
// Run this test with stdout enabled to see output.
228-
// cargo test counter_aggregation_delta --features=metrics,testing -- --nocapture
228+
// cargo test updown_counter_aggregation_delta --features=metrics,testing -- --nocapture
229229
updown_counter_aggregation_helper(Temporality::Delta);
230230
}
231231

232232
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
233233
async fn gauge_aggregation() {
234234
// Run this test with stdout enabled to see output.
235235
// cargo test gauge_aggregation --features=metrics,testing -- --nocapture
236-
gauge_aggregation_helper();
236+
237+
// Gauge should use last value aggregation regardless of the aggregation temporality used.
238+
gauge_aggregation_helper(Temporality::Delta);
239+
gauge_aggregation_helper(Temporality::Cumulative);
237240
}
238241

239242
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
@@ -1190,9 +1193,9 @@ mod tests {
11901193
}
11911194
}
11921195

1193-
fn gauge_aggregation_helper() {
1196+
fn gauge_aggregation_helper(temporality: Temporality) {
11941197
// Arrange
1195-
let mut test_context = TestContext::new(Temporality::Delta);
1198+
let mut test_context = TestContext::new(temporality);
11961199
let gauge = test_context.meter().i64_gauge("my_gauge").init();
11971200

11981201
// Act
@@ -1330,15 +1333,15 @@ mod tests {
13301333
let counter = test_context.i64_up_down_counter("test", "my_updown_counter", None);
13311334

13321335
// Act
1333-
counter.add(1, &[KeyValue::new("key1", "value1")]);
1334-
counter.add(1, &[KeyValue::new("key1", "value1")]);
1335-
counter.add(1, &[KeyValue::new("key1", "value1")]);
1336-
counter.add(1, &[KeyValue::new("key1", "value1")]);
1336+
counter.add(10, &[KeyValue::new("key1", "value1")]);
1337+
counter.add(-1, &[KeyValue::new("key1", "value1")]);
1338+
counter.add(-5, &[KeyValue::new("key1", "value1")]);
1339+
counter.add(0, &[KeyValue::new("key1", "value1")]);
13371340
counter.add(1, &[KeyValue::new("key1", "value1")]);
13381341

1339-
counter.add(1, &[KeyValue::new("key1", "value2")]);
1340-
counter.add(1, &[KeyValue::new("key1", "value2")]);
1341-
counter.add(1, &[KeyValue::new("key1", "value2")]);
1342+
counter.add(10, &[KeyValue::new("key1", "value2")]);
1343+
counter.add(0, &[KeyValue::new("key1", "value2")]);
1344+
counter.add(-3, &[KeyValue::new("key1", "value2")]);
13421345

13431346
test_context.flush_metrics();
13441347

@@ -1367,19 +1370,19 @@ mod tests {
13671370

13681371
let data_point1 = find_datapoint_with_key_value(&sum.data_points, "key1", "value2")
13691372
.expect("datapoint with key1=value2 expected");
1370-
assert_eq!(data_point1.value, 3);
1373+
assert_eq!(data_point1.value, 7);
13711374

13721375
// Reset and report more measurements
13731376
test_context.reset_metrics();
1374-
counter.add(1, &[KeyValue::new("key1", "value1")]);
1375-
counter.add(1, &[KeyValue::new("key1", "value1")]);
1376-
counter.add(1, &[KeyValue::new("key1", "value1")]);
1377-
counter.add(1, &[KeyValue::new("key1", "value1")]);
1377+
counter.add(10, &[KeyValue::new("key1", "value1")]);
1378+
counter.add(-1, &[KeyValue::new("key1", "value1")]);
1379+
counter.add(-5, &[KeyValue::new("key1", "value1")]);
1380+
counter.add(0, &[KeyValue::new("key1", "value1")]);
13781381
counter.add(1, &[KeyValue::new("key1", "value1")]);
13791382

1380-
counter.add(1, &[KeyValue::new("key1", "value2")]);
1381-
counter.add(1, &[KeyValue::new("key1", "value2")]);
1382-
counter.add(1, &[KeyValue::new("key1", "value2")]);
1383+
counter.add(10, &[KeyValue::new("key1", "value2")]);
1384+
counter.add(0, &[KeyValue::new("key1", "value2")]);
1385+
counter.add(-3, &[KeyValue::new("key1", "value2")]);
13831386

13841387
test_context.flush_metrics();
13851388

@@ -1396,9 +1399,9 @@ mod tests {
13961399
let data_point1 = find_datapoint_with_key_value(&sum.data_points, "key1", "value2")
13971400
.expect("datapoint with key1=value2 expected");
13981401
if temporality == Temporality::Cumulative {
1399-
assert_eq!(data_point1.value, 6);
1402+
assert_eq!(data_point1.value, 14);
14001403
} else {
1401-
assert_eq!(data_point1.value, 3);
1404+
assert_eq!(data_point1.value, 7);
14021405
}
14031406
}
14041407

0 commit comments

Comments
 (0)