Skip to content

Commit

Permalink
Adapt remote.chunkedSeries to use prompb.ChunkedSeries
Browse files Browse the repository at this point in the history
  • Loading branch information
leizor committed Jul 17, 2024
1 parent 6616a90 commit 604a84e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
1 change: 1 addition & 0 deletions storage/remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"

"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/prompb"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/storage/remote/azuread"
Expand Down
30 changes: 11 additions & 19 deletions storage/remote/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,12 @@ func (s *chunkedSeriesSet) Next() bool {
}

s.current = &chunkedSeries{
labels: res.ChunkedSeries[0].Labels,
chunks: res.ChunkedSeries[0].Chunks,
mint: s.mint,
maxt: s.maxt,
ChunkedSeries: prompb.ChunkedSeries{
Labels: res.ChunkedSeries[0].Labels,
Chunks: res.ChunkedSeries[0].Chunks,
},
mint: s.mint,
maxt: s.maxt,
}

return true
Expand All @@ -602,25 +604,24 @@ func (s *chunkedSeriesSet) Warnings() annotations.Annotations {
}

type chunkedSeries struct {
labels []prompb.Label
chunks []prompb.Chunk
prompb.ChunkedSeries
mint, maxt int64
}

var _ storage.Series = &chunkedSeries{}

func (s *chunkedSeries) Labels() labels.Labels {
b := labels.NewScratchBuilder(len(s.labels))
return labelProtosToLabels(&b, s.labels)
b := labels.NewScratchBuilder(0)
return s.ToLabels(&b, nil)
}

func (s *chunkedSeries) Iterator(it chunkenc.Iterator) chunkenc.Iterator {
csIt, ok := it.(*chunkedSeriesIterator)
if ok {
csIt.reset(s.chunks, s.mint, s.maxt)
csIt.reset(s.Chunks, s.mint, s.maxt)
return csIt
}
return newChunkedSeriesIterator(s.chunks, s.mint, s.maxt)
return newChunkedSeriesIterator(s.Chunks, s.mint, s.maxt)
}

type chunkedSeriesIterator struct {
Expand Down Expand Up @@ -825,15 +826,6 @@ func FromLabelMatchers(matchers []*prompb.LabelMatcher) ([]*labels.Matcher, erro
return result, nil
}

// LabelProtosToMetric unpack a []*prompb.Label to a model.Metric.
func LabelProtosToMetric(labelPairs []*prompb.Label) model.Metric {
metric := make(model.Metric, len(labelPairs))
for _, l := range labelPairs {
metric[model.LabelName(l.Name)] = model.LabelValue(l.Value)
}
return metric
}

// DecodeWriteRequest from an io.Reader into a prompb.WriteRequest, handling
// snappy decompression.
// Used also by documentation/examples/remote_storage.
Expand Down
10 changes: 6 additions & 4 deletions storage/remote/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,13 @@ func TestChunkedSeries(t *testing.T) {
chks := buildTestChunks(t)

s := chunkedSeries{
labels: []prompb.Label{
{Name: "foo", Value: "bar"},
{Name: "asdf", Value: "zxcv"},
ChunkedSeries: prompb.ChunkedSeries{
Labels: []prompb.Label{
{Name: "foo", Value: "bar"},
{Name: "asdf", Value: "zxcv"},
},
Chunks: chks,
},
chunks: chks,
}

require.Equal(t, labels.FromStrings("asdf", "zxcv", "foo", "bar"), s.Labels())
Expand Down

0 comments on commit 604a84e

Please sign in to comment.