Skip to content

Commit b7695dc

Browse files
Rename gateway client observation metric to avoid WebClient conflict
Renames DefaultGatewayObservationConvention's metric from 'http.client.requests' to 'spring.cloud.gateway.http.client.requests' so it no longer collides with Spring Web's DefaultClientRequestObservationConvention, which uses the same name with a different low-cardinality label set and causes Prometheus to drop one of the two series. Fixes gh-3153 Signed-off-by: JooYoung Jung <143606756+LivingLikeKrillin@users.noreply.github.com>
1 parent 15bd55a commit b7695dc

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

spring-cloud-gateway-server-webflux/src/main/java/org/springframework/cloud/gateway/filter/headers/observation/DefaultGatewayObservationConvention.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public KeyValues getHighCardinalityKeyValues(GatewayContext context) {
7272

7373
@Override
7474
public String getName() {
75-
return "http.client.requests";
75+
return "spring.cloud.gateway.http.client.requests";
7676
}
7777

7878
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2013-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.gateway.filter.headers.observation;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
23+
class DefaultGatewayObservationConventionTests {
24+
25+
@Test
26+
void getName_returnsSpringCloudGatewayPrefixedName() {
27+
assertThat(DefaultGatewayObservationConvention.INSTANCE.getName())
28+
.isEqualTo("spring.cloud.gateway.http.client.requests");
29+
}
30+
31+
}

spring-cloud-gateway-server-webflux/src/test/java/org/springframework/cloud/gateway/filter/headers/observation/ObservedHttpHeadersFilterTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ public SampleTestRunnerConsumer yourCode() throws Exception {
9999
.hasTag("spring.cloud.gateway.route.uri", "http://localhost:8080/")
100100
.hasTag("spring.cloud.gateway.route.id", "foo"));
101101
MeterRegistryAssert.then(meterRegistry)
102-
.hasTimerWithNameAndTags("http.client.requests",
102+
.hasTimerWithNameAndTags("spring.cloud.gateway.http.client.requests",
103103
Tags.of("spring.cloud.gateway.route.id", "foo", "error", "none", "http.method", "GET",
104104
"http.status_code", "200", "spring.cloud.gateway.route.uri", "http://localhost:8080/"))
105-
.hasMeterWithNameAndTags("http.client.requests.active", Tags.of("spring.cloud.gateway.route.id", "foo",
106-
"http.method", "GET", "spring.cloud.gateway.route.uri", "http://localhost:8080/"));
105+
.hasMeterWithNameAndTags("spring.cloud.gateway.http.client.requests.active",
106+
Tags.of("spring.cloud.gateway.route.id", "foo", "http.method", "GET",
107+
"spring.cloud.gateway.route.uri", "http://localhost:8080/"));
107108
};
108109
}
109110

0 commit comments

Comments
 (0)