Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include MeterRegistryCustomizer #10

Merged
merged 2 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the exact property in the changelog could be useful


## [0.1.0] - 2019-07-11

Initial, early access release including:
Expand All @@ -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
- ...
Original file line number Diff line number Diff line change
@@ -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
* <p>
* Callback interface that can be used to customize auto-configured {@link MeterRegistry
* MeterRegistries}.
* <p>
* Customizers are guaranteed to be applied before any {@link Meter} is registered with
* the registry.
*
* @author Jon Schneider
* @param <T> the registry type to customize
* @since 0.1.1
*/
@FunctionalInterface
public interface MeterRegistryCustomizer<T extends MeterRegistry> {

/**
* Customize the given {@code registry}.
* @param registry the registry to customize
*/
void customize(T registry);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -63,6 +65,7 @@ private void processRegistryFactoryWrapper(RegistryFactoryWrapper factoryWrapper
}

final MeterRegistry registry = factoryWrapper.getRegistryFactory().createRegistry();
this.customize(registry);
this.addFilters(registry);

globalMeterRegistry.add(registry);
Expand All @@ -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);
}
Expand Down
Loading