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();
}
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);
}
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();
}
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();
}
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"));
}
Aggregations