PCA (Prometheus Certified Associate) sample exam question with answer 89
Question:
Which of the following PromQL expressions will return data for a metric named http_requests_total with a status_code label equal to 200 or 400?
- http_requests_total{status_code=~"200|400"}
- http_requests_total{status_code="200" OR status_code="400"}
- http_requests_total{status_code="200"} OR http_requests_total{status_code="400"}
- http_requests_total{status_code="200"} AND http_requests_total{status_code="400"}
Answer:
A - The =~ operator allows for regular expression matching, which in this case matches the status_code label to either 200 or 400.
Option B is incorrect because it uses the OR keyword, which is not a valid operator in PromQL.
Option C is incorrect because it uses the OR operator between two different metric selectors, which is not supported in PromQL.
Option D is incorrect because it uses the AND operator, which requires both conditions to be true simultaneously, which is not possible in this case