LogQL count average from json transform

Hello,

Recently we got a codebase that we should maintain (or at least keep it alive), luckily we can pipe the logs to Loki. Now we should make “bussiness analytics” with logql.

For example right now we have to make an average run time counter for some of the cron jobs since, it is writing a log message containing the run time.
The logs are in json and the runTime field contains the time in the following format 5 sec.
I managed to remove the " sec" but now the avg() functions fails.
Can someone help me out with this one?
Without avg the query looks like this:

{compose_service="stock-counter-everything"} |= "runTime" | json | line_format `{{TrimSuffix .runTime " sec"}}`

But I’m not 100% sure about this query also, at least it extracts the numbers that I need to count avg from:

At this point I’m hard stuck and have no idea where to go from here.
May someone give me a helping hand? :smiley: