Skip to content

Prometheus Query Offset Time Shift Not Working Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Prometheus Query Offset Time Shift Not Working Fix. We cover key concepts, practical examples, and best practices.

Your Prometheus week-over-week comparison returns empty data — the offset modifier shifts the query but returns no results, or the shifted data does not align with the actual time series. Offset must reference a time range where data exists.

The Problem

// Week-over-week comparison — returns empty
rate(http_requests_total[5m]) offset 1w

If no data exists exactly 1 week ago (e.g., the service was not running, or retention is less than 1 week), the offset query returns nothing for that time period.

Step-by-Step Fix

1. Check data availability for the offset period

// Check if data exists 1 week ago
rate(http_requests_total[5m] offset 1w)

// If empty, check with a shorter offset first
rate(http_requests_total[5m] offset 1d)
rate(http_requests_total[5m] offset 1h)

2. Compare current vs past in one query

// Current vs 1 week ago (both must have data)
rate(http_requests_total[5m])
/
rate(http_requests_total[5m] offset 1w)

// Difference
rate(http_requests_total[5m]) - rate(http_requests_total[5m] offset 1w)

3. Use offset with aggregation

// Week-over-week by service
sum by (service) (rate(http_requests_total[5m]))
/
sum by (service) (rate(http_requests_total[5m] offset 1w))

4. Handle missing data in offset

// Use or operator to handle missing past data
rate(http_requests_total[5m])
/
(
  rate(http_requests_total[5m] offset 1w)
  or
  rate(http_requests_total[5m])  // Fallback: compare to current
)

5. Offset limitations

// Offset works with any PromQL function
rate(http_requests_total[5m] offset 1w)
avg_over_time(cpu_usage_percent[5m] offset 1d)
max by (instance) (memory_usage_bytes offset 1h)

// Offset cannot be negative
// Use offset to look backward only

Expected output:

// This week: 150 req/s
rate(http_requests_total[5m]) → 150

// Last week: 120 req/s
rate(http_requests_total[5m] offset 1w) → 120

// Change: +25%
rate(http_requests_total[5m]) / rate(http_requests_total[5m] offset 1w) → 1.25

Prevention Tips

  • Verify data retention covers the offset period (retention must exceed 1w for week-over-week)
  • Use shorter offsets for shorter retention periods
  • Handle missing data with or fallback
  • Use offset with rate() to avoid stale data issues
  • Test offset queries in Prometheus UI before adding to dashboards

Common Mistakes with query offset

  1. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  2. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  3. Misunderstanding that String is [Char] with poor performance for large text operations

These mistakes appear frequently in real-world PROMETHEUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What's the maximum offset I can use?

The maximum offset equals your Prometheus data retention period (default 15d). If retention is 7 days, offset 1w works but offset 30d returns nothing. Increase retention with --storage.tsdb.retention.time if you need longer comparisons.

Can I use negative offset or @ modifier?

The @ modifier allows querying at a specific timestamp: rate(http_requests_total[5m] @ 1687564800). This is useful for comparing against a specific point in time. Negative offset is not supported — use @ with a Unix timestamp instead.

Does offset work with recording rules?

Yes, offset is a PromQL modifier that works in any expression, including recording rules. However, recording rules with offset evaluate slower because Prometheus must fetch data from the past. Use offset sparingly in recording rules.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro