Search in sources :

Example 1 with Counter

use of io.pravega.shared.metrics.Counter in project pravega by pravega.

the class ControllerPrometheusTest method testPrometheusMetrics.

@Test
public void testPrometheusMetrics() throws Exception {
    MetricsProvider.initialize(MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_PROMETHEUS, true).with(MetricsConfig.METRICS_PREFIX, "promtestcontroller").build());
    @Cleanup StatsProvider statsProvider = MetricsProvider.getMetricsProvider();
    statsProvider.start();
    @Cleanup ControllerServiceStarter starter = new ControllerServiceStarter(createControllerServiceConfig(), storeClient, null);
    starter.startAsync();
    starter.awaitRunning();
    Counter c = statsProvider.createStatsLogger("promtest").createCounter("promtestcounter");
    c.add(1);
    HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
    HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://localhost:" + this.restPort + "/prometheus")).build();
    HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
    assertTrue(response.body().lines().anyMatch(x -> Pattern.matches("promtestcounter.*1\\.0", x)));
    starter.stopAsync();
    starter.awaitTerminated();
}
Also used : HttpRequest(java.net.http.HttpRequest) StoreClientConfig(io.pravega.controller.store.client.StoreClientConfig) RunWith(org.junit.runner.RunWith) Cleanup(lombok.Cleanup) GRPCServerConfigImpl(io.pravega.controller.server.rpc.grpc.impl.GRPCServerConfigImpl) StoreClient(io.pravega.controller.store.client.StoreClient) TimeoutServiceConfig(io.pravega.controller.timeout.TimeoutServiceConfig) HttpRequest(java.net.http.HttpRequest) RESTServerConfigImpl(io.pravega.shared.rest.impl.RESTServerConfigImpl) ControllerServiceConfigImpl(io.pravega.controller.server.impl.ControllerServiceConfigImpl) StoreClientConfigImpl(io.pravega.controller.store.client.impl.StoreClientConfigImpl) HostMonitorConfig(io.pravega.controller.store.host.HostMonitorConfig) Duration(java.time.Duration) Timeout(org.junit.rules.Timeout) HttpClient(java.net.http.HttpClient) URI(java.net.URI) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) HttpResponse(java.net.http.HttpResponse) StoreClientFactory(io.pravega.controller.store.client.StoreClientFactory) SerializedClassRunner(io.pravega.test.common.SerializedClassRunner) Assert.assertTrue(org.junit.Assert.assertTrue) StatsProvider(io.pravega.shared.metrics.StatsProvider) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) MetricsProvider(io.pravega.shared.metrics.MetricsProvider) Slf4j(lombok.extern.slf4j.Slf4j) Rule(org.junit.Rule) Config(io.pravega.controller.util.Config) Counter(io.pravega.shared.metrics.Counter) MetricsConfig(io.pravega.shared.metrics.MetricsConfig) Optional(java.util.Optional) TestUtils(io.pravega.test.common.TestUtils) Pattern(java.util.regex.Pattern) Counter(io.pravega.shared.metrics.Counter) StatsProvider(io.pravega.shared.metrics.StatsProvider) HttpClient(java.net.http.HttpClient) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 2 with Counter

use of io.pravega.shared.metrics.Counter in project pravega by pravega.

the class PrometheusTest method testPrometheusMetrics.

@Test
public void testPrometheusMetrics() throws Exception {
    @Cleanup StatsProvider statsProvider = MetricsProvider.getMetricsProvider();
    statsProvider.start();
    Counter c = statsProvider.createStatsLogger("promtest").createCounter("promtestcounter");
    c.add(1);
    HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
    HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://localhost:" + this.restPort + "/prometheus")).build();
    HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
    assertTrue(response.body().lines().anyMatch(x -> Pattern.matches("promtestcounter.*1\\.0", x)));
}
Also used : HttpRequest(java.net.http.HttpRequest) SerializedClassRunner(io.pravega.test.common.SerializedClassRunner) RunWith(org.junit.runner.RunWith) ServiceConfig(io.pravega.segmentstore.server.store.ServiceConfig) Cleanup(lombok.Cleanup) Assert.assertTrue(org.junit.Assert.assertTrue) StatsProvider(io.pravega.shared.metrics.StatsProvider) Test(org.junit.Test) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) HttpRequest(java.net.http.HttpRequest) MetricsProvider(io.pravega.shared.metrics.MetricsProvider) Counter(io.pravega.shared.metrics.Counter) TestingServerStarter(io.pravega.test.common.TestingServerStarter) After(org.junit.After) Duration(java.time.Duration) TestingServer(org.apache.curator.test.TestingServer) MetricsConfig(io.pravega.shared.metrics.MetricsConfig) HttpClient(java.net.http.HttpClient) TestUtils(io.pravega.test.common.TestUtils) URI(java.net.URI) Pattern(java.util.regex.Pattern) Before(org.junit.Before) HttpResponse(java.net.http.HttpResponse) Counter(io.pravega.shared.metrics.Counter) StatsProvider(io.pravega.shared.metrics.StatsProvider) HttpClient(java.net.http.HttpClient) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Aggregations

Counter (io.pravega.shared.metrics.Counter)2 MetricsConfig (io.pravega.shared.metrics.MetricsConfig)2 MetricsProvider (io.pravega.shared.metrics.MetricsProvider)2 StatsProvider (io.pravega.shared.metrics.StatsProvider)2 SerializedClassRunner (io.pravega.test.common.SerializedClassRunner)2 TestUtils (io.pravega.test.common.TestUtils)2 URI (java.net.URI)2 HttpClient (java.net.http.HttpClient)2 HttpRequest (java.net.http.HttpRequest)2 HttpResponse (java.net.http.HttpResponse)2 Duration (java.time.Duration)2 Pattern (java.util.regex.Pattern)2 Cleanup (lombok.Cleanup)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 ControllerServiceConfigImpl (io.pravega.controller.server.impl.ControllerServiceConfigImpl)1 GRPCServerConfigImpl (io.pravega.controller.server.rpc.grpc.impl.GRPCServerConfigImpl)1 StoreClient (io.pravega.controller.store.client.StoreClient)1 StoreClientConfig (io.pravega.controller.store.client.StoreClientConfig)1