Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from thanos-io:main #485

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/container-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
shell: bash

- name: Create Pull Request
uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f # v7.0.6
uses: peter-evans/create-pull-request@dd2324fc52d5d43c699a5636bcf19fceaa70c284 # v7.0.7
with:
signoff: true
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ jobs:
with:
go-version: 1.24.x

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
- uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4.2.1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
- uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4.2.1
with:
path: .mdoxcache
key: ${{ runner.os }}-mdox-${{ hashFiles('docs/**/*.md', 'examples/**/*.md', 'mixin/**/*.md', '*.md') }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
with:
go-version: 1.24.x

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
- uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4.2.1
with:
path: |
~/.cache/go-build
Expand All @@ -84,7 +84,7 @@ jobs:
with:
go-version: 1.24.x

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
- uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4.2.1
with:
path: |
~/.cache/go-build
Expand All @@ -111,7 +111,7 @@ jobs:
with:
go-version: 1.24.x

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
- uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4.2.1
with:
path: |
~/.cache/go-build
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
with:
go-version: 1.24.x

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
- uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4.2.1
with:
path: |
~/.cache/go-build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
node-version: ${{ matrix.node }}

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
- uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4.2.1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

- [#7890](https://github.com/thanos-io/thanos/pull/7890) Query,Ruler: *breaking :warning:* deprecated `--store.sd-file` and `--store.sd-interval` to be replaced with `--endpoint.sd-config` and `--endpoint-sd-config-reload-interval`; removed legacy flags to pass endpoints `--store`, `--metadata`, `--rule`, `--exemplar`.
- [#7012](https://github.com/thanos-io/thanos/pull/7012) Query: Automatically adjust `max_source_resolution` based on promql query to avoid querying data from higher resolution resulting empty results.
- [#8118](https://github.com/thanos-io/thanos/pull/8118) Query: Bumped promql-engine

### Removed

Expand Down
8 changes: 4 additions & 4 deletions cmd/thanos/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestRegression4960_Deadlock(t *testing.T) {
[]labels.Labels{{{Name: "a", Value: "1"}}},
1, 0, downsample.ResLevel1DownsampleRange+1, // Pass the minimum ResLevel1DownsampleRange check.
labels.Labels{{Name: "e1", Value: "1"}},
downsample.ResLevel0, metadata.NoneFunc)
downsample.ResLevel0, metadata.NoneFunc, nil)
testutil.Ok(t, err)
testutil.Ok(t, block.Upload(ctx, logger, bkt, path.Join(dir, id.String()), metadata.NoneFunc))
}
Expand All @@ -147,7 +147,7 @@ func TestRegression4960_Deadlock(t *testing.T) {
[]labels.Labels{{{Name: "a", Value: "2"}}},
1, 0, downsample.ResLevel1DownsampleRange+1, // Pass the minimum ResLevel1DownsampleRange check.
labels.Labels{{Name: "e1", Value: "2"}},
downsample.ResLevel0, metadata.NoneFunc)
downsample.ResLevel0, metadata.NoneFunc, nil)
testutil.Ok(t, err)
testutil.Ok(t, block.Upload(ctx, logger, bkt, path.Join(dir, id2.String()), metadata.NoneFunc))
}
Expand All @@ -158,7 +158,7 @@ func TestRegression4960_Deadlock(t *testing.T) {
[]labels.Labels{{{Name: "a", Value: "2"}}},
1, 0, downsample.ResLevel1DownsampleRange+1, // Pass the minimum ResLevel1DownsampleRange check.
labels.Labels{{Name: "e1", Value: "2"}},
downsample.ResLevel0, metadata.NoneFunc)
downsample.ResLevel0, metadata.NoneFunc, nil)
testutil.Ok(t, err)
testutil.Ok(t, block.Upload(ctx, logger, bkt, path.Join(dir, id3.String()), metadata.NoneFunc))
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestCleanupDownsampleCacheFolder(t *testing.T) {
[]labels.Labels{{{Name: "a", Value: "1"}}},
1, 0, downsample.ResLevel1DownsampleRange+1, // Pass the minimum ResLevel1DownsampleRange check.
labels.Labels{{Name: "e1", Value: "1"}},
downsample.ResLevel0, metadata.NoneFunc)
downsample.ResLevel0, metadata.NoneFunc, nil)
testutil.Ok(t, err)
testutil.Ok(t, block.Upload(ctx, logger, bkt, path.Join(dir, id.String()), metadata.NoneFunc))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func runQuery(
})
}

engineFactory := apiv1.NewQueryEngineFactory(engineOpts, remoteEngineEndpoints)
engineFactory := apiv1.NewQueryFactory(engineOpts, remoteEngineEndpoints)

lookbackDeltaCreator := LookbackDeltaFactory(engineOpts.EngineOpts, dynamicLookbackDelta)

Expand Down
2 changes: 2 additions & 0 deletions docs/components/compact.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ message AggrChunk {

This means that for each series we collect various aggregations with a given interval: 5m or 1h (depending on resolution). This allows us to keep precision on large duration queries, without fetching too many samples.

Native histogram downsampling leverages the fact that one can aggregate & reduce schema i.e. downsample native histograms. Native histograms only store 3 aggregations - counter, count, and sum. Sum and count are used to produce "an average" native histogram. Counter is a counter that is used with functions irate, rate, increase, and resets.

### ⚠ ️Downsampling: Note About Resolution and Retention ⚠️

Resolution is a distance between data points on your graphs. E.g.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ require (
github.com/sony/gobreaker v0.5.0
github.com/stretchr/testify v1.10.0
github.com/thanos-io/objstore v0.0.0-20241111205755-d1dd89d41f97
github.com/thanos-io/promql-engine v0.0.0-20250211181629-815830ca3e2e
github.com/thanos-io/promql-engine v0.0.0-20250221084015-4230034ebb6c
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/vimeo/galaxycache v0.0.0-20210323154928-b7e5d71c067a
github.com/weaveworks/common v0.0.0-20230728070032-dd9e68f319d5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2258,8 +2258,8 @@ github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e h1:f1
github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e/go.mod h1:jXcofnrSln/cLI6/dhlBxPQZEEQHVPCcFaH75M+nSzM=
github.com/thanos-io/objstore v0.0.0-20241111205755-d1dd89d41f97 h1:VjG0mwhN1DkncwDHFvrpd12/2TLfgYNRmEQA48ikp+0=
github.com/thanos-io/objstore v0.0.0-20241111205755-d1dd89d41f97/go.mod h1:vyzFrBXgP+fGNG2FopEGWOO/zrIuoy7zt3LpLeezRsw=
github.com/thanos-io/promql-engine v0.0.0-20250211181629-815830ca3e2e h1:jDKxQzp4JIhpbn6NFHXc8TCsRy8GkfHMZ7XNicY1mx8=
github.com/thanos-io/promql-engine v0.0.0-20250211181629-815830ca3e2e/go.mod h1:aHSV5hL94fNb7PklN9L0V10j+/RGIlzqbw7OLdNgZFs=
github.com/thanos-io/promql-engine v0.0.0-20250221084015-4230034ebb6c h1:p/XSjq43vYSorePYsxethwoNpwrJp6HD4QQ7xOH2DGI=
github.com/thanos-io/promql-engine v0.0.0-20250221084015-4230034ebb6c/go.mod h1:aHSV5hL94fNb7PklN9L0V10j+/RGIlzqbw7OLdNgZFs=
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab h1:7ZR3hmisBWw77ZpO1/o86g+JV3VKlk3d48jopJxzTjU=
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab/go.mod h1:eheTFp954zcWZXCU8d0AT76ftsQOTo4DTqkN/h3k1MY=
github.com/tinylib/msgp v1.1.5 h1:2gXmtWueD2HefZHQe1QOy9HVzmFrLOVvsXwXBQ0ayy0=
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/blocks/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestMarkBlockEndpoint(t *testing.T) {
labels.FromStrings("a", "3"),
labels.FromStrings("a", "4"),
labels.FromStrings("b", "1"),
}, 100, 0, 1000, labels.FromStrings("ext1", "val1"), 124, metadata.NoneFunc)
}, 100, 0, 1000, labels.FromStrings("ext1", "val1"), 124, metadata.NoneFunc, nil)
testutil.Ok(t, err)

// upload block
Expand Down
141 changes: 141 additions & 0 deletions pkg/api/query/engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.

// Copyright 2016 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This package is a modified copy from
// github.com/prometheus/prometheus/web/api/v1@2121b4628baa7d9d9406aa468712a6a332e77aff.

package v1

import (
"context"
"time"

"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage"
"github.com/thanos-io/promql-engine/api"
"github.com/thanos-io/promql-engine/engine"
"github.com/thanos-io/promql-engine/logicalplan"
)

type Engine interface {
MakeInstantQuery(ctx context.Context, q storage.Queryable, opts *engine.QueryOpts, qs string, ts time.Time) (promql.Query, error)
MakeRangeQuery(ctx context.Context, q storage.Queryable, opts *engine.QueryOpts, qs string, start, end time.Time, step time.Duration) (promql.Query, error)
MakeInstantQueryFromPlan(ctx context.Context, q storage.Queryable, opts *engine.QueryOpts, plan logicalplan.Node, ts time.Time) (promql.Query, error)
MakeRangeQueryFromPlan(ctx context.Context, q storage.Queryable, opts *engine.QueryOpts, root logicalplan.Node, start, end time.Time, step time.Duration) (promql.Query, error)
}

type prometheusEngineAdapter struct {
engine promql.QueryEngine
}

func (a *prometheusEngineAdapter) MakeInstantQuery(ctx context.Context, q storage.Queryable, opts *engine.QueryOpts, qs string, ts time.Time) (promql.Query, error) {
return a.engine.NewInstantQuery(ctx, q, opts, qs, ts)
}

func (a *prometheusEngineAdapter) MakeRangeQuery(ctx context.Context, q storage.Queryable, opts *engine.QueryOpts, qs string, start, end time.Time, step time.Duration) (promql.Query, error) {
return a.engine.NewRangeQuery(ctx, q, opts, qs, start, end, step)
}

func (a *prometheusEngineAdapter) MakeInstantQueryFromPlan(ctx context.Context, q storage.Queryable, opts *engine.QueryOpts, plan logicalplan.Node, ts time.Time) (promql.Query, error) {
return a.engine.NewInstantQuery(ctx, q, opts, plan.String(), ts)
}

func (a *prometheusEngineAdapter) MakeRangeQueryFromPlan(ctx context.Context, q storage.Queryable, opts *engine.QueryOpts, plan logicalplan.Node, start, end time.Time, step time.Duration) (promql.Query, error) {
return a.engine.NewRangeQuery(ctx, q, opts, plan.String(), start, end, step)
}

type QueryFactory struct {
prometheus Engine
thanos Engine
}

func NewQueryFactory(
engineOpts engine.Opts,
remoteEngineEndpoints api.RemoteEndpoints,
) *QueryFactory {

var thanosEngine Engine
if remoteEngineEndpoints == nil {
thanosEngine = engine.New(engineOpts)
} else {
thanosEngine = engine.NewDistributedEngine(engineOpts, remoteEngineEndpoints)
}
promEngine := promql.NewEngine(engineOpts.EngineOpts)
return &QueryFactory{
prometheus: &prometheusEngineAdapter{promEngine},
thanos: thanosEngine,
}
}

// Always has query, sometimes already has a plan.
type planOrQuery struct {
query string
plan logicalplan.Node
}

func (f *QueryFactory) makeInstantQuery(
ctx context.Context,
e PromqlEngineType,
q storage.Queryable,
qry planOrQuery,
opts *engine.QueryOpts,
ts time.Time,
) (res promql.Query, err error) {
if e == PromqlEngineThanos {
if qry.plan != nil {
res, err = f.thanos.MakeInstantQueryFromPlan(ctx, q, opts, qry.plan, ts)
} else {
res, err = f.thanos.MakeInstantQuery(ctx, q, opts, qry.query, ts)
}
if err != nil {
if engine.IsUnimplemented(err) {
goto fallback
}
return nil, err
}
return res, nil
}
fallback:
return f.prometheus.MakeInstantQuery(ctx, q, opts, qry.query, ts)
}

func (f *QueryFactory) makeRangeQuery(
ctx context.Context,
e PromqlEngineType,
q storage.Queryable,
qry planOrQuery,
opts *engine.QueryOpts,
start time.Time,
end time.Time,
step time.Duration,
) (res promql.Query, err error) {
if e == PromqlEngineThanos {
if qry.plan != nil {
res, err = f.thanos.MakeRangeQueryFromPlan(ctx, q, opts, qry.plan, start, end, step)
} else {
res, err = f.thanos.MakeRangeQuery(ctx, q, opts, qry.query, start, end, step)
}
if err != nil {
if engine.IsUnimplemented(err) {
goto fallback
}
return nil, err
}
return res, nil
}
fallback:
return f.prometheus.MakeRangeQuery(ctx, q, opts, qry.query, start, end, step)
}
Loading