mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
66dfb951c4
* Add errors and Warnings to SeriesSet Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Change Querier interface and refactor accordingly Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Refactor promql/engine to propagate warnings at eval stage Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Address review issues Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Make sure all the series from all Selects are pre-advanced Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Address review issues Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Separate merge series sets Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Clean Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Refactor merge querier failure handling Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Refactored and simplified fanout with improvements from incoming chunk iterator PRs. * Secondary logic is hidden, instead of weird failed series set logic we had. * Fanout is well commented * Fanout closing record all errors * MergeQuerier improved API (clearer) * deferredGenericMergeSeriesSet is not needed as we return no samples anyway for failed series sets (next = false). Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Fix formatting Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Fix CI issues Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Added final tests for error handling. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Addressed Brian's comments. * Moved hints in populate to be allocated only when needed. * Used sync.Once in secondary Querier to achieve all-or-nothing partial response logic. * Select after first Next is done will panic. NOTE: in lazySeriesSet in theory we could just panic, I think however we can totally just return error, it will panic in expand anyway. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Utilize errWithWarnings Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Fix recently introduced expansion issue Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Add tests for secondary querier error handling Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Implement lazy merge Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Add name to test cases Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Reorganize Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Address review comments Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Address review comments Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Remove redundant warnings Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Fix rebase mistake Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
192 lines
6.1 KiB
Go
192 lines
6.1 KiB
Go
// Copyright 2018 The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package tsdb
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/prometheus/prometheus/pkg/labels"
|
|
"github.com/prometheus/prometheus/util/testutil"
|
|
)
|
|
|
|
// Make entries ~50B in size, to emulate real-world high cardinality.
|
|
const (
|
|
postingsBenchSuffix = "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd"
|
|
)
|
|
|
|
func BenchmarkPostingsForMatchers(b *testing.B) {
|
|
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
|
testutil.Ok(b, err)
|
|
defer func() {
|
|
testutil.Ok(b, os.RemoveAll(chunkDir))
|
|
}()
|
|
h, err := NewHead(nil, nil, nil, 1000, chunkDir, nil, DefaultStripeSize, nil)
|
|
testutil.Ok(b, err)
|
|
defer func() {
|
|
testutil.Ok(b, h.Close())
|
|
}()
|
|
|
|
app := h.Appender()
|
|
addSeries := func(l labels.Labels) {
|
|
app.Add(l, 0, 0)
|
|
}
|
|
|
|
for n := 0; n < 10; n++ {
|
|
for i := 0; i < 100000; i++ {
|
|
addSeries(labels.FromStrings("i", strconv.Itoa(i)+postingsBenchSuffix, "n", strconv.Itoa(n)+postingsBenchSuffix, "j", "foo"))
|
|
// Have some series that won't be matched, to properly test inverted matches.
|
|
addSeries(labels.FromStrings("i", strconv.Itoa(i)+postingsBenchSuffix, "n", strconv.Itoa(n)+postingsBenchSuffix, "j", "bar"))
|
|
addSeries(labels.FromStrings("i", strconv.Itoa(i)+postingsBenchSuffix, "n", "0_"+strconv.Itoa(n)+postingsBenchSuffix, "j", "bar"))
|
|
addSeries(labels.FromStrings("i", strconv.Itoa(i)+postingsBenchSuffix, "n", "1_"+strconv.Itoa(n)+postingsBenchSuffix, "j", "bar"))
|
|
addSeries(labels.FromStrings("i", strconv.Itoa(i)+postingsBenchSuffix, "n", "2_"+strconv.Itoa(n)+postingsBenchSuffix, "j", "foo"))
|
|
}
|
|
}
|
|
testutil.Ok(b, app.Commit())
|
|
|
|
ir, err := h.Index()
|
|
testutil.Ok(b, err)
|
|
b.Run("Head", func(b *testing.B) {
|
|
benchmarkPostingsForMatchers(b, ir)
|
|
})
|
|
|
|
tmpdir, err := ioutil.TempDir("", "test_benchpostingsformatchers")
|
|
testutil.Ok(b, err)
|
|
defer func() {
|
|
testutil.Ok(b, os.RemoveAll(tmpdir))
|
|
}()
|
|
|
|
blockdir := createBlockFromHead(b, tmpdir, h)
|
|
block, err := OpenBlock(nil, blockdir, nil)
|
|
testutil.Ok(b, err)
|
|
defer func() {
|
|
testutil.Ok(b, block.Close())
|
|
}()
|
|
ir, err = block.Index()
|
|
testutil.Ok(b, err)
|
|
defer ir.Close()
|
|
b.Run("Block", func(b *testing.B) {
|
|
benchmarkPostingsForMatchers(b, ir)
|
|
})
|
|
}
|
|
|
|
func benchmarkPostingsForMatchers(b *testing.B, ir IndexReader) {
|
|
n1 := labels.MustNewMatcher(labels.MatchEqual, "n", "1"+postingsBenchSuffix)
|
|
|
|
jFoo := labels.MustNewMatcher(labels.MatchEqual, "j", "foo")
|
|
jNotFoo := labels.MustNewMatcher(labels.MatchNotEqual, "j", "foo")
|
|
|
|
iStar := labels.MustNewMatcher(labels.MatchRegexp, "i", "^.*$")
|
|
iPlus := labels.MustNewMatcher(labels.MatchRegexp, "i", "^.+$")
|
|
i1Plus := labels.MustNewMatcher(labels.MatchRegexp, "i", "^1.+$")
|
|
iEmptyRe := labels.MustNewMatcher(labels.MatchRegexp, "i", "^$")
|
|
iNotEmpty := labels.MustNewMatcher(labels.MatchNotEqual, "i", "")
|
|
iNot2 := labels.MustNewMatcher(labels.MatchNotEqual, "n", "2"+postingsBenchSuffix)
|
|
iNot2Star := labels.MustNewMatcher(labels.MatchNotRegexp, "i", "^2.*$")
|
|
|
|
cases := []struct {
|
|
name string
|
|
matchers []*labels.Matcher
|
|
}{
|
|
{`n="1"`, []*labels.Matcher{n1}},
|
|
{`n="1",j="foo"`, []*labels.Matcher{n1, jFoo}},
|
|
{`j="foo",n="1"`, []*labels.Matcher{jFoo, n1}},
|
|
{`n="1",j!="foo"`, []*labels.Matcher{n1, jNotFoo}},
|
|
{`i=~".*"`, []*labels.Matcher{iStar}},
|
|
{`i=~".+"`, []*labels.Matcher{iPlus}},
|
|
{`i=~""`, []*labels.Matcher{iEmptyRe}},
|
|
{`i!=""`, []*labels.Matcher{iNotEmpty}},
|
|
{`n="1",i=~".*",j="foo"`, []*labels.Matcher{n1, iStar, jFoo}},
|
|
{`n="1",i=~".*",i!="2",j="foo"`, []*labels.Matcher{n1, iStar, iNot2, jFoo}},
|
|
{`n="1",i!=""`, []*labels.Matcher{n1, iNotEmpty}},
|
|
{`n="1",i!="",j="foo"`, []*labels.Matcher{n1, iNotEmpty, jFoo}},
|
|
{`n="1",i=~".+",j="foo"`, []*labels.Matcher{n1, iPlus, jFoo}},
|
|
{`n="1",i=~"1.+",j="foo"`, []*labels.Matcher{n1, i1Plus, jFoo}},
|
|
{`n="1",i=~".+",i!="2",j="foo"`, []*labels.Matcher{n1, iPlus, iNot2, jFoo}},
|
|
{`n="1",i=~".+",i!~"2.*",j="foo"`, []*labels.Matcher{n1, iPlus, iNot2Star, jFoo}},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
b.Run(c.name, func(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := PostingsForMatchers(ir, c.matchers...)
|
|
testutil.Ok(b, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkQuerierSelect(b *testing.B) {
|
|
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
|
testutil.Ok(b, err)
|
|
defer func() {
|
|
testutil.Ok(b, os.RemoveAll(chunkDir))
|
|
}()
|
|
h, err := NewHead(nil, nil, nil, 1000, chunkDir, nil, DefaultStripeSize, nil)
|
|
testutil.Ok(b, err)
|
|
defer h.Close()
|
|
app := h.Appender()
|
|
numSeries := 1000000
|
|
for i := 0; i < numSeries; i++ {
|
|
app.Add(labels.FromStrings("foo", "bar", "i", fmt.Sprintf("%d%s", i, postingsBenchSuffix)), int64(i), 0)
|
|
}
|
|
testutil.Ok(b, app.Commit())
|
|
|
|
bench := func(b *testing.B, br BlockReader, sorted bool) {
|
|
matcher := labels.MustNewMatcher(labels.MatchEqual, "foo", "bar")
|
|
for s := 1; s <= numSeries; s *= 10 {
|
|
b.Run(fmt.Sprintf("%dof%d", s, numSeries), func(b *testing.B) {
|
|
q, err := NewBlockQuerier(br, 0, int64(s-1))
|
|
testutil.Ok(b, err)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
ss := q.Select(sorted, nil, matcher)
|
|
for ss.Next() {
|
|
}
|
|
testutil.Ok(b, ss.Err())
|
|
}
|
|
q.Close()
|
|
})
|
|
}
|
|
}
|
|
|
|
b.Run("Head", func(b *testing.B) {
|
|
bench(b, h, false)
|
|
})
|
|
b.Run("SortedHead", func(b *testing.B) {
|
|
bench(b, h, true)
|
|
})
|
|
|
|
tmpdir, err := ioutil.TempDir("", "test_benchquerierselect")
|
|
testutil.Ok(b, err)
|
|
defer func() {
|
|
testutil.Ok(b, os.RemoveAll(tmpdir))
|
|
}()
|
|
|
|
blockdir := createBlockFromHead(b, tmpdir, h)
|
|
block, err := OpenBlock(nil, blockdir, nil)
|
|
testutil.Ok(b, err)
|
|
defer func() {
|
|
testutil.Ok(b, block.Close())
|
|
}()
|
|
|
|
b.Run("Block", func(b *testing.B) {
|
|
bench(b, block, false)
|
|
})
|
|
}
|