Problem with Lab: Building PromQL Queries exercise

"Challenge
How would you query for the amount of error requests encountered by all the different API service paths?

Use the Explore page to write and test your query. Then save your answer in /home/grafana/answer.txt."

I can use in the metric browser the follow query: http_request_duration_seconds_count{service=“api”,status_code=~“401|404|500”}

but in the grot checker said that “service” label not found.

image

welcome @josemagarrido to the community.
First check what labels exist on your metric:
promql

http_request_duration_seconds_count

Also note your query uses service=~“.api.” → dots in regex match any character. Use exact match service=“api” instead.

Expand any result in Explore to see exact label names.
If service label exists:
promql

sum by (service, path, status_code) (
  http_request_duration_seconds_count{service="api", status_code=~"4..|5.."}
)

If Grot checker says service label not found:
promql

sum by (path, status_code) (
  http_request_duration_seconds_count{status_code=~"4..|5.."}
)

status_code=~“4..|5..” → catches all 4xx and 5xx errors automatically, better than hardcoding 401|404|500
sum by (path, status_code) → groups by API path showing per-endpoint error counts


bash

echo 'your_working_query' > /home/grafana/answer.txt