Grouping not allowed for count_over_time aggregation


I’m trying to use Loki to generate visualisations from a service’s event logs. I have written a script that authorises and parses the JSON API of the service, and dumps the results into a file on disk. Using jq I can either choose to analyse these logs in .csv or .json format - and I think that .csv is going to be easier.

Here’s an example of the logs:


I’ve scraped the logs into Loki using promtail, and added labels using the following pattern


I’d now like to create a visualisation of the various event types - say a timeseries chart of eventType=1000, a graph of the most accessed itemIds etc.

I’m a bit stuck at this point - a query that I thought should work:

  | pattern `<event>,<eventType>,<itemId>,<collectionId>,<groupId>,<policyId>,<memberId>,<actingUserId>,<installationId>,<date>,<device>,<ipAddress>` [1m]) by (eventType)

gives a grouping not allowed for count_over_time aggregation error.

I’d be most grateful if anybody could give me some ideas or suggestions as to how to produce visualisations based on this data. At the moment my knowledge is limiting me to logs!

The error is correct, count_over_time does not have a grouping part. You can include your query with a sum function, like this:

sum by (eventType) (
      | pattern `<event>,<eventType>,<itemId>,<collectionId>,<groupId>,<policyId>,<memberId>,<actingUserId>,<installationId>,<date>,<device>,<ipAddress>`
      | __error__=""

Hi Tony,

Thanks - I’ve managed to come up with working queries now.

I’ve now run into the issue that because I’m using a script to import, the log entries are being timestamped with the time they were scraped rather than the time present in the log line.

I’m attempting to battle this with regex and the promtail config file - I’ll have a play over the weekend and open a new thread if I can’t figure it out.

Thanks once again.