Search in sources :

Example 1 with PrometheusMetricsProvider

use of org.apache.pulsar.broker.stats.prometheus.metrics.PrometheusMetricsProvider in project incubator-pulsar by apache.

the class ManagedLedgerClientFactory method initialize.

public void initialize(ServiceConfiguration conf, MetadataStoreExtended metadataStore, BookKeeperClientFactory bookkeeperProvider, EventLoopGroup eventLoopGroup) throws Exception {
    ManagedLedgerFactoryConfig managedLedgerFactoryConfig = new ManagedLedgerFactoryConfig();
    managedLedgerFactoryConfig.setMaxCacheSize(conf.getManagedLedgerCacheSizeMB() * 1024L * 1024L);
    managedLedgerFactoryConfig.setCacheEvictionWatermark(conf.getManagedLedgerCacheEvictionWatermark());
    managedLedgerFactoryConfig.setNumManagedLedgerSchedulerThreads(conf.getManagedLedgerNumSchedulerThreads());
    managedLedgerFactoryConfig.setCacheEvictionFrequency(conf.getManagedLedgerCacheEvictionFrequency());
    managedLedgerFactoryConfig.setCacheEvictionTimeThresholdMillis(conf.getManagedLedgerCacheEvictionTimeThresholdMillis());
    managedLedgerFactoryConfig.setCopyEntriesInCache(conf.isManagedLedgerCacheCopyEntries());
    managedLedgerFactoryConfig.setPrometheusStatsLatencyRolloverSeconds(conf.getManagedLedgerPrometheusStatsLatencyRolloverSeconds());
    managedLedgerFactoryConfig.setTraceTaskExecution(conf.isManagedLedgerTraceTaskExecution());
    managedLedgerFactoryConfig.setCursorPositionFlushSeconds(conf.getManagedLedgerCursorPositionFlushSeconds());
    managedLedgerFactoryConfig.setManagedLedgerInfoCompressionType(conf.getManagedLedgerInfoCompressionType());
    managedLedgerFactoryConfig.setStatsPeriodSeconds(conf.getManagedLedgerStatsPeriodSeconds());
    managedLedgerFactoryConfig.setManagedCursorInfoCompressionType(conf.getManagedCursorInfoCompressionType());
    Configuration configuration = new ClientConfiguration();
    if (conf.isBookkeeperClientExposeStatsToPrometheus()) {
        configuration.addProperty(PrometheusMetricsProvider.PROMETHEUS_STATS_LATENCY_ROLLOVER_SECONDS, conf.getManagedLedgerPrometheusStatsLatencyRolloverSeconds());
        configuration.addProperty(PrometheusMetricsProvider.CLUSTER_NAME, conf.getClusterName());
        statsProvider = new PrometheusMetricsProvider();
    }
    statsProvider.start(configuration);
    StatsLogger statsLogger = statsProvider.getStatsLogger("pulsar_managedLedger_client");
    this.defaultBkClient = bookkeeperProvider.create(conf, metadataStore, eventLoopGroup, Optional.empty(), null);
    BookkeeperFactoryForCustomEnsemblePlacementPolicy bkFactory = (EnsemblePlacementPolicyConfig ensemblePlacementPolicyConfig) -> {
        BookKeeper bkClient = null;
        // find or create bk-client in cache for a specific ensemblePlacementPolicy
        if (ensemblePlacementPolicyConfig != null && ensemblePlacementPolicyConfig.getPolicyClass() != null) {
            bkClient = bkEnsemblePolicyToBkClientMap.computeIfAbsent(ensemblePlacementPolicyConfig, (key) -> {
                try {
                    return bookkeeperProvider.create(conf, metadataStore, eventLoopGroup, Optional.ofNullable(ensemblePlacementPolicyConfig.getPolicyClass()), ensemblePlacementPolicyConfig.getProperties());
                } catch (Exception e) {
                    log.error("Failed to initialize bk-client for policy {}, properties {}", ensemblePlacementPolicyConfig.getPolicyClass(), ensemblePlacementPolicyConfig.getProperties(), e);
                }
                return this.defaultBkClient;
            });
        }
        return bkClient != null ? bkClient : defaultBkClient;
    };
    this.managedLedgerFactory = new ManagedLedgerFactoryImpl(metadataStore, bkFactory, managedLedgerFactoryConfig, statsLogger);
}
Also used : StatsLogger(org.apache.bookkeeper.stats.StatsLogger) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Configuration(org.apache.commons.configuration.Configuration) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) BookkeeperFactoryForCustomEnsemblePlacementPolicy(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl.BookkeeperFactoryForCustomEnsemblePlacementPolicy) PrometheusMetricsProvider(org.apache.pulsar.broker.stats.prometheus.metrics.PrometheusMetricsProvider) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl)

Example 2 with PrometheusMetricsProvider

use of org.apache.pulsar.broker.stats.prometheus.metrics.PrometheusMetricsProvider in project pulsar by yahoo.

the class ManagedLedgerClientFactory method initialize.

public void initialize(ServiceConfiguration conf, MetadataStoreExtended metadataStore, BookKeeperClientFactory bookkeeperProvider, EventLoopGroup eventLoopGroup) throws Exception {
    ManagedLedgerFactoryConfig managedLedgerFactoryConfig = new ManagedLedgerFactoryConfig();
    managedLedgerFactoryConfig.setMaxCacheSize(conf.getManagedLedgerCacheSizeMB() * 1024L * 1024L);
    managedLedgerFactoryConfig.setCacheEvictionWatermark(conf.getManagedLedgerCacheEvictionWatermark());
    managedLedgerFactoryConfig.setNumManagedLedgerSchedulerThreads(conf.getManagedLedgerNumSchedulerThreads());
    managedLedgerFactoryConfig.setCacheEvictionFrequency(conf.getManagedLedgerCacheEvictionFrequency());
    managedLedgerFactoryConfig.setCacheEvictionTimeThresholdMillis(conf.getManagedLedgerCacheEvictionTimeThresholdMillis());
    managedLedgerFactoryConfig.setCopyEntriesInCache(conf.isManagedLedgerCacheCopyEntries());
    managedLedgerFactoryConfig.setPrometheusStatsLatencyRolloverSeconds(conf.getManagedLedgerPrometheusStatsLatencyRolloverSeconds());
    managedLedgerFactoryConfig.setTraceTaskExecution(conf.isManagedLedgerTraceTaskExecution());
    managedLedgerFactoryConfig.setCursorPositionFlushSeconds(conf.getManagedLedgerCursorPositionFlushSeconds());
    managedLedgerFactoryConfig.setManagedLedgerInfoCompressionType(conf.getManagedLedgerInfoCompressionType());
    managedLedgerFactoryConfig.setStatsPeriodSeconds(conf.getManagedLedgerStatsPeriodSeconds());
    managedLedgerFactoryConfig.setManagedCursorInfoCompressionType(conf.getManagedCursorInfoCompressionType());
    Configuration configuration = new ClientConfiguration();
    if (conf.isBookkeeperClientExposeStatsToPrometheus()) {
        configuration.addProperty(PrometheusMetricsProvider.PROMETHEUS_STATS_LATENCY_ROLLOVER_SECONDS, conf.getManagedLedgerPrometheusStatsLatencyRolloverSeconds());
        configuration.addProperty(PrometheusMetricsProvider.CLUSTER_NAME, conf.getClusterName());
        statsProvider = new PrometheusMetricsProvider();
    }
    statsProvider.start(configuration);
    StatsLogger statsLogger = statsProvider.getStatsLogger("pulsar_managedLedger_client");
    this.defaultBkClient = bookkeeperProvider.create(conf, metadataStore, eventLoopGroup, Optional.empty(), null);
    BookkeeperFactoryForCustomEnsemblePlacementPolicy bkFactory = (EnsemblePlacementPolicyConfig ensemblePlacementPolicyConfig) -> {
        BookKeeper bkClient = null;
        // find or create bk-client in cache for a specific ensemblePlacementPolicy
        if (ensemblePlacementPolicyConfig != null && ensemblePlacementPolicyConfig.getPolicyClass() != null) {
            bkClient = bkEnsemblePolicyToBkClientMap.computeIfAbsent(ensemblePlacementPolicyConfig, (key) -> {
                try {
                    return bookkeeperProvider.create(conf, metadataStore, eventLoopGroup, Optional.ofNullable(ensemblePlacementPolicyConfig.getPolicyClass()), ensemblePlacementPolicyConfig.getProperties());
                } catch (Exception e) {
                    log.error("Failed to initialize bk-client for policy {}, properties {}", ensemblePlacementPolicyConfig.getPolicyClass(), ensemblePlacementPolicyConfig.getProperties(), e);
                }
                return this.defaultBkClient;
            });
        }
        return bkClient != null ? bkClient : defaultBkClient;
    };
    this.managedLedgerFactory = new ManagedLedgerFactoryImpl(metadataStore, bkFactory, managedLedgerFactoryConfig, statsLogger);
}
Also used : StatsLogger(org.apache.bookkeeper.stats.StatsLogger) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Configuration(org.apache.commons.configuration.Configuration) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) BookkeeperFactoryForCustomEnsemblePlacementPolicy(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl.BookkeeperFactoryForCustomEnsemblePlacementPolicy) PrometheusMetricsProvider(org.apache.pulsar.broker.stats.prometheus.metrics.PrometheusMetricsProvider) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl)

Example 3 with PrometheusMetricsProvider

use of org.apache.pulsar.broker.stats.prometheus.metrics.PrometheusMetricsProvider in project pulsar by apache.

the class ManagedLedgerClientFactory method initialize.

public void initialize(ServiceConfiguration conf, MetadataStoreExtended metadataStore, BookKeeperClientFactory bookkeeperProvider, EventLoopGroup eventLoopGroup) throws Exception {
    ManagedLedgerFactoryConfig managedLedgerFactoryConfig = new ManagedLedgerFactoryConfig();
    managedLedgerFactoryConfig.setMaxCacheSize(conf.getManagedLedgerCacheSizeMB() * 1024L * 1024L);
    managedLedgerFactoryConfig.setCacheEvictionWatermark(conf.getManagedLedgerCacheEvictionWatermark());
    managedLedgerFactoryConfig.setNumManagedLedgerSchedulerThreads(conf.getManagedLedgerNumSchedulerThreads());
    managedLedgerFactoryConfig.setCacheEvictionFrequency(conf.getManagedLedgerCacheEvictionFrequency());
    managedLedgerFactoryConfig.setCacheEvictionTimeThresholdMillis(conf.getManagedLedgerCacheEvictionTimeThresholdMillis());
    managedLedgerFactoryConfig.setCopyEntriesInCache(conf.isManagedLedgerCacheCopyEntries());
    managedLedgerFactoryConfig.setPrometheusStatsLatencyRolloverSeconds(conf.getManagedLedgerPrometheusStatsLatencyRolloverSeconds());
    managedLedgerFactoryConfig.setTraceTaskExecution(conf.isManagedLedgerTraceTaskExecution());
    managedLedgerFactoryConfig.setCursorPositionFlushSeconds(conf.getManagedLedgerCursorPositionFlushSeconds());
    managedLedgerFactoryConfig.setManagedLedgerInfoCompressionType(conf.getManagedLedgerInfoCompressionType());
    managedLedgerFactoryConfig.setStatsPeriodSeconds(conf.getManagedLedgerStatsPeriodSeconds());
    Configuration configuration = new ClientConfiguration();
    if (conf.isBookkeeperClientExposeStatsToPrometheus()) {
        configuration.addProperty(PrometheusMetricsProvider.PROMETHEUS_STATS_LATENCY_ROLLOVER_SECONDS, conf.getManagedLedgerPrometheusStatsLatencyRolloverSeconds());
        configuration.addProperty(PrometheusMetricsProvider.CLUSTER_NAME, conf.getClusterName());
        statsProvider = new PrometheusMetricsProvider();
    }
    statsProvider.start(configuration);
    StatsLogger statsLogger = statsProvider.getStatsLogger("pulsar_managedLedger_client");
    this.defaultBkClient = bookkeeperProvider.create(conf, metadataStore, eventLoopGroup, Optional.empty(), null);
    BookkeeperFactoryForCustomEnsemblePlacementPolicy bkFactory = (EnsemblePlacementPolicyConfig ensemblePlacementPolicyConfig) -> {
        BookKeeper bkClient = null;
        // find or create bk-client in cache for a specific ensemblePlacementPolicy
        if (ensemblePlacementPolicyConfig != null && ensemblePlacementPolicyConfig.getPolicyClass() != null) {
            bkClient = bkEnsemblePolicyToBkClientMap.computeIfAbsent(ensemblePlacementPolicyConfig, (key) -> {
                try {
                    return bookkeeperProvider.create(conf, metadataStore, eventLoopGroup, Optional.ofNullable(ensemblePlacementPolicyConfig.getPolicyClass()), ensemblePlacementPolicyConfig.getProperties());
                } catch (Exception e) {
                    log.error("Failed to initialize bk-client for policy {}, properties {}", ensemblePlacementPolicyConfig.getPolicyClass(), ensemblePlacementPolicyConfig.getProperties(), e);
                }
                return this.defaultBkClient;
            });
        }
        return bkClient != null ? bkClient : defaultBkClient;
    };
    this.managedLedgerFactory = new ManagedLedgerFactoryImpl(metadataStore, bkFactory, managedLedgerFactoryConfig, statsLogger);
}
Also used : StatsLogger(org.apache.bookkeeper.stats.StatsLogger) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Configuration(org.apache.commons.configuration.Configuration) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) BookkeeperFactoryForCustomEnsemblePlacementPolicy(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl.BookkeeperFactoryForCustomEnsemblePlacementPolicy) PrometheusMetricsProvider(org.apache.pulsar.broker.stats.prometheus.metrics.PrometheusMetricsProvider) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl)

Aggregations

IOException (java.io.IOException)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 BookKeeper (org.apache.bookkeeper.client.BookKeeper)3 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)3 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)3 ManagedLedgerFactoryImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl)3 BookkeeperFactoryForCustomEnsemblePlacementPolicy (org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl.BookkeeperFactoryForCustomEnsemblePlacementPolicy)3 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)3 Configuration (org.apache.commons.configuration.Configuration)3 PrometheusMetricsProvider (org.apache.pulsar.broker.stats.prometheus.metrics.PrometheusMetricsProvider)3 EnsemblePlacementPolicyConfig (org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig)3