Skip to content

Commit

Permalink
Rework Micrometer export configuration properties classes (fixes #113)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Sep 15, 2017
1 parent 6834b0a commit 258d804
Show file tree
Hide file tree
Showing 20 changed files with 880 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ default String prefix() {
}

/**
* The tag that will be mapped to "host" when shipping metrics to Influx, or {@code null} if
* host should be omitted on publishing.
* The db to send metrics to. Defaults to "mydb".
*/
default String db() {
String v = get(prefix() + ".db");
return v == null ? "mydb" : v;
}

/**
* Sets the write consistency for the point. The Influx default is 'one'. Must
* Sets the write consistency for each point. The Influx default is 'one'. Must
* be one of 'any', 'one', 'quorum', or 'all'.
*
* Only available for InfluxEnterprise clusters.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright 2017 Pivotal Software, Inc.
*
* 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
*
* http://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 io.micrometer.spring.autoconfigure.export;

import io.micrometer.core.instrument.spectator.step.StepRegistryConfig;

import java.time.Duration;

public abstract class DefaultStepRegistryConfig implements StepRegistryConfig {
private final StepRegistryProperties props;

private final StepRegistryConfig defaults = new StepRegistryConfig() {
@Override
public String prefix() {
return null;
}

@Override
public String get(String k) {
return null;
}
};

public DefaultStepRegistryConfig(StepRegistryProperties props) {
this.props = props;
}

@Override
public String prefix() {
return null;
}

@Override
public String get(String k) {
return null;
}

@Override
public Duration step() {
return props.getStep();
}

@Override
public boolean enabled() {
return props.getEnabled();
}

@Override
public Duration connectTimeout() {
return props.getConnectTimeout() == null ? defaults.connectTimeout() : props.getConnectTimeout();
}

@Override
public Duration readTimeout() {
return props.getReadTimeout() == null ? defaults.readTimeout() : props.getReadTimeout();
}

@Override
public int numThreads() {
return props.getNumThreads() == null ? defaults.numThreads() : props.getNumThreads();
}

@Override
public int batchSize() {
return props.getBatchSize() == null ? defaults.batchSize() : props.getBatchSize();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,93 @@
*/
package io.micrometer.spring.autoconfigure.export;

import io.micrometer.core.instrument.spectator.step.StepRegistryConfig;

import java.time.Duration;

/**
* Specialization of {@link RegistryProperties} for configuring a metrics registry that
* pushes aggregated metrics on a regular interval.
* Base configuration for a metrics registry that pushes aggregated
* metrics on a regular interval.
*
* @author Jon Schneider
* @author Andy Wilkinson
*/
public abstract class StepRegistryProperties extends RegistryProperties
implements StepRegistryConfig {
public abstract class StepRegistryProperties {

/**
* The step size (reporting frequency) to use.
*/
private Duration step = Duration.ofMinutes(1);

/**
* Enable publishing to the backend.
*/
private Boolean enabled = true;

/**
* The connection timeout for requests to the backend.
*/
private Duration connectTimeout;

/**
* The read timeout for requests to the backend.
*/
private Duration readTimeout;

/**
* The number of threads to use with the metrics publishing scheduler.
*/
private Integer numThreads;

/**
* The number of measurements per request to use for the backend. If more
* measurements are found, then multiple requests will be made.
*/
private Integer batchSize;

public Duration getStep() {
return step;
}

public void setStep(Duration step) {
set("step", step);
this.step = step;
}

public Boolean getEnabled() {
return enabled;
}

public void setEnabled(Boolean enabled) {
set("enabled", enabled);
this.enabled = enabled;
}

public void setBatchSize(Integer batchSize) {
set("batchSize", batchSize);
public Duration getConnectTimeout() {
return connectTimeout;
}

public void setConnectTimeout(Duration connectTimeout) {
set("connectTimeout", connectTimeout);
this.connectTimeout = connectTimeout;
}

public Duration getReadTimeout() {
return readTimeout;
}

public void setReadTimeout(Duration readTimeout) {
set("readTimeout", readTimeout);
this.readTimeout = readTimeout;
}

public Integer getNumThreads() {
return numThreads;
}

public void setNumThreads(Integer numThreads) {
set("numThreads", numThreads);
this.numThreads = numThreads;
}

public Integer getBatchSize() {
return batchSize;
}

public void setBatchSize(Integer batchSize) {
this.batchSize = batchSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import com.netflix.spectator.atlas.AtlasConfig;
import io.micrometer.atlas.AtlasMeterRegistry;
import io.micrometer.core.instrument.Clock;
import io.micrometer.spring.autoconfigure.export.DefaultStepRegistryConfig;
import io.micrometer.spring.autoconfigure.export.MetricsExporter;
import io.micrometer.spring.autoconfigure.export.StepRegistryProperties;
import io.micrometer.spring.autoconfigure.export.StringToDurationConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -28,6 +30,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.time.Duration;

/**
* Configuration for exporting metrics to Atlas.
*
Expand All @@ -40,6 +44,57 @@
@EnableConfigurationProperties(AtlasProperties.class)
public class AtlasExportConfiguration {

private class DefaultAtlasConfig extends DefaultStepRegistryConfig implements AtlasConfig {
private final AtlasProperties props;
private final AtlasConfig defaults = k -> null;

public DefaultAtlasConfig(AtlasProperties props) {
super(props);
this.props = props;
}

@Override
public String uri() {
return props.getUri() == null ? defaults.uri() : props.getUri();
}

@Override
public Duration meterTTL() {
return props.getMeterTimeToLive() == null ? defaults.meterTTL() : props.getMeterTimeToLive();
}

@Override
public boolean lwcEnabled() {
return props.getLwcEnabled() == null ? defaults.lwcEnabled() : props.getLwcEnabled();
}

@Override
public Duration configRefreshFrequency() {
return props.getConfigRefreshFrequency() == null ? defaults.configRefreshFrequency() : props.getConfigRefreshFrequency();
}

@Override
public Duration configTTL() {
return props.getConfigTimeToLive() == null ? defaults.configTTL() : props.getConfigTimeToLive();
}

@Override
public String configUri() {
return props.getConfigUri() == null ? defaults.configUri() : props.getConfigUri();
}

@Override
public String evalUri() {
return props.getEvalUri() == null ? defaults.evalUri() : props.getEvalUri();
}
}

@Bean
@ConditionalOnMissingBean(AtlasConfig.class)
public AtlasConfig atlasConfig(AtlasProperties props) {
return new DefaultAtlasConfig(props);
}

@Bean
@ConditionalOnProperty(value = "spring.metrics.atlas.enabled", matchIfMissing = true)
public MetricsExporter atlasExporter(AtlasConfig config, Clock clock) {
Expand All @@ -51,5 +106,4 @@ public MetricsExporter atlasExporter(AtlasConfig config, Clock clock) {
public Clock clock() {
return Clock.SYSTEM;
}

}
Loading

0 comments on commit 258d804

Please sign in to comment.