Skip to content

Commit c8ba093

Browse files
authored
Sync instrument stress test (#7986)
1 parent fd0ffde commit c8ba093

12 files changed

Lines changed: 650 additions & 1047 deletions

sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleCounterTest.java

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
2222
import io.opentelemetry.sdk.testing.time.TestClock;
2323
import java.time.Duration;
24-
import java.util.stream.IntStream;
2524
import org.junit.jupiter.api.Test;
2625
import org.junit.jupiter.api.extension.RegisterExtension;
2726

@@ -174,96 +173,4 @@ void doubleCounterAdd_NaN() {
174173
doubleCounter.add(Double.NaN);
175174
assertThat(sdkMeterReader.collectAllMetrics()).hasSize(0);
176175
}
177-
178-
@Test
179-
void stressTest() {
180-
DoubleCounter doubleCounter = sdkMeter.counterBuilder("testCounter").ofDoubles().build();
181-
182-
StressTestRunner.Builder stressTestBuilder =
183-
StressTestRunner.builder().setCollectionIntervalMs(100);
184-
185-
for (int i = 0; i < 4; i++) {
186-
stressTestBuilder.addOperation(
187-
StressTestRunner.Operation.create(
188-
1_000, 1, () -> doubleCounter.add(10, Attributes.builder().put("K", "V").build())));
189-
}
190-
191-
stressTestBuilder.build().run();
192-
assertThat(sdkMeterReader.collectAllMetrics())
193-
.satisfiesExactly(
194-
metric ->
195-
assertThat(metric)
196-
.hasResource(RESOURCE)
197-
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
198-
.hasName("testCounter")
199-
.hasDoubleSumSatisfying(
200-
sum ->
201-
sum.isCumulative()
202-
.isMonotonic()
203-
.hasPointsSatisfying(
204-
point ->
205-
point
206-
.hasStartEpochNanos(testClock.now())
207-
.hasEpochNanos(testClock.now())
208-
.hasValue(40000)
209-
.hasAttributes(attributeEntry("K", "V")))));
210-
}
211-
212-
@Test
213-
void stressTest_WithDifferentLabelSet() {
214-
String[] keys = {"Key_1", "Key_2", "Key_3", "Key_4"};
215-
String[] values = {"Value_1", "Value_2", "Value_3", "Value_4"};
216-
DoubleCounter doubleCounter = sdkMeter.counterBuilder("testCounter").ofDoubles().build();
217-
218-
StressTestRunner.Builder stressTestBuilder =
219-
StressTestRunner.builder().setCollectionIntervalMs(100);
220-
221-
IntStream.range(0, 4)
222-
.forEach(
223-
i ->
224-
stressTestBuilder.addOperation(
225-
StressTestRunner.Operation.create(
226-
2_000,
227-
1,
228-
() ->
229-
doubleCounter.add(
230-
10, Attributes.builder().put(keys[i], values[i]).build()))));
231-
232-
stressTestBuilder.build().run();
233-
assertThat(sdkMeterReader.collectAllMetrics())
234-
.satisfiesExactly(
235-
metric ->
236-
assertThat(metric)
237-
.hasResource(RESOURCE)
238-
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
239-
.hasDoubleSumSatisfying(
240-
sum ->
241-
sum.isCumulative()
242-
.isMonotonic()
243-
.hasPointsSatisfying(
244-
point ->
245-
point
246-
.hasStartEpochNanos(testClock.now())
247-
.hasEpochNanos(testClock.now())
248-
.hasValue(20_000)
249-
.hasAttributes(attributeEntry(keys[0], values[0])),
250-
point ->
251-
point
252-
.hasStartEpochNanos(testClock.now())
253-
.hasEpochNanos(testClock.now())
254-
.hasValue(20_000)
255-
.hasAttributes(attributeEntry(keys[1], values[1])),
256-
point ->
257-
point
258-
.hasStartEpochNanos(testClock.now())
259-
.hasEpochNanos(testClock.now())
260-
.hasValue(20_000)
261-
.hasAttributes(attributeEntry(keys[2], values[2])),
262-
point ->
263-
point
264-
.hasStartEpochNanos(testClock.now())
265-
.hasEpochNanos(testClock.now())
266-
.hasValue(20_000)
267-
.hasAttributes(attributeEntry(keys[3], values[3])))));
268-
}
269176
}

sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleGaugeTest.java

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import io.opentelemetry.sdk.trace.SdkTracerProvider;
2828
import java.time.Duration;
2929
import java.util.Collections;
30-
import java.util.stream.IntStream;
3130
import org.junit.jupiter.api.Test;
3231

3332
/** Unit tests for {@link SdkDoubleGauge}. */
@@ -271,98 +270,4 @@ void collectMetrics_WithMultipleCollects() {
271270
.hasValue(222d)
272271
.hasAttributes(attributeEntry("K", "V")))));
273272
}
274-
275-
@Test
276-
void stressTest() {
277-
DoubleGauge doubleGauge = sdkMeter.gaugeBuilder("testGauge").build();
278-
279-
StressTestRunner.Builder stressTestBuilder =
280-
StressTestRunner.builder().setCollectionIntervalMs(100);
281-
282-
for (int i = 0; i < 4; i++) {
283-
stressTestBuilder.addOperation(
284-
StressTestRunner.Operation.create(
285-
1_000,
286-
1,
287-
() -> {
288-
doubleGauge.set(10, Attributes.builder().put("K", "V").build());
289-
doubleGauge.set(11, Attributes.builder().put("K", "V").build());
290-
}));
291-
}
292-
293-
stressTestBuilder.build().run();
294-
assertThat(cumulativeReader.collectAllMetrics())
295-
.satisfiesExactly(
296-
metric ->
297-
assertThat(metric)
298-
.hasResource(RESOURCE)
299-
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
300-
.hasName("testGauge")
301-
.hasDoubleGaugeSatisfying(
302-
gauge ->
303-
gauge.hasPointsSatisfying(
304-
point ->
305-
point
306-
.hasStartEpochNanos(testClock.now())
307-
.hasEpochNanos(testClock.now())
308-
.hasValue(11)
309-
.hasAttributes(attributeEntry("K", "V")))));
310-
}
311-
312-
@Test
313-
void stressTest_WithDifferentLabelSet() {
314-
String[] keys = {"Key_1", "Key_2", "Key_3", "Key_4"};
315-
String[] values = {"Value_1", "Value_2", "Value_3", "Value_4"};
316-
DoubleGauge doubleGauge = sdkMeter.gaugeBuilder("testGauge").build();
317-
318-
StressTestRunner.Builder stressTestBuilder =
319-
StressTestRunner.builder().setCollectionIntervalMs(100);
320-
321-
IntStream.range(0, 4)
322-
.forEach(
323-
i ->
324-
stressTestBuilder.addOperation(
325-
StressTestRunner.Operation.create(
326-
2_000,
327-
1,
328-
() -> {
329-
doubleGauge.set(10, Attributes.builder().put(keys[i], values[i]).build());
330-
doubleGauge.set(11, Attributes.builder().put(keys[i], values[i]).build());
331-
})));
332-
333-
stressTestBuilder.build().run();
334-
assertThat(cumulativeReader.collectAllMetrics())
335-
.satisfiesExactly(
336-
metric ->
337-
assertThat(metric)
338-
.hasResource(RESOURCE)
339-
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
340-
.hasDoubleGaugeSatisfying(
341-
gauge ->
342-
gauge.hasPointsSatisfying(
343-
point ->
344-
point
345-
.hasStartEpochNanos(testClock.now())
346-
.hasEpochNanos(testClock.now())
347-
.hasValue(11)
348-
.hasAttributes(attributeEntry(keys[0], values[0])),
349-
point ->
350-
point
351-
.hasStartEpochNanos(testClock.now())
352-
.hasEpochNanos(testClock.now())
353-
.hasValue(11)
354-
.hasAttributes(attributeEntry(keys[1], values[1])),
355-
point ->
356-
point
357-
.hasStartEpochNanos(testClock.now())
358-
.hasEpochNanos(testClock.now())
359-
.hasValue(11)
360-
.hasAttributes(attributeEntry(keys[2], values[2])),
361-
point ->
362-
point
363-
.hasStartEpochNanos(testClock.now())
364-
.hasEpochNanos(testClock.now())
365-
.hasValue(11)
366-
.hasAttributes(attributeEntry(keys[3], values[3])))));
367-
}
368273
}

sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogramTest.java

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.time.Duration;
2828
import java.util.Arrays;
2929
import java.util.Collections;
30-
import java.util.stream.IntStream;
3130
import org.junit.jupiter.api.Test;
3231
import org.junit.jupiter.api.extension.RegisterExtension;
3332

@@ -369,108 +368,4 @@ void collectMetrics_ExemplarsWithExplicitBucketHistogram() {
369368
.put("key", "value")
370369
.build())))));
371370
}
372-
373-
@Test
374-
void stressTest() {
375-
DoubleHistogram doubleHistogram = sdkMeter.histogramBuilder("testHistogram").build();
376-
377-
StressTestRunner.Builder stressTestBuilder =
378-
StressTestRunner.builder().setCollectionIntervalMs(100);
379-
380-
for (int i = 0; i < 4; i++) {
381-
stressTestBuilder.addOperation(
382-
StressTestRunner.Operation.create(
383-
1_000,
384-
1,
385-
() -> doubleHistogram.record(10, Attributes.builder().put("K", "V").build())));
386-
}
387-
388-
stressTestBuilder.build().run();
389-
assertThat(sdkMeterReader.collectAllMetrics())
390-
.satisfiesExactly(
391-
metric ->
392-
assertThat(metric)
393-
.hasResource(RESOURCE)
394-
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
395-
.hasName("testHistogram")
396-
.hasHistogramSatisfying(
397-
histogram ->
398-
histogram.hasPointsSatisfying(
399-
point ->
400-
point
401-
.hasStartEpochNanos(testClock.now())
402-
.hasEpochNanos(testClock.now())
403-
.hasAttributes(attributeEntry("K", "V"))
404-
.hasCount(4_000)
405-
.hasSum(40_000))));
406-
}
407-
408-
@Test
409-
void stressTest_WithDifferentLabelSet() {
410-
String[] keys = {"Key_1", "Key_2", "Key_3", "Key_4"};
411-
String[] values = {"Value_1", "Value_2", "Value_3", "Value_4"};
412-
DoubleHistogram doubleHistogram = sdkMeter.histogramBuilder("testHistogram").build();
413-
414-
StressTestRunner.Builder stressTestBuilder =
415-
StressTestRunner.builder().setCollectionIntervalMs(100);
416-
417-
IntStream.range(0, 4)
418-
.forEach(
419-
i ->
420-
stressTestBuilder.addOperation(
421-
StressTestRunner.Operation.create(
422-
2_000,
423-
1,
424-
() ->
425-
doubleHistogram.record(
426-
10, Attributes.builder().put(keys[i], values[i]).build()))));
427-
428-
stressTestBuilder.build().run();
429-
assertThat(sdkMeterReader.collectAllMetrics())
430-
.satisfiesExactly(
431-
metric ->
432-
assertThat(metric)
433-
.hasResource(RESOURCE)
434-
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
435-
.hasName("testHistogram")
436-
.hasHistogramSatisfying(
437-
histogram ->
438-
histogram.hasPointsSatisfying(
439-
point ->
440-
point
441-
.hasStartEpochNanos(testClock.now())
442-
.hasEpochNanos(testClock.now())
443-
.hasCount(2_000)
444-
.hasSum(20_000)
445-
.hasBucketCounts(
446-
0, 0, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
447-
.hasAttributes(attributeEntry(keys[0], values[0])),
448-
point ->
449-
point
450-
.hasStartEpochNanos(testClock.now())
451-
.hasEpochNanos(testClock.now())
452-
.hasCount(2_000)
453-
.hasSum(20_000)
454-
.hasBucketCounts(
455-
0, 0, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
456-
.hasAttributes(attributeEntry(keys[1], values[1])),
457-
point ->
458-
point
459-
.hasStartEpochNanos(testClock.now())
460-
.hasEpochNanos(testClock.now())
461-
.hasCount(2_000)
462-
.hasSum(20_000)
463-
.hasBucketCounts(
464-
0, 0, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
465-
.hasAttributes(attributeEntry(keys[2], values[2])),
466-
point ->
467-
point
468-
.hasStartEpochNanos(testClock.now())
469-
.hasEpochNanos(testClock.now())
470-
.hasCount(2_000)
471-
.hasSum(20_000)
472-
.hasBucketCounts(
473-
0, 0, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
474-
.hasAttributes(attributeEntry(keys[3], values[3])))));
475-
}
476371
}

0 commit comments

Comments
 (0)