Hi Pierre - hoping that this thread is not too stale...
I have a similar requirement (needing to check prometheus metrics during the test) and I've tried this approach, but I'm getting the response:
16:13:07.867 [gatling-http-thread-1-2] WARN i.gatling.http.ahc.ResponseProcessor - Request 'get prometheus metric - systemload_average' failed: jsonPath($..value[1]).find.greaterThan(0.0), but actually can't compare nothing and 0.0
1.67
My request looks like this (developing in Intellij):
def getPrometheusMetric(metricName: String, namespace: String) = scenario(s"get prometheus metric - $metricName")
.exec(http(s"get prometheus metric - $metricName")
.get(s"/api/v1/query")
.queryParam("query", s"$metricName{namespace=\"$namespace\"}")
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.check(status.is(HttpStatus.SC_OK))
.check(bodyString.saveAs("sBodyString"))
.check(jsonPath("$..value[1]").saveAs("metricValue"))
.check(jsonPath("$..value[1]").ofType[Double].greaterThan(0.0))
)
.exec { session =>
println( session( "metricValue" ).as[String] )
session}
The error message seems to indicate that there is nothing returned by the json path, but I can see that the metric is being collected because it is printed out immediately after the check (1.67)
This has been driving me mad for weeks...
Thanks in advance.