diff --git a/CHANGELOG.md b/CHANGELOG.md
index acdf0218..226f2997 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,19 @@ Version template:
# Alfred Telemetry Changelog
+## [0.1.2] - UNRELEASED
+### Added
+* MeterRegistryCustomizer to support complex customization of MeterRegistries
+
+## [0.1.1] - 2019-08-13
+
+### Fixed
+* MeterFilters are applied after metrics are possibly already exposed to the global MeterRegistry
+
+### Changed
+* Changed default logging level to INFO
+* Disable Cache metrics by default
+
## [0.1.0] - 2019-07-11
Initial, early access release including:
@@ -33,13 +46,4 @@ if available on the classpath.
- The possibility to customize meters with custom `MeterFilter` implementations.
- Integration with the out of the box Alfresco metrics included since 6.1.
- Limited support for Care4Alf compatible metrics.
-- ...
-
-## [0.1.1] - 2019-08-13
-
-### Fixed
-* MeterFilters are applied after metrics are possibly already exposed to the global MeterRegistry
-
-### Changed
-* Changed default logging level to INFO
-* Disable Cache metrics by default
\ No newline at end of file
+- ...
\ No newline at end of file
diff --git a/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/MeterRegistryCustomizer.java b/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/MeterRegistryCustomizer.java
new file mode 100644
index 00000000..353af5d6
--- /dev/null
+++ b/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/MeterRegistryCustomizer.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package eu.xenit.alfred.telemetry;
+
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.MeterRegistry;
+
+/**
+ * Exact copy of Spring Boot MeterRegistryCustomizer: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryCustomizer.java
+ *
+ * Callback interface that can be used to customize auto-configured {@link MeterRegistry
+ * MeterRegistries}.
+ *
+ * Customizers are guaranteed to be applied before any {@link Meter} is registered with
+ * the registry.
+ *
+ * @author Jon Schneider
+ * @param the registry type to customize
+ * @since 0.1.1
+ */
+@FunctionalInterface
+public interface MeterRegistryCustomizer {
+
+ /**
+ * Customize the given {@code registry}.
+ * @param registry the registry to customize
+ */
+ void customize(T registry);
+
+}
\ No newline at end of file
diff --git a/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/binder/MeterBinderRegistrar.java b/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/binder/MeterBinderRegistrar.java
index 55824385..91457a54 100644
--- a/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/binder/MeterBinderRegistrar.java
+++ b/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/binder/MeterBinderRegistrar.java
@@ -3,7 +3,6 @@
import com.google.common.base.CaseFormat;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder;
-import io.micrometer.core.instrument.config.MeterFilter;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
diff --git a/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/registry/RegistryRegistrar.java b/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/registry/RegistryRegistrar.java
index 6e66e199..aeeee5a8 100644
--- a/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/registry/RegistryRegistrar.java
+++ b/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/registry/RegistryRegistrar.java
@@ -1,6 +1,8 @@
package eu.xenit.alfred.telemetry.registry;
+import eu.xenit.alfred.telemetry.MeterRegistryCustomizer;
+import eu.xenit.alfred.telemetry.util.LambdaSafe;
import eu.xenit.alfred.telemetry.util.VersionUtil;
import eu.xenit.alfred.telemetry.util.VersionUtil.Version;
import io.micrometer.core.instrument.Counter;
@@ -63,6 +65,7 @@ private void processRegistryFactoryWrapper(RegistryFactoryWrapper factoryWrapper
}
final MeterRegistry registry = factoryWrapper.getRegistryFactory().createRegistry();
+ this.customize(registry);
this.addFilters(registry);
globalMeterRegistry.add(registry);
@@ -71,6 +74,14 @@ private void processRegistryFactoryWrapper(RegistryFactoryWrapper factoryWrapper
this.incrementRegistryCounter();
}
+ @SuppressWarnings("unchecked")
+ private void customize(final MeterRegistry registry) {
+ LambdaSafe.callbacks(MeterRegistryCustomizer.class, ctx.getBeansOfType(MeterRegistryCustomizer.class).values(),
+ registry)
+ .withLogger(this.getClass())
+ .invoke((c) -> c.customize(registry));
+ }
+
private void addFilters(final MeterRegistry registry) {
ctx.getBeansOfType(MeterFilter.class).values().forEach(registry.config()::meterFilter);
}
diff --git a/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/util/LambdaSafe.java b/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/util/LambdaSafe.java
new file mode 100644
index 00000000..45215461
--- /dev/null
+++ b/alfred-telemetry-platform/src/main/java/eu/xenit/alfred/telemetry/util/LambdaSafe.java
@@ -0,0 +1,429 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package eu.xenit.alfred.telemetry.util;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+import java.util.stream.Stream;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.core.ResolvableType;
+import org.springframework.util.Assert;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ReflectionUtils;
+
+/**
+ * Exact copy of the Spring Boot LambdaSafe class. https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/util/LambdaSafe.java
+ *