Commit 6230d905 authored by Phillip Webb's avatar Phillip Webb

Polish

parent 9b5e5f7b
...@@ -29,9 +29,8 @@ import org.springframework.util.StringUtils; ...@@ -29,9 +29,8 @@ import org.springframework.util.StringUtils;
* collecting data from many sources in the same form (like a scaled-out application). The * collecting data from many sources in the same form (like a scaled-out application). The
* source has metrics with names in the form {@code *.*.counter.**} and * source has metrics with names in the form {@code *.*.counter.**} and
* {@code *.*.[anything].**}, and the result has metric names in the form * {@code *.*.[anything].**}, and the result has metric names in the form
* {@code aggregate.count.**} and {@code aggregate.[anything].**}. Counters are * {@code aggregate.count.**} and {@code aggregate.[anything].**}. Counters are summed and
* summed and anything else (i.e. gauges) are aggregated by choosing the most recent * anything else (i.e. gauges) are aggregated by choosing the most recent value.
* value.
* *
* @author Dave Syer * @author Dave Syer
* @since 1.3.0 * @since 1.3.0
...@@ -60,7 +59,6 @@ public class AggregateMetricReader implements MetricReader { ...@@ -60,7 +59,6 @@ public class AggregateMetricReader implements MetricReader {
* names)</li> * names)</li>
* </ul> * </ul>
* Default is "d.d" (we assume there is a global prefix of length 2). * Default is "d.d" (we assume there is a global prefix of length 2).
*
* @param keyPattern the keyPattern to set * @param keyPattern the keyPattern to set
*/ */
public void setKeyPattern(String keyPattern) { public void setKeyPattern(String keyPattern) {
...@@ -68,13 +66,15 @@ public class AggregateMetricReader implements MetricReader { ...@@ -68,13 +66,15 @@ public class AggregateMetricReader implements MetricReader {
} }
/** /**
* Prefix to apply to all output metrics. A period will be appended if not present in the * Prefix to apply to all output metrics. A period will be appended if not present in
* provided value. * the provided value.
*
* @param prefix the prefix to use (default "aggregator.") * @param prefix the prefix to use (default "aggregator.")
*/ */
public void setPrefix(String prefix) { public void setPrefix(String prefix) {
this.prefix = prefix.endsWith(".") ? prefix : (StringUtils.hasText(prefix) ? prefix + "." : ""); if (StringUtils.hasText(prefix) && !prefix.endsWith(".")) {
prefix = prefix + ".";
}
this.prefix = prefix;
} }
@Override @Override
...@@ -139,20 +139,15 @@ public class AggregateMetricReader implements MetricReader { ...@@ -139,20 +139,15 @@ public class AggregateMetricReader implements MetricReader {
String[] keys = StringUtils.delimitedListToStringArray(name, "."); String[] keys = StringUtils.delimitedListToStringArray(name, ".");
String[] patterns = StringUtils.delimitedListToStringArray(this.keyPattern, "."); String[] patterns = StringUtils.delimitedListToStringArray(this.keyPattern, ".");
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
int index = 0; for (int i = 0; i < patterns.length; i++) {
for (index = 0; index < patterns.length; index++) { if ("k".equals(patterns[i])) {
if ("k".equals(patterns[index])) { builder.append(builder.length() > 0 ? "." : "");
if (builder.length() > 0) { builder.append(keys[i]);
builder.append(".");
}
builder.append(keys[index]);
}
} }
for (; index < keys.length; index++) {
if (builder.length() > 0) {
builder.append(".");
} }
builder.append(keys[index]); for (int i = patterns.length; i < keys.length; i++) {
builder.append(builder.length() > 0 ? "." : "");
builder.append(keys[i]);
} }
return builder.toString(); return builder.toString();
} }
......
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
package org.springframework.boot.actuate.metrics.aggregate; package org.springframework.boot.actuate.metrics.aggregate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.Date; import java.util.Date;
import org.junit.Test; import org.junit.Test;
...@@ -26,6 +23,9 @@ import org.springframework.boot.actuate.metrics.Metric; ...@@ -26,6 +23,9 @@ import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository; import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository;
import org.springframework.boot.actuate.metrics.writer.Delta; import org.springframework.boot.actuate.metrics.writer.Delta;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
/** /**
* Tests for {@link AggregateMetricReader}. * Tests for {@link AggregateMetricReader}.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment