Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
60a76ce6
Commit
60a76ce6
authored
Apr 21, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Update validation of Micrometer configuration"
See gh-21067
parent
95798265
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
36 deletions
+28
-36
ValidationFailureAnalyzer.java
...uate/autoconfigure/metrics/ValidationFailureAnalyzer.java
+11
-13
GangliaProperties.java
...toconfigure/metrics/export/ganglia/GangliaProperties.java
+8
-7
PushRegistryPropertiesConfigAdapter.java
...xport/properties/PushRegistryPropertiesConfigAdapter.java
+0
-5
ValidationFailureAnalyzerTests.java
...autoconfigure/metrics/ValidationFailureAnalyzerTests.java
+6
-7
GangliaPropertiesTests.java
...figure/metrics/export/ganglia/GangliaPropertiesTests.java
+2
-1
WavefrontPropertiesTests.java
...re/metrics/export/wavefront/WavefrontPropertiesTests.java
+1
-3
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/ValidationFailureAnalyzer.java
View file @
60a76ce6
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,31 +16,29 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
;
import
io.micrometer.core.instrument.config.validate.Validated.Invalid
;
import
io.micrometer.core.instrument.config.validate.ValidationException
;
import
org.springframework.boot.diagnostics.AbstractFailureAnalyzer
;
import
org.springframework.boot.diagnostics.FailureAnalysis
;
import
java.util.stream.Collectors
;
/**
* An {@link AbstractFailureAnalyzer} that performs analysis of failures caused by a
* {@link ValidationException}.
*
* @author Andy Wilkinson
*/
class
ValidationFailureAnalyzer
extends
AbstractFailureAnalyzer
<
ValidationException
>
{
class
ValidationFailureAnalyzer
extends
AbstractFailureAnalyzer
<
ValidationException
>
{
@Override
protected
FailureAnalysis
analyze
(
Throwable
rootFailure
,
ValidationException
cause
)
{
String
description
=
cause
.
getValidation
().
failures
().
stream
()
.
map
(
failure
->
"management.metrics.export."
+
failure
.
getProperty
()
+
" was '"
+
(
failure
.
getValue
()
==
null
?
"null"
:
failure
.
getValue
().
toString
())
+
"' but it "
+
failure
.
getMessage
()
+
"."
)
.
collect
(
Collectors
.
joining
(
"\n"
));
return
new
FailureAnalysis
(
description
,
"Update your application to provide the missing configuration."
,
cause
);
StringBuilder
description
=
new
StringBuilder
(
String
.
format
(
"Invalid Micrometer configuration detected:%n"
));
for
(
Invalid
<?>
failure
:
cause
.
getValidation
().
failures
())
{
description
.
append
(
String
.
format
(
"%n - management.metrics.export.%s was '%s' but it %s"
,
failure
.
getProperty
(),
failure
.
getValue
(),
failure
.
getMessage
()));
}
return
new
FailureAnalysis
(
description
.
toString
(),
"Update your application to correct the invalid configuration."
,
cause
);
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaProperties.java
View file @
60a76ce6
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import
info.ganglia.gmetric4j.gmetric.GMetric
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.DeprecatedConfigurationProperty
;
/**
* {@link ConfigurationProperties @ConfigurationProperties} for configuring Ganglia
...
...
@@ -46,10 +47,7 @@ public class GangliaProperties {
/**
* Base time unit used to report rates.
*
* @deprecated No longer used by Micrometer.
*/
@Deprecated
private
TimeUnit
rateUnits
;
/**
...
...
@@ -59,10 +57,7 @@ public class GangliaProperties {
/**
* Ganglia protocol version. Must be either 3.1 or 3.0.
*
* @deprecated No longer used by Micrometer.
*/
@Deprecated
private
String
protocolVersion
;
/**
...
...
@@ -102,10 +97,13 @@ public class GangliaProperties {
this
.
step
=
step
;
}
@Deprecated
@DeprecatedConfigurationProperty
(
reason
=
"No longer used by Micormeter"
)
public
TimeUnit
getRateUnits
()
{
return
this
.
rateUnits
;
}
@Deprecated
public
void
setRateUnits
(
TimeUnit
rateUnits
)
{
this
.
rateUnits
=
rateUnits
;
}
...
...
@@ -118,10 +116,13 @@ public class GangliaProperties {
this
.
durationUnits
=
durationUnits
;
}
@Deprecated
@DeprecatedConfigurationProperty
(
reason
=
"No longer used by Micormeter"
)
public
String
getProtocolVersion
()
{
return
this
.
protocolVersion
;
}
@Deprecated
public
void
setProtocolVersion
(
String
protocolVersion
)
{
this
.
protocolVersion
=
protocolVersion
;
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/PushRegistryPropertiesConfigAdapter.java
View file @
60a76ce6
...
...
@@ -36,11 +36,6 @@ public abstract class PushRegistryPropertiesConfigAdapter<T extends PushRegistry
super
(
properties
);
}
@Override
public
String
prefix
()
{
return
null
;
}
@Override
public
String
get
(
String
k
)
{
return
null
;
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ValidationFailureAnalyzerTests.java
View file @
60a76ce6
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -39,12 +39,11 @@ class ValidationFailureAnalyzerTests {
@Test
void
analyzesMissingRequiredConfiguration
()
{
FailureAnalysis
analysis
=
new
ValidationFailureAnalyzer
()
.
analyze
(
createFailure
(
MissingAccountIdConfiguration
.
class
));
.
analyze
(
createFailure
(
MissingAccountId
AndApiKey
Configuration
.
class
));
assertThat
(
analysis
).
isNotNull
();
assertThat
(
analysis
.
getDescription
()).
isEqualTo
(
"management.metrics.export.newrelic.apiKey was 'null' but it is required when publishing to Insights API.\n"
+
"management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API."
);
assertThat
(
analysis
.
getAction
()).
isEqualTo
(
"Update your application to provide the missing configuration."
);
assertThat
(
analysis
.
getDescription
()).
isEqualTo
(
String
.
format
(
"Invalid Micrometer configuration detected:%n%n"
+
" - management.metrics.export.newrelic.apiKey was 'null' but it is required when publishing to Insights API%n"
+
" - management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API"
));
}
private
Exception
createFailure
(
Class
<?>
configuration
)
{
...
...
@@ -58,7 +57,7 @@ class ValidationFailureAnalyzerTests {
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
MissingAccountIdConfiguration
{
static
class
MissingAccountId
AndApiKey
Configuration
{
@Bean
NewRelicMeterRegistry
meterRegistry
()
{
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesTests.java
View file @
60a76ce6
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class
GangliaPropertiesTests
{
@Test
@SuppressWarnings
(
"deprecation"
)
void
defaultValuesAreConsistent
()
{
GangliaProperties
properties
=
new
GangliaProperties
();
GangliaConfig
config
=
GangliaConfig
.
DEFAULT
;
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesTests.java
View file @
60a76ce6
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,14 +16,12 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
export
.
wavefront
;
import
io.micrometer.core.instrument.config.validate.ValidationException
;
import
io.micrometer.wavefront.WavefrontConfig
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesTests
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatThrownBy
;
/**
* Tests for {@link WavefrontProperties}.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment