Skip to content

Commit b0f52cd

Browse files
committed
Add LabelQuerier.LabelValuesSet method
Signed-off-by: Arve Knudsen <[email protected]>
1 parent 002ae0a commit b0f52cd

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

storage/fanout_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ func (errQuerier) LabelValues(string, ...*labels.Matcher) ([]string, storage.War
237237
return nil, nil, errors.New("label values error")
238238
}
239239

240+
func (errQuerier) LabelValuesStream(string, ...*labels.Matcher) (LabelValuesSet, error) {
241+
return nil, errors.New("label values set error")
242+
}
243+
240244
func (errQuerier) LabelNames(...*labels.Matcher) ([]string, storage.Warnings, error) {
241245
return nil, nil, errors.New("label names error")
242246
}

storage/interface.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ func (q *MockQuerier) LabelValues(string, ...*labels.Matcher) ([]string, Warning
122122
return nil, nil, nil
123123
}
124124

125+
func (q *MockQuerier) LabelValuesStream(string, ...*labels.Matcher) (LabelValuesSet, error) {
126+
return nil, nil
127+
}
128+
125129
func (q *MockQuerier) LabelNames(...*labels.Matcher) ([]string, Warnings, error) {
126130
return nil, nil, nil
127131
}
@@ -159,6 +163,12 @@ type LabelQuerier interface {
159163
// to label values of metrics matching the matchers.
160164
LabelValues(name string, matchers ...*labels.Matcher) ([]string, Warnings, error)
161165

166+
// LabelValuesSet returns an iterator over all potential values for a label name.
167+
// It is not safe to use the strings beyond the lifetime of the querier.
168+
// If matchers are specified the returned result set is reduced
169+
// to label values of metrics matching the matchers.
170+
LabelValuesSet(name string, matchers ...*labels.Matcher) (LabelValuesSet, error)
171+
162172
// LabelNames returns all the unique label names present in the block in sorted order.
163173
// If matchers are specified the returned result set is reduced
164174
// to label names of metrics matching the matchers.
@@ -444,3 +454,16 @@ type ChunkIterable interface {
444454
}
445455

446456
type Warnings []error
457+
458+
// LabelValuesSet contains a set of label values.
459+
type LabelValuesSet interface {
460+
Next() bool
461+
// At returns a label value.
462+
At() string
463+
// The error that iteration as failed with.
464+
// When an error occurs, set cannot continue to iterate.
465+
Err() error
466+
// A collection of warnings for the whole set.
467+
// Warnings could be return even iteration has not failed with error.
468+
Warnings() Warnings
469+
}

storage/merge_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,16 @@ func (m *mockGenericQuerier) LabelValues(name string, matchers ...*labels.Matche
10141014
return m.resp, m.warnings, m.err
10151015
}
10161016

1017+
func (m *mockGenericQuerier) LabelValuesSet(name string, matchers ...*labels.Matcher) (LabelValuesSet, error) {
1018+
m.mtx.Lock()
1019+
m.labelNamesRequested = append(m.labelNamesRequested, labelNameRequest{
1020+
name: name,
1021+
matchers: matchers,
1022+
})
1023+
m.mtx.Unlock()
1024+
return m.resp, m.warnings, m.err
1025+
}
1026+
10171027
func (m *mockGenericQuerier) LabelNames(...*labels.Matcher) ([]string, Warnings, error) {
10181028
m.mtx.Lock()
10191029
m.labelNamesCalls++

storage/noop.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func (noopQuerier) LabelValues(string, ...*labels.Matcher) ([]string, Warnings,
3232
return nil, nil, nil
3333
}
3434

35+
func (noopQuerier) LabelValuesSet(string, ...*labels.Matcher) (LabelValuesSet, error) {
36+
return nil, nil
37+
}
38+
3539
func (noopQuerier) LabelNames(...*labels.Matcher) ([]string, Warnings, error) {
3640
return nil, nil, nil
3741
}
@@ -55,6 +59,13 @@ func (noopChunkQuerier) LabelValues(string, ...*labels.Matcher) ([]string, Warni
5559
return nil, nil, nil
5660
}
5761

62+
func (noopChunkQuerier) LabelValuesSet(string, ...*labels.Matcher) (LabelValuesSet, Warnings, error) {
63+
return nil, nil
64+
}
65+
func (noopChunkQuerier) LabelValues(string, ...*labels.Matcher) ([]string, Warnings, error) {
66+
return nil, nil, nil
67+
}
68+
5869
func (noopChunkQuerier) LabelNames(...*labels.Matcher) ([]string, Warnings, error) {
5970
return nil, nil, nil
6071
}

storage/remote/read.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ func (q *querier) LabelValues(string, ...*labels.Matcher) ([]string, storage.War
217217
return nil, nil, errors.New("not implemented")
218218
}
219219

220+
// LabelValuesStream implements storage.Querier and is a noop.
221+
func (q *querier) LabelValuesStream(string, ...*labels.Matcher) ([]string, error) {
222+
// TODO: Implement: https://github.com/prometheus/prometheus/issues/3351
223+
return nil, errors.New("not implemented")
224+
}
225+
220226
// LabelNames implements storage.Querier and is a noop.
221227
func (q *querier) LabelNames(...*labels.Matcher) ([]string, storage.Warnings, error) {
222228
// TODO: Implement: https://github.com/prometheus/prometheus/issues/3351

storage/secondary.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func (s *secondaryQuerier) LabelValues(name string, matchers ...*labels.Matcher)
5555
return vals, w, nil
5656
}
5757

58+
func (s *secondaryQuerier) LabelValuesSet(name string, matchers ...*labels.Matcher) (LabelValuesSet, error) {
59+
vals, err := s.genericQuerier.LabelValuesStream(name, matchers...)
60+
return vals, err
61+
}
62+
5863
func (s *secondaryQuerier) LabelNames(matchers ...*labels.Matcher) ([]string, Warnings, error) {
5964
names, w, err := s.genericQuerier.LabelNames(matchers...)
6065
if err != nil {

0 commit comments

Comments
 (0)