How to use Arithmetic Binary Operators for raw values in Loki's Log record?

How can I use Arithmetic Binary Operators in raw Loki row data?

For example, I have row with JSON {"total_duration_sec": 123, "total_items": 41} and need to build graph by “total_duration_sec / total_items” formula.

I can build query like this:

avg_over_time({job="my-job"} | json | total_duration_sec [$__interval])
avg_over_time({job="my-job"} | json | total_items [$__interval])

But it will give me wrong results, because of averaging the value in each interval, so we will receive the avg(total_duration_sec) / avg(total_items), instead of avg(total_duration_sec / total_items)!

So I need to have something like this:

  ({job="my-job"} | json | total_duration_sec)
  ({job="my-job"} | json | total_items)

But this isn’t work.

Can anyone give me a working example, that show me exact calculated values?

Bumping this.

Did you find a solution? I have the same use case and struggle to construct a query that allows me to do that.

Same problem here. Any solution? It seems a very usual use case…