mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-04 08:09:27 +00:00
### Problem
When using `histogram(_timestamp, '7 days')` in SQL queries, the
interval was incorrectly adjusted to 86400 seconds (1 day) instead of
the correct 604800 seconds (7 days).
### Root Cause
The `validate_and_adjust_histogram_interval` function only checked if
intervals were **factors** of 24 hours (values that divide evenly into
24 hours), but didn't check if they were **multiples** of 24 hours (2
days, 7 days, 30 days, etc.).
### Fix
Added a check for intervals that are multiples of 24 hours **before**
checking for factors:
```rust
// Check if the interval is a multiple of 24 hours (like 2 days, 7 days, etc.)
if interval_seconds % TWENTY_FOUR_HOURS_SECONDS == 0 {
return interval_seconds;
}
// Check if the interval can divide 24 hours evenly (is a factor of 24h)
if TWENTY_FOUR_HOURS_SECONDS % interval_seconds == 0 {
return interval_seconds;
}
```
___
### **PR Type**
Bug fix, Enhancement, Tests
___
### **Description**
- Validate interval multiples of 24h first
- Factor-of-24h intervals returned unchanged
- Round other intervals to nearest factor
- Add tests for multiples and edge cases
___
### Diagram Walkthrough
```mermaid
flowchart LR
A["Interval seconds"]
B{"Multiple of 24h?"}
E{"Factor of 24h?"}
F["Round up to nearest factor"]
C["Return adjusted interval"]
A -- "input" --> B
B -- "yes" --> C
B -- "no" --> E
E -- "yes" --> C
E -- "no" --> F
F --> C
```
<details> <summary><h3> File Walkthrough</h3></summary>
<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
<tr>
<td>
<details>
<summary><strong>histogram_interval.rs</strong><dd><code>Enhance
histogram interval validation logic</code>
</dd></summary>
<hr>
src/service/search/sql/visitor/histogram_interval.rs
<ul><li>Added doc comments describing new validation logic<br> <li>
Inserted multiple-of-24h check before factor check<br> <li> Retained
factor check and added rounding fallback<br> <li> Extended tests for
multiples and edge scenarios</ul>
</details>
</td>
<td><a
href="https://github.com/openobserve/openobserve/pull/10167/files#diff-0442907b4d8a3b5c4bd9553fd5475c3044fe74a2853cda8e4017bf295d714b4b">+60/-3</a>
</td>
</tr>
</table></td></tr></tr></tbody></table>
</details>
___
---------
Co-authored-by: Shrinath Rao <shnath@openobserve.ai>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
pytest-openobserve
This is a repo to test openobserve API endpoints.
Introduction:
The tests are running using pytest against alpha1 for now.
Idea is to parametrize it for the other endpoints like production as well.
Getting Started
- We use
ryeto manage the python version and environment - https://github.com/mitsuhiko/rye - Once installed, simply run the following steps:
rye syncrye run pytest
TODOS:
- Parametrize tests to run against different environments
- Run the tests as cron-job every few hours or daily etc. for different environments
- Send slack-notification ( use github-actions ) in case something fails on
alpha1orproductionendpoints.