Skip to content

[BUGFIX] Loki: dispatch to instant query when context.mode is instant#737

Merged
jgbernalp merged 1 commit into
perses:mainfrom
tgitelman:fix/loki-instant-query-mode
Jul 21, 2026
Merged

[BUGFIX] Loki: dispatch to instant query when context.mode is instant#737
jgbernalp merged 1 commit into
perses:mainfrom
tgitelman:fix/loki-instant-query-mode

Conversation

@tgitelman

Copy link
Copy Markdown
Contributor

Summary

Ref: perses/perses#4270

getLokiTimeSeriesData() always calls client.queryRange() regardless of context.mode. When a panel requests instant mode (e.g. Table without column plugins), the Loki plugin ignores it and sends query_range — unlike the Prometheus plugin which checks context.mode and dispatches to instantQuery() vs rangeQuery().

This also causes empty results for large time ranges (14d+): query_range with large range vectors triggers Loki's split_queries_by_interval, which truncates lookback windows. The instant endpoint (/loki/api/v1/query) does not split and evaluates correctly.

Changes

loki/src/queries/loki-time-series-query/get-loki-time-series-data.ts:

  • Check context.mode — dispatch to client.query() (/loki/api/v1/query) for instant mode
  • Added convertVectorToTimeSeries() to convert instant query vector responses to the TimeSeries format
  • streams resultType (raw log queries without aggregation) returns empty — not applicable for time series panels
  • Range query path completely unchanged

loki/src/queries/loki-time-series-query/loki-time-series-query-types.ts:

  • Updated LokiTimeSeriesQueryResponse to include LokiQueryResponse (instant query responses)

Reproduction

  1. Create a dashboard with a LokiDatasource
  2. Add a Table panel (no column plugins) with count_over_time(... [$__range])
  3. Enable Loki gateway debug logs (--log.level=debug)
  4. Before fix: 100% of requests are /loki/api/v1/query_range, zero instant queries
  5. After fix: Table requests go to /loki/api/v1/query
  6. Select "Last 14 days" — before fix: empty results; after fix: correct totals

Test plan

  • Loki gateway logs show /loki/api/v1/query (instant) requests when Table panel loads
  • Large time ranges (14d+) return correct data instead of empty results
  • Range queries (time series charts) continue working unchanged
  • Aggregation queries (count_over_time, sum_over_time) return correct single values
  • Raw log queries (no aggregation) in instant mode return empty gracefully

@tgitelman
tgitelman requested a review from a team as a code owner July 19, 2026 20:45
@tgitelman
tgitelman requested review from shahrokni and removed request for a team July 19, 2026 20:45
@tgitelman
tgitelman force-pushed the fix/loki-instant-query-mode branch from bf52d85 to 0574eab Compare July 21, 2026 09:18
@jgbernalp jgbernalp changed the title fix(loki): dispatch to instant query when context.mode is instant [BUGFIX] Loki: dispatch to instant query when context.mode is instant Jul 21, 2026
@jgbernalp
jgbernalp self-requested a review July 21, 2026 09:44
Comment thread loki/src/queries/loki-time-series-query/get-loki-time-series-data.ts Outdated
@tgitelman
tgitelman force-pushed the fix/loki-instant-query-mode branch 2 times, most recently from dd263f9 to da60f25 Compare July 21, 2026 12:04
Signed-off-by: Tal Gitelman <tgitelma@redhat.com>
@tgitelman
tgitelman force-pushed the fix/loki-instant-query-mode branch from da60f25 to 56f6e6e Compare July 21, 2026 12:06
@jgbernalp
jgbernalp added this pull request to the merge queue Jul 21, 2026
Merged via the queue into perses:main with commit d046105 Jul 21, 2026
16 checks passed
@Nexucis Nexucis mentioned this pull request Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants