Skip to content

Commit

Permalink
store: fix stringlabel build errors for prometheus store api (thanos-…
Browse files Browse the repository at this point in the history
…io#6861)

Signed-off-by: Michael Hoffmann <[email protected]>
  • Loading branch information
MichaHoffmann authored and fpetkovski committed Sep 24, 2024
1 parent 6726274 commit ef8b26a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
33 changes: 14 additions & 19 deletions pkg/store/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ func (p *PrometheusStore) Info(_ context.Context, _ *storepb.InfoRequest) (*stor
mint, maxt := p.timestamps()

res := &storepb.InfoResponse{
Labels: make([]labelpb.ZLabel, 0, len(lset)),
Labels: labelpb.ZLabelsFromPromLabels(lset),
StoreType: p.component.ToProto(),
MinTime: mint,
MaxTime: maxt,
}
res.Labels = append(res.Labels, labelpb.ZLabelsFromPromLabels(lset)...)

// Until we deprecate the single labels in the reply, we just duplicate
// them here for migration/compatibility purposes.
Expand Down Expand Up @@ -194,7 +193,7 @@ func (p *PrometheusStore) Series(r *storepb.SeriesRequest, s storepb.Store_Serie
return err
}
for _, lbm := range labelMaps {
lset := make([]labelpb.ZLabel, 0, len(lbm)+len(finalExtLset))
lset := make([]labelpb.ZLabel, 0, len(lbm)+finalExtLset.Len())
for k, v := range lbm {
lset = append(lset, labelpb.ZLabel{Name: k, Value: v})
}
Expand Down Expand Up @@ -293,19 +292,18 @@ func (p *PrometheusStore) queryPrometheus(
}

externalLbls := rmLabels(p.externalLabelsFn().Copy(), extLsetToRemove)
b := labels.NewScratchBuilder(16)
for _, vector := range matrix {
seriesLbls := labels.Labels(make([]labels.Label, 0, len(vector.Metric)))
b.Reset()

// Attach labels from samples.
for k, v := range vector.Metric {
seriesLbls = append(seriesLbls, labels.FromStrings(string(k), string(v))...)
b.Add(string(k), string(v))
}
sort.Slice(seriesLbls, func(i, j int) bool {
return seriesLbls.Less(i, j)
})
// Attach external labels for compatibility with remote read.
finalLbls := labelpb.ExtendSortedLabels(seriesLbls, externalLbls)
finalLbls = append(finalLbls, dedup.PushdownMarker)
b.Add(dedup.PushdownMarker.Name, dedup.PushdownMarker.Value)
b.Sort()

finalLbls := labelpb.ExtendSortedLabels(b.Labels(), externalLbls)

series := &prompb.TimeSeries{
Labels: labelpb.ZLabelsFromPromLabels(finalLbls),
Expand Down Expand Up @@ -606,7 +604,7 @@ func matchesExternalLabels(ms []storepb.LabelMatcher, externalLabels labels.Labe
return false, nil, err
}

if len(externalLabels) == 0 {
if externalLabels.IsEmpty() {
return true, tms, nil
}

Expand Down Expand Up @@ -683,9 +681,9 @@ func (p *PrometheusStore) LabelNames(ctx context.Context, r *storepb.LabelNamesR
}

if len(lbls) > 0 {
for _, extLbl := range extLset {
lbls = append(lbls, extLbl.Name)
}
extLset.Range(func(l labels.Label) {
lbls = append(lbls, l.Name)
})
sort.Strings(lbls)
}

Expand Down Expand Up @@ -761,10 +759,7 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue
}

func (p *PrometheusStore) LabelSet() []labelpb.ZLabelSet {
lset := p.externalLabelsFn()

labels := make([]labelpb.ZLabel, 0, len(lset))
labels = append(labels, labelpb.ZLabelsFromPromLabels(lset)...)
labels := labelpb.ZLabelsFromPromLabels(p.externalLabelsFn())

labelset := []labelpb.ZLabelSet{}
if len(labels) > 0 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/store/storepb/testutil/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func ReadSeriesFromBlock(t testing.TB, h tsdb.BlockReader, extLabels labels.Labe
all := allPostings(t, ir)
for all.Next() {
testutil.Ok(t, ir.Series(all.At(), &builder, &chunkMetas))
lset := builder.Labels()
expected = append(expected, &storepb.Series{Labels: labelpb.ZLabelsFromPromLabels(append(extLabels.Copy(), lset...))})
lset := labelpb.ExtendSortedLabels(builder.Labels(), extLabels)
expected = append(expected, &storepb.Series{Labels: labelpb.ZLabelsFromPromLabels(lset)})

if skipChunks {
continue
Expand Down Expand Up @@ -189,7 +189,7 @@ func appendFloatSamples(t testing.TB, app storage.Appender, tsLabel int, opts He
testutil.Ok(t, err)

for is := 1; is < opts.SamplesPerSeries; is++ {
_, err := app.Append(ref, nil, int64(tsLabel+is)*opts.ScrapeInterval.Milliseconds(), opts.Random.Float64())
_, err := app.Append(ref, labels.EmptyLabels(), int64(tsLabel+is)*opts.ScrapeInterval.Milliseconds(), opts.Random.Float64())
testutil.Ok(t, err)
}
}
Expand All @@ -211,7 +211,7 @@ func appendHistogramSamples(t testing.TB, app storage.Appender, tsLabel int, opt
testutil.Ok(t, err)

for i, h := range histograms[1:] {
_, err := app.AppendHistogram(ref, nil, int64(tsLabel+i+1)*opts.ScrapeInterval.Milliseconds(), h, nil)
_, err := app.AppendHistogram(ref, labels.EmptyLabels(), int64(tsLabel+i+1)*opts.ScrapeInterval.Milliseconds(), h, nil)
testutil.Ok(t, err)
}
}
Expand Down

0 comments on commit ef8b26a

Please sign in to comment.