Skip to content

Commit

Permalink
Merge branch 'main' into mhoffm-smaller-blocksize-for-streamed-postings
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
  • Loading branch information
MichaHoffmann committed Jun 21, 2023
2 parents ac382fd + 2ef6c76 commit 1f6643e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
12 changes: 6 additions & 6 deletions docs/blog/2023-06-02-lfx-mentorship-query-observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ Thanos needs to specify which engine to utilize to execute the promql queries. A

Here is the sketch of how the engine switch should look (made by Giedrius):

<img src="img/giedrius-sketch.png" alt="Giedrius&#39;s Sketch" width="800"/>
![Giedrius's Sketch](img/giedrius-sketch.png)

I looked into Thanos and made changes in Thanos components from the API to the UI to implement this engine switch. I tried to make the UI as close as possible to the sketch.

<img src="img/engine-1.png" alt="Engine Switch 1" width="800"/>
![Engine Switch 1](img/engine-1.png)

After initial review, I move this switch to each panel. As this helps to run the same query over the different engines and compare the results.

<img src="img/engine-2.png" alt="Engine Switch 2" width="800"/>
![Engine Switch 2](img/engine-2.png)

**Pull Requests**
- Add engine param to Thanos engine constructor ([thanos-io/promql-engine#228](https://github.com/thanos-io/promql-engine/pull/228))
Expand All @@ -56,11 +56,11 @@ I started with generating query explanations through the Thanos promql-engine an

Thanos UI got updated with time, resulting in the development of the explanation tree that can be seen through the screenshots provided.

<img src="img/tree-1.png" alt="Tree 1" width="800"/>
![Tree 1](img/tree-1.png)

<img src="img/tree-2.png" alt="Tree 2" width="800"/>
![Tree 2](img/tree-2.png)

<img src="img/tree-3.png" alt="Tree 3" width="800"/>
![Tree 3](img/tree-3.png)

**Pull Requests**
- Add method to explain query vector ([thanos-io/promql-engine#252](https://github.com/thanos-io/promql-engine/pull/252))
Expand Down
71 changes: 44 additions & 27 deletions pkg/query/remote_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"io"
"math"
"sync"
"time"

"github.com/go-kit/log"
Expand Down Expand Up @@ -82,6 +83,13 @@ type remoteEngine struct {
logger log.Logger

client Client

mintOnce sync.Once
mint int64
maxtOnce sync.Once
maxt int64
labelSetsOnce sync.Once
labelSets []labels.Labels
}

func newRemoteEngine(logger log.Logger, queryClient Client, opts Opts) api.RemoteEngine {
Expand All @@ -98,43 +106,52 @@ func newRemoteEngine(logger log.Logger, queryClient Client, opts Opts) api.Remot
// Calculating the MinT this way makes remote queries resilient to cases where one tsdb replica would delete
// a block due to retention before other replicas did the same.
// See https://github.com/thanos-io/promql-engine/issues/187.
func (r remoteEngine) MinT() int64 {
var (
hashBuf = make([]byte, 0, 128)
highestMintByLabelSet = make(map[uint64]int64)
)
for _, lset := range r.infosWithoutReplicaLabels() {
key, _ := labelpb.ZLabelsToPromLabels(lset.Labels.Labels).HashWithoutLabels(hashBuf)
lsetMinT, ok := highestMintByLabelSet[key]
if !ok {
highestMintByLabelSet[key] = lset.MinTime
continue
}
func (r *remoteEngine) MinT() int64 {
r.mintOnce.Do(func() {
var (
hashBuf = make([]byte, 0, 128)
highestMintByLabelSet = make(map[uint64]int64)
)
for _, lset := range r.infosWithoutReplicaLabels() {
key, _ := labelpb.ZLabelsToPromLabels(lset.Labels.Labels).HashWithoutLabels(hashBuf)
lsetMinT, ok := highestMintByLabelSet[key]
if !ok {
highestMintByLabelSet[key] = lset.MinTime
continue
}

if lset.MinTime > lsetMinT {
highestMintByLabelSet[key] = lset.MinTime
if lset.MinTime > lsetMinT {
highestMintByLabelSet[key] = lset.MinTime
}
}
}

var mint int64 = math.MaxInt64
for _, m := range highestMintByLabelSet {
if m < mint {
mint = m
var mint int64 = math.MaxInt64
for _, m := range highestMintByLabelSet {
if m < mint {
mint = m
}
}
}
r.mint = mint
})

return mint
return r.mint
}

func (r remoteEngine) MaxT() int64 {
return r.client.tsdbInfos.MaxT()
func (r *remoteEngine) MaxT() int64 {
r.maxtOnce.Do(func() {
r.maxt = r.client.tsdbInfos.MaxT()
})
return r.maxt
}

func (r remoteEngine) LabelSets() []labels.Labels {
return r.infosWithoutReplicaLabels().LabelSets()
func (r *remoteEngine) LabelSets() []labels.Labels {
r.labelSetsOnce.Do(func() {
r.labelSets = r.infosWithoutReplicaLabels().LabelSets()
})
return r.labelSets
}

func (r remoteEngine) infosWithoutReplicaLabels() infopb.TSDBInfos {
func (r *remoteEngine) infosWithoutReplicaLabels() infopb.TSDBInfos {
replicaLabelSet := make(map[string]struct{})
for _, lbl := range r.opts.ReplicaLabels {
replicaLabelSet[lbl] = struct{}{}
Expand All @@ -161,7 +178,7 @@ func (r remoteEngine) infosWithoutReplicaLabels() infopb.TSDBInfos {
return infos
}

func (r remoteEngine) NewRangeQuery(_ context.Context, opts *promql.QueryOpts, qs string, start, end time.Time, interval time.Duration) (promql.Query, error) {
func (r *remoteEngine) NewRangeQuery(_ context.Context, opts *promql.QueryOpts, qs string, start, end time.Time, interval time.Duration) (promql.Query, error) {
return &remoteQuery{
logger: r.logger,
client: r.client,
Expand Down
4 changes: 4 additions & 0 deletions website/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,7 @@ input[type="search"]::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
padding-bottom: 15px;
}
}

.blog-post img {
width: 100%;
}

0 comments on commit 1f6643e

Please sign in to comment.