Как сделать так, чтобы метрики клиента RestTemplate при весенней загрузке не создавали новый тег для параметров запроса - PullRequest
0 голосов
/ 23 марта 2020

У меня есть приложение весенней загрузки, которое определяет бин RestTemplate следующим образом:

@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
    return builder.build();
}

Кроме того, добавляются spring-boot-starter-actuator и io.micrometer:micrometer-registry-prometheus.

Когда Я использую введенный RestTemplate следующим образом:

@Autowired
private RestTemplate restTemplate;

private String uriTemplate = "http://my.domain.com/bookstore-api/books";

public List<Book> getBooksByAuthor(String author) {
    // create URI for "http://my.domain.com/bookstore-api/books?author={authorId}"
    UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder
            .fromUriString(uriTemplate)
            .queryParam("author", author);

    // make the GET 
    ResponseEntity<Book[]> responseEntity = restTemplate.getForEntity(uriComponentsBuilder.toUriString(),Book[].class);

    // rest ommitted for brevity
}

Когда вызывается getBooksByAuthor("Tolkien"), мы можем нажать /metrics/prometheus и увидеть следующее:

http_client_requests_seconds_count{clientName="my.domain.com",method="GET",status="200",uri="/bookstore-api/books?author=Tolkien",} 2.0
http_client_requests_seconds_sum{clientName="my.domain.com",method="GET",status="200",uri="/bookstore-api/books?author=Tolkien",} 0.253227898

Это было бы хорошо, за исключением того, что существует множество авторов, и в итоге я получу исключение «слишком много тегов».

Я бы предпочел иметь следующее (аналогично тому, как переменные пути получают шаблон):

http_client_requests_seconds_count{clientName="my.domain.com",method="GET",status="200",uri="/bookstore-api/books?author={author}",} 2.0
http_client_requests_seconds_sum{clientName="my.domain.com",method="GET",status="200",uri="/bookstore-api/books?author={author}",} 0.253227898

Этого можно добиться, изменив способ использования UriComponentsBuilder? Самое близкое, что я нашел, - это определить мой собственный RestTemplateExchangeTagsProvider и переопределить значение по умолчанию, чтобы сделать какую-то безумную замену регулярных выражений.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...