Prometheus Query Offset Time Shift Not Working Fix
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
orfallback - Use offset with rate() to avoid stale data issues
- Test offset queries in Prometheus UI before adding to dashboards
Common Mistakes with query offset
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro