Skip to content

Commit e6a9cd5

Browse files
committed
Add new property for GatewayTagsProvider
Avoid conflict with the ability to add custom tags. Fixes #4007
1 parent 464bf02 commit e6a9cd5

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

docs/modules/ROOT/pages/spring-cloud-gateway/global-filters.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ This filter adds a timer metric named `spring.cloud.gateway.requests` with the f
5252
* `httpStatusCode`: The HTTP Status of the request returned to the client.
5353
* `httpMethod`: The HTTP method used for the request.
5454

55-
In addition, through the `spring.cloud.gateway.metrics.tags.path.enabled` property (by default, `false`), you can activate an extra metric with the path tag:
55+
In addition, through the `spring.cloud.gateway.metrics.path-tags.enabled` property (by default, `false`), you can activate an extra metric with the path tag:
5656

5757
* `path`: The path of the request.
5858

59+
WARNING: The property `spring.cloud.gateway.metrics.tags.path.enabled` will also add the above metric but has the side effect of the value ending up as a tag. This property is deprecated and will be removed in a future release.
60+
5961
These metrics are then available to be scraped from `/actuator/metrics/spring.cloud.gateway.requests` and can be easily integrated with Prometheus to create a link:images/gateway-grafana-dashboard.jpeg[Grafana] link:gateway-grafana-dashboard.json[dashboard].
6062
You can also alarm with these useful metrics to take an example from link:gateway-alarming.adoc[alarming-template].
6163

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GatewayMetricsAutoConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
3333
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
3434
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
35+
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
3536
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3637
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3738
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
@@ -69,8 +70,10 @@ public GatewayHttpTagsProvider gatewayHttpTagsProvider() {
6970
return new GatewayHttpTagsProvider();
7071
}
7172

73+
// TODO: remove support for the property `metrics.tags.path.enabled` in the next major
7274
@Bean
73-
@ConditionalOnProperty(name = GatewayProperties.PREFIX + ".metrics.tags.path.enabled")
75+
@ConditionalOnExpression("'${" + GatewayProperties.PREFIX + ".metrics.tags.path.enabled:false}' == 'true' || '${"
76+
+ GatewayProperties.PREFIX + ".metrics.path-tags-provider.enabled:false}' == 'true'")
7477
public GatewayPathTagsProvider gatewayPathTagsProvider() {
7578
return new GatewayPathTagsProvider();
7679
}

spring-cloud-gateway-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,22 @@
436436
"type": "java.lang.Boolean",
437437
"description": "If RedisRouteDefinitionRepository should be enabled.",
438438
"defaultValue": "true"
439+
},
440+
{
441+
"name": "spring.cloud.gateway.metrics.tags.path.enabled",
442+
"type": "java.lang.Boolean",
443+
"description": "Enables the gateway path tag provider.",
444+
"defaultValue": "false",
445+
"deprecation": {
446+
"reason": "Setting this property to true will cause the path tag to be added to all metrics.",
447+
"replacement": "spring.cloud.gateway.metrics.path-tags-provider.enabled"
448+
}
449+
},
450+
{
451+
"name": "spring.cloud.gateway.metrics.path-tags-provider.enabled",
452+
"type": "java.lang.Boolean",
453+
"description": "Enables the gateway path tag provider.",
454+
"defaultValue": "false"
439455
}
440456
]
441457
}

0 commit comments

Comments
 (0)