DEV Community

Cover image for Request Prometheus API from Robot Framework
Antoine
Antoine

Posted on

Request Prometheus API from Robot Framework

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"]}]}}
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

Hope this helps !

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs