Skip to content

WebFluxTags defaults uri label to "UNKNOWN" on http_server_request metrics despite path being none empty  #16208

@jrushto1

Description

@jrushto1

http_server_requests metrics uri label shows up as "UNKNOWN" on gateway routes when using spring cloud gateway with spring boot release 2.1.3. This seems to have been introduced between spring boot 2.1.1 and 2.1.2 releases. Sample project here.

http_server_requests_seconds_count{exception="SSLHandshakeException",method="GET",outcome="SERVER_ERROR",status="500",uri="UNKNOWN",} 2.0
http_server_requests_seconds_sum{exception="SSLHandshakeException",method="GET",outcome="SERVER_ERROR",status="500",uri="UNKNOWN",} 1.022870125

Steps to reproduce:

  1. Clone repo
  2. Start Application
  3. curL http://localhost:8080/test-service/200 a couple of times
  4. Go to http://localhost:8080/actuator/prometheus

N.B. The curl command will result in 500 server errors due to separate https routing issue on gateway.

Digging a little deeper and it looks to be a problem with the WebFluxTags#uri() method. In 2.1.1 the method is:

public static Tag uri(ServerWebExchange exchange) {
		PathPattern pathPattern = exchange
				.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
		if (pathPattern != null) {
			return Tag.of("uri", pathPattern.getPatternString());
		}
		HttpStatus status = exchange.getResponse().getStatusCode();
		if (status != null) {
			if (status.is3xxRedirection()) {
				return URI_REDIRECTION;
			}
			if (status == HttpStatus.NOT_FOUND) {
				return URI_NOT_FOUND;
			}
		}
		String path = exchange.getRequest().getPath().value();
		if (path.isEmpty()) {
			return URI_ROOT;
		}
		return Tag.of("uri", path);
	}

where as in 2.1.3 the method is:

	public static Tag uri(ServerWebExchange exchange) {
		PathPattern pathPattern = exchange
				.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
		if (pathPattern != null) {
			return Tag.of("uri", pathPattern.getPatternString());
		}
		HttpStatus status = exchange.getResponse().getStatusCode();
		if (status != null) {
			if (status.is3xxRedirection()) {
				return URI_REDIRECTION;
			}
			if (status == HttpStatus.NOT_FOUND) {
				return URI_NOT_FOUND;
			}
		}
		String path = getPathInfo(exchange);
		if (path.isEmpty()) {
			return URI_ROOT;
		}
		return URI_UNKNOWN;
	}

The default always returns URI_UNKNOWN despite path being not empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions