Impossible to divide two Loki requests

Hello,

  • Grafana 11.0.0
  • Source : Loki 3.0.0

I can’t solve a puzzle about a simple operation: dividing two query results between them.

  • Query A (total requests with http_code >= 500) :
sum(
    count_over_time({job="apache"}
    | pattern `<_> <_> <_> <_> <_> <_> <_> [<_>] "<_> <_> <_>" <http_code> <_> "<_>" "<_>" <_> <_> <_>`
    | http_code >= 500
    [$__auto]
    )
)

=> This one gives me a coherent result for total 5xx

  • Query B (total apache requests / 100) :
sum(
    count_over_time({job="apache"}
    [$__auto]
    )
)
/ 100

=> This one also gives me a coherent result, without any problem to do the division.

  • Query C (percentage of 5xx errors) :
(
    sum(
        count_over_time({job="apache"}
        | pattern `<_> <_> <_> <_> <_> <_> <_> [<_>] "<_> <_> <_>" <http_code> <_> "<_>" "<_>" <_> <_> <_>`
        | http_code >= 500
        [$__auto]
        )
    )
)

/

(
    sum(
        count_over_time({job="apache"}
        [$__auto]
        )
    )
/ 100
)

When I try to divide the result of A by B, I always get an error: parse error at line 6, col 5: syntax error: unexpected SUM, expecting IDENTIFIER or (.
What’s more, I can’t apply a calculation to my A query with this error: parse error at line 4, col 41: syntax error: unexpected SUM

I’m sure I’m doing something wrong, but I don’t understand the difference between query A and B that would explain why I can’t do division on A, and why query C doesn’t work. I’m a beginner on Grafana.

Thanks for your help and sorry for my English!