0

I'm trying to send a complex query http://myserver:1234/api/v1/query?query=(sum(cluster_health{Component='kafka'}))/count(cluster_health{Component='kafka'})";

java.lang.IllegalArgumentException: Not enough variable values available to expand 'Component=\'kafka\''

I read about this Exception and found that

  1. in Using RestTemplate in Spring. Exception- Not enough variables available to expand It was discussed to use POST to handle complex queries. How do I put the query in request body? I tried a few ways but always got bad data reply.

  2. Using {sort} and define sort string with special characters How would that work with WebClient? I tried the following and it did not work.

    String DPCOMP="{Component="kafka"}";

    Mono responseMono = this.webClient.get() .uri(uriBuilder -> uriBuilder .queryParam("query", "(sum(sa_cluster_health{DPCOMP}))", DPCOMP) .build()) .retrieve() .bodyToMono(PrometheusResponse.class);

Thanks.

Jin Ma
  • 169
  • 2
  • 12
  • tried this https://stackoverflow.com/questions/58178910/spring-webclient-illegalargumentexception-not-enough-variables-to-expand-comm it did not work for me – Jin Ma Oct 09 '21 at 00:23

1 Answers1

0

I eventually make it work by implementing both:

  1. disable Encoding (setting to NONE)
  2. use askii code (%ascii_code) in pace for all the ( ) / { } ' " in the uri and it worked. Ascii code can be obtained from https://www.rapidtables.com/code/text/ascii-table.html
Jin Ma
  • 169
  • 2
  • 12