This commit is contained in:
Phillip Webb
2016-12-28 15:23:26 -08:00
parent 97d7ffd8e8
commit 8b69856fc9
22 changed files with 64 additions and 41 deletions

View File

@@ -115,7 +115,7 @@ import org.springframework.util.StringUtils;
* @author Christian Dupuis
* @author Matt Benson
* @see ShellProperties
* @deprecated as of 1.5
* @deprecated as of 1.5 since CRaSH is not actively maintained
*/
@Configuration
@ConditionalOnClass(PluginLifeCycle.class)

View File

@@ -158,8 +158,9 @@ public class MetricRepositoryAutoConfiguration {
@Bean
@ExportMetricReader
@ActuatorMetricWriter
public InMemoryMultiMetricRepository actuatorMultiMetricRepository() {
return new InMemoryMultiMetricRepository(actuatorMetricRepository());
public InMemoryMultiMetricRepository actuatorMultiMetricRepository(
InMemoryMetricRepository actuatorMetricRepository) {
return new InMemoryMultiMetricRepository(actuatorMetricRepository);
}
}

View File

@@ -38,7 +38,7 @@ import org.springframework.util.StringUtils;
* @author Phillip Webb
* @author Eddú Meléndez
* @author Stephane Nicoll
* @deprecated as of 1.5
* @deprecated as of 1.5 since CRaSH is not actively maintained
*/
@ConfigurationProperties(prefix = ShellProperties.SHELL_PREFIX, ignoreUnknownFields = true)
@Deprecated

View File

@@ -44,16 +44,16 @@ public class InMemoryMetricRepository implements MetricRepository {
final int amount = delta.getValue().intValue();
final Date timestamp = delta.getTimestamp();
this.metrics.update(metricName, new Callback<Metric<?>>() {
@Override
public Metric<?> modify(Metric<?> current) {
if (current != null) {
return new Metric<Long>(metricName,
current.increment(amount).getValue(), timestamp);
}
else {
return new Metric<Long>(metricName, (long) amount, timestamp);
}
return new Metric<Long>(metricName, (long) amount, timestamp);
}
});
}

View File

@@ -22,6 +22,7 @@ import java.util.HashSet;
import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.boot.actuate.metrics.writer.Delta;
import org.springframework.util.Assert;
/**
* {@link MultiMetricRepository} implementation backed by a
@@ -36,14 +37,24 @@ public class InMemoryMultiMetricRepository implements MultiMetricRepository {
private final Collection<String> groups = new HashSet<String>();
public InMemoryMultiMetricRepository(InMemoryMetricRepository repository) {
this.repository = repository;
}
/**
* Create a new {@link InMemoryMetricRepository} backed by a new
* {@link InMemoryMetricRepository}.
*/
public InMemoryMultiMetricRepository() {
this(new InMemoryMetricRepository());
}
/**
* Create a new {@link InMemoryMetricRepository} backed by the specified
* {@link InMemoryMetricRepository}.
* @param repository the backing repository
*/
public InMemoryMultiMetricRepository(InMemoryMetricRepository repository) {
Assert.notNull(repository, "Repository must not be null");
this.repository = repository;
}
@Override
public void set(String group, Collection<Metric<?>> values) {
String prefix = group;

View File

@@ -145,7 +145,7 @@ public class JolokiaAutoConfigurationTests {
Collection<? extends MvcEndpoint> endpoints) {
EndpointHandlerMapping mapping = new EndpointHandlerMapping(endpoints);
mapping.setSecurityInterceptor(
new MvcEndpointSecurityInterceptor(false, Collections.EMPTY_LIST));
new MvcEndpointSecurityInterceptor(false, Collections.emptyList()));
return mapping;
}

View File

@@ -54,8 +54,8 @@ public class PrefixMetricGroupExporterTests {
@Test
public void countersIncremented() {
this.writer.increment("counter.foo", new Delta<Long>("bar", 1L));
this.reader.set("counter", Collections.<Metric<?>>singletonList(
new Metric<Number>("counter.foo.bar", 1)));
this.reader.set("counter", Collections
.<Metric<?>>singletonList(new Metric<Number>("counter.foo.bar", 1)));
this.exporter.setGroups(Collections.singleton("counter.foo"));
this.exporter.export();
assertThat(this.writer.findAll("counter.foo").iterator().next().getValue())
@@ -65,8 +65,7 @@ public class PrefixMetricGroupExporterTests {
@Test
public void unprefixedMetricsNotCopied() {
this.reader.set("foo", Arrays.<Metric<?>>asList(
new Metric<Number>("foo.bar", 2.3),
new Metric<Number>("foo.spam", 1.3)));
new Metric<Number>("foo.bar", 2.3), new Metric<Number>("foo.spam", 1.3)));
this.exporter.setGroups(Collections.singleton("bar"));
this.exporter.export();
assertThat(Iterables.collection(this.writer.groups())).isEmpty();
@@ -84,10 +83,9 @@ public class PrefixMetricGroupExporterTests {
@Test
public void onlyPrefixedMetricsCopied() {
this.reader.set("foo", Arrays.<Metric<?>>asList(
new Metric<Number>("foo.bar", 2.3),
new Metric<Number>("foo.spam", 1.3)));
this.reader.set("foobar", Collections.<Metric<?>>singletonList(
new Metric<Number>("foobar.spam", 1.3)));
new Metric<Number>("foo.bar", 2.3), new Metric<Number>("foo.spam", 1.3)));
this.reader.set("foobar", Collections
.<Metric<?>>singletonList(new Metric<Number>("foobar.spam", 1.3)));
this.exporter.setGroups(Collections.singleton("foo"));
this.exporter.export();
assertThat(Iterables.collection(this.writer.groups())).hasSize(1);

View File

@@ -28,6 +28,8 @@ import static org.assertj.core.api.Assertions.offset;
/**
* Tests for {@link InMemoryMetricRepository}.
*
* @author Dave Syer
*/
public class InMemoryMetricRepositoryTests {

View File

@@ -29,12 +29,13 @@ import org.springframework.boot.actuate.metrics.writer.Delta;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link InMemoryMultiMetricRepository}.
*
* @author Dave Syer
*/
public class InMemoryMultiMetricRepositoryTests {
private final InMemoryMultiMetricRepository repository =
new InMemoryMultiMetricRepository();
private final InMemoryMultiMetricRepository repository = new InMemoryMultiMetricRepository();
@Test
public void registeredPrefixCounted() {