This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop fetching timestamps for regular series from the DB
Regular series contain a timestamp series of pre-determined timestamp values. Previously, this was provided by the database using generate_series call but this is wasteful not only in terms of DB work but also the memory used for the fetched timestamp array. Here we change that to provide the series from a Go interface instead and regular series are trivially implemented as a simple Golang class.
- Loading branch information
Showing
6 changed files
with
117 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package querier | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/jackc/pgtype" | ||
prommodel "github.com/prometheus/common/model" | ||
"github.com/timescale/promscale/pkg/pgmodel/model" | ||
) | ||
|
||
type TimestampSeries interface { | ||
At(index int) int64 | ||
Len() int | ||
} | ||
|
||
type rowTimestampSeries struct { | ||
times *pgtype.TimestamptzArray | ||
} | ||
|
||
func NewRowTimestampSeries(times *pgtype.TimestamptzArray) *rowTimestampSeries { | ||
return &rowTimestampSeries{times: times} | ||
} | ||
|
||
func (t *rowTimestampSeries) At(index int) int64 { | ||
return model.TimestamptzToMs(t.times.Elements[index]) | ||
} | ||
|
||
func (t *rowTimestampSeries) Len() int { | ||
return len(t.times.Elements) | ||
} | ||
|
||
type regularTimestampSeries struct { | ||
start time.Time | ||
end time.Time | ||
step time.Duration | ||
len int | ||
} | ||
|
||
func NewRegularTimestampSeries(start time.Time, end time.Time, step time.Duration) *regularTimestampSeries { | ||
len := (end.Sub(start) / step) + 1 | ||
return ®ularTimestampSeries{ | ||
start: start, | ||
end: end, | ||
step: step, | ||
len: int(len), | ||
} | ||
} | ||
|
||
func (t *regularTimestampSeries) Len() int { | ||
return t.len | ||
} | ||
|
||
func (t *regularTimestampSeries) At(index int) int64 { | ||
time := t.start.Add(time.Duration(index) * t.step) | ||
return int64(prommodel.TimeFromUnixNano(time.UnixNano())) | ||
} |