Skip to content

Commit

Permalink
Merge branch 'master' into kotlin-support
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Jan 18, 2018
2 parents 1330adc + 4718fdc commit a2a619a
Show file tree
Hide file tree
Showing 306 changed files with 5,614 additions and 2,100 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ subprojects {

def check = tasks.findByName('check')
if(check) project.rootProject.tasks.releaseCheck.dependsOn check

//noinspection GroovyAssignabilityCheck
test {
// set heap size for the test JVM(s)
maxHeapSize = "1500m"
}

}

task wrapper(type: Wrapper) {
Expand Down
2 changes: 2 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
machine:
environment:
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
java:
version: oraclejdk8
test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.micrometer.core.instrument.*;
import io.micrometer.core.instrument.config.NamingConvention;
import io.micrometer.core.instrument.histogram.HistogramConfig;
import io.micrometer.core.instrument.histogram.pause.PauseDetector;
import io.micrometer.core.instrument.internal.DefaultMeter;
import io.micrometer.core.instrument.step.StepFunctionCounter;
import io.micrometer.core.instrument.step.StepFunctionTimer;
Expand Down Expand Up @@ -109,30 +110,30 @@ protected io.micrometer.core.instrument.DistributionSummary newDistributionSumma

for (double percentile : histogramConfig.getPercentiles()) {
gauge(id.getName(), Tags.concat(getConventionTags(id), "percentile", percentileFormat.format(percentile)),
percentile, summary::percentile);
summary, s -> s.percentile(percentile));
}

return summary;
}

@Override
protected Timer newTimer(Meter.Id id, HistogramConfig histogramConfig) {
protected Timer newTimer(Meter.Id id, HistogramConfig histogramConfig, PauseDetector pauseDetector) {
com.netflix.spectator.api.Timer internalTimer = registry.timer(spectatorId(id));

if (histogramConfig.isPercentileHistogram()) {
// This doesn't report the normal count/totalTime/max stats, so we treat it as additive
PercentileTimer.get(registry, spectatorId(id));
}

SpectatorTimer timer = new SpectatorTimer(id, internalTimer, clock, histogramConfig);
SpectatorTimer timer = new SpectatorTimer(id, internalTimer, clock, histogramConfig, pauseDetector, getBaseTimeUnit());

for (long sla : histogramConfig.getSlaBoundaries()) {
gauge(id.getName(), Tags.concat(getConventionTags(id), "sla", Duration.ofNanos(sla).toString()), sla, timer::histogramCountAtValue);
}

for (double percentile : histogramConfig.getPercentiles()) {
gauge(id.getName(), Tags.concat(getConventionTags(id), "percentile", percentileFormat.format(percentile)),
percentile, p -> timer.percentile(p, TimeUnit.SECONDS));
timer, t -> t.percentile(percentile, TimeUnit.SECONDS));
}

return timer;
Expand Down Expand Up @@ -201,4 +202,12 @@ public Registry getSpectatorRegistry() {
protected TimeUnit getBaseTimeUnit() {
return TimeUnit.SECONDS;
}

@Override
protected HistogramConfig defaultHistogramConfig() {
return HistogramConfig.builder()
.histogramExpiry(atlasConfig.step())
.build()
.merge(HistogramConfig.DEFAULT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.histogram.HistogramConfig;
import io.micrometer.core.instrument.util.MeterEquivalence;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.stream.StreamSupport.stream;

public class SpectatorDistributionSummary extends AbstractDistributionSummary {
private final com.netflix.spectator.api.DistributionSummary summary;
private final Logger logger = LoggerFactory.getLogger(SpectatorDistributionSummary.class);

SpectatorDistributionSummary(Id id,
com.netflix.spectator.api.DistributionSummary distributionSummary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class SpectatorLongTaskTimer extends AbstractMeter implements LongTaskTim
}

@Override
public long start() {
return timer.start();
public Sample start() {
return new Sample(this, timer.start());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@
import io.micrometer.core.instrument.AbstractTimer;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.histogram.HistogramConfig;
import io.micrometer.core.instrument.histogram.pause.PauseDetector;
import io.micrometer.core.instrument.util.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

import static java.util.stream.StreamSupport.stream;

public class SpectatorTimer extends AbstractTimer {
private final com.netflix.spectator.api.Timer timer;
private final Logger logger = LoggerFactory.getLogger(SpectatorTimer.class);

public SpectatorTimer(Id id, Timer timer, Clock clock, HistogramConfig statsConf) {
super(id, clock, statsConf);
public SpectatorTimer(Id id, Timer timer, Clock clock, HistogramConfig statsConf, PauseDetector pauseDetector, TimeUnit baseTimeUnit) {
super(id, clock, statsConf, pauseDetector, baseTimeUnit);
this.timer = timer;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright 2017 Pivotal Software, Inc.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/
@NonNullApi
@NonNullFields
package io.micrometer.atlas;

import io.micrometer.core.lang.NonNullApi;
import io.micrometer.core.lang.NonNullFields;
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package io.micrometer.atlas;

import com.netflix.spectator.atlas.AtlasConfig;
import io.micrometer.core.instrument.MockClock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.MockClock;
import io.micrometer.core.tck.MeterRegistryCompatibilityKit;

import java.time.Duration;
Expand All @@ -38,8 +38,13 @@ public String get(String k) {

@Override
public Duration step() {
return Duration.ofSeconds(1);
return Duration.ofMinutes(1);
}
}, new MockClock());
}

@Override
public Duration step() {
return Duration.ofMinutes(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ default String namespace() {
@Override
default int batchSize() {
String v = get(prefix() + ".batchSize");
int vInt = v == null ? MAX_BATCH_SIZE : Integer.parseInt(v);
if (v == null) {
return MAX_BATCH_SIZE;
}
int vInt = Integer.parseInt(v);
if(vInt > MAX_BATCH_SIZE)
throw new IllegalStateException(prefix() + ".batchSize must be <= " + MAX_BATCH_SIZE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@

import com.amazonaws.handlers.AsyncHandler;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchAsync;
import com.amazonaws.services.cloudwatch.model.Dimension;
import com.amazonaws.services.cloudwatch.model.MetricDatum;
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest;
import com.amazonaws.services.cloudwatch.model.PutMetricDataResult;
import com.amazonaws.services.cloudwatch.model.StandardUnit;
import com.amazonaws.services.cloudwatch.model.*;
import io.micrometer.core.instrument.*;
import io.micrometer.core.instrument.config.NamingConvention;
import io.micrometer.core.instrument.histogram.HistogramConfig;
import io.micrometer.core.instrument.step.StepMeterRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

Expand All @@ -48,18 +43,19 @@ public class CloudWatchMeterRegistry extends StepMeterRegistry {
private final AmazonCloudWatchAsync amazonCloudWatchAsync;
private final DecimalFormat percentileFormat = new DecimalFormat("#.####");
private final Logger logger = LoggerFactory.getLogger(CloudWatchMeterRegistry.class);
private final Map<Meter, HistogramConfig> histogramConfigs = new ConcurrentHashMap<>();

public CloudWatchMeterRegistry(CloudWatchConfig config, Clock clock, AmazonCloudWatchAsync amazonCloudWatchAsync) {
public CloudWatchMeterRegistry(CloudWatchConfig config, Clock clock,
AmazonCloudWatchAsync amazonCloudWatchAsync) {
this(config, clock, amazonCloudWatchAsync, Executors.defaultThreadFactory());
}

public CloudWatchMeterRegistry(CloudWatchConfig config, Clock clock,
AmazonCloudWatchAsync amazonCloudWatchAsync, ThreadFactory threadFactory) {
super(config, clock);
this.amazonCloudWatchAsync = amazonCloudWatchAsync;
this.config = config;
this.config().namingConvention(NamingConvention.identity);
start();
}

public CloudWatchMeterRegistry(CloudWatchConfig config, AmazonCloudWatchAsync amazonCloudWatchAsync) {
this(config, Clock.SYSTEM, amazonCloudWatchAsync);
start(threadFactory);
}

@Override
Expand Down Expand Up @@ -90,13 +86,14 @@ private List<MetricDatum> metricData() {
return getMeters().stream().flatMap(m -> {
if (m instanceof Timer) {
return metricData((Timer) m);
} else if (m instanceof DistributionSummary) {
}
if (m instanceof DistributionSummary) {
return metricData((DistributionSummary) m);
} else if (m instanceof FunctionTimer) {
}
if (m instanceof FunctionTimer) {
return metricData((FunctionTimer) m);
} else {
return metricData(m);
}
return metricData(m);
}).collect(toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ final class CloudWatchUtils {

/**
* Minimum allowed value as specified by
* #{{@link com.amazonaws.services.cloudwatch.model.MetricDatum#setValue(Double)}}
* {@link com.amazonaws.services.cloudwatch.model.MetricDatum#setValue(Double)}
*/
private static final double MINIMUM_ALLOWED_VALUE = 8.515920e-109;

/**
* Maximum allowed value as specified by
* #{{@link com.amazonaws.services.cloudwatch.model.MetricDatum#setValue(Double)}}
* {@link com.amazonaws.services.cloudwatch.model.MetricDatum#setValue(Double)}
*/
private static final double MAXIMUM_ALLOWED_VALUE = 1.174271e+108;

Expand All @@ -37,29 +37,24 @@ private CloudWatchUtils() {

/**
* Clean up metric to be within the allowable range as specified in
* #{{@link com.amazonaws.services.cloudwatch.model.MetricDatum#setValue(Double)}}
* {@link com.amazonaws.services.cloudwatch.model.MetricDatum#setValue(Double)}
*
* @param value unsanitized value
* @return value clamped to allowable range, 0, or NaN
*/
static double clampMetricValue(double value) {
final double result;
if (!Double.isNaN(value)) {
double magnitude = Math.abs(value);
if (magnitude == 0) {
// Leave zero as zero
result = 0;
} else {
// Non-zero magnitude, clamp to allowed range
double clampedMag = Math.min(Math.max(magnitude, MINIMUM_ALLOWED_VALUE), MAXIMUM_ALLOWED_VALUE);
result = Math.copySign(clampedMag, value);
}
} else {
// Leave as is and let the SDK reject it
result = value;
// Leave as is and let the SDK reject it
if (Double.isNaN(value)) {
return value;
}

return result;
double magnitude = Math.abs(value);
if (magnitude == 0) {
// Leave zero as zero
return 0;
}
// Non-zero magnitude, clamp to allowed range
double clampedMag = Math.min(Math.max(magnitude, MINIMUM_ALLOWED_VALUE), MAXIMUM_ALLOWED_VALUE);
return Math.copySign(clampedMag, value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.micrometer.cloudwatch;

import io.micrometer.core.instrument.MockClock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.MockClock;
import io.micrometer.core.tck.MeterRegistryCompatibilityKit;

import java.time.Duration;
Expand All @@ -39,12 +39,11 @@ public boolean enabled() {
public String namespace() {
return "DOESNOTMATTER";
}

@Override
public Duration step() {
return Duration.ofMillis(800);
}

}, new MockClock(), null);
}

@Override
public Duration step() {
return CloudWatchConfig.DEFAULT.step();
}
}
Loading

0 comments on commit a2a619a

Please sign in to comment.