Skip to content

query_range response contains samples outside requested [start, end] when align_queries_with_step=true #7289

@venkatchinmay

Description

@venkatchinmay

Bug Description

When querier.align-querier-with-step: true is configured, the query_range API returns data points outside the user's requested time window.

Steps to Reproduce

  1. Configure Cortex with:
    querier:
      align_queries_with_step: true
      split_queries_by_interval: 1h
  2. Send a query_range request:
    start=2024-01-01T09:01:00Z
    end=2024-01-01T10:00:00Z
    step=10m
    
  3. Observe the response contains a sample at 09:00:00 — outside the requested range.

Expected Behaviour

Response contains only samples within [start, end] as requested.

Actual Behaviour

Response contains samples starting from 09:00:00 (floored to nearest step) instead of 09:01:00.

Root Cause

StepAlignMiddleware mutates the request before the results cache and downstream querier:

start = floor(start / step) * step   // 09:01 → 09:00

Once this mutation happens, the original start is permanently lost — no downstream middleware can trim the response back to the user's requested range.

Proposed Fix

See PR: #7288

A new opt-in RangeTrimMiddleware controlled by querier.trim-response-to-requested-range (default: false) that clips the final response to the original [start, end].

Environment

  • Cortex version: latest master
  • Affected config: querier.align-querier-with-step: true

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions