io.micrometer.core.instrument.search.MeterNotFoundException Java Examples

The following examples show how to use io.micrometer.core.instrument.search.MeterNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimedAspectTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void timeMethodFailure() {
    MeterRegistry failingRegistry = new FailingMeterRegistry();
    
    AspectJProxyFactory pf = new AspectJProxyFactory(new TimedService());
    pf.addAspect(new TimedAspect(failingRegistry));
    
    TimedService service = pf.getProxy();
    
    service.call();
    
    assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> {
        failingRegistry.get("call")
                .tag("class", "io.micrometer.core.aop.TimedAspectTest$TimedService")
                .tag("method", "call")
                .tag("extra", "tag")
                .timer();
    });
}
 
Example #2
Source File: TimedAspectTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void timeMethodFailureWithLongTaskTimer() {
    MeterRegistry failingRegistry = new FailingMeterRegistry();

    AspectJProxyFactory pf = new AspectJProxyFactory(new TimedService());
    pf.addAspect(new TimedAspect(failingRegistry));

    TimedService service = pf.getProxy();

    service.longCall();

    assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> {
        failingRegistry.get("longCall")
                .tag("class", "io.micrometer.core.aop.TimedAspectTest$TimedService")
                .tag("method", "longCall")
                .tag("extra", "tag")
                .longTaskTimer();
    });
}
 
Example #3
Source File: TimedAspectTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void timeMethodFailureWhenCompletedExceptionally() {
    MeterRegistry failingRegistry = new FailingMeterRegistry();

    AspectJProxyFactory pf = new AspectJProxyFactory(new AsyncTimedService());
    pf.addAspect(new TimedAspect(failingRegistry));

    AsyncTimedService service = pf.getProxy();

    GuardedResult guardedResult = new GuardedResult();
    CompletableFuture<?> completableFuture = service.call(guardedResult);
    guardedResult.complete();
    completableFuture.join();

    assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> failingRegistry.get("call")
            .tag("class", "io.micrometer.core.aop.TimedAspectTest$AsyncTimedService")
            .tag("method", "call")
            .tag("extra", "tag")
            .tag("exception", "none")
            .timer());
}
 
Example #4
Source File: TimedAspectTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void timeMethodFailureWithLongTaskTimerWhenCompleted() {
    MeterRegistry failingRegistry = new FailingMeterRegistry();

    AspectJProxyFactory pf = new AspectJProxyFactory(new AsyncTimedService());
    pf.addAspect(new TimedAspect(failingRegistry));

    AsyncTimedService service = pf.getProxy();

    GuardedResult guardedResult = new GuardedResult();
    CompletableFuture<?> completableFuture = service.longCall(guardedResult);
    guardedResult.complete();
    completableFuture.join();

    assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> {
        failingRegistry.get("longCall")
                .tag("class", "io.micrometer.core.aop.TimedAspectTest$AsyncTimedService")
                .tag("method", "longCall")
                .tag("extra", "tag")
                .longTaskTimer();
    });
}
 
Example #5
Source File: SpanMetricsCustomizerTest.java    From brave with Apache License 2.0 6 votes vote down vote up
@Test public void onlyRecordsSpansMatchingSpanName() {
  tracing.tracer().nextSpan().name("foo").start().finish();
  tracing.tracer().nextSpan().name("bar").start().finish();
  tracing.tracer().nextSpan().name("foo").start().finish();

  assertThat(registry.get("span")
    .tags("name", "foo", "exception", "None").timer().count())
    .isEqualTo(2L);

  try {
    registry.get("span").tags("name", "bar", "exception", "None").timer();

    failBecauseExceptionWasNotThrown(MeterNotFoundException.class);
  } catch (MeterNotFoundException expected) {
  }
}
 
Example #6
Source File: MicrometerHttpRequestExecutorTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void uriIsReadFromHttpHeader(@WiremockResolver.Wiremock WireMockServer server) throws IOException {
    server.stubFor(any(anyUrl()));
    HttpClient client = client(executor(false));
    HttpGet getWithHeader = new HttpGet(server.baseUrl());
    getWithHeader.addHeader(DefaultUriMapper.URI_PATTERN_HEADER, "/some/pattern");
    EntityUtils.consume(client.execute(getWithHeader).getEntity());
    assertThat(registry.get(EXPECTED_METER_NAME)
            .tags("uri", "/some/pattern")
            .timer().count()).isEqualTo(1L);
    assertThrows(MeterNotFoundException.class, () -> registry.get(EXPECTED_METER_NAME)
            .tags("uri", "UNKNOWN")
            .timer());
}
 
Example #7
Source File: OkHttpConnectionPoolMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void maxIfNotGiven() {
    OkHttpConnectionPoolMetrics instance = new OkHttpConnectionPoolMetrics(connectionPool, "huge.pool", Tags.of("foo", "bar"), null);
    instance.bindTo(registry);
    assertThrows(MeterNotFoundException.class, () -> registry.get("huge.pool.connection.limit")
            .tags(Tags.of("foo", "bar"))
            .gauge());
}
 
Example #8
Source File: CountedAspectTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void countedWithoutSuccessfulMetrics() {
    countedService.succeedWithoutMetrics();

    assertThatThrownBy(() -> meterRegistry.get("metric.none").counter())
            .isInstanceOf(MeterNotFoundException.class);
}
 
Example #9
Source File: CountedAspectTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void countedWithoutSuccessfulMetricsWhenCompleted() {
    GuardedResult guardedResult = new GuardedResult();
    CompletableFuture<?> completableFuture = asyncCountedService.succeedWithoutMetrics(guardedResult);
    guardedResult.complete();
    completableFuture.join();

    assertThatThrownBy(() -> meterRegistry.get("metric.none").counter())
            .isInstanceOf(MeterNotFoundException.class);
}
 
Example #10
Source File: MicrometerRegistry.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Override public Meter get(Id id) {
  try {
    return impl.get(id.name())
        .tags(convert(id.tags()))
        .meters()
        .stream()
        .filter(m -> id.equals(convert(m.getId())))
        .map(this::convert)
        .filter(Objects::nonNull)
        .findFirst()
        .orElse(null);
  } catch (MeterNotFoundException e) {
    return null;
  }
}