-
Notifications
You must be signed in to change notification settings - Fork 455
/
list_series.go
51 lines (43 loc) · 1.15 KB
/
list_series.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: AGPL-3.0-only
package ingester
import (
"errors"
"fmt"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/tsdb"
"github.com/prometheus/prometheus/tsdb/index"
)
// Series is a wrapper around index.Postings and tsdb.IndexReader. It implements
// the generic iterator interface to list all series in the index that are
// contained in the given postings.
type Series struct {
postings index.Postings
idx tsdb.IndexReader
buf labels.ScratchBuilder
err error
}
func NewSeries(postings index.Postings, index tsdb.IndexReader) *Series {
return &Series{
postings: postings,
idx: index,
buf: labels.NewScratchBuilder(10),
}
}
func (s *Series) Next() bool {
return s.postings.Next()
}
func (s *Series) At() labels.Labels {
s.buf.Reset()
err := s.idx.Series(s.postings.At(), &s.buf, nil)
if err != nil {
s.err = fmt.Errorf("error getting series: %w", err)
return labels.Labels{}
}
return s.buf.Labels()
}
func (s *Series) Err() error {
if s.err != nil {
return fmt.Errorf("error listing series: %w", errors.Join(s.err, s.postings.Err()))
}
return s.postings.Err()
}