Skip to content

Commit

Permalink
fix missing results on day start
Browse files Browse the repository at this point in the history
  • Loading branch information
msaf1980 committed Aug 24, 2022
1 parent 90044bb commit b00e1b5
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions autocomplete/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (h *Handler) ServeTags(w http.ResponseWriter, r *http.Request) {

queryLimit := limit + len(usedTags)

fromDate := time.Now().AddDate(0, 0, -h.config.ClickHouse.TaggedAutocompleDays)
fromDate := time.Now().AddDate(0, 0, -h.config.ClickHouse.TaggedAutocompleDays).UTC()
wr.Andf("Date >= '%s'", fromDate.Format("2006-01-02"))

sql := fmt.Sprintf("SELECT %s FROM %s %s %s GROUP BY value ORDER BY value LIMIT %d",
Expand Down Expand Up @@ -235,7 +235,7 @@ func (h *Handler) ServeValues(w http.ResponseWriter, r *http.Request) {
wr.And(where.HasPrefix("arrayJoin(Tags)", tag+"="+valuePrefix))
}

fromDate := time.Now().AddDate(0, 0, -h.config.ClickHouse.TaggedAutocompleDays)
fromDate := time.Now().AddDate(0, 0, -h.config.ClickHouse.TaggedAutocompleDays).UTC()
wr.Andf("Date >= '%s'", fromDate.Format("2006-01-02"))

sql := fmt.Sprintf("SELECT %s FROM %s %s %s GROUP BY value ORDER BY value LIMIT %d",
Expand Down
4 changes: 2 additions & 2 deletions finder/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (b *DateFinder) Execute(ctx context.Context, query string, from int64, unti
dateWhere := where.New()
dateWhere.Andf(
"Date >='%s' AND Date <= '%s'",
time.Unix(from, 0).Format("2006-01-02"),
time.Unix(until, 0).Format("2006-01-02"),
time.Unix(from, 0).UTC().Format("2006-01-02"),
time.Unix(until, 0).UTC().Format("2006-01-02"),
)

if b.tableVersion == 2 {
Expand Down
4 changes: 2 additions & 2 deletions finder/date_reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (f *DateFinderV3) Execute(ctx context.Context, query string, from int64, un
dateWhere := where.New()
dateWhere.Andf(
"Date >='%s' AND Date <= '%s'",
time.Unix(from, 0).Format("2006-01-02"),
time.Unix(until, 0).Format("2006-01-02"),
time.Unix(from, 0).UTC().Format("2006-01-02"),
time.Unix(until, 0).UTC().Format("2006-01-02"),
)

f.body, err = clickhouse.Query(
Expand Down
4 changes: 2 additions & 2 deletions finder/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func (idx *IndexFinder) Execute(ctx context.Context, query string, from int64, u
if idx.useDaily {
w.Andf(
"Date >='%s' AND Date <= '%s'",
time.Unix(from, 0).Format("2006-01-02"),
time.Unix(until, 0).Format("2006-01-02"),
time.Unix(from, 0).UTC().Format("2006-01-02"),
time.Unix(until, 0).UTC().Format("2006-01-02"),
)
} else {
w.And(where.Eq("Date", DefaultTreeDate))
Expand Down
4 changes: 2 additions & 2 deletions finder/tagged.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ func (t *TaggedFinder) ExecutePrepared(ctx context.Context, terms []TaggedTerm,
if t.dailyEnabled {
w.Andf(
"Date >='%s' AND Date <= '%s'",
time.Unix(from, 0).Format("2006-01-02"),
time.Unix(until, 0).Format("2006-01-02"),
time.Unix(from, 0).UTC().Format("2006-01-02"),
time.Unix(until, 0).UTC().Format("2006-01-02"),
)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/where/where.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func InTable(field string, table string) string {

func DateBetween(field string, from int64, until int64) string {
return fmt.Sprintf(
"%s >= toDate(%d) AND %s <= toDate(%d)",
"%s >= toDate(%d, 'UTC') AND %s <= toDate(%d, 'UTC')",
field, from, field, until,
)
}
Expand Down
5 changes: 3 additions & 2 deletions prometheus/querier.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !noprom
// +build !noprom

package prometheus
Expand Down Expand Up @@ -43,7 +44,7 @@ func (q *Querier) LabelValues(label string) ([]string, storage.Warnings, error)
w := where.New()
w.And(where.HasPrefix("Tag1", label+"="))

fromDate := time.Now().AddDate(0, 0, -q.config.ClickHouse.TaggedAutocompleDays)
fromDate := time.Now().AddDate(0, 0, -q.config.ClickHouse.TaggedAutocompleDays).UTC()
w.Andf("Date >= '%s'", fromDate.Format("2006-01-02"))

sql := fmt.Sprintf("SELECT splitByChar('=', Tag1)[2] as value FROM %s %s GROUP BY value ORDER BY value",
Expand Down Expand Up @@ -76,7 +77,7 @@ func (q *Querier) LabelValues(label string) ([]string, storage.Warnings, error)
// LabelNames returns all the unique label names present in the block in sorted order.
func (q *Querier) LabelNames() ([]string, storage.Warnings, error) {
w := where.New()
fromDate := time.Now().AddDate(0, 0, -q.config.ClickHouse.TaggedAutocompleDays)
fromDate := time.Now().AddDate(0, 0, -q.config.ClickHouse.TaggedAutocompleDays).UTC()
w.Andf("Date >= '%s'", fromDate.Format("2006-01-02"))

sql := fmt.Sprintf("SELECT splitByChar('=', Tag1)[1] as value FROM %s %s GROUP BY value ORDER BY value",
Expand Down

0 comments on commit b00e1b5

Please sign in to comment.