Creating a Grafana query to aggregate metrics for multiple URLs using variables

Hello,

I have a PromQL query that calculates the average request duration for a specific URI pattern:

avg(http_client_requests_seconds_sum{client_name="data-api.eu.bio-beat.cloud", uri=~"/yarinapi-get-measurement?.*"} / http_client_requests_seconds_count{client_name="data-api.eu.bio-beat.cloud", uri=~"/yarinapi-get-measurement?.*"})

The query works as expected for a single URI pattern. However, I have 20 similar URI patterns, and I want to display the results for all of them in the same panel, line per URI. Creating multiple queries with different URIs in the same panel is not ideal because it will be difficult to manage.

What I thought about is to use Grafana variables to store all my URI’s and then use a single query to display results for all the URLs. To achieve this, I tried creating a variable named uris with multiple URIs, for example: /yarinapi-get-measurement?, /dolevapi-get-id?, and running the following query:

avg(http_client_requests_seconds_sum{client_name="data-api.eu.bio-beat.cloud", uri=~"${uris}.*"} / http_client_requests_seconds_count{client_name="data-api.eu.bio-beat.cloud", uri=~"${uris}.*"})

However, this results in a single line on the panel, representing the average of all the URLs, rather than a line per URI.

When I tried adding by (uri) to the query, it displayed too many graphs, one per device/datetime, which is the suffix of my URI that I want to aggregate, of course.

Can you please help me create a query using variables in Grafana that would display a separate line for each URL on the same panel without overloading the panel with graphs for each device/datetime? Any guidance would be greatly appreciated.

Thank you!