Search in sources :

Example 31 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project tritium by palantir.

the class InstrumentedSslContextTest method testServerInstrumentationHttp2.

@Test
void testServerInstrumentationHttp2() throws Exception {
    assumeThat(IS_JAVA_8).describedAs("Java 8 does not support ALPN without additional help").isFalse();
    TaggedMetricRegistry metrics = new DefaultTaggedMetricRegistry();
    OkHttpClient client = new OkHttpClient.Builder().retryOnConnectionFailure(false).sslSocketFactory(newClientContext().getSocketFactory(), newTrustManager()).build();
    try (Closeable ignored = server(MetricRegistries.instrument(metrics, newServerContext(), "h2-server"));
        Response response = client.newCall(new Request.Builder().url("https://localhost:" + PORT).get().build()).execute()) {
        assertThat(response.code()).isEqualTo(200);
        // If http/2 does not work on java 9+ we have not properly implemented java 9 ALPN components properly
        assertThat(response.protocol()).isEqualTo(Protocol.HTTP_2);
    }
    MetricName name = findName(metrics, MetricName.builder().safeName("tls.handshake").putSafeTags("context", "h2-server").putSafeTags("cipher", ENABLED_CIPHER).putSafeTags("protocol", ENABLED_PROTOCOL).build());
    assertThat(metrics.getMetrics()).containsOnlyKeys(name);
    assertThat(metrics.meter(name).getCount()).isOne();
}
Also used : Response(okhttp3.Response) MetricName(com.palantir.tritium.metrics.registry.MetricName) OkHttpClient(okhttp3.OkHttpClient) Closeable(java.io.Closeable) Request(okhttp3.Request) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) Test(org.junit.jupiter.api.Test)

Example 32 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project tritium by palantir.

the class CaffeineCacheStatsTest method registerCacheWithoutRecordingStatsTagged.

@Test
void registerCacheWithoutRecordingStatsTagged() {
    Cache<Integer, String> cache = Caffeine.newBuilder().build();
    CaffeineCacheStats.registerCache(taggedMetricRegistry, cache, "test");
    MetricName disabledMetricName = MetricName.builder().safeName("cache.stats.disabled").putSafeTags("cache", "test").build();
    assertThat(taggedMetricRegistry.getMetrics()).hasSize(1).containsOnlyKeys(disabledMetricName).extractingByKey(disabledMetricName).isInstanceOf(Counter.class).asInstanceOf(type(Counter.class)).extracting(Counter::getCount).isEqualTo(1L);
}
Also used : MetricName(com.palantir.tritium.metrics.registry.MetricName) Counter(com.codahale.metrics.Counter) Test(org.junit.jupiter.api.Test)

Example 33 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project tritium by palantir.

the class InstrumentedSslContextTest method testClientInstrumentationOkHttp.

@Test
void testClientInstrumentationOkHttp() throws Exception {
    TaggedMetricRegistry metrics = new DefaultTaggedMetricRegistry();
    SSLSocketFactory socketFactory = MetricRegistries.instrument(metrics, newClientContext().getSocketFactory(), "okhttp-client");
    OkHttpClient client = new OkHttpClient.Builder().retryOnConnectionFailure(false).sslSocketFactory(socketFactory, newTrustManager()).protocols(Collections.singletonList(Protocol.HTTP_1_1)).build();
    try (Closeable ignored = server(newServerContext());
        Response response = client.newCall(new Request.Builder().url("https://localhost:" + PORT).get().build()).execute()) {
        assertThat(response.code()).isEqualTo(200);
        assertThat(response.protocol()).isEqualTo(Protocol.HTTP_1_1);
    }
    MetricName name = findName(metrics, MetricName.builder().safeName("tls.handshake").putSafeTags("context", "okhttp-client").putSafeTags("cipher", ENABLED_CIPHER).putSafeTags("protocol", ENABLED_PROTOCOL).build());
    assertThat(metrics.getMetrics()).containsOnlyKeys(name);
    assertThat(metrics.meter(name).getCount()).isOne();
}
Also used : Response(okhttp3.Response) MetricName(com.palantir.tritium.metrics.registry.MetricName) OkHttpClient(okhttp3.OkHttpClient) Closeable(java.io.Closeable) Request(okhttp3.Request) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Test(org.junit.jupiter.api.Test)

Example 34 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project tritium by palantir.

the class InstrumentedSslContextTest method testClientInstrumentationOkHttpHttp2.

@Test
void testClientInstrumentationOkHttpHttp2() throws Exception {
    TaggedMetricRegistry metrics = new DefaultTaggedMetricRegistry();
    SSLSocketFactory socketFactory = MetricRegistries.instrument(metrics, newClientContext().getSocketFactory(), "okhttp-client");
    OkHttpClient client = new OkHttpClient.Builder().retryOnConnectionFailure(false).sslSocketFactory(socketFactory, newTrustManager()).build();
    try (Closeable ignored = server(newServerContext());
        Response response = client.newCall(new Request.Builder().url("https://localhost:" + PORT).get().build()).execute()) {
        assertThat(response.code()).isEqualTo(200);
        // If http/2 does not work on java 9+ we have not properly implemented java 9 ALPN components properly
        assertThat(response.protocol()).isEqualTo(Protocol.HTTP_2);
    }
    MetricName name = findName(metrics, MetricName.builder().safeName("tls.handshake").putSafeTags("context", "okhttp-client").putSafeTags("cipher", ENABLED_CIPHER).putSafeTags("protocol", ENABLED_PROTOCOL).build());
    assertThat(metrics.getMetrics()).containsOnlyKeys(name);
    assertThat(metrics.meter(name).getCount()).isOne();
}
Also used : Response(okhttp3.Response) MetricName(com.palantir.tritium.metrics.registry.MetricName) OkHttpClient(okhttp3.OkHttpClient) Closeable(java.io.Closeable) Request(okhttp3.Request) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Test(org.junit.jupiter.api.Test)

Example 35 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project tritium by palantir.

the class MetricRegistriesTest method testGarbageCollectionMetrics.

@Test
void testGarbageCollectionMetrics() {
    TaggedMetricRegistry registry = new DefaultTaggedMetricRegistry();
    MetricRegistries.registerGarbageCollection(registry);
    assertThat(registry.getMetrics().keySet()).filteredOn(metricName -> metricName.safeName().startsWith("jvm.gc.time") || metricName.safeName().startsWith("jvm.gc.count")).allSatisfy(metricName -> assertThat(metricName.safeTags()).containsOnlyKeys("collector", "libraryName", "libraryVersion"));
    assertThat(registry.getMetrics().keySet()).filteredOn(metricName -> metricName.safeName().equals("jvm.gc.finalizer.queue.size")).hasSize(1).allSatisfy(metricName -> assertThat(metricName.safeTags()).containsOnlyKeys("libraryName", "libraryVersion"));
}
Also used : Histogram(com.codahale.metrics.Histogram) LoadingCache(com.google.common.cache.LoadingCache) MetricName(com.palantir.tritium.metrics.registry.MetricName) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) HdrHistogramReservoir(org.mpierce.metrics.reservoir.hdrhistogram.HdrHistogramReservoir) MetricSet(com.codahale.metrics.MetricSet) Awaitility.waitAtMost(org.awaitility.Awaitility.waitAtMost) Meter(com.codahale.metrics.Meter) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Duration(java.time.Duration) Counter(com.codahale.metrics.Counter) MetricFilter(com.codahale.metrics.MetricFilter) ZoneOffset(java.time.ZoneOffset) Nonnull(javax.annotation.Nonnull) Awaitility.await(org.awaitility.Awaitility.await) MetricRegistry(com.codahale.metrics.MetricRegistry) ImmutableMap(com.google.common.collect.ImmutableMap) Metric(com.codahale.metrics.Metric) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) Snapshot(com.codahale.metrics.Snapshot) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) CacheLoader(com.google.common.cache.CacheLoader) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) DateTimeFormatter(java.time.format.DateTimeFormatter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) Timer(com.codahale.metrics.Timer) Gauge(com.codahale.metrics.Gauge) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) SortedMap(java.util.SortedMap) Mockito.mock(org.mockito.Mockito.mock) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

MetricName (com.palantir.tritium.metrics.registry.MetricName)37 TaggedMetricRegistry (com.palantir.tritium.metrics.registry.TaggedMetricRegistry)11 Test (org.junit.jupiter.api.Test)10 Metric (com.codahale.metrics.Metric)9 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)9 Timer (com.codahale.metrics.Timer)7 Counter (com.codahale.metrics.Counter)6 Histogram (com.codahale.metrics.Histogram)6 Meter (com.codahale.metrics.Meter)6 Test (org.junit.Test)6 Gauge (com.codahale.metrics.Gauge)5 Closeable (java.io.Closeable)5 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 ConsoleReporter (com.codahale.metrics.ConsoleReporter)3 MetricSet (com.codahale.metrics.MetricSet)3 OkHttpClient (okhttp3.OkHttpClient)3 Request (okhttp3.Request)3 Response (okhttp3.Response)3 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2