Search in sources :

Example 1 with NoopResourceLimitChecks

use of org.eclipse.hono.adapter.resourcelimits.NoopResourceLimitChecks in project hono by eclipse.

the class AbstractProtocolAdapterApplication method prometheusResourceLimitChecks.

/**
 * Creates resource limit checks based on data retrieved from a Prometheus server
 * via its HTTP API.
 *
 * @param config The configuration properties.
 * @param tenantClient The client to use for retrieving tenant configuration data.
 * @throws NullPointerException if any of the parameters are {@code null}-
 * @return The checks.
 */
protected ResourceLimitChecks prometheusResourceLimitChecks(final PrometheusBasedResourceLimitChecksConfig config, final TenantClient tenantClient) {
    Objects.requireNonNull(config);
    Objects.requireNonNull(tenantClient);
    if (config.isHostConfigured()) {
        final WebClientOptions webClientOptions = new WebClientOptions();
        webClientOptions.setConnectTimeout(config.getConnectTimeout());
        webClientOptions.setDefaultHost(config.getHost());
        webClientOptions.setDefaultPort(config.getPort());
        webClientOptions.setTrustOptions(config.getTrustOptions());
        webClientOptions.setKeyCertOptions(config.getKeyCertOptions());
        webClientOptions.setSsl(config.isTlsEnabled());
        final var webClient = WebClient.create(vertx, webClientOptions);
        final var cacheTimeout = Duration.ofSeconds(config.getCacheTimeout());
        final Caffeine<Object, Object> builder = Caffeine.newBuilder().executor(Executors.newSingleThreadExecutor(r -> {
            final var t = new Thread(r);
            t.setDaemon(true);
            return t;
        })).initialCapacity(config.getCacheMinSize()).maximumSize(config.getCacheMaxSize()).expireAfterWrite(cacheTimeout).refreshAfterWrite(cacheTimeout.dividedBy(2));
        return new PrometheusBasedResourceLimitChecks(builder.buildAsync(new ConnectedDevicesAsyncCacheLoader(webClient, config, tracer)), builder.buildAsync(new ConnectionDurationAsyncCacheLoader(webClient, config, tracer)), builder.buildAsync(new DataVolumeAsyncCacheLoader(webClient, config, tracer)), tenantClient, tracer);
    } else {
        return new NoopResourceLimitChecks();
    }
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) MessagingKafkaConsumerConfigProperties(org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties) MessagingKafkaProducerConfigProperties(org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties) ProtonBasedDeviceRegistrationClient(org.eclipse.hono.client.registry.amqp.ProtonBasedDeviceRegistrationClient) KafkaBasedEventSender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender) KafkaBasedCommandResponseSender(org.eclipse.hono.client.command.kafka.KafkaBasedCommandResponseSender) LoggerFactory(org.slf4j.LoggerFactory) LoggingConnectionEventProducer(org.eclipse.hono.adapter.monitoring.LoggingConnectionEventProducer) CommandRouterCommandConsumerFactory(org.eclipse.hono.client.command.CommandRouterCommandConsumerFactory) PrometheusBasedResourceLimitChecksConfig(org.eclipse.hono.adapter.resourcelimits.PrometheusBasedResourceLimitChecksConfig) KafkaAdminClientOptions(org.eclipse.hono.client.kafka.KafkaAdminClientOptions) NoopResourceLimitChecks(org.eclipse.hono.adapter.resourcelimits.NoopResourceLimitChecks) AbstractServiceApplication(org.eclipse.hono.service.quarkus.AbstractServiceApplication) TelemetrySender(org.eclipse.hono.client.telemetry.TelemetrySender) ProtonBasedInternalCommandConsumer(org.eclipse.hono.client.command.amqp.ProtonBasedInternalCommandConsumer) MessagingType(org.eclipse.hono.util.MessagingType) Duration(java.time.Duration) CredentialsClient(org.eclipse.hono.client.registry.CredentialsClient) RegistrationResult(org.eclipse.hono.util.RegistrationResult) DataVolumeAsyncCacheLoader(org.eclipse.hono.adapter.resourcelimits.DataVolumeAsyncCacheLoader) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) ProtonBasedCredentialsClient(org.eclipse.hono.client.registry.amqp.ProtonBasedCredentialsClient) KafkaConsumerOptions(org.eclipse.hono.client.kafka.consumer.KafkaConsumerOptions) NotificationConstants(org.eclipse.hono.notification.NotificationConstants) ConnectionEventProducerConfig(org.eclipse.hono.adapter.monitoring.ConnectionEventProducerConfig) MessagingClientProviders(org.eclipse.hono.adapter.MessagingClientProviders) EventSender(org.eclipse.hono.client.telemetry.EventSender) CredentialsResult(org.eclipse.hono.util.CredentialsResult) ProtonBasedNotificationReceiver(org.eclipse.hono.client.notification.amqp.ProtonBasedNotificationReceiver) CachingKafkaProducerFactory(org.eclipse.hono.client.kafka.producer.CachingKafkaProducerFactory) TenantClient(org.eclipse.hono.client.registry.TenantClient) Caches(org.eclipse.hono.service.cache.Caches) Future(io.vertx.core.Future) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) ConfigMapping(io.smallrye.config.ConfigMapping) List(java.util.List) KafkaProducerFactory(org.eclipse.hono.client.kafka.producer.KafkaProducerFactory) ConnectionDurationAsyncCacheLoader(org.eclipse.hono.adapter.resourcelimits.ConnectionDurationAsyncCacheLoader) Buffer(io.vertx.core.buffer.Buffer) CommandRouterClient(org.eclipse.hono.client.command.CommandRouterClient) Optional(java.util.Optional) MicrometerKafkaClientMetricsSupport(org.eclipse.hono.client.kafka.metrics.MicrometerKafkaClientMetricsSupport) ConnectionEventProducerOptions(org.eclipse.hono.adapter.monitoring.ConnectionEventProducerOptions) NotificationEventBusSupport(org.eclipse.hono.notification.NotificationEventBusSupport) KafkaBasedTelemetrySender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedTelemetrySender) WebClient(io.vertx.ext.web.client.WebClient) ProtonBasedCommandResponseSender(org.eclipse.hono.client.command.amqp.ProtonBasedCommandResponseSender) ProtonBasedTenantClient(org.eclipse.hono.client.registry.amqp.ProtonBasedTenantClient) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionEventProducer(org.eclipse.hono.adapter.monitoring.ConnectionEventProducer) ClientOptions(org.eclipse.hono.config.quarkus.ClientOptions) Cache(com.github.benmanes.caffeine.cache.Cache) CommandResponseSender(org.eclipse.hono.client.command.CommandResponseSender) Inject(javax.inject.Inject) CompositeFuture(io.vertx.core.CompositeFuture) CommonKafkaClientOptions(org.eclipse.hono.client.kafka.CommonKafkaClientOptions) KafkaClientMetricsSupport(org.eclipse.hono.client.kafka.metrics.KafkaClientMetricsSupport) KafkaBasedInternalCommandConsumer(org.eclipse.hono.client.command.kafka.KafkaBasedInternalCommandConsumer) KafkaMetricsOptions(org.eclipse.hono.client.kafka.metrics.KafkaMetricsOptions) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) PrometheusBasedResourceLimitCheckOptions(org.eclipse.hono.adapter.resourcelimits.PrometheusBasedResourceLimitCheckOptions) KafkaAdminClientConfigProperties(org.eclipse.hono.client.kafka.KafkaAdminClientConfigProperties) PrometheusBasedResourceLimitChecks(org.eclipse.hono.adapter.resourcelimits.PrometheusBasedResourceLimitChecks) WrappedLifecycleComponentVerticle(org.eclipse.hono.util.WrappedLifecycleComponentVerticle) HonoConnection(org.eclipse.hono.client.HonoConnection) ProtonBasedCommandRouterClient(org.eclipse.hono.client.command.amqp.ProtonBasedCommandRouterClient) RequestResponseClientConfigProperties(org.eclipse.hono.client.RequestResponseClientConfigProperties) NotificationReceiver(org.eclipse.hono.notification.NotificationReceiver) NotificationKafkaConsumerConfigProperties(org.eclipse.hono.client.notification.kafka.NotificationKafkaConsumerConfigProperties) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) TenantResult(org.eclipse.hono.util.TenantResult) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) AbstractProtocolAdapterBase(org.eclipse.hono.adapter.AbstractProtocolAdapterBase) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) KafkaBasedNotificationReceiver(org.eclipse.hono.client.notification.kafka.KafkaBasedNotificationReceiver) KafkaProducerOptions(org.eclipse.hono.client.kafka.producer.KafkaProducerOptions) RequestResponseClientOptions(org.eclipse.hono.client.RequestResponseClientOptions) TenantObject(org.eclipse.hono.util.TenantObject) NoopKafkaClientMetricsSupport(org.eclipse.hono.client.kafka.metrics.NoopKafkaClientMetricsSupport) DeploymentOptions(io.vertx.core.DeploymentOptions) ProtonBasedDownstreamSender(org.eclipse.hono.client.telemetry.amqp.ProtonBasedDownstreamSender) ResourceLimitChecks(org.eclipse.hono.adapter.resourcelimits.ResourceLimitChecks) ConnectedDevicesAsyncCacheLoader(org.eclipse.hono.adapter.resourcelimits.ConnectedDevicesAsyncCacheLoader) SendMessageSampler(org.eclipse.hono.client.SendMessageSampler) HonoEventConnectionEventProducer(org.eclipse.hono.adapter.monitoring.HonoEventConnectionEventProducer) CredentialsObject(org.eclipse.hono.util.CredentialsObject) WebClientOptions(io.vertx.ext.web.client.WebClientOptions) PrometheusBasedResourceLimitChecks(org.eclipse.hono.adapter.resourcelimits.PrometheusBasedResourceLimitChecks) ConnectionDurationAsyncCacheLoader(org.eclipse.hono.adapter.resourcelimits.ConnectionDurationAsyncCacheLoader) ConnectedDevicesAsyncCacheLoader(org.eclipse.hono.adapter.resourcelimits.ConnectedDevicesAsyncCacheLoader) DataVolumeAsyncCacheLoader(org.eclipse.hono.adapter.resourcelimits.DataVolumeAsyncCacheLoader) TenantObject(org.eclipse.hono.util.TenantObject) CredentialsObject(org.eclipse.hono.util.CredentialsObject) NoopResourceLimitChecks(org.eclipse.hono.adapter.resourcelimits.NoopResourceLimitChecks)

Aggregations

Cache (com.github.benmanes.caffeine.cache.Cache)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 Tracer (io.opentracing.Tracer)1 ConfigMapping (io.smallrye.config.ConfigMapping)1 CompositeFuture (io.vertx.core.CompositeFuture)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 Future (io.vertx.core.Future)1 Buffer (io.vertx.core.buffer.Buffer)1 WebClient (io.vertx.ext.web.client.WebClient)1 WebClientOptions (io.vertx.ext.web.client.WebClientOptions)1 Duration (java.time.Duration)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Executors (java.util.concurrent.Executors)1 Inject (javax.inject.Inject)1 AbstractProtocolAdapterBase (org.eclipse.hono.adapter.AbstractProtocolAdapterBase)1 MessagingClientProviders (org.eclipse.hono.adapter.MessagingClientProviders)1 ConnectionEventProducer (org.eclipse.hono.adapter.monitoring.ConnectionEventProducer)1