Search in sources :

Example 1 with StatsProvider

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

the class Main method main.

public static void main(String[] args) {
    StatsProvider statsProvider = null;
    try {
        // 0. Initialize metrics provider
        MetricsProvider.initialize(Config.METRICS_CONFIG);
        statsProvider = MetricsProvider.getMetricsProvider();
        statsProvider.start();
        ZKClientConfig zkClientConfig = ZKClientConfigImpl.builder().connectionString(Config.ZK_URL).secureConnectionToZooKeeper(Config.SECURE_ZK).trustStorePath(Config.ZK_TRUSTSTORE_FILE_PATH).trustStorePasswordPath(Config.ZK_TRUSTSTORE_PASSWORD_FILE_PATH).namespace("pravega/" + Config.CLUSTER_NAME).initialSleepInterval(Config.ZK_RETRY_SLEEP_MS).maxRetries(Config.ZK_MAX_RETRIES).sessionTimeoutMs(Config.ZK_SESSION_TIMEOUT_MS).build();
        StoreClientConfig storeClientConfig;
        if (Config.USE_PRAVEGA_TABLES) {
            storeClientConfig = StoreClientConfigImpl.withPravegaTablesClient(zkClientConfig);
        } else {
            storeClientConfig = StoreClientConfigImpl.withZKClient(zkClientConfig);
        }
        HostMonitorConfig hostMonitorConfig = HostMonitorConfigImpl.builder().hostMonitorEnabled(Config.HOST_MONITOR_ENABLED).hostMonitorMinRebalanceInterval(Config.CLUSTER_MIN_REBALANCE_INTERVAL).containerCount(Config.HOST_STORE_CONTAINER_COUNT).hostContainerMap(HostMonitorConfigImpl.getHostContainerMap(Config.SERVICE_HOST, Config.SERVICE_PORT, Config.HOST_STORE_CONTAINER_COUNT)).build();
        TimeoutServiceConfig timeoutServiceConfig = TimeoutServiceConfig.builder().maxLeaseValue(Config.MAX_LEASE_VALUE).build();
        ControllerEventProcessorConfig eventProcessorConfig = ControllerEventProcessorConfigImpl.withDefault();
        GRPCServerConfig grpcServerConfig = Config.GRPC_SERVER_CONFIG;
        RESTServerConfig restServerConfig = RESTServerConfigImpl.builder().host(Config.REST_SERVER_IP).port(Config.REST_SERVER_PORT).tlsEnabled(Config.TLS_ENABLED).tlsProtocolVersion(Config.TLS_PROTOCOL_VERSION.toArray(new String[Config.TLS_PROTOCOL_VERSION.size()])).keyFilePath(Config.REST_KEYSTORE_FILE_PATH).keyFilePasswordPath(Config.REST_KEYSTORE_PASSWORD_FILE_PATH).build();
        ControllerServiceConfig serviceConfig = ControllerServiceConfigImpl.builder().threadPoolSize(Config.ASYNC_TASK_POOL_SIZE).storeClientConfig(storeClientConfig).hostMonitorConfig(hostMonitorConfig).controllerClusterListenerEnabled(true).timeoutServiceConfig(timeoutServiceConfig).eventProcessorConfig(Optional.of(eventProcessorConfig)).grpcServerConfig(Optional.of(grpcServerConfig)).restServerConfig(Optional.of(restServerConfig)).tlsEnabledForSegmentStore(Config.TLS_ENABLED_FOR_SEGMENT_STORE).build();
        setUncaughtExceptionHandler(Main::logUncaughtException);
        ControllerServiceMain controllerServiceMain = new ControllerServiceMain(serviceConfig);
        controllerServiceMain.startAsync();
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            onShutdown(controllerServiceMain);
        }));
        controllerServiceMain.awaitTerminated();
        log.info("Controller service exited");
        System.exit(0);
    } catch (Throwable e) {
        log.error("Controller service failed", e);
        System.exit(-1);
    } finally {
        if (statsProvider != null) {
            statsProvider.close();
        }
    }
}
Also used : ControllerEventProcessorConfig(io.pravega.controller.server.eventProcessor.ControllerEventProcessorConfig) GRPCServerConfig(io.pravega.controller.server.rpc.grpc.GRPCServerConfig) HostMonitorConfig(io.pravega.controller.store.host.HostMonitorConfig) RESTServerConfig(io.pravega.shared.rest.RESTServerConfig) TimeoutServiceConfig(io.pravega.controller.timeout.TimeoutServiceConfig) ZKClientConfig(io.pravega.controller.store.client.ZKClientConfig) StatsProvider(io.pravega.shared.metrics.StatsProvider) StoreClientConfig(io.pravega.controller.store.client.StoreClientConfig)

Example 2 with StatsProvider

use of io.pravega.shared.metrics.StatsProvider 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 3 with StatsProvider

use of io.pravega.shared.metrics.StatsProvider 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)

Example 4 with StatsProvider

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

the class SegmentStoreAdapter method shutDown.

@Override
protected void shutDown() {
    this.serviceBuilder.close();
    stopBookKeeper();
    val zk = this.zkClient;
    if (zk != null) {
        zk.close();
        this.zkClient = null;
    }
    StatsProvider sp = this.statsProvider;
    if (sp != null) {
        sp.close();
        this.statsProvider = null;
    }
    SingletonStorageFactory storageFactory = this.storageFactory.getAndSet(null);
    if (storageFactory != null) {
        storageFactory.close();
    }
    Runtime.getRuntime().removeShutdownHook(this.stopBookKeeperProcess);
}
Also used : lombok.val(lombok.val) StatsProvider(io.pravega.shared.metrics.StatsProvider)

Example 5 with StatsProvider

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

the class FileSystemStorageTest method setUp.

@Before
public void setUp() throws Exception {
    this.baseDir = Files.createTempDirectory("test_nfs").toFile().getAbsoluteFile();
    MetricsConfig metricsConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).build();
    MetricsProvider.initialize(metricsConfig);
    StatsProvider statsProvider = MetricsProvider.getMetricsProvider();
    statsProvider.startWithoutExporting();
    this.adapterConfig = FileSystemStorageConfig.builder().with(FileSystemStorageConfig.ROOT, this.baseDir.getAbsolutePath()).with(FileSystemStorageConfig.REPLACE_ENABLED, true).build();
}
Also used : StatsProvider(io.pravega.shared.metrics.StatsProvider) MetricsConfig(io.pravega.shared.metrics.MetricsConfig) Before(org.junit.Before)

Aggregations

StatsProvider (io.pravega.shared.metrics.StatsProvider)7 MetricsConfig (io.pravega.shared.metrics.MetricsConfig)5 Cleanup (lombok.Cleanup)3 Test (org.junit.Test)3 StoreClientConfig (io.pravega.controller.store.client.StoreClientConfig)2 HostMonitorConfig (io.pravega.controller.store.host.HostMonitorConfig)2 TimeoutServiceConfig (io.pravega.controller.timeout.TimeoutServiceConfig)2 Counter (io.pravega.shared.metrics.Counter)2 MetricsProvider (io.pravega.shared.metrics.MetricsProvider)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 lombok.val (lombok.val)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Before (org.junit.Before)2