1

I'm trying to mimic metrics in Prometheus using Push Gateway. When I'm passing these values in PostMan, I'm able to see the entry of metrics in Push Gateway. But, when I'm trying the same with Rest Assured, it is not working. I'm getting error as RESPONSE :text format parsing error in line 1: invalid metric name.

Anyone has any idea?

public void sendRequestsToPushGateway()  {
        System.out.println("Send request to Push Gateway");

        validatableResponse = given().contentType(ContentType.TEXT)
                .body("\"container_cpu_cfs_throttled_seconds_total\"" + "{" + "\"container_name\" = \"test\", "
                        + "\"pod_name\"=\"test-stable\"," + "\"exported_namespace\"=\"demo\"" + "} "
                        + "100.0\n")
                .when()
                .put("http://prometheus-pushgateway.eu-mesh-poc-aws.dev.io/metrics/job/cpusaturationtest/instance/3")
                .then();

        String RESPONSE = validatableResponse.extract().asString();
        System.out.println("RESPONSE :" + RESPONSE);
    }
ndclt
  • 2,590
  • 2
  • 12
  • 26
Vibha Singh
  • 29
  • 1
  • 8

2 Answers2

4

Given the code, the page content will be:

"container_cpu_cfs_throttled_seconds_total"{"container_name" = "test", "pod_name"="test-stable","exported_namespace"="demo"} 100.0

There are too many " and spaces. The content should be:

container_cpu_cfs_throttled_seconds_total{container_name="test",pod_name="test-stable",exported_namespace="demo"} 100.0

You can refer to the Prometheus textfile format.

Michael Doubez
  • 5,937
  • 25
  • 39
0

I got the solution. I have to remove extra "" from tags like container_name, pod_name & exported_namespace

validatableResponse = given().contentType(ContentType.TEXT)
                .body("container_cpu_cfs_throttled_seconds_total"
                        + "{container_name = \"test\", pod_name =\"test-stable\",exported_namespace=\"demo\"}"
                        + "100.0\n")
                .when()
                .put("http://prometheus-pushgateway.eu-mesh-poc-aws.dev.io/metrics/job/cpusaturationtest/instance/3")
                .then();
Vibha Singh
  • 29
  • 1
  • 8