Search in sources :

Example 1 with AutoScaleMonitor

use of io.pravega.segmentstore.server.host.stat.AutoScaleMonitor in project pravega by pravega.

the class ServiceStarter method start.

// endregion
// region Service Operation
public void start() throws Exception {
    Exceptions.checkNotClosed(this.closed, this);
    healthServiceManager = new HealthServiceManager(serviceConfig.getHealthCheckInterval());
    healthServiceManager.start();
    log.info("Initializing HealthService ...");
    MetricsConfig metricsConfig = builderConfig.getConfig(MetricsConfig::builder);
    if (metricsConfig.isEnableStatistics()) {
        log.info("Initializing metrics provider ...");
        MetricsProvider.initialize(metricsConfig);
        statsProvider = MetricsProvider.getMetricsProvider();
        statsProvider.start();
    }
    log.info("Initializing ZooKeeper Client ...");
    this.zkClient = createZKClient();
    log.info("Initializing Service Builder ...");
    this.serviceBuilder.initialize();
    log.info("Creating StreamSegmentService ...");
    StreamSegmentStore service = this.serviceBuilder.createStreamSegmentService();
    log.info("Creating TableStoreService ...");
    TableStore tableStoreService = this.serviceBuilder.createTableStoreService();
    log.info("Creating Segment Stats recorder ...");
    autoScaleMonitor = new AutoScaleMonitor(service, builderConfig.getConfig(AutoScalerConfig::builder));
    AutoScalerConfig autoScalerConfig = builderConfig.getConfig(AutoScalerConfig::builder);
    TokenVerifierImpl tokenVerifier = null;
    if (autoScalerConfig.isAuthEnabled()) {
        tokenVerifier = new TokenVerifierImpl(autoScalerConfig.getTokenSigningKey());
    }
    // Log the configuration
    log.info(serviceConfig.toString());
    log.info(autoScalerConfig.toString());
    this.listener = new PravegaConnectionListener(this.serviceConfig.isEnableTls(), this.serviceConfig.isEnableTlsReload(), this.serviceConfig.getListeningIPAddress(), this.serviceConfig.getListeningPort(), service, tableStoreService, autoScaleMonitor.getStatsRecorder(), autoScaleMonitor.getTableSegmentStatsRecorder(), tokenVerifier, this.serviceConfig.getCertFile(), this.serviceConfig.getKeyFile(), this.serviceConfig.isReplyWithStackTraceOnError(), serviceBuilder.getLowPriorityExecutor(), this.serviceConfig.getTlsProtocolVersion(), healthServiceManager);
    this.listener.startListening();
    log.info("PravegaConnectionListener started successfully.");
    if (serviceConfig.isEnableAdminGateway()) {
        this.adminListener = new AdminConnectionListener(this.serviceConfig.isEnableTls(), this.serviceConfig.isEnableTlsReload(), this.serviceConfig.getListeningIPAddress(), this.serviceConfig.getAdminGatewayPort(), service, tableStoreService, tokenVerifier, this.serviceConfig.getCertFile(), this.serviceConfig.getKeyFile(), this.serviceConfig.getTlsProtocolVersion(), healthServiceManager);
        this.adminListener.startListening();
        log.info("AdminConnectionListener started successfully.");
    }
    log.info("StreamSegmentService started.");
    healthServiceManager.register(new ZKHealthContributor(zkClient));
    healthServiceManager.register(new CacheManagerHealthContributor(serviceBuilder.getCacheManager()));
    healthServiceManager.register(new SegmentContainerRegistryHealthContributor(serviceBuilder.getSegmentContainerRegistry()));
    if (this.serviceConfig.isRestServerEnabled()) {
        log.info("Initializing RESTServer ...");
        List<Object> resources = new ArrayList<>();
        resources.add(new HealthImpl(new AuthHandlerManager(serviceConfig.getRestServerConfig()), healthServiceManager.getEndpoint()));
        MetricsProvider.getMetricsProvider().prometheusResource().ifPresent(resources::add);
        restServer = new RESTServer(serviceConfig.getRestServerConfig(), Set.copyOf(resources));
        restServer.startAsync();
        restServer.awaitRunning();
    }
}
Also used : HealthServiceManager(io.pravega.shared.health.HealthServiceManager) AutoScaleMonitor(io.pravega.segmentstore.server.host.stat.AutoScaleMonitor) AdminConnectionListener(io.pravega.segmentstore.server.host.handler.AdminConnectionListener) AutoScalerConfig(io.pravega.segmentstore.server.host.stat.AutoScalerConfig) ArrayList(java.util.ArrayList) ZKHealthContributor(io.pravega.segmentstore.server.host.health.ZKHealthContributor) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MetricsConfig(io.pravega.shared.metrics.MetricsConfig) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) HealthImpl(io.pravega.shared.health.bindings.resources.HealthImpl) SegmentContainerRegistryHealthContributor(io.pravega.segmentstore.server.host.health.SegmentContainerRegistryHealthContributor) AuthHandlerManager(io.pravega.shared.rest.security.AuthHandlerManager) CacheManagerHealthContributor(io.pravega.segmentstore.server.CacheManager.CacheManagerHealthContributor) TokenVerifierImpl(io.pravega.segmentstore.server.host.delegationtoken.TokenVerifierImpl) RESTServer(io.pravega.shared.rest.RESTServer)

Example 2 with AutoScaleMonitor

use of io.pravega.segmentstore.server.host.stat.AutoScaleMonitor in project pravega by pravega.

the class InProcessMockClientAdapter method startUp.

// endregion
// region ClientAdapterBase Implementation
@Override
protected void startUp() throws Exception {
    int segmentStorePort = this.testConfig.getSegmentStorePort(0);
    val store = getStreamSegmentStore();
    this.autoScaleMonitor = new AutoScaleMonitor(store, AutoScalerConfig.builder().build());
    this.listener = new PravegaConnectionListener(false, false, "localhost", segmentStorePort, store, getTableStore(), autoScaleMonitor.getStatsRecorder(), TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), null, null, false, NoOpScheduledExecutor.get(), SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
    this.listener.startListening();
    this.streamManager = new MockStreamManager(SCOPE, LISTENING_ADDRESS, segmentStorePort);
    this.streamManager.createScope(SCOPE);
    this.kvtManager = new MockKVTManager(this.streamManager);
    super.startUp();
}
Also used : lombok.val(lombok.val) AutoScaleMonitor(io.pravega.segmentstore.server.host.stat.AutoScaleMonitor) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)

Example 3 with AutoScaleMonitor

use of io.pravega.segmentstore.server.host.stat.AutoScaleMonitor in project pravega by pravega.

the class EndToEndAutoScaleUpWithTxnTest method main.

public static void main(String[] args) throws Exception {
    try {
        @Cleanup TestingServer zkTestServer = new TestingServerStarter().start();
        int port = Config.SERVICE_PORT;
        @Cleanup ControllerWrapper controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), port);
        Controller controller = controllerWrapper.getController();
        controllerWrapper.getControllerService().createScope(NameUtils.INTERNAL_SCOPE_NAME, 0L).get();
        @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
        @Cleanup ClientFactoryImpl internalCF = new ClientFactoryImpl(NameUtils.INTERNAL_SCOPE_NAME, controller, connectionFactory);
        @Cleanup("shutdownNow") val executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
        @Cleanup ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
        serviceBuilder.initialize();
        StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
        TableStore tableStore = serviceBuilder.createTableStoreService();
        @Cleanup AutoScaleMonitor autoScaleMonitor = new AutoScaleMonitor(store, internalCF, AutoScalerConfig.builder().with(AutoScalerConfig.MUTE_IN_SECONDS, 0).with(AutoScalerConfig.COOLDOWN_IN_SECONDS, 0).build());
        @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, false, "localhost", 12345, store, tableStore, autoScaleMonitor.getStatsRecorder(), autoScaleMonitor.getTableSegmentStatsRecorder(), null, null, null, true, serviceBuilder.getLowPriorityExecutor(), Config.TLS_PROTOCOL_VERSION.toArray(new String[Config.TLS_PROTOCOL_VERSION.size()]));
        server.startListening();
        controllerWrapper.awaitRunning();
        controllerWrapper.getControllerService().createScope("test", 0L).get();
        controller.createStream("test", "test", CONFIG).get();
        @Cleanup MockClientFactory clientFactory = new MockClientFactory("test", controller, internalCF.getConnectionPool());
        // Mocking pravega service by putting scale up and scale down requests for the stream
        EventWriterConfig writerConfig = EventWriterConfig.builder().transactionTimeoutTime(30000).build();
        TransactionalEventStreamWriter<String> test = clientFactory.createTransactionalEventWriter("writer", "test", new UTF8StringSerializer(), writerConfig);
        // region Successful commit tests
        Transaction<String> txn1 = test.beginTxn();
        txn1.writeEvent("1");
        txn1.flush();
        Map<Double, Double> map = new HashMap<>();
        map.put(0.0, 1.0 / 3.0);
        map.put(1.0 / 3.0, 2.0 / 3.0);
        map.put(2.0 / 3.0, 1.0);
        Stream stream = new StreamImpl("test", "test");
        controller.startScale(stream, Collections.singletonList(0L), map).get();
        Transaction<String> txn2 = test.beginTxn();
        txn2.writeEvent("2");
        txn2.flush();
        txn2.commit();
        txn1.commit();
        Thread.sleep(1000);
        @Cleanup ReaderGroupManager readerGroupManager = new ReaderGroupManagerImpl("test", controller, clientFactory);
        readerGroupManager.createReaderGroup("readergrp", ReaderGroupConfig.builder().stream("test/test").build());
        final EventStreamReader<String> reader = clientFactory.createReader("1", "readergrp", new JavaSerializer<>(), ReaderConfig.builder().build());
        String event1 = reader.readNextEvent(SECONDS.toMillis(60)).getEvent();
        String event2 = reader.readNextEvent(SECONDS.toMillis(60)).getEvent();
        assert event1.equals("1");
        assert event2.equals("2");
        final AtomicBoolean done = new AtomicBoolean(false);
        startWriter(test, done);
        Retry.withExpBackoff(10, 10, 100, 10000).retryingOn(NotDoneException.class).throwingOn(RuntimeException.class).runAsync(() -> controller.getCurrentSegments("test", "test").thenAccept(streamSegments -> {
            if (streamSegments.getSegments().stream().anyMatch(x -> NameUtils.getEpoch(x.getSegmentId()) > 5)) {
                System.err.println("Success");
                log.info("Success");
                System.exit(0);
            } else {
                throw new NotDoneException();
            }
        }), executor).exceptionally(e -> {
            System.err.println("Failure");
            log.error("Failure");
            System.exit(1);
            return null;
        }).get();
    } catch (Throwable e) {
        System.err.print("Test failed with exception: " + e.getMessage());
        log.error("Test failed with exception: {}", e);
        System.exit(-1);
    }
    System.exit(0);
}
Also used : ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Retry(io.pravega.common.util.Retry) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) AutoScaleMonitor(io.pravega.segmentstore.server.host.stat.AutoScaleMonitor) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Cleanup(lombok.Cleanup) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) TestingServerStarter(io.pravega.test.common.TestingServerStarter) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) TestingServer(org.apache.curator.test.TestingServer) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) Transaction(io.pravega.client.stream.Transaction) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) TransactionalEventStreamWriter(io.pravega.client.stream.TransactionalEventStreamWriter) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) AutoScalerConfig(io.pravega.segmentstore.server.host.stat.AutoScalerConfig) NameUtils(io.pravega.shared.NameUtils) lombok.val(lombok.val) EventStreamReader(io.pravega.client.stream.EventStreamReader) Slf4j(lombok.extern.slf4j.Slf4j) Config(io.pravega.controller.util.Config) ReaderConfig(io.pravega.client.stream.ReaderConfig) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Collections(java.util.Collections) Controller(io.pravega.client.control.impl.Controller) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) UTF8StringSerializer(io.pravega.client.stream.impl.UTF8StringSerializer) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ClientConfig(io.pravega.client.ClientConfig) AutoScaleMonitor(io.pravega.segmentstore.server.host.stat.AutoScaleMonitor) HashMap(java.util.HashMap) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) Stream(io.pravega.client.stream.Stream) UTF8StringSerializer(io.pravega.client.stream.impl.UTF8StringSerializer) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) TestingServer(org.apache.curator.test.TestingServer) lombok.val(lombok.val) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) TestingServerStarter(io.pravega.test.common.TestingServerStarter) Controller(io.pravega.client.control.impl.Controller) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) StreamImpl(io.pravega.client.stream.impl.StreamImpl)

Example 4 with AutoScaleMonitor

use of io.pravega.segmentstore.server.host.stat.AutoScaleMonitor in project pravega by pravega.

the class MetricsTest method setup.

@Before
public void setup() throws Exception {
    final int controllerPort = TestUtils.getAvailableListenPort();
    final String serviceHost = "localhost";
    final int servicePort = TestUtils.getAvailableListenPort();
    final int containerCount = 4;
    // 1. Start Metrics service
    log.info("Initializing metrics provider ...");
    MetricsConfig metricsConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_STATSD_REPORTER, false).build();
    metricsConfig.setDynamicCacheEvictionDuration(Duration.ofSeconds(2));
    MetricsProvider.initialize(metricsConfig);
    statsProvider = MetricsProvider.getMetricsProvider();
    statsProvider.startWithoutExporting();
    log.info("Metrics Stats provider is started");
    // 2. Start ZK
    this.zkTestServer = new TestingServerStarter().start();
    // 3. Start Pravega SegmentStore service.
    serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    monitor = new AutoScaleMonitor(store, AutoScalerConfig.builder().build());
    TableStore tableStore = serviceBuilder.createTableStoreService();
    this.server = new PravegaConnectionListener(false, false, "localhost", servicePort, store, tableStore, monitor.getStatsRecorder(), monitor.getTableSegmentStatsRecorder(), new PassingTokenVerifier(), null, null, true, this.serviceBuilder.getLowPriorityExecutor(), SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
    this.server.startListening();
    // 4. Start Pravega Controller service
    this.controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), false, controllerPort, serviceHost, servicePort, containerCount);
    this.controllerWrapper.awaitRunning();
    this.controller = controllerWrapper.getController();
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) AutoScaleMonitor(io.pravega.segmentstore.server.host.stat.AutoScaleMonitor) TestingServerStarter(io.pravega.test.common.TestingServerStarter) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MetricsConfig(io.pravega.shared.metrics.MetricsConfig) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) Before(org.junit.Before)

Example 5 with AutoScaleMonitor

use of io.pravega.segmentstore.server.host.stat.AutoScaleMonitor in project pravega by pravega.

the class StreamMetricsTest method setup.

@Before
public void setup() throws Exception {
    controllerPort = TestUtils.getAvailableListenPort();
    final String serviceHost = "localhost";
    final int servicePort = TestUtils.getAvailableListenPort();
    final int containerCount = 4;
    // 1. Start Metrics service
    log.info("Initializing metrics provider ...");
    MetricsConfig metricsConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_STATSD_REPORTER, false).build();
    metricsConfig.setDynamicCacheEvictionDuration(Duration.ofSeconds(60));
    MetricsProvider.initialize(metricsConfig);
    statsProvider = MetricsProvider.getMetricsProvider();
    statsProvider.startWithoutExporting();
    log.info("Metrics Stats provider is started");
    // 2. Start ZK
    this.zkTestServer = new TestingServerStarter().start();
    // 3. Start Pravega SegmentStore service.
    serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    monitor = new AutoScaleMonitor(store, AutoScalerConfig.builder().build());
    TableStore tableStore = serviceBuilder.createTableStoreService();
    this.server = new PravegaConnectionListener(false, false, "localhost", servicePort, store, tableStore, monitor.getStatsRecorder(), monitor.getTableSegmentStatsRecorder(), new PassingTokenVerifier(), null, null, true, this.serviceBuilder.getLowPriorityExecutor(), SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
    this.server.startListening();
    // 4. Start Pravega Controller service
    this.controllerWrapper = new ControllerWrapper(zkTestServer.getConnectString(), false, controllerPort, serviceHost, servicePort, containerCount);
    this.controllerWrapper.awaitRunning();
    this.controller = controllerWrapper.getController();
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) AutoScaleMonitor(io.pravega.segmentstore.server.host.stat.AutoScaleMonitor) TestingServerStarter(io.pravega.test.common.TestingServerStarter) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MetricsConfig(io.pravega.shared.metrics.MetricsConfig) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) Before(org.junit.Before)

Aggregations

AutoScaleMonitor (io.pravega.segmentstore.server.host.stat.AutoScaleMonitor)9 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)8 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)7 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)7 TestingServerStarter (io.pravega.test.common.TestingServerStarter)5 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)4 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)4 AutoScalerConfig (io.pravega.segmentstore.server.host.stat.AutoScalerConfig)4 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)4 ClientConfig (io.pravega.client.ClientConfig)3 Controller (io.pravega.client.control.impl.Controller)3 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)3 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)3 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)3 ExecutorServiceHelpers (io.pravega.common.concurrent.ExecutorServiceHelpers)3 Retry (io.pravega.common.util.Retry)3 Config (io.pravega.controller.util.Config)3 PassingTokenVerifier (io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier)3 ServiceBuilderConfig (io.pravega.segmentstore.server.store.ServiceBuilderConfig)3 NameUtils (io.pravega.shared.NameUtils)3