Move default TenantResolver registration in hawkbit-core (#2778)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -58,12 +58,6 @@ import org.springframework.util.CollectionUtils;
|
|||||||
@Import(RepositoryConfiguration.class)
|
@Import(RepositoryConfiguration.class)
|
||||||
public class SecurityAutoConfiguration {
|
public class SecurityAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public TenantResolver tenantResolver() {
|
|
||||||
return new DefaultTenantResolver();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link ContextAware} (hence {@link TenantAware}) bean based on the given {@link UserAuthoritiesResolver},
|
* Creates a {@link ContextAware} (hence {@link TenantAware}) bean based on the given {@link UserAuthoritiesResolver},
|
||||||
* {@link SecurityContextSerializer} and {@link TenantResolver}.
|
* {@link SecurityContextSerializer} and {@link TenantResolver}.
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ import io.micrometer.common.KeyValue;
|
|||||||
import io.micrometer.common.KeyValues;
|
import io.micrometer.common.KeyValues;
|
||||||
import io.micrometer.core.instrument.Tag;
|
import io.micrometer.core.instrument.Tag;
|
||||||
import io.micrometer.observation.ObservationRegistry;
|
import io.micrometer.observation.ObservationRegistry;
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware.TenantResolver;
|
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties;
|
import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties;
|
||||||
import org.springframework.boot.actuate.autoconfigure.observation.web.servlet.WebMvcObservationAutoConfiguration;
|
import org.springframework.boot.actuate.autoconfigure.observation.web.servlet.WebMvcObservationAutoConfiguration;
|
||||||
@@ -29,35 +26,48 @@ import org.springframework.boot.actuate.metrics.data.RepositoryTagsProvider;
|
|||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.data.repository.core.support.RepositoryMethodInvocationListener.RepositoryMethodInvocation;
|
import org.springframework.data.repository.core.support.RepositoryMethodInvocationListener;
|
||||||
import org.springframework.http.server.observation.DefaultServerRequestObservationConvention;
|
import org.springframework.http.server.observation.DefaultServerRequestObservationConvention;
|
||||||
import org.springframework.http.server.observation.ServerRequestObservationContext;
|
import org.springframework.http.server.observation.ServerRequestObservationContext;
|
||||||
import org.springframework.http.server.observation.ServerRequestObservationConvention;
|
import org.springframework.http.server.observation.ServerRequestObservationConvention;
|
||||||
import org.springframework.web.filter.ServerHttpObservationFilter;
|
import org.springframework.web.filter.ServerHttpObservationFilter;
|
||||||
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@AutoConfiguration
|
||||||
public class TenantMetricsConfiguration {
|
public class DefaultTenantConfiguration {
|
||||||
|
|
||||||
public static final String TENANT_TAG = "tenant";
|
public static final String TENANT_TAG = "tenant";
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
TenantAware.TenantResolver tenantResolver() {
|
||||||
|
return new TenantAware.DefaultTenantResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
TenantAwareCacheManager cacheManager() {
|
||||||
|
return TenantAwareCacheManager.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
@AutoConfiguration(afterName = {
|
@AutoConfiguration(afterName = {
|
||||||
"org.springframework.boot.actuate.autoconfigure.observation.ObservationAutoConfiguration",
|
"org.springframework.boot.actuate.autoconfigure.observation.ObservationAutoConfiguration",
|
||||||
"org.eclipse.hawkbit.autoconfigure.security.SecurityAutoConfiguration" })
|
"org.eclipse.hawkbit.autoconfigure.security.SecurityAutoConfiguration" })
|
||||||
@ConditionalOnProperty(name = "hawkbit.metrics.tenancy.web.enabled", havingValue = "true", matchIfMissing = true)
|
@ConditionalOnProperty(name = "hawkbit.metrics.tenancy.web.enabled", havingValue = "true", matchIfMissing = true)
|
||||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
||||||
@ConditionalOnClass(name = { "org.springframework.web.servlet.DispatcherServlet", "io.micrometer.observation.Observation" })
|
@ConditionalOnClass(name = { "org.springframework.web.servlet.DispatcherServlet", "io.micrometer.observation.Observation" })
|
||||||
@ConditionalOnBean({ ObservationRegistry.class, TenantResolver.class })
|
@ConditionalOnBean({ ObservationRegistry.class, TenantAware.TenantResolver.class })
|
||||||
public static class WebConfig {
|
public static class WebConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
public DefaultServerRequestObservationConvention serverRequestObservationConvention(final TenantResolver tenantResolver) {
|
public DefaultServerRequestObservationConvention serverRequestObservationConvention(final TenantAware.TenantResolver tenantResolver) {
|
||||||
return new DefaultServerRequestObservationConvention() {
|
return new DefaultServerRequestObservationConvention() {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -94,15 +104,15 @@ public class TenantMetricsConfiguration {
|
|||||||
@ConditionalOnClass(name = {
|
@ConditionalOnClass(name = {
|
||||||
"io.micrometer.core.instrument.Tag",
|
"io.micrometer.core.instrument.Tag",
|
||||||
"org.springframework.data.repository.core.support.RepositoryMethodInvocationListener" })
|
"org.springframework.data.repository.core.support.RepositoryMethodInvocationListener" })
|
||||||
@ConditionalOnBean(TenantResolver.class)
|
@ConditionalOnBean(TenantAware.TenantResolver.class)
|
||||||
public static class RepositoryConfig {
|
public static class RepositoryConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RepositoryTagsProvider repositoryTagsProvider(final TenantResolver tenantResolver) {
|
public RepositoryTagsProvider repositoryTagsProvider(final TenantAware.TenantResolver tenantResolver) {
|
||||||
return new DefaultRepositoryTagsProvider() {
|
return new DefaultRepositoryTagsProvider() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Tag> repositoryTags(final RepositoryMethodInvocation invocation) {
|
public Iterable<Tag> repositoryTags(final RepositoryMethodInvocationListener.RepositoryMethodInvocation invocation) {
|
||||||
final Iterable<Tag> defaultTags = super.repositoryTags(invocation);
|
final Iterable<Tag> defaultTags = super.repositoryTags(invocation);
|
||||||
final String tenant = Optional.ofNullable(tenantResolver.resolveTenant()).orElse("n/a");
|
final String tenant = Optional.ofNullable(tenantResolver.resolveTenant()).orElse("n/a");
|
||||||
return () -> {
|
return () -> {
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2025 Contributors to the Eclipse Foundation
|
|
||||||
*
|
|
||||||
* This program and the accompanying materials are made
|
|
||||||
* available under the terms of the Eclipse Public License 2.0
|
|
||||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: EPL-2.0
|
|
||||||
*/
|
|
||||||
package org.eclipse.hawkbit.tenancy;
|
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class TenantCacheConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
TenantAwareCacheManager cacheManager() {
|
|
||||||
return TenantAwareCacheManager.getInstance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
org.eclipse.hawkbit.tenancy.TenantCacheConfiguration
|
org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration
|
||||||
org.eclipse.hawkbit.tenancy.TenantMetricsConfiguration.WebConfig
|
org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration.WebConfig
|
||||||
org.eclipse.hawkbit.tenancy.TenantMetricsConfiguration.RepositoryConfig
|
org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration.RepositoryConfig
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.eclipse.hawkbit.repository.AutoAssignExecutor;
|
import org.eclipse.hawkbit.repository.AutoAssignExecutor;
|
||||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantMetricsConfiguration;
|
import org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration;
|
||||||
import org.springframework.integration.support.locks.LockRegistry;
|
import org.springframework.integration.support.locks.LockRegistry;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ public class AutoAssignScheduler {
|
|||||||
meterRegistry
|
meterRegistry
|
||||||
.map(mReg -> mReg.timer(
|
.map(mReg -> mReg.timer(
|
||||||
"hawkbit.scheduler.executor",
|
"hawkbit.scheduler.executor",
|
||||||
TenantMetricsConfiguration.TENANT_TAG, tenant))
|
DefaultTenantConfiguration.TENANT_TAG, tenant))
|
||||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNanoT, TimeUnit.NANOSECONDS));
|
.ifPresent(timer -> timer.record(System.nanoTime() - startNanoT, TimeUnit.NANOSECONDS));
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import org.eclipse.hawkbit.repository.RolloutExecutor;
|
|||||||
import org.eclipse.hawkbit.repository.RolloutHandler;
|
import org.eclipse.hawkbit.repository.RolloutHandler;
|
||||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||||
import org.eclipse.hawkbit.repository.jpa.utils.DeploymentHelper;
|
import org.eclipse.hawkbit.repository.jpa.utils.DeploymentHelper;
|
||||||
|
import org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantMetricsConfiguration;
|
|
||||||
import org.springframework.integration.support.locks.LockRegistry;
|
import org.springframework.integration.support.locks.LockRegistry;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ public class JpaRolloutHandler implements RolloutHandler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
meterRegistry
|
meterRegistry
|
||||||
.map(mReg -> mReg.timer("hawkbit.rollout.handler.all", TenantMetricsConfiguration.TENANT_TAG, tenantAware.getCurrentTenant()))
|
.map(mReg -> mReg.timer("hawkbit.rollout.handler.all", DefaultTenantConfiguration.TENANT_TAG, tenantAware.getCurrentTenant()))
|
||||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
||||||
|
|
||||||
log.debug("Finished handling of the rollouts.");
|
log.debug("Finished handling of the rollouts.");
|
||||||
@@ -116,9 +116,8 @@ public class JpaRolloutHandler implements RolloutHandler {
|
|||||||
meterRegistry
|
meterRegistry
|
||||||
.map(mReg -> mReg.timer(
|
.map(mReg -> mReg.timer(
|
||||||
"hawkbit.rollout.handler",
|
"hawkbit.rollout.handler",
|
||||||
TenantMetricsConfiguration.TENANT_TAG, tenantAware.getCurrentTenant(),
|
DefaultTenantConfiguration.TENANT_TAG, tenantAware.getCurrentTenant(),
|
||||||
"rollout", String.valueOf(rolloutId)))
|
"rollout", String.valueOf(rolloutId)))
|
||||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.repository.RolloutHandler;
|
|||||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||||
import org.eclipse.hawkbit.repository.jpa.rollout.BlockWhenFullPolicy;
|
import org.eclipse.hawkbit.repository.jpa.rollout.BlockWhenFullPolicy;
|
||||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantMetricsConfiguration;
|
import org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ public class RolloutScheduler {
|
|||||||
meterRegistry
|
meterRegistry
|
||||||
.map(mReg -> mReg.timer(
|
.map(mReg -> mReg.timer(
|
||||||
"hawkbit.rollout.scheduler",
|
"hawkbit.rollout.scheduler",
|
||||||
TenantMetricsConfiguration.TENANT_TAG, tenant))
|
DefaultTenantConfiguration.TENANT_TAG, tenant))
|
||||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user