Skip to content

Commit

Permalink
Add LabelQuerier.LabelValuesSet method
Browse files Browse the repository at this point in the history
Signed-off-by: Arve Knudsen <[email protected]>
  • Loading branch information
aknuds1 committed Jul 21, 2023
1 parent 2a075ce commit d9df8ef
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions storage/fanout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ func (errQuerier) LabelValues(string, ...*labels.Matcher) ([]string, storage.War
return nil, nil, errors.New("label values error")
}

func (errQuerier) LabelValuesStream(string, ...*labels.Matcher) (LabelValuesSet, error) {
return nil, errors.New("label values set error")
}

func (errQuerier) LabelNames(...*labels.Matcher) ([]string, storage.Warnings, error) {
return nil, nil, errors.New("label names error")
}
Expand Down
23 changes: 23 additions & 0 deletions storage/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (q *MockQuerier) LabelValues(string, ...*labels.Matcher) ([]string, Warning
return nil, nil, nil
}

func (q *MockQuerier) LabelValuesStream(string, ...*labels.Matcher) (LabelValuesSet, error) {
return nil, nil
}

func (q *MockQuerier) LabelNames(...*labels.Matcher) ([]string, Warnings, error) {
return nil, nil, nil
}
Expand Down Expand Up @@ -159,6 +163,12 @@ type LabelQuerier interface {
// to label values of metrics matching the matchers.
LabelValues(name string, matchers ...*labels.Matcher) ([]string, Warnings, error)

// LabelValuesSet returns an iterator over all potential values for a label name.
// It is not safe to use the strings beyond the lifetime of the querier.
// If matchers are specified the returned result set is reduced
// to label values of metrics matching the matchers.
LabelValuesSet(name string, matchers ...*labels.Matcher) (LabelValuesSet, error)

// LabelNames returns all the unique label names present in the block in sorted order.
// If matchers are specified the returned result set is reduced
// to label names of metrics matching the matchers.
Expand Down Expand Up @@ -444,3 +454,16 @@ type ChunkIterable interface {
}

type Warnings []error

// LabelValuesSet contains a set of label values.
type LabelValuesSet interface {
Next() bool
// At returns a label value.
At() string
// The error that iteration as failed with.
// When an error occurs, set cannot continue to iterate.
Err() error
// A collection of warnings for the whole set.
// Warnings could be return even iteration has not failed with error.
Warnings() Warnings
}
10 changes: 10 additions & 0 deletions storage/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,16 @@ func (m *mockGenericQuerier) LabelValues(name string, matchers ...*labels.Matche
return m.resp, m.warnings, m.err
}

func (m *mockGenericQuerier) LabelValuesSet(name string, matchers ...*labels.Matcher) (LabelValuesSet, error) {
m.mtx.Lock()
m.labelNamesRequested = append(m.labelNamesRequested, labelNameRequest{
name: name,
matchers: matchers,
})
m.mtx.Unlock()
return m.resp, m.warnings, m.err
}

func (m *mockGenericQuerier) LabelNames(...*labels.Matcher) ([]string, Warnings, error) {
m.mtx.Lock()
m.labelNamesCalls++
Expand Down
11 changes: 11 additions & 0 deletions storage/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (noopQuerier) LabelValues(string, ...*labels.Matcher) ([]string, Warnings,
return nil, nil, nil
}

func (noopQuerier) LabelValuesSet(string, ...*labels.Matcher) (LabelValuesSet, error) {
return nil, nil
}

func (noopQuerier) LabelNames(...*labels.Matcher) ([]string, Warnings, error) {
return nil, nil, nil
}
Expand All @@ -55,6 +59,13 @@ func (noopChunkQuerier) LabelValues(string, ...*labels.Matcher) ([]string, Warni
return nil, nil, nil
}

func (noopChunkQuerier) LabelValuesSet(string, ...*labels.Matcher) (LabelValuesSet, Warnings, error) {
return nil, nil
}
func (noopChunkQuerier) LabelValues(string, ...*labels.Matcher) ([]string, Warnings, error) {
return nil, nil, nil
}

func (noopChunkQuerier) LabelNames(...*labels.Matcher) ([]string, Warnings, error) {
return nil, nil, nil
}
Expand Down
6 changes: 6 additions & 0 deletions storage/remote/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ func (q *querier) LabelValues(string, ...*labels.Matcher) ([]string, storage.War
return nil, nil, errors.New("not implemented")
}

// LabelValuesStream implements storage.Querier and is a noop.
func (q *querier) LabelValuesStream(string, ...*labels.Matcher) ([]string, error) {
// TODO: Implement: https://github.com/prometheus/prometheus/issues/3351
return nil, errors.New("not implemented")
}

// LabelNames implements storage.Querier and is a noop.
func (q *querier) LabelNames(...*labels.Matcher) ([]string, storage.Warnings, error) {
// TODO: Implement: https://github.com/prometheus/prometheus/issues/3351
Expand Down
5 changes: 5 additions & 0 deletions storage/secondary.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (s *secondaryQuerier) LabelValues(name string, matchers ...*labels.Matcher)
return vals, w, nil
}

func (s *secondaryQuerier) LabelValuesSet(name string, matchers ...*labels.Matcher) (LabelValuesSet, error) {
vals, err := s.genericQuerier.LabelValuesStream(name, matchers...)
return vals, err
}

func (s *secondaryQuerier) LabelNames(matchers ...*labels.Matcher) ([]string, Warnings, error) {
names, w, err := s.genericQuerier.LabelNames(matchers...)
if err != nil {
Expand Down

0 comments on commit d9df8ef

Please sign in to comment.