Fix bug where metrics fail if actuator is not added as a project dependency
This commit is contained in:
@@ -886,15 +886,17 @@ spring:
|
||||
|
||||
=== Gateway Metrics Filter
|
||||
|
||||
The Gateway Metrics Filter runs as long as the property `spring.cloud.gateway.metrics.enabled` is not set to `false`. This filter adds a timer metric named "gateway.requests" with the following tags:
|
||||
To enable Gateway Metrics add spring-boot-starter-actuator as a project dependency. Then, by default, the Gateway Metrics Filter runs as long as the property `spring.cloud.gateway.metrics.enabled` is not set to `false`. This filter adds a timer metric named "gateway.requests" with the following tags:
|
||||
|
||||
* `routeId`: The route id
|
||||
* `routeUri`: The URI that the API will be routed to
|
||||
* `outcome` |Outcome as classified by link:https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/HttpStatus.Series.html[HttpStatus.Series]
|
||||
* `outcome`: Outcome as classified by link:https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/HttpStatus.Series.html[HttpStatus.Series]
|
||||
* `status`: Http Status of the request returned to the client
|
||||
|
||||
These metrics are then available to be scraped from ``/actuator/metrics/gateway.requests`` and can be easily integated with Prometheus to create a link:images/gateway-grafana-dashboard.jpeg[Grafana] link:gateway-grafana-dashboard.json[dashboard].
|
||||
|
||||
NOTE: To enable the pometheus endpoint add micrometer-registry-prometheus as a project dependency.
|
||||
|
||||
=== Making An Exchange As Routed
|
||||
|
||||
After the Gateway has routed a `ServerWebExchange` it will mark that exchange as "routed" by adding `gatewayAlreadyRouted`
|
||||
|
||||
@@ -17,12 +17,7 @@
|
||||
|
||||
package org.springframework.cloud.gateway.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -41,6 +36,8 @@ import rx.RxReactiveStreams;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -51,7 +48,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.web.server.WebServerException;
|
||||
import org.springframework.cloud.gateway.actuate.GatewayControllerEndpoint;
|
||||
import org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter;
|
||||
import org.springframework.cloud.gateway.filter.ForwardPathFilter;
|
||||
@@ -128,7 +124,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.web.reactive.DispatcherHandler;
|
||||
@@ -147,7 +142,9 @@ import static org.springframework.cloud.gateway.config.HttpClientProperties.Pool
|
||||
@ConditionalOnProperty(name = "spring.cloud.gateway.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties
|
||||
@AutoConfigureBefore(HttpHandlerAutoConfiguration.class)
|
||||
@AutoConfigureAfter({GatewayLoadBalancerClientAutoConfiguration.class, GatewayClassPathWarningAutoConfiguration.class})
|
||||
@AutoConfigureAfter({ GatewayLoadBalancerClientAutoConfiguration.class,
|
||||
GatewayClassPathWarningAutoConfiguration.class, MetricsAutoConfiguration.class,
|
||||
CompositeMeterRegistryAutoConfiguration.class })
|
||||
@ConditionalOnClass(DispatcherHandler.class)
|
||||
public class GatewayAutoConfiguration {
|
||||
|
||||
@@ -341,15 +338,18 @@ public class GatewayAutoConfiguration {
|
||||
return new XForwardedHeadersFilter();
|
||||
}
|
||||
|
||||
|
||||
// GlobalFilter beans
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "spring.cloud.gateway.metrics.enabled", matchIfMissing = true)
|
||||
public GatewayMetricsFilter gatewayMetricFilter(MeterRegistry meterRegistry) {
|
||||
return new GatewayMetricsFilter(meterRegistry);
|
||||
@Configuration
|
||||
@ConditionalOnBean(MeterRegistry.class)
|
||||
protected static class MetricsConfig {
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "spring.cloud.gateway.metrics.enabled", matchIfMissing = true)
|
||||
public GatewayMetricsFilter gatewayMetricFilter(MeterRegistry meterRegistry) {
|
||||
return new GatewayMetricsFilter(meterRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public AdaptCachedBodyGlobalFilter adaptCachedBodyGlobalFilter() {
|
||||
return new AdaptCachedBodyGlobalFilter();
|
||||
|
||||
@@ -24,6 +24,12 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<exclusions> <!-- exclude metrics to verify that gateway doesn't fall over when it is not available -->
|
||||
<exclusion>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
Reference in New Issue
Block a user