private long getCount(String tagKey, String tagValue) { return this.meterRegistry.get(REQUEST_METRICS_NAME).tag(tagKey, tagValue) .timer().count(); }
@Test public void onNextTimerCountsFuseable() { Flux<Integer> source = Flux.range(1, 123); new FluxMetricsFuseable<>(source, registry) .blockLast(); Timer nextMeter = registry .find(METER_ON_NEXT_DELAY) .timer(); assertThat(nextMeter).isNotNull(); assertThat(nextMeter.count()).isEqualTo(123L); Flux<Integer> source2 = Flux.range(1, 10); new FluxMetricsFuseable<>(source2, registry) .take(3) .blockLast(); assertThat(nextMeter.count()).isEqualTo(126L); Flux<Integer> source3 = Flux.range(1, 1000) .name("foo"); new FluxMetricsFuseable<>(source3, registry) .blockLast(); assertThat(nextMeter.count()) .as("notTakingNamedIntoAccount") .isEqualTo(126L); }
@Test public void splitMetricsOnNameFuseable() { final Mono<Integer> unnamedSource = Mono.just(0).map(v -> 100 / v); final Mono<Integer> namedSource = Mono.just(0).map(v -> 100 / v) .name("foo"); final Mono<Integer> unnamed = new MonoMetricsFuseable<>(unnamedSource, registry) .onErrorResume(e -> Mono.empty()); final Mono<Integer> named = new MonoMetricsFuseable<>(namedSource, registry) .onErrorResume(e -> Mono.empty()); Mono.when(unnamed, named).block(); Timer unnamedMeter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .tag(TAG_EXCEPTION, ArithmeticException.class.getName()) .tag(TAG_SEQUENCE_NAME, REACTOR_DEFAULT_NAME) .timer(); Timer namedMeter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .tag(TAG_EXCEPTION, ArithmeticException.class.getName()) .tag(TAG_SEQUENCE_NAME, "foo") .timer(); assertThat(unnamedMeter).isNotNull(); assertThat(unnamedMeter.count()).isOne(); assertThat(namedMeter).isNotNull(); assertThat(namedMeter.count()).isOne(); }
@Test public void onNextTimerCounts() { Flux<Integer> source = Flux.range(1, 123) .hide(); new FluxMetrics<>(source, registry) .blockLast(); Timer nextMeter = registry .find(METER_ON_NEXT_DELAY) .timer(); assertThat(nextMeter).isNotNull(); assertThat(nextMeter.count()).isEqualTo(123L); Flux<Integer> source2 = Flux.range(1, 10) .hide(); new FluxMetrics<>(source2, registry) .take(3) .blockLast(); assertThat(nextMeter.count()).isEqualTo(126L); Flux<Integer> source3 = Flux.range(1, 1000) .name("foo") .hide(); new FluxMetrics<>(source3, registry) .blockLast(); assertThat(nextMeter.count()) .as("notTakingNamedIntoAccount") .isEqualTo(126L); }
@Test public void splitMetricsOnNameFuseable() { final Flux<Integer> unnamedSource = Flux.just(0).map(v -> 100 / v); final Flux<Integer> namedSource = Flux.range(1, 40) .map(i -> 100 / (40 - i)) .name("foo"); final Flux<Integer> unnamed = new FluxMetricsFuseable<>(unnamedSource, registry) .onErrorResume(e -> Mono.empty()); final Flux<Integer> named = new FluxMetricsFuseable<>(namedSource, registry) .onErrorResume(e -> Mono.empty()); Mono.when(unnamed, named).block(); Timer unnamedMeter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .tag(TAG_SEQUENCE_NAME, REACTOR_DEFAULT_NAME) .timer(); Timer namedMeter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .tag(TAG_SEQUENCE_NAME, "foo") .timer(); assertThat(unnamedMeter).isNotNull(); assertThat(unnamedMeter.count()).isOne(); assertThat(namedMeter).isNotNull(); assertThat(namedMeter.count()).isOne(); }
@Test public void usesTagsFuseable() { Mono<Integer> source = Mono.just(8) .tag("tag1", "A") .name("usesTags") .tag("tag2", "foo"); new MonoMetricsFuseable<>(source, registry) .block(); Timer meter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_COMPLETE) .tag(TAG_SEQUENCE_NAME, "usesTags") .tag("tag1", "A") .tag("tag2", "foo") .timer(); assertThat(meter).isNotNull(); assertThat(meter.count()).isEqualTo(1L); }
@Test public void splitMetricsOnName() { final Mono<Integer> unnamedSource = Mono.<Integer>error(new ArithmeticException("boom")) .hide(); final Mono<Integer> unnamed = new MonoMetrics<>(unnamedSource, registry) .onErrorResume(e -> Mono.empty()); final Mono<Integer> namedSource = Mono.just(40) .name("foo") .map(i -> 100 / (40 - i)) .hide(); final Mono<Integer> named = new MonoMetrics<>(namedSource, registry) .onErrorResume(e -> Mono.empty()); Mono.when(unnamed, named).block(); Timer unnamedMeter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .tag(TAG_EXCEPTION, ArithmeticException.class.getName()) .tag(TAG_SEQUENCE_NAME, REACTOR_DEFAULT_NAME) .timer(); Timer namedMeter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .tag(TAG_EXCEPTION, ArithmeticException.class.getName()) .tag(TAG_SEQUENCE_NAME, "foo") .timer(); assertThat(unnamedMeter).isNotNull(); assertThat(namedMeter).isNotNull(); assertThat(unnamedMeter.count()).isOne(); assertThat(namedMeter.count()).isOne(); }
@Test public void splitMetricsOnName() { final Flux<Integer> unnamedSource = Flux.<Integer>error(new ArithmeticException("boom")) .hide(); final Flux<Integer> unnamed = new FluxMetrics<>(unnamedSource, registry) .onErrorResume(e -> Mono.empty()); final Flux<Integer> namedSource = Flux.range(1, 40) .name("foo") .map(i -> 100 / (40 - i)) .hide(); final Flux<Integer> named = new FluxMetrics<>(namedSource, registry) .onErrorResume(e -> Mono.empty()); Mono.when(unnamed, named).block(); Timer unnamedMeter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .tag(TAG_EXCEPTION, ArithmeticException.class.getName()) .tag(TAG_SEQUENCE_NAME, REACTOR_DEFAULT_NAME) .timer(); Timer namedMeter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .tag(TAG_EXCEPTION, ArithmeticException.class.getName()) .tag(TAG_SEQUENCE_NAME, "foo") .timer(); assertThat(unnamedMeter).isNotNull(); assertThat(namedMeter).isNotNull(); assertThat(unnamedMeter.count()).isOne(); assertThat(namedMeter.count()).isOne(); }
@Test public void usesTagsFuseable() { Flux<Integer> source = Flux.range(1, 8) .tag("tag1", "A") .name("usesTags") .tag("tag2", "foo"); new FluxMetricsFuseable<>(source, registry) .blockLast(); Timer meter = registry .find(METER_ON_NEXT_DELAY) .tag(TAG_SEQUENCE_NAME, "usesTags") .tag("tag1", "A") .tag("tag2", "foo") .timer(); assertThat(meter).isNotNull(); assertThat(meter.count()).isEqualTo(8L); }
@Test public void usesTags() { Mono<Integer> source = Mono.just(1) .tag("tag1", "A") .name("usesTags") .tag("tag2", "foo") .hide(); new MonoMetrics<>(source, registry) .block(); Timer meter = registry .find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_COMPLETE) .tag(TAG_SEQUENCE_NAME, "usesTags") .tag("tag1", "A") .tag("tag2", "foo") .timer(); assertThat(meter).isNotNull(); assertThat(meter.count()).isEqualTo(1L); }
@Test public void usesTags() { Flux<Integer> source = Flux.range(1, 8) .tag("tag1", "A") .name("usesTags") .tag("tag2", "foo") .hide(); new FluxMetrics<>(source, registry) .blockLast(); Timer meter = registry .find(METER_ON_NEXT_DELAY) .tag(TAG_SEQUENCE_NAME, "usesTags") .tag("tag1", "A") .tag("tag2", "foo") .timer(); assertThat(meter).isNotNull(); assertThat(meter.count()).isEqualTo(8L); }
@DisplayName("requestResponse gathers metrics") @Test void requestResponse() { Payload payload = DefaultPayload.create("test-metadata", "test-data"); when(delegate.requestResponse(payload)).thenReturn(Mono.empty()); new MicrometerRSocket(delegate, meterRegistry, Tag.of("test-key", "test-value")) .requestResponse(payload) .as(StepVerifier::create) .verifyComplete(); assertThat(findTimer("request.response", SignalType.ON_COMPLETE).count()).isEqualTo(1); }
.tag("name", "eipBean.handler") .tag("result", "success") .timer().count()).isEqualTo(1); .timer().count()).isEqualTo(1); .timer().count()).isEqualTo(1); .timer().count()).isEqualTo(1); .timer().count()).isEqualTo(1); .tag("name", "nullChannel") .tag("result", "success") .timer().count()).isEqualTo(1); .tag("name", "newChannel") .tag("result", "success") .timer().count()).isEqualTo(1);
.tag("name", "queue") .tag("result", "success") .timer().count()).isEqualTo(1);
private static JsonObject timerToJson(JsonObject obj, Timer timer) { return obj.put("type", "timer") .put("count", timer.count()) .put("totalTimeMs", timer.totalTime(TimeUnit.MILLISECONDS)) .put("meanMs", timer.mean(TimeUnit.MILLISECONDS)) .put("maxMs", timer.max(TimeUnit.MILLISECONDS)); }
Optional<String> writeTimer(Timer timer) { return Optional.of(writeDocument(timer, builder -> { builder.append(",\"count\":").append(timer.count()); builder.append(",\"sum\":").append(timer.totalTime(getBaseTimeUnit())); builder.append(",\"mean\":").append(timer.mean(getBaseTimeUnit())); builder.append(",\"max\":").append(timer.max(getBaseTimeUnit())); })); }
this.meterRegistry.find(METRIC_NAME_CLIENT_PROCESSING_DURATION).timer(); assertNotNull(clientTimer); assertEquals(1, clientTimer.count()); assertTrue(clientTimer.max(TimeUnit.SECONDS) < 1); .timer(); assertNotNull(serverTimer); assertEquals(1, serverTimer.count()); assertTrue(serverTimer.max(TimeUnit.SECONDS) < 1); assertEquals(2, clientTimer.count()); assertTrue(clientTimer.max(TimeUnit.SECONDS) < 1); assertEquals(2, serverTimer.count()); assertTrue(serverTimer.max(TimeUnit.SECONDS) < 1);
private Stream<String> writeTimer(Timer timer) { return Stream.of(event(timer.getId(), new Attribute("count", timer.count()), new Attribute("avg", timer.mean(getBaseTimeUnit())), new Attribute("totalTime", timer.totalTime(getBaseTimeUnit())), new Attribute("max", timer.max(getBaseTimeUnit())) )); }
@Test @DisplayName("record a runnable task") default void recordWithRunnable(MeterRegistry registry) { Timer t = registry.timer("myTimer"); try { t.record(() -> clock(registry).add(10, TimeUnit.NANOSECONDS)); clock(registry).add(step()); } finally { assertAll(() -> assertEquals(1L, t.count()), () -> assertEquals(10, t.totalTime(TimeUnit.NANOSECONDS), 1.0e-12)); } }