Photo by Ildefonso Polo on Unsplash
Having Prometheus to use for local test is great. It can be achieved using Prometheus in a docker-compose.
But it could be cool to use it along with integration testing. So let's request Prometheus at the end of the tests.
Prometheus exposes a REST API that can be queried.
Query
Prometheus has at least 2 API that can be queried :
/api/v1/query and /api/v1/query_range .
Using the sample project from previous blog, we can make this call 
http://localhost:9090/api/v1/query?query=delta(dotnet_total_memory_bytes[2h]) that will gives us this response:
{"status":"success","data":{"resultType":"vector","result":[{"metric":{"instance":"app:80","job":"application"},"value":[1604065760.49,"14929036.50833937"]}]}}
Request
Robot Framework has a library that can be leveraged to request REST API and consumes response.
*** Settings ***
Library           RequestsLibrary
Library           SeleniumLibrary
*** Test Cases ***
GET the delta of total memory
    Create Session  prometheus  http://localhost:9090   
    ${resp}=    Get Request     prometheus  /api/v1/query?query=delta(dotnet_total_memory_bytes[2h])
    Should Be Equal As Strings  ${resp.status_code}     200
    Should Be True  ${resp.json()['data']['result']['result'][0]['value'][0]} < 2000000000
    [Teardown]
Hope this helps !
 
 
              
 
    
Top comments (0)