mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
remove unused PrefixMatcher
(#474)
* remove unused `PrefixMatcher` Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
parent
2e0571caba
commit
090b6852e1
|
@ -1,5 +1,6 @@
|
||||||
## master / unreleased
|
## master / unreleased
|
||||||
- [CHANGE] New `WALSegmentSize` option to override the `DefaultOptions.WALSegmentSize`. Added to allow using smaller wal files. For example using tmpfs on a RPI to minimise the SD card wear out from the constant WAL writes. As part of this change the `DefaultOptions.WALSegmentSize` constant was also exposed.
|
- [CHANGE] New `WALSegmentSize` option to override the `DefaultOptions.WALSegmentSize`. Added to allow using smaller wal files. For example using tmpfs on a RPI to minimise the SD card wear out from the constant WAL writes. As part of this change the `DefaultOptions.WALSegmentSize` constant was also exposed.
|
||||||
|
- [REMOVED] `PrefixMatcher` is considered unused so was removed.
|
||||||
- [CLEANUP] `Options.WALFlushInterval` is removed as it wasn't used anywhere.
|
- [CLEANUP] `Options.WALFlushInterval` is removed as it wasn't used anywhere.
|
||||||
|
|
||||||
## 0.3.1
|
## 0.3.1
|
||||||
|
|
|
@ -15,7 +15,6 @@ package labels
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Selector holds constraints for matching against a label set.
|
// Selector holds constraints for matching against a label set.
|
||||||
|
@ -99,22 +98,3 @@ func (m *notMatcher) Matches(v string) bool { return !m.Matcher.Matches(v) }
|
||||||
func Not(m Matcher) Matcher {
|
func Not(m Matcher) Matcher {
|
||||||
return ¬Matcher{m}
|
return ¬Matcher{m}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrefixMatcher implements Matcher for labels which values matches prefix.
|
|
||||||
type PrefixMatcher struct {
|
|
||||||
name, prefix string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPrefixMatcher returns new Matcher for label name matching prefix.
|
|
||||||
func NewPrefixMatcher(name, prefix string) Matcher {
|
|
||||||
return &PrefixMatcher{name: name, prefix: prefix}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name implements Matcher interface.
|
|
||||||
func (m *PrefixMatcher) Name() string { return m.name }
|
|
||||||
|
|
||||||
// Prefix returns matching prefix.
|
|
||||||
func (m *PrefixMatcher) Prefix() string { return m.prefix }
|
|
||||||
|
|
||||||
// Matches implements Matcher interface.
|
|
||||||
func (m *PrefixMatcher) Matches(v string) bool { return strings.HasPrefix(v, m.prefix) }
|
|
||||||
|
|
47
querier.go
47
querier.go
|
@ -247,37 +247,6 @@ func PostingsForMatchers(ix IndexReader, ms ...labels.Matcher) (index.Postings,
|
||||||
return ix.SortedPostings(index.Intersect(its...)), nil
|
return ix.SortedPostings(index.Intersect(its...)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// tuplesByPrefix uses binary search to find prefix matches within ts.
|
|
||||||
func tuplesByPrefix(m *labels.PrefixMatcher, ts StringTuples) ([]string, error) {
|
|
||||||
var outErr error
|
|
||||||
tslen := ts.Len()
|
|
||||||
i := sort.Search(tslen, func(i int) bool {
|
|
||||||
vs, err := ts.At(i)
|
|
||||||
if err != nil {
|
|
||||||
outErr = fmt.Errorf("Failed to read tuple %d/%d: %v", i, tslen, err)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
val := vs[0]
|
|
||||||
l := len(m.Prefix())
|
|
||||||
if l > len(vs) {
|
|
||||||
l = len(val)
|
|
||||||
}
|
|
||||||
return val[:l] >= m.Prefix()
|
|
||||||
})
|
|
||||||
if outErr != nil {
|
|
||||||
return nil, outErr
|
|
||||||
}
|
|
||||||
var matches []string
|
|
||||||
for ; i < tslen; i++ {
|
|
||||||
vs, err := ts.At(i)
|
|
||||||
if err != nil || !m.Matches(vs[0]) {
|
|
||||||
return matches, err
|
|
||||||
}
|
|
||||||
matches = append(matches, vs[0])
|
|
||||||
}
|
|
||||||
return matches, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func postingsForMatcher(ix IndexReader, m labels.Matcher) (index.Postings, error) {
|
func postingsForMatcher(ix IndexReader, m labels.Matcher) (index.Postings, error) {
|
||||||
// If the matcher selects an empty value, it selects all the series which don't
|
// If the matcher selects an empty value, it selects all the series which don't
|
||||||
// have the label name set too. See: https://github.com/prometheus/prometheus/issues/3575
|
// have the label name set too. See: https://github.com/prometheus/prometheus/issues/3575
|
||||||
|
@ -301,21 +270,13 @@ func postingsForMatcher(ix IndexReader, m labels.Matcher) (index.Postings, error
|
||||||
}
|
}
|
||||||
|
|
||||||
var res []string
|
var res []string
|
||||||
if pm, ok := m.(*labels.PrefixMatcher); ok {
|
for i := 0; i < tpls.Len(); i++ {
|
||||||
res, err = tuplesByPrefix(pm, tpls)
|
vals, err := tpls.At(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if m.Matches(vals[0]) {
|
||||||
} else {
|
res = append(res, vals[0])
|
||||||
for i := 0; i < tpls.Len(); i++ {
|
|
||||||
vals, err := tpls.At(i)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if m.Matches(vals[0]) {
|
|
||||||
res = append(res, vals[0])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -375,47 +375,6 @@ func TestBlockQuerier(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
lset: map[string]string{
|
|
||||||
"p": "abcd",
|
|
||||||
"x": "xyz",
|
|
||||||
},
|
|
||||||
chunks: [][]sample{
|
|
||||||
{
|
|
||||||
{1, 2}, {2, 3}, {3, 4},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{5, 2}, {6, 3}, {7, 4},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lset: map[string]string{
|
|
||||||
"a": "ab",
|
|
||||||
"p": "abce",
|
|
||||||
},
|
|
||||||
chunks: [][]sample{
|
|
||||||
{
|
|
||||||
{1, 1}, {2, 2}, {3, 3},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{5, 3}, {6, 6},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lset: map[string]string{
|
|
||||||
"p": "xyz",
|
|
||||||
},
|
|
||||||
chunks: [][]sample{
|
|
||||||
{
|
|
||||||
{1, 1}, {2, 2}, {3, 3},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{4, 4}, {5, 5}, {6, 6},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
queries: []query{
|
queries: []query{
|
||||||
|
@ -455,25 +414,6 @@ func TestBlockQuerier(t *testing.T) {
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
mint: 2,
|
|
||||||
maxt: 6,
|
|
||||||
ms: []labels.Matcher{labels.NewPrefixMatcher("p", "abc")},
|
|
||||||
exp: newMockSeriesSet([]Series{
|
|
||||||
newSeries(map[string]string{
|
|
||||||
"a": "ab",
|
|
||||||
"p": "abce",
|
|
||||||
},
|
|
||||||
[]Sample{sample{2, 2}, sample{3, 3}, sample{5, 3}, sample{6, 6}},
|
|
||||||
),
|
|
||||||
newSeries(map[string]string{
|
|
||||||
"p": "abcd",
|
|
||||||
"x": "xyz",
|
|
||||||
},
|
|
||||||
[]Sample{sample{2, 3}, sample{3, 4}, sample{5, 2}, sample{6, 3}},
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue