Skip to content

Commit

Permalink
make bufferLength and expiry configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartisk committed Sep 15, 2020
1 parent 2b0956d commit af13982
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jboss.logging.Logger;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
Expand Down Expand Up @@ -50,4 +51,10 @@ public void initializeJsonRegistry(MicrometerConfig config,
log.debug("Initialized a JSON meter registry on path=" + config.export.json.path);
}

@BuildStep(onlyIf = JsonRegistryEnabled.class)
@Record(ExecutionTime.STATIC_INIT)
void configureJsonRegistry(MicrometerConfig config, JsonRecorder recorder, BeanContainerBuildItem beanContainerBuildItem) {
recorder.configureJsonRegistry(config, beanContainerBuildItem.getValue());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.micrometer.runtime.config;

import java.time.Duration;
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
Expand All @@ -20,6 +21,22 @@ public class JsonConfig implements MicrometerConfig.CapabilityEnabled {
@ConfigItem(defaultValue = "/metrics")
public String path;

/**
* Statistics like max, percentiles, and histogram counts decay over time to give greater weight to recent
* samples. Samples are accumulated to such statistics in ring buffers which rotate after
* the expiry, with this buffer length.
*/
@ConfigItem(defaultValue = "1024")
public Integer bufferLength;

/**
* Statistics like max, percentiles, and histogram counts decay over time to give greater weight to recent
* samples. Samples are accumulated to such statistics in ring buffers which rotate after
* this expiry, with a particular buffer length.
*/
@ConfigItem(defaultValue = "P3D")
public Duration expiry;

@Override
public Optional<Boolean> getEnabled() {
return enabled;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.micrometer.runtime.export;

import java.time.Duration;

import javax.enterprise.inject.Produces;
import javax.inject.Singleton;

Expand All @@ -9,9 +11,17 @@
@Singleton
public class JsonMeterRegistryProvider {

private Integer bufferLength;
private Duration expiry;

@Produces
@Singleton
public JsonMeterRegistry registry(Clock clock) {
return new JsonMeterRegistry(clock);
return new JsonMeterRegistry(clock, bufferLength, expiry);
}

public void configureJsonRegistry(Integer bufferLength, Duration expiry) {
this.bufferLength = bufferLength;
this.expiry = expiry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.function.Function;

import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.micrometer.runtime.config.MicrometerConfig;
import io.quarkus.micrometer.runtime.export.handlers.JsonHandler;
import io.quarkus.runtime.annotations.Recorder;
import io.vertx.ext.web.Route;
Expand All @@ -19,6 +21,12 @@ public JsonHandler getHandler() {
return handler;
}

public void configureJsonRegistry(MicrometerConfig config, BeanContainer beanContainer) {
beanContainer
.instance(JsonMeterRegistryProvider.class)
.configureJsonRegistry(config.export.json.bufferLength, config.export.json.expiry);
}

public Function<Router, Route> route(String path) {
return new Function<Router, Route>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@
public class JsonMeterRegistry extends MeterRegistry {

private final JsonExporter jsonExporter;
private final Integer bufferLength;
private final Duration expiry;

public JsonMeterRegistry(Clock clock) {
public JsonMeterRegistry(Clock clock, Integer bufferLength, Duration expiry) {
super(clock);
this.jsonExporter = new JsonExporter();
this.bufferLength = bufferLength;
this.expiry = expiry;
}

@Override
Expand Down Expand Up @@ -101,8 +105,8 @@ protected DistributionStatisticConfig defaultHistogramConfig() {
.percentilesHistogram(false)
.minimumExpectedValue(Double.MIN_VALUE)
.maximumExpectedValue(Double.POSITIVE_INFINITY)
.bufferLength(1024)
.expiry(Duration.ofDays(3))
.bufferLength(bufferLength)
.expiry(expiry)
.build();
}

Expand Down

0 comments on commit af13982

Please sign in to comment.