Grafana Loki Sum & Count Without Previous Timespan


I’m trying to count total requests group by country code from Nginx log with 5 minute interval. The problem, its always include the value from previous timespan when current cell value is empty.

As you can see, country TW has count as 1 but empty for current timespan.

Yes I have already set the transformer into last(), but still the result is TW == 1

Also is it normal for Loki to return previous timespan even I have filtered the time range within:

2024-01-23 12:10:00 - 2024-01-23 12:15:00


I think I can resolve the problem only if Grafana not included the previous timespan.

This my sample data

 "agent": "promtail",
 "filename": "/var/log/nginx/json-analytics.log",
 "geoip_country_code": "AP",
 "host": "",
 "http_referer": "(direct)",
 "http_user_agent": "Mozilla/5.0 (Linux; U; Android 12; V2120 Build/SP1A.210812.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/120.0.6099.211 Mobile Safari/537.36 OPR/65.1.2254.63284",
 "job": "nginx",
 "remote_addr": "",
 "request_time": "0.261",
 "request_uri": "/",
 "server_name": "",
 "status": "200",
 "time_local": "23/Jan/2024:12:14:18 +0700"

My query

(sum by (geoip_country_code) (count_over_time({host=""} | json [$__interval])))

The table result is perfectly fine only if current timespan cell is not empty

I hope I make it clear.


Ok got it. The solution just change the type into “Instant”


Since its the result is not timeseries anymore, then the transformer needed only “Organize” to rename the column.