MECS-21328: Tenant metric label case unification (#2907)
This commit is contained in:
committed by
GitHub
parent
9f7ca0a3ed
commit
ff21d788b3
@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.tenancy;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import io.micrometer.common.KeyValue;
|
||||
import io.micrometer.common.KeyValues;
|
||||
@@ -45,6 +46,10 @@ public class DefaultTenantConfiguration {
|
||||
|
||||
public static final String TENANT_TAG = "tenant";
|
||||
|
||||
public static final Supplier<String> TENANT_TAG_VALUE_PROVIDER = () -> Optional.ofNullable(AccessContext.tenant())
|
||||
.map(String::toUpperCase)
|
||||
.orElse("N/A");
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
TenantAwareCacheManager cacheManager() {
|
||||
@@ -73,7 +78,7 @@ public class DefaultTenantConfiguration {
|
||||
}
|
||||
|
||||
private KeyValue tenant() {
|
||||
return KeyValue.of(TENANT_TAG, Optional.ofNullable(AccessContext.tenant()).orElse("n/a"));
|
||||
return KeyValue.of(TENANT_TAG, TENANT_TAG_VALUE_PROVIDER.get());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -108,7 +113,7 @@ public class DefaultTenantConfiguration {
|
||||
@Override
|
||||
public Iterable<Tag> repositoryTags(final RepositoryMethodInvocationListener.RepositoryMethodInvocation invocation) {
|
||||
final Iterable<Tag> defaultTags = super.repositoryTags(invocation);
|
||||
final String tenant = Optional.ofNullable(AccessContext.tenant()).orElse("n/a");
|
||||
final String tenant = TENANT_TAG_VALUE_PROVIDER.get();
|
||||
return () -> {
|
||||
final Iterator<Tag> defaultTagsIterator = defaultTags.iterator();
|
||||
return new Iterator<>() {
|
||||
|
||||
@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.repository.jpa.scheduler;
|
||||
import static org.eclipse.hawkbit.context.AccessContext.asActor;
|
||||
import static org.eclipse.hawkbit.context.AccessContext.withSecurityContext;
|
||||
import static org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration.TENANT_TAG;
|
||||
import static org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration.TENANT_TAG_VALUE_PROVIDER;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -119,7 +120,7 @@ public class JpaAutoAssignHandler implements AutoAssignHandler {
|
||||
} finally {
|
||||
meterRegistry // handle single targetFilterQuery
|
||||
.map(mReg -> mReg.timer(
|
||||
"hawkbit.autoassign.handle", TENANT_TAG, AccessContext.tenant(), "targetFilterQuery",
|
||||
"hawkbit.autoassign.handle", TENANT_TAG, TENANT_TAG_VALUE_PROVIDER.get(), "targetFilterQuery",
|
||||
String.valueOf(targetFilterQuery.getId())))
|
||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNanoPartial, TimeUnit.NANOSECONDS));
|
||||
}
|
||||
@@ -132,7 +133,7 @@ public class JpaAutoAssignHandler implements AutoAssignHandler {
|
||||
// only if there is at least one targetFilterQuery and lock has been obtained then will be measured (as in rollouts)
|
||||
meterRegistry // handle single targetFilterQuery for single target
|
||||
.map(mReg -> mReg.timer(
|
||||
"hawkbit.autoassign.handle.all", TENANT_TAG, AccessContext.tenant()))
|
||||
"hawkbit.autoassign.handle.all", TENANT_TAG, TENANT_TAG_VALUE_PROVIDER.get()))
|
||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
||||
log.debug("Auto assign check all targets finished");
|
||||
}
|
||||
@@ -151,7 +152,7 @@ public class JpaAutoAssignHandler implements AutoAssignHandler {
|
||||
} finally {
|
||||
meterRegistry // handle single targetFilterQuery for single target
|
||||
.map(mReg -> mReg.timer(
|
||||
"hawkbit.autoassign.handle.single", TENANT_TAG, AccessContext.tenant(), "targetFilterQuery",
|
||||
"hawkbit.autoassign.handle.single", TENANT_TAG, TENANT_TAG_VALUE_PROVIDER.get(), "targetFilterQuery",
|
||||
String.valueOf(targetFilterQuery.getId())))
|
||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNanoPartial, TimeUnit.NANOSECONDS));
|
||||
}
|
||||
@@ -159,7 +160,7 @@ public class JpaAutoAssignHandler implements AutoAssignHandler {
|
||||
|
||||
meterRegistry // handle single targetFilterQuery for single target
|
||||
.map(mReg -> mReg.timer(
|
||||
"hawkbit.autoassign.handle.single.all", TENANT_TAG, AccessContext.tenant()))
|
||||
"hawkbit.autoassign.handle.single.all", TENANT_TAG, TENANT_TAG_VALUE_PROVIDER.get()))
|
||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
||||
log.debug("Auto assign check call for device {} finished", controllerId);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.scheduler;
|
||||
|
||||
import static org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration.TENANT_TAG;
|
||||
import static org.eclipse.hawkbit.tenancy.DefaultTenantConfiguration.TENANT_TAG_VALUE_PROVIDER;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -91,7 +92,7 @@ public class JpaRolloutHandler implements RolloutHandler {
|
||||
log.trace("Unlock lock {}", lock);
|
||||
}
|
||||
meterRegistry // handle all rollouts of a tenant
|
||||
.map(mReg -> mReg.timer("hawkbit.rollout.handle.all", TENANT_TAG, AccessContext.tenant()))
|
||||
.map(mReg -> mReg.timer("hawkbit.rollout.handle.all", TENANT_TAG, TENANT_TAG_VALUE_PROVIDER.get()))
|
||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
||||
}
|
||||
}
|
||||
@@ -113,7 +114,7 @@ public class JpaRolloutHandler implements RolloutHandler {
|
||||
|
||||
meterRegistry // handle single rollout
|
||||
.map(mReg -> mReg.timer(
|
||||
"hawkbit.rollout.handle", TENANT_TAG, AccessContext.tenant(), "rollout", String.valueOf(rolloutId)))
|
||||
"hawkbit.rollout.handle", TENANT_TAG, TENANT_TAG_VALUE_PROVIDER.get(), "rollout", String.valueOf(rolloutId)))
|
||||
.ifPresent(timer -> timer.record(System.nanoTime() - startNano, TimeUnit.NANOSECONDS));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user