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