Splits a start/end nanosecond timerange into exponentially growing hourly buckets for efficient logs list queries, and generates enrichment keys. Reuse when paginating/querying time-bucketed log data.
// Source: https://github.com/SigNoz/signoz | License: MIT | Copyright 2020-present SigNoz Inc
// Provided via justclaw.it.com; keep this notice with the code.
package utils
import v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"
const HOUR_NANO = int64(3600000000000)
type LogsListTsRange struct {
Start int64
End int64
}
func GetListTsRanges(start, end int64) []LogsListTsRange {
startNano := GetEpochNanoSecs(start)
endNano := GetEpochNanoSecs(end)
result := []LogsListTsRange{}
if endNano-startNano > HOUR_NANO {
bucket := HOUR_NANO
tStartNano := endNano - bucket
complete := false
for {
result = append(result, LogsListTsRange{Start: tStartNano, End: endNano})
if complete {
break
}
bucket = bucket * 2
endNano = tStartNano
tStartNano = tStar
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key