From 5938c967a30c5a82f99115bb5ecd8d032ca8c0df Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 8 Jul 2015 12:01:19 -0700 Subject: [PATCH] Polish --- ...tWebMvcManagementContextConfiguration.java | 9 +- .../boot/actuate/endpoint/HealthEndpoint.java | 4 +- .../export/MetricExportProperties.java | 84 +++++++++---------- .../redis/AggregateMetricsConfiguration.java | 1 + 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfiguration.java index 0a84d3229bd..2b71dbb2369 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfiguration.java @@ -45,6 +45,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; +import org.springframework.core.env.Environment; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -170,20 +171,22 @@ public class EndpointWebMvcManagementContextConfiguration { } private static class LogFileCondition extends SpringBootCondition { + @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - String config = context.getEnvironment().resolvePlaceholders( - "${logging.file:}"); + Environment environment = context.getEnvironment(); + String config = environment.resolvePlaceholders("${logging.file:}"); if (StringUtils.hasText(config)) { return ConditionOutcome.match("Found logging.file: " + config); } - config = context.getEnvironment().resolvePlaceholders("${logging.path:}"); + config = environment.resolvePlaceholders("${logging.path:}"); if (StringUtils.hasText(config)) { return ConditionOutcome.match("Found logging.path: " + config); } return ConditionOutcome.noMatch("Found no log file configuration"); } + } } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java index 96f8f1325ba..22f4102dcda 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java @@ -61,8 +61,8 @@ public class HealthEndpoint extends AbstractEndpoint { } /** - * Time to live for cached result. This is particularly useful to cache the - * result of this endpoint to prevent a DOS attack if it is accessed anonymously. + * Time to live for cached result. This is particularly useful to cache the result of + * this endpoint to prevent a DOS attack if it is accessed anonymously. * @return time to live in milliseconds (default 1000) */ public long getTimeToLive() { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java index aacfdbf176f..38fff856499 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java @@ -83,10 +83,6 @@ public class MetricExportProperties extends TriggerProperties { return this.redis; } - public void setRedis(Redis redis) { - this.redis = redis; - } - public Aggregate getAggregate() { return this.aggregate; } @@ -95,6 +91,10 @@ public class MetricExportProperties extends TriggerProperties { this.aggregate = aggregate; } + public void setRedis(Redis redis) { + this.redis = redis; + } + /** * Find a matching trigger configuration. * @param name the bean name to match @@ -109,6 +109,44 @@ public class MetricExportProperties extends TriggerProperties { return this; } + public static class Aggregate { + + /** + * Prefix for global repository if active. Should be unique for this JVM, but most + * useful if it also has the form "a.b" where "a" is unique to this logical + * process (this application) and "b" is unique to this physical process. If you + * set spring.application.name elsewhere, then the default will be in the right + * form. + */ + private String prefix = ""; + + /** + * Pattern that tells the aggregator what to do with the keys from the source + * repository. The keys in the source repository are assumed to be period + * separated, and the pattern is in the same format, e.g. "d.d.k.d". Here "d" + * means "discard" and "k" means "keep" the key segment in the corresponding + * position in the source. + */ + private String keyPattern = ""; + + public String getPrefix() { + return this.prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getKeyPattern() { + return this.keyPattern; + } + + public void setKeyPattern(String keyPattern) { + this.keyPattern = keyPattern; + } + + } + public static class Redis { /** @@ -161,42 +199,4 @@ public class MetricExportProperties extends TriggerProperties { } - public static class Aggregate { - - /** - * Prefix for global repository if active. Should be unique for this JVM, but most - * useful if it also has the form "a.b" where "a" is unique to this logical - * process (this application) and "b" is unique to this physical process. If you - * set spring.application.name elsewhere, then the default will be in the right - * form. - */ - private String prefix = ""; - - /** - * Pattern that tells the aggregator what to do with the keys from the source - * repository. The keys in the source repository are assumed to be period - * separated, and the pattern is in the same format, e.g. "d.d.k.d". Here "d" - * means "discard" and "k" means "keep" the key segment in the corresponding - * position in the source. - */ - private String keyPattern = ""; - - public String getPrefix() { - return this.prefix; - } - - public void setPrefix(String prefix) { - this.prefix = prefix; - } - - public String getKeyPattern() { - return this.keyPattern; - } - - public void setKeyPattern(String keyPattern) { - this.keyPattern = keyPattern; - } - - } - } diff --git a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/AggregateMetricsConfiguration.java b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/AggregateMetricsConfiguration.java index 163f2c2289a..835257e2c6c 100644 --- a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/AggregateMetricsConfiguration.java +++ b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/AggregateMetricsConfiguration.java @@ -52,4 +52,5 @@ public class AggregateMetricsConfiguration { repository.setKeyPattern(this.export.getAggregate().getKeyPattern()); return repository; } + }