Update `DataSourceHealthContributorAutoConfiguration` so that any
`AbstractRoutingDataSource` beans are still included in the overall
health. Prior to this commit, a regression in Spring Boot 2.2 meant
that if a single routing bean was found an `IllegalArgumentException`
would be thrown.
In Spring Boot 2.1 all `AbstractRoutingDataSource` would be filtered
from the results, but if no results existed the following was returned:
"details": {
"db": {
"status": "UNKNOWN"
},
In Spring Boot 2.2 we now always include routing datasource beans, even
if other non-routing database beans are found. The health details
includes `"routing" : true` to help users disambiguate any results.
Fixes gh-18661
Update `NewRelicProperties` so that the event type sent with each
metric can be configured. An additional `boolean` property has
also been added if the previous behavior using the "meter-name"
is required.
NewRelic's own agents publish metrics to eventTypes aligned with broader
categories. To align with their recommendation the default behavior is
to publish metrics under a "SpringBootSample" category. When doing so,
additional context is provided by including "metricName" and
"metricType" attributes.
See gh-18472
Previously, Maven's default behaviour was relied up which resulted
in the artifact ID being appended to each URL as it was inherited.
This behaviour can only be disabled in Maven 3.6 and later, a version
that we cannot use due to an incompatibility with the Flatten Plugin.
This commit works around Maven's default behaviour by defining
properties for the SCM URL, connection, and developer connection and
then explicitly defining the settings in each pom using these
properties. The explicit definition of the properties in each pom
prevents them being inherited from the parent, thereby disabling the
unwanted appending of the artifact ID to the URL.
Fixes gh-18328
Update `JerseyManagementContextConfiguration` so that customizer beans
are not longer applied. The endpoint resource endpoints are now added
with a registrar bean `@PostConstruct` method.
Prior to this commit, when running the management server on a different
port a `Resource` added by a customizer could be added two different
`ResourceConfig` instance. This breaks the singleton contract expected
by Jersey.
Fixes gh-17801
Co-authored-by: Phillip Webb <pwebb@pivotal.io>
Update `LegacyHealthEndpointCompatibilityConfiguration` to ensure that
the default configuration is only overwritten when the user has
explicitly set new values.
Fixes gh-18354
Add a `show-components` property under `management.endpoint.health` and
`management.endpoint.health.group.<name>` that can be used to change
when components are displayed.
Prior to this commit it was only possible to set `show-details` which
offered an "all or nothing" approach to the resulting JSON. The new
switch allows component information to be displayed whilst still hiding
potentially sensitive details returned from the actual `HealthIndicator`.
Closes gh-15076
Update the health endpoint so the nested components are now exposed
under `components` rather than `details` when v3 of the actuator
REST API is being used.
This distinction helps to clarify the difference between composite
health (health composed of other health components) and health
details (technology specific information gathered by the indicator).
Since this is a breaking change for the REST API, it is only returned
for v3 payloads. Requests made accepting only a v2 response will have
JSON provided in the original form.
Closes gh-17929
Add `ApiVersion` enum that can be injected into actuator endpoints if
they need to support more than one API revision.
Spring MVC, WebFlux and Jersey integrations now detect the API version
based on the HTTP accept header. If the request explicitly accepts a
`application/vnd.spring-boot.actuator.v` media type then the version
is set from the header. If no explicit Spring Boot media type is
accepted then the latest `ApiVersion` is assumed.
A new v3 API revision has also been introduced to allow upcoming health
endpoint format changes. By default all endpoints now consume and
can produce v3, v2 and `application/json` media types.
See gh-17929
Allow legacy actuator endpoint IDs that contain dots to be transparently
migrated to the new format. This update will allow Spring Cloud users
to proactively migrate from endpoints such as `hystrix.stream` to
`hystrixstream`.
Closes gh-18148
Restore `HealthIndicatorRegistry` and `ReactiveHealthIndicatorRegistry`
auto-configured beans with a version that adapts to the new contributor
interfaces.
Closes gh-16903
This commit moves `@ConfigurationProperties` to the `@Bean` factory
method as this is unusual to put it at class level if it's exposed
that way.
As HealthIndicatorProperties has a constructor, this makes sure that
the annotation processor enables JavaBean binding mode.
Fix caching issues in `ApplicationContextRequestMatcher` and allow
subclasses to ignore an application context entirely. Update existing
matcher implementations so that they deal with the management context
correctly.
Prior to this commit, the `ApplicationContextRequestMatcher` would
return a context cached from the first request. It also didn't
provide any way to ignore a context. This meant that if the user was
running the management server on a different port the matching results
could be inconsistent depending on if the first request arrived on
the regular context or the management context. It also meant that we
could not distinguish between the regular context and the management
context when matching.
Closes gh-18012
This commit also changes the request matcher for MVC
endpoints to use an AntPathRequestMatcher instead of an
MvcRequestMatcher. The endpoint is always available
under the mapped endpoint path and this way the same matcher
can be used for both MVC and Jersey.
Fixes gh-17912
Co-authored-by: Phillip Webb <pwebb@pivotal.io>
Move management `ErrorPage` registration from the
`WebMvcEndpointChildContextConfiguration` to
`WebMvcEndpointChildContextConfiguration` and only add it when the
error controller is registered.
Fixes gh-17938
This commit renames ApplicationHealthIndicator to PingHealthIndicator
and changes the auto-configuration so that it is now always configured
by default.
Closes gh-17926
Update the `HealthEndpoint` to support health groups. The
`HealthEndpointSettings` interface has been replaced with
`HealthEndpointGroups` which provides access to the primary group
as well as an optional set of additional groups.
Groups can be configured via properties and may have custom
`StatusAggregator` and `HttpCodeStatusMapper` settings.
Closes gh-14022
Co-authored-by: Stephane Nicoll <snicoll@pivotal.io>
Overhaul `HealthEndpoint` support to make it easier to support health
groups. Prior to this commit the `HealthIndicator` interface was used
for both regular indicators and composite indicators. In addition the
`Health` result was used to both represent individual, system and
composite health. This design unfortunately means that all health
contributors need to be aware of the `HealthAggregator` and could not
easily support heath groups if per-group aggregation is required.
This commit reworks many aspects of the health support in order to
provide a cleaner separation between a `HealthIndicator`and a
composite. The following changes have been made:
- A `HealthContributor` interface has been introduced to represent
the general concept of something that contributes health information.
A contributor can either be a `HealthIndicator` or a
`CompositeHealthContributor`.
- A `HealthComponent` class has been introduced to mirror the
contributor arrangement. The component can be either
`CompositeHealth` or `Health`.
- The `HealthAggregator` interface has been replaced with a more
focused `StatusAggregator` interface which only deals with `Status`
results.
- `CompositeHealthIndicator` has been replaced with
`CompositeHealthContributor` which only provides access to other
contributors. A composite can no longer directly return `Health`.
- `HealthIndicatorRegistry` has been replaced with
`HealthContributorRegistry` and the default implementation now
uses a copy-on-write strategy.
- `HealthEndpoint`, `HealthEndpointWebExtension` and
`ReactiveHealthEndpointWebExtension` now extend a common
`HealthEndpointSupport` class. They are now driven by a
health contributor registry and `HealthEndpointSettings`.
- The `HealthStatusHttpMapper` class has been replaced by a
`HttpCodeStatusMapper` interface.
- The `HealthWebEndpointResponseMapper` class has been replaced
by a `HealthEndpointSettings` strategy. This allows us to move
role related logic and `ShowDetails` to the auto-configure module.
- `SimpleHttpCodeStatusMapper` and `SimpleStatusAggregator`
implementations have been added which are configured via constructor
arguments rather than setters.
- Endpoint auto-configuration has been reworked and the
`CompositeHealthIndicatorConfiguration` class has been replaced
by `CompositeHealthContributorConfiguration`.
- The endpoint JSON has been changed make `details` distinct from
`components`.
See gh-17926
Meta-annotate `ClassPathExclusions` and `ClassPathOverrides` with
so that the `ModifiedClassPathExtension` no longer needs to be
used directly.
See gh-17491
Using a random value for the logfile name caused
the logfile endpoint to return a 404 as the name
was resolved from the environment on every request.
This commit registers a bean for LogFile which is then
used by the logfile endpoint.
Fixes gh-17434
When a request that accepts text/plain is received, the threaddump
endpoint will now return a thread dump in plain text. The format of
this text is modelled after the output produced by JVisualVM when
connecting to a remote process over JMX. Note that this output does
not include all of the information in, for example, JStack's output
as it is not available via Java 8's ThreadInfo API.
Rather than the custom formatting logic, using ThreadInfo's toString()
method was considered but its output is documented as being undefined
and implementation specific. The implementation used while developing
this feature produced output that did not match that of JStack or
JVisualVM and truncated stack traces quite considerably.
At the time of writing the format produced by the endpoint could be
consumed by both Thread Dump Analyzer [1] and https://fastthread.io.
Closes gh-2339
[1] https://github.com/irockel/tda
Apply checkstyle rule to ensure that private and package private
classes do not have unnecessary public methods. Test classes have
also been unified as much as possible to use default scoped
inner-classes.
Closes gh-7316
Since the move to JUnit 5, a number of tests were failing on Windows.
The majority were failing due to open file handles preventing the
clean up of the tests' temporary directory. This commit addresses
these failures by updating the tests to close JarFiles, InputStreams,
OutputStreams etc.
A change has also been made to CachingOperationInvokerTests to make
a flakey test more robust. Due to System.currentTimeMillis() being
less precise on Windows than it is on *nix platforms, the test could
fail as it would not sleep for long enough for the TTL period to have
expired.
Split the JUnit 5 `OutputCapture` class into separate `OutputExtension`
and `CapturedOutput` classes. The JUnit 5 callback methods are now
contained only in the `OutputExtension` class so no longer pollute the
public API that users will interact with.
The `CapturedOutput` class has also been updated to capture System.err
and System.out separately to allow distinct assertions if required.
Closes gh-17029
Refactor `Autotime` from a properties object to an interface and
change the existing metric recording implementations. The `AutoTimer`
interface is a general purpose callback that can be applied to a
`Timer.Builder` to configure it. Autotime properties are now located
in `spring-boot-actuator-autoconfigure` and have become an
implementation of the interface.
Closes gh-17026
This commit merges the conditions for determining if an endpoint is
available in a single condition, deprecating
`ConditionalOnEnabledEndpoint` in the process.
Closes gh-16169
Prior to this commit, the audit auto-configuration provided
an `InMemoryAuditEventRepository` bean. This commit changes the auto-config
so that an `AuditEventRepository` is not provided and instead the auto-config
is conditional on the presence of a `AuditEventRepository` bean. This is done
to encourage the use of a custom implementation of `AuditEventRepository`
since the in-memory one is quite limited and not suitable for production.
A flag is available if the auto-configuration needs to be turned off even
in the presence of a bean.
Closes gh-16110
Prior to this commit, the http trace auto-configuration provided
an `InMemoryHttpTraceRepository` bean. This commit changes the auto-config
so that an `HttpTraceRepository` is not provided and instead the auto-config
is conditional on the presence of a `HttpTraceRepository` bean. This is done
to encourage the use of a custom implementation of `HttpTraceRepository`
since the in-memory one is quite limited and not suitable for production.
A flag is available if the auto-configuration needs to be turned off even
in the presence of a bean.
Closes gh-15039
When `management.metrics.web.server.auto-time-requests` is enabled
(default=true), Spring Boot collects metrics on controller methods even
when they are not annotated with `@Timed`.
When this happens, created metrics are based on the default
`@Timed` configuration and there is no way to customize the
configuration of those auto-timed controller metrics.
This commit adds default configurations to auto-timed requests on both
client and server sides.
See gh-15988
This commit also adds tests to ensure that the child
management context works when lazy initialization is
enabled. Also, it adds a BeanFactoryPostProcessor to
the child context so that the server is created and
listening for requests but other beans in the child
context are not created until requested.
See gh-16184
This commit migrates `AnnotationConfigReactiveWebApplicationContext`
parent to the `GenericApplicationContext` abstraction. Any use of
`AnnotationConfigWebApplicationContext` is also removed as it also
inherits from the `AbstractRefreshableApplicationContext` outdated
hierarchy.
A new `AnnotationConfigServletWebApplicationContext` context is
introduced instead, extending from `GenericApplicationContext` and
providing the counter part of the reactive context for the Servlet-based
web app tests.
See gh-16096
This commit updates CORS handling according to Framework changes
introduced via [1]. It also fixes tests according to the new behavior.
See gh-16410
[1] d27b5d0ab6.
This commit replaces the default Asciidoctor styling with
Spring specific styling.
First, we need to unzip the contents of the Spring Asciidoctor
documentation resources provided by the
`io.spring.docsresources:spring-docs-resources` distribution zip. This
is done in a `/target/refdocs` folder. We then copy all files from
`src/main/asciidoc` to the same location, and then launch the generation
process.
See gh-16326
Update the `CustomEndpointConfiguration` class in
`ScheduledTasksEndpointAutoConfigurationTests` to be package private
so that it can be enhanced by cglib.
Prior to merge commit 361437f4 the class was a lite configuration so
it didn't matter that it was a private class.
Previously, environment binding always happened in a post processor once
the bean has been created. Constructor binding requires to perform the
binding at creating time so this commit performs binding at creation
time if possible.
When this happens, a special `ConfigurationPropertiesBeanDefinition` is
created with a supplier that invokes the binder. To avoid a case where
a bean is processed twice, the post-processor now ignores any bean that
has already been bound to the environment.
Closes gh-8762
Co-authored-by: Madhura Bhave <mbhave@pivotal.io>
This commit adds the newly introduced `@ConditionalOnExposedEndpoint`
conditional annotation to all auto-configured `Endpoint` in Actuator.
With that change, `EndPoint` instances and related infrastructure will
only be created when they are meant to be exposed and used. This will
save CPU and memory resources when Actuator is present.
Closes gh-16093
Prior to this commit, Actuator `Endpoint` instantiations would be
guarded by `@ConditionalOnEnabledEnpoint` condition annotations. This
feature saves resources as disabled endpoints aren't unnecessarily
instantiated.
By default, only `"health"` and `"info"` endpoints are exposed over the
web and all endpoints are exposed over JMX.
As of gh-16090, JMX is now disabled by default. This is an opportunity
to avoid instantiating endpoints if they won't be exposed at all, which
is more likely due to the exposure defaults.
This commit adds a new `@ConditionalOnExposedEndpoint` conditional
annotation that checks the `Environment` for configuration properties
under `"management.endpoints.web.exposure.*"` and
`"management.endpoints.jmx.exposure.*"`. In the case of JMX, an
additional check is perfomed, checking that JMX is enabled first.
The rules implemented in the condition itself are following the ones
described in `ExposeExcludePropertyEndpointFilter`.
See gh-16093
This commit switches the default value for the `spring.jmx.enabled`
configuration property.
JMX is now disabled by default and can be enabled with
`spring.jmx.enabled=true`.
Closes gh-16090
This commit splits the management context configuration for jersey
into two separate configurations depending on if the type is SAME or
CHILD. The configuration for the SAME context should only kick in if
there is no existing ResourceConfig bean.
Fixes gh-15891
This commit also ensures that Jersey-based actuator endpoints are
available before the user has configured a `ResourceConfig` bean
Fixes gh-15625
Fixes gh-15877