Skip to content

Instantly share code, notes, and snippets.

@jkschneider
Last active September 15, 2017 00:23
Show Gist options
  • Save jkschneider/138003a6af6fe8ae8868bf5062361fbb to your computer and use it in GitHub Desktop.
Save jkschneider/138003a6af6fe8ae8868bf5062361fbb to your computer and use it in GitHub Desktop.
/**
* 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.atlas;
import com.netflix.spectator.atlas.AtlasConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import java.time.Duration;
/**
* {@link ConfigurationProperties} for configuring Atlas metrics export.
*
* @author Jon Schneider
*/
@ConfigurationProperties(prefix = "spring.metrics.atlas")
public class AtlasProperties {
/**
* 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;
/**
* The URI for the Atlas backend
*/
private String uri;
private Duration meterTimeToLive;
private Boolean lwcEnabled;
private Duration configRefreshFrequency;
private Duration configTimeToLive;
private String configUri;
private String evalUri;
private class DefaultAtlasConfig implements AtlasConfig {
@Override
public String get(String k) {
return null;
}
}
@ConditionalOnMissingBean
@Bean
public AtlasConfig getAtlasConfig() {
return new DefaultAtlasConfig() {
@Override
public Duration step() {
return step;
}
@Override
public boolean enabled() {
return enabled;
}
@Override
public Duration connectTimeout() {
return connectTimeout == null ? super.connectTimeout() : connectTimeout;
}
@Override
public Duration readTimeout() {
return readTimeout == null ? super.readTimeout() : readTimeout;
}
@Override
public int numThreads() {
return numThreads == null ? super.numThreads() : numThreads;
}
@Override
public int batchSize() {
return batchSize == null ? super.batchSize() : batchSize;
}
@Override
public String uri() {
return uri == null ? super.uri() : uri;
}
@Override
public Duration meterTTL() {
return meterTimeToLive == null ? super.meterTTL() : meterTimeToLive;
}
@Override
public boolean lwcEnabled() {
return lwcEnabled == null ? super.lwcEnabled() : lwcEnabled;
}
@Override
public Duration configRefreshFrequency() {
return configRefreshFrequency == null ? super.configRefreshFrequency() : configRefreshFrequency;
}
@Override
public Duration configTTL() {
return configTimeToLive == null ? super.configTTL() : configTimeToLive;
}
@Override
public String configUri() {
return configUri == null ? super.configUri() : configUri;
}
@Override
public String evalUri() {
return evalUri == null ? super.evalUri() : evalUri;
}
};
}
public void setStep(Duration step) {
this.step = step;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public void setConnectTimeout(Duration connectTimeout) {
this.connectTimeout = connectTimeout;
}
public void setReadTimeout(Duration readTimeout) {
this.readTimeout = readTimeout;
}
public void setNumThreads(Integer numThreads) {
this.numThreads = numThreads;
}
public void setBatchSize(Integer batchSize) {
this.batchSize = batchSize;
}
public void setUri(String uri) {
this.uri = uri;
}
public void setMeterTimeToLive(Duration meterTimeToLive) {
this.meterTimeToLive = meterTimeToLive;
}
public void setLwcEnabled(Boolean lwcEnabled) {
this.lwcEnabled = lwcEnabled;
}
public void setConfigRefreshFrequency(Duration configRefreshFrequency) {
this.configRefreshFrequency = configRefreshFrequency;
}
public void setConfigTimeToLive(Duration configTimeToLive) {
this.configTimeToLive = configTimeToLive;
}
public void setConfigUri(String configUri) {
this.configUri = configUri;
}
public void setEvalUri(String evalUri) {
this.evalUri = evalUri;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment