Search in sources :

Example 1 with RestMetricsClient

use of org.infinispan.client.rest.RestMetricsClient in project infinispan by infinispan.

the class RestMetricsResource method testTimerMetrics.

@Test
public void testTimerMetrics() throws Exception {
    RestClient client = SERVER_TEST.rest().create();
    RestMetricsClient metricsClient = client.metrics();
    // this is a histogram of write times
    String metricName = "cache_manager_default_cache_" + SERVER_TEST.getMethodName() + "_statistics_store_times";
    int NUM_PUTS = 10;
    try (RestResponse response = sync(metricsClient.metrics())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor", metricName);
        checkRule(body, "vendor_" + metricName, (stringValue) -> {
            double parsed = Double.parseDouble(stringValue);
            assertThat(parsed).isZero();
        });
    }
    // put some entries then check that the stats were updated
    RestCacheClient cache = client.cache(SERVER_TEST.getMethodName());
    for (int i = 0; i < NUM_PUTS; i++) {
        RestResponse putResp = sync(cache.put("k" + i, "v" + i));
        assertEquals(204, putResp.getStatus());
    }
    try (RestResponse response = sync(metricsClient.metrics())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor", metricName);
        checkRule(body, "vendor_" + metricName, (stringValue) -> {
            double parsed = Double.parseDouble(stringValue);
            assertThat(parsed).isPositive();
        });
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) RestMetricsClient(org.infinispan.client.rest.RestMetricsClient) Test(org.junit.Test)

Example 2 with RestMetricsClient

use of org.infinispan.client.rest.RestMetricsClient in project infinispan by infinispan.

the class RestMetricsResource method testBaseAndVendorMetrics.

@Test
public void testBaseAndVendorMetrics() throws Exception {
    RestMetricsClient metricsClient = SERVER_TEST.rest().create().metrics();
    try (RestResponse response = sync(metricsClient.metrics())) {
        assertEquals(200, response.getStatus());
        // that is the default
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        checkRule(body, "base_classloader_loadedClasses_count", (stringValue) -> {
            double parsed = Double.parseDouble(stringValue);
            assertThat(parsed).isPositive();
        });
        checkRule(body, "vendor_memoryPool_Metaspace_usage_bytes", (stringValue) -> {
            double parsed = Double.parseDouble(stringValue);
            assertThat(parsed).isPositive();
        });
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestMetricsClient(org.infinispan.client.rest.RestMetricsClient) Test(org.junit.Test)

Example 3 with RestMetricsClient

use of org.infinispan.client.rest.RestMetricsClient in project infinispan by infinispan.

the class RestMetricsResource method testMetrics.

@Test
public void testMetrics() throws Exception {
    RestClient client = SERVER_TEST.rest().create();
    RestMetricsClient metricsClient = client.metrics();
    String metricName = "cache_manager_default_cache_" + SERVER_TEST.getMethodName() + "_statistics_stores";
    int NUM_PUTS = 10;
    try (RestResponse response = sync(metricsClient.metrics())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor", metricName);
        checkRule(body, "vendor_" + metricName, (stringValue) -> {
            double parsed = Double.parseDouble(stringValue);
            assertThat(parsed).isZero();
        });
    }
    // put some entries then check that the stats were updated
    RestCacheClient cache = client.cache(SERVER_TEST.getMethodName());
    for (int i = 0; i < NUM_PUTS; i++) {
        RestResponse putResp = sync(cache.put("k" + i, "v" + i));
        assertEquals(204, putResp.getStatus());
    }
    try (RestResponse response = sync(metricsClient.metrics())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor", metricName);
        checkRule(body, "vendor_" + metricName, (stringValue) -> {
            double parsed = Double.parseDouble(stringValue);
            assertThat(parsed).isEqualTo(10.0);
        });
    }
    // delete cache and check that the metric is gone
    sync(client.cache(SERVER_TEST.getMethodName()).delete());
    try (RestResponse response = sync(metricsClient.metrics())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor");
        // metric is not present anymore:
        assertThat(body).doesNotContain(metricName);
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) RestMetricsClient(org.infinispan.client.rest.RestMetricsClient) Test(org.junit.Test)

Example 4 with RestMetricsClient

use of org.infinispan.client.rest.RestMetricsClient in project infinispan by infinispan.

the class RestMetricsResource method testOpenMetrics.

@Test
public void testOpenMetrics() {
    RestMetricsClient metricsClient = SERVER_TEST.rest().create().metrics();
    String metricName = "cache_manager_default_cache_" + SERVER_TEST.getMethodName() + "_statistics_stores";
    try (RestResponse response = sync(metricsClient.metrics(true))) {
        assertEquals(200, response.getStatus());
        checkIsOpenmetrics(response.contentType());
        String metricsText = response.getBody();
        assertTrue(metricsText.contains("# TYPE vendor_" + metricName + " gauge\n"));
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestMetricsClient(org.infinispan.client.rest.RestMetricsClient) Test(org.junit.Test)

Example 5 with RestMetricsClient

use of org.infinispan.client.rest.RestMetricsClient in project infinispan by infinispan.

the class RestMetricsResource method testMetricsMetadata.

@Test
public void testMetricsMetadata() throws Exception {
    RestClient client = SERVER_TEST.rest().create();
    RestMetricsClient metricsClient = client.metrics();
    String metricName = "cache_manager_default_cache_" + SERVER_TEST.getMethodName() + "_statistics_stores";
    try (RestResponse response = sync(metricsClient.metricsMetadata())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor", metricName);
        checkRule(body, "vendor_" + metricName, (stringValue) -> {
            double parsed = Double.parseDouble(stringValue);
            assertThat(parsed).isZero();
        });
    }
    // delete cache and check that the metric is gone
    sync(client.cache(SERVER_TEST.getMethodName()).delete());
    try (RestResponse response = sync(metricsClient.metricsMetadata())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor");
        // metric is not present anymore:
        assertThat(body).doesNotContain(metricName);
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) RestMetricsClient(org.infinispan.client.rest.RestMetricsClient) Test(org.junit.Test)

Aggregations

RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)6 RestResponse (org.infinispan.client.rest.RestResponse)6 Test (org.junit.Test)6 RestClient (org.infinispan.client.rest.RestClient)4 RestCacheClient (org.infinispan.client.rest.RestCacheClient)2 StringConfiguration (org.infinispan.commons.configuration.StringConfiguration)1