2017-04-10 11:59:45 -07:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
package index
|
2017-03-06 08:36:03 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
2017-03-14 07:24:08 -07:00
|
|
|
"math/rand"
|
2017-03-06 08:36:03 -08:00
|
|
|
"os"
|
2017-03-08 07:54:13 -08:00
|
|
|
"path/filepath"
|
2017-03-14 07:24:08 -07:00
|
|
|
"sort"
|
2017-03-07 02:29:20 -08:00
|
|
|
"testing"
|
2017-03-06 08:36:03 -08:00
|
|
|
|
2017-03-29 16:18:41 -07:00
|
|
|
"github.com/pkg/errors"
|
2017-11-30 06:34:49 -08:00
|
|
|
"github.com/prometheus/tsdb/chunkenc"
|
2017-04-24 08:10:12 -07:00
|
|
|
"github.com/prometheus/tsdb/chunks"
|
2017-04-04 02:27:26 -07:00
|
|
|
"github.com/prometheus/tsdb/labels"
|
2017-12-06 17:06:14 -08:00
|
|
|
"github.com/prometheus/tsdb/testutil"
|
2017-03-06 08:36:03 -08:00
|
|
|
)
|
|
|
|
|
2017-03-29 16:18:41 -07:00
|
|
|
type series struct {
|
|
|
|
l labels.Labels
|
2017-11-30 06:34:49 -08:00
|
|
|
chunks []chunks.Meta
|
2017-03-07 02:29:20 -08:00
|
|
|
}
|
|
|
|
|
2017-03-29 16:18:41 -07:00
|
|
|
type mockIndex struct {
|
2017-09-04 07:08:38 -07:00
|
|
|
series map[uint64]series
|
2017-03-29 16:18:41 -07:00
|
|
|
labelIndex map[string][]string
|
2017-11-30 06:34:49 -08:00
|
|
|
postings map[labels.Label][]uint64
|
2017-08-05 04:31:48 -07:00
|
|
|
symbols map[string]struct{}
|
2017-03-07 02:29:20 -08:00
|
|
|
}
|
|
|
|
|
2017-03-29 16:18:41 -07:00
|
|
|
func newMockIndex() mockIndex {
|
2017-10-09 06:21:46 -07:00
|
|
|
ix := mockIndex{
|
2017-09-04 07:08:38 -07:00
|
|
|
series: make(map[uint64]series),
|
2017-03-29 16:18:41 -07:00
|
|
|
labelIndex: make(map[string][]string),
|
2017-11-30 06:34:49 -08:00
|
|
|
postings: make(map[labels.Label][]uint64),
|
2017-08-05 04:31:48 -07:00
|
|
|
symbols: make(map[string]struct{}),
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
2017-10-09 06:21:46 -07:00
|
|
|
return ix
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
|
|
|
|
2017-08-05 04:31:48 -07:00
|
|
|
func (m mockIndex) Symbols() (map[string]struct{}, error) {
|
|
|
|
return m.symbols, nil
|
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
func (m mockIndex) AddSeries(ref uint64, l labels.Labels, chunks ...chunks.Meta) error {
|
2017-03-29 16:18:41 -07:00
|
|
|
if _, ok := m.series[ref]; ok {
|
|
|
|
return errors.Errorf("series with reference %d already added", ref)
|
|
|
|
}
|
2017-08-05 04:31:48 -07:00
|
|
|
for _, lbl := range l {
|
|
|
|
m.symbols[lbl.Name] = struct{}{}
|
|
|
|
m.symbols[lbl.Value] = struct{}{}
|
|
|
|
}
|
2017-03-29 16:18:41 -07:00
|
|
|
|
2017-04-24 08:10:12 -07:00
|
|
|
s := series{l: l}
|
|
|
|
// Actual chunk data is not stored in the index.
|
|
|
|
for _, c := range chunks {
|
2017-08-06 11:41:24 -07:00
|
|
|
c.Chunk = nil
|
|
|
|
s.chunks = append(s.chunks, c)
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
2017-04-24 08:10:12 -07:00
|
|
|
m.series[ref] = s
|
2017-03-29 16:18:41 -07:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockIndex) WriteLabelIndex(names []string, values []string) error {
|
|
|
|
// TODO support composite indexes
|
|
|
|
if len(names) != 1 {
|
|
|
|
return errors.New("composite indexes not supported yet")
|
|
|
|
}
|
|
|
|
sort.Strings(values)
|
|
|
|
m.labelIndex[names[0]] = values
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockIndex) WritePostings(name, value string, it Postings) error {
|
2017-11-30 06:34:49 -08:00
|
|
|
l := labels.Label{Name: name, Value: value}
|
|
|
|
if _, ok := m.postings[l]; ok {
|
|
|
|
return errors.Errorf("postings for %s already added", l)
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
2017-11-30 06:34:49 -08:00
|
|
|
ep, err := ExpandPostings(it)
|
2017-08-05 04:31:48 -07:00
|
|
|
if err != nil {
|
2017-03-29 16:18:41 -07:00
|
|
|
return err
|
|
|
|
}
|
2017-11-30 06:34:49 -08:00
|
|
|
m.postings[l] = ep
|
|
|
|
return nil
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockIndex) Close() error {
|
|
|
|
return nil
|
2017-03-07 02:29:20 -08:00
|
|
|
}
|
|
|
|
|
2017-03-29 16:18:41 -07:00
|
|
|
func (m mockIndex) LabelValues(names ...string) (StringTuples, error) {
|
|
|
|
// TODO support composite indexes
|
|
|
|
if len(names) != 1 {
|
|
|
|
return nil, errors.New("composite indexes not supported yet")
|
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
return NewStringTuples(m.labelIndex[names[0]], 1)
|
2017-03-07 02:29:20 -08:00
|
|
|
}
|
|
|
|
|
2017-03-29 16:18:41 -07:00
|
|
|
func (m mockIndex) Postings(name, value string) (Postings, error) {
|
2017-11-30 06:34:49 -08:00
|
|
|
l := labels.Label{Name: name, Value: value}
|
|
|
|
return NewListPostings(m.postings[l]), nil
|
2017-08-05 04:31:48 -07:00
|
|
|
}
|
2017-03-29 16:18:41 -07:00
|
|
|
|
2017-08-05 04:31:48 -07:00
|
|
|
func (m mockIndex) SortedPostings(p Postings) Postings {
|
2017-11-30 06:34:49 -08:00
|
|
|
ep, err := ExpandPostings(p)
|
2017-08-05 04:31:48 -07:00
|
|
|
if err != nil {
|
2017-11-30 06:34:49 -08:00
|
|
|
return ErrPostings(errors.Wrap(err, "expand postings"))
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
|
|
|
|
2017-08-05 04:31:48 -07:00
|
|
|
sort.Slice(ep, func(i, j int) bool {
|
|
|
|
return labels.Compare(m.series[ep[i]].l, m.series[ep[j]].l) < 0
|
|
|
|
})
|
2017-11-30 06:34:49 -08:00
|
|
|
return NewListPostings(ep)
|
2017-03-07 02:29:20 -08:00
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
func (m mockIndex) Series(ref uint64, lset *labels.Labels, chks *[]chunks.Meta) error {
|
2017-03-29 16:18:41 -07:00
|
|
|
s, ok := m.series[ref]
|
|
|
|
if !ok {
|
2017-11-30 06:34:49 -08:00
|
|
|
return errors.New("not found")
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
2017-08-05 04:31:48 -07:00
|
|
|
*lset = append((*lset)[:0], s.l...)
|
|
|
|
*chks = append((*chks)[:0], s.chunks...)
|
2017-03-29 16:18:41 -07:00
|
|
|
|
2017-08-05 04:31:48 -07:00
|
|
|
return nil
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockIndex) LabelIndices() ([][]string, error) {
|
|
|
|
res := make([][]string, 0, len(m.labelIndex))
|
|
|
|
for k := range m.labelIndex {
|
|
|
|
res = append(res, []string{k})
|
|
|
|
}
|
|
|
|
return res, nil
|
2017-03-07 02:29:20 -08:00
|
|
|
}
|
|
|
|
|
2017-03-08 07:54:13 -08:00
|
|
|
func TestIndexRW_Create_Open(t *testing.T) {
|
|
|
|
dir, err := ioutil.TempDir("", "test_index_create")
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-06 08:36:03 -08:00
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
fn := filepath.Join(dir, "index")
|
|
|
|
|
2017-03-08 07:54:13 -08:00
|
|
|
// An empty index must still result in a readable file.
|
2017-11-30 06:34:49 -08:00
|
|
|
iw, err := NewWriter(fn)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Ok(t, iw.Close())
|
2017-03-06 08:36:03 -08:00
|
|
|
|
2018-02-09 04:11:03 -08:00
|
|
|
ir, err := NewFileReader(fn)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Ok(t, ir.Close())
|
2017-03-06 08:36:03 -08:00
|
|
|
|
2017-03-08 07:54:13 -08:00
|
|
|
// Modify magic header must cause open to fail.
|
2017-11-30 06:34:49 -08:00
|
|
|
f, err := os.OpenFile(fn, os.O_WRONLY, 0666)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-08 07:54:13 -08:00
|
|
|
_, err = f.WriteAt([]byte{0, 0}, 0)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-06 08:36:03 -08:00
|
|
|
|
2018-02-09 04:11:03 -08:00
|
|
|
_, err = NewFileReader(dir)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.NotOk(t, err)
|
2017-03-08 07:54:13 -08:00
|
|
|
}
|
2017-03-06 08:36:03 -08:00
|
|
|
|
2017-03-09 00:39:30 -08:00
|
|
|
func TestIndexRW_Postings(t *testing.T) {
|
|
|
|
dir, err := ioutil.TempDir("", "test_index_postings")
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-09 00:39:30 -08:00
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
fn := filepath.Join(dir, "index")
|
|
|
|
|
|
|
|
iw, err := NewWriter(fn)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-09 00:39:30 -08:00
|
|
|
|
|
|
|
series := []labels.Labels{
|
|
|
|
labels.FromStrings("a", "1", "b", "1"),
|
|
|
|
labels.FromStrings("a", "1", "b", "2"),
|
|
|
|
labels.FromStrings("a", "1", "b", "3"),
|
|
|
|
labels.FromStrings("a", "1", "b", "4"),
|
|
|
|
}
|
|
|
|
|
2017-08-05 04:31:48 -07:00
|
|
|
err = iw.AddSymbols(map[string]struct{}{
|
2018-05-07 05:39:54 -07:00
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"1": {},
|
|
|
|
"2": {},
|
|
|
|
"3": {},
|
|
|
|
"4": {},
|
2017-08-05 04:31:48 -07:00
|
|
|
})
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-08-05 04:31:48 -07:00
|
|
|
|
2017-03-09 00:39:30 -08:00
|
|
|
// Postings lists are only written if a series with the respective
|
|
|
|
// reference was added before.
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, iw.AddSeries(1, series[0]))
|
|
|
|
testutil.Ok(t, iw.AddSeries(2, series[1]))
|
|
|
|
testutil.Ok(t, iw.AddSeries(3, series[2]))
|
|
|
|
testutil.Ok(t, iw.AddSeries(4, series[3]))
|
2017-03-09 00:39:30 -08:00
|
|
|
|
2017-09-04 07:08:38 -07:00
|
|
|
err = iw.WritePostings("a", "1", newListPostings([]uint64{1, 2, 3, 4}))
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-09 00:39:30 -08:00
|
|
|
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, iw.Close())
|
2017-03-09 00:39:30 -08:00
|
|
|
|
2018-02-09 04:11:03 -08:00
|
|
|
ir, err := NewFileReader(fn)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-09 00:39:30 -08:00
|
|
|
|
|
|
|
p, err := ir.Postings("a", "1")
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-09 00:39:30 -08:00
|
|
|
|
2017-08-05 04:31:48 -07:00
|
|
|
var l labels.Labels
|
2017-11-30 06:34:49 -08:00
|
|
|
var c []chunks.Meta
|
2017-08-05 04:31:48 -07:00
|
|
|
|
2017-03-09 00:39:30 -08:00
|
|
|
for i := 0; p.Next(); i++ {
|
2017-08-05 04:31:48 -07:00
|
|
|
err := ir.Series(p.At(), &l, &c)
|
2017-03-09 00:39:30 -08:00
|
|
|
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Equals(t, 0, len(c))
|
|
|
|
testutil.Equals(t, series[i], l)
|
2017-03-09 00:39:30 -08:00
|
|
|
}
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, p.Err())
|
2017-03-09 00:39:30 -08:00
|
|
|
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, ir.Close())
|
2017-03-09 00:39:30 -08:00
|
|
|
}
|
|
|
|
|
2017-03-14 07:24:08 -07:00
|
|
|
func TestPersistence_index_e2e(t *testing.T) {
|
|
|
|
dir, err := ioutil.TempDir("", "test_persistence_e2e")
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-14 07:24:08 -07:00
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
2018-10-25 02:32:57 -07:00
|
|
|
lbls, err := labels.ReadLabels(filepath.Join("..", "testdata", "20kseries.json"), 20000)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2017-08-05 04:31:48 -07:00
|
|
|
// Sort labels as the index writer expects series in sorted order.
|
|
|
|
sort.Sort(labels.Slice(lbls))
|
|
|
|
|
|
|
|
symbols := map[string]struct{}{}
|
|
|
|
for _, lset := range lbls {
|
|
|
|
for _, l := range lset {
|
|
|
|
symbols[l.Name] = struct{}{}
|
|
|
|
symbols[l.Value] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 07:24:08 -07:00
|
|
|
var input indexWriterSeriesSlice
|
|
|
|
|
|
|
|
// Generate ChunkMetas for every label set.
|
|
|
|
for i, lset := range lbls {
|
2017-11-30 06:34:49 -08:00
|
|
|
var metas []chunks.Meta
|
2017-03-14 07:24:08 -07:00
|
|
|
|
|
|
|
for j := 0; j <= (i % 20); j++ {
|
2017-11-30 06:34:49 -08:00
|
|
|
metas = append(metas, chunks.Meta{
|
2017-03-14 07:24:08 -07:00
|
|
|
MinTime: int64(j * 10000),
|
|
|
|
MaxTime: int64((j + 1) * 10000),
|
|
|
|
Ref: rand.Uint64(),
|
2017-11-30 06:34:49 -08:00
|
|
|
Chunk: chunkenc.NewXORChunk(),
|
2017-03-14 07:24:08 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
input = append(input, &indexWriterSeries{
|
|
|
|
labels: lset,
|
|
|
|
chunks: metas,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
iw, err := NewWriter(filepath.Join(dir, "index"))
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, iw.AddSymbols(symbols))
|
2017-08-05 04:31:48 -07:00
|
|
|
|
2017-03-14 07:24:08 -07:00
|
|
|
// Population procedure as done by compaction.
|
|
|
|
var (
|
2017-11-30 06:34:49 -08:00
|
|
|
postings = NewMemPostings()
|
|
|
|
values = map[string]map[string]struct{}{}
|
2017-03-14 07:24:08 -07:00
|
|
|
)
|
|
|
|
|
2017-03-29 16:18:41 -07:00
|
|
|
mi := newMockIndex()
|
|
|
|
|
2017-03-14 07:24:08 -07:00
|
|
|
for i, s := range input {
|
2017-09-04 07:08:38 -07:00
|
|
|
err = iw.AddSeries(uint64(i), s.labels, s.chunks...)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-09-04 07:08:38 -07:00
|
|
|
mi.AddSeries(uint64(i), s.labels, s.chunks...)
|
2017-03-14 07:24:08 -07:00
|
|
|
|
|
|
|
for _, l := range s.labels {
|
|
|
|
valset, ok := values[l.Name]
|
|
|
|
if !ok {
|
2017-11-30 06:34:49 -08:00
|
|
|
valset = map[string]struct{}{}
|
2017-03-14 07:24:08 -07:00
|
|
|
values[l.Name] = valset
|
|
|
|
}
|
2017-11-30 06:34:49 -08:00
|
|
|
valset[l.Value] = struct{}{}
|
2017-03-14 07:24:08 -07:00
|
|
|
}
|
2017-11-30 06:34:49 -08:00
|
|
|
postings.Add(uint64(i), s.labels)
|
2017-03-14 07:24:08 -07:00
|
|
|
i++
|
|
|
|
}
|
2017-04-08 08:42:04 -07:00
|
|
|
|
|
|
|
for k, v := range values {
|
2017-12-21 02:55:58 -08:00
|
|
|
var vals []string
|
|
|
|
for e := range v {
|
|
|
|
vals = append(vals, e)
|
|
|
|
}
|
|
|
|
sort.Strings(vals)
|
2017-04-08 08:42:04 -07:00
|
|
|
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, iw.WriteLabelIndex([]string{k}, vals))
|
|
|
|
testutil.Ok(t, mi.WriteLabelIndex([]string{k}, vals))
|
2017-04-08 08:42:04 -07:00
|
|
|
}
|
|
|
|
|
2017-09-04 07:08:38 -07:00
|
|
|
all := make([]uint64, len(lbls))
|
2017-03-14 07:24:08 -07:00
|
|
|
for i := range all {
|
2017-09-04 07:08:38 -07:00
|
|
|
all[i] = uint64(i)
|
2017-03-14 07:24:08 -07:00
|
|
|
}
|
|
|
|
err = iw.WritePostings("", "", newListPostings(all))
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-29 16:18:41 -07:00
|
|
|
mi.WritePostings("", "", newListPostings(all))
|
|
|
|
|
2018-11-02 07:27:19 -07:00
|
|
|
for n, e := range postings.m {
|
|
|
|
for v := range e {
|
|
|
|
err = iw.WritePostings(n, v, postings.Get(n, v))
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
mi.WritePostings(n, v, postings.Get(n, v))
|
|
|
|
}
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
2017-03-14 07:24:08 -07:00
|
|
|
|
|
|
|
err = iw.Close()
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2018-02-09 04:11:03 -08:00
|
|
|
ir, err := NewFileReader(filepath.Join(dir, "index"))
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
for p := range mi.postings {
|
2017-09-05 02:45:18 -07:00
|
|
|
gotp, err := ir.Postings(p.Name, p.Value)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2017-09-05 02:45:18 -07:00
|
|
|
expp, err := mi.Postings(p.Name, p.Value)
|
2019-01-02 08:48:42 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-08-05 04:31:48 -07:00
|
|
|
|
|
|
|
var lset, explset labels.Labels
|
2017-11-30 06:34:49 -08:00
|
|
|
var chks, expchks []chunks.Meta
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2017-03-29 16:18:41 -07:00
|
|
|
for gotp.Next() {
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Assert(t, expp.Next() == true, "")
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2017-03-29 16:18:41 -07:00
|
|
|
ref := gotp.At()
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2017-08-05 04:31:48 -07:00
|
|
|
err := ir.Series(ref, &lset, &chks)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2017-08-05 04:31:48 -07:00
|
|
|
err = mi.Series(expp.At(), &explset, &expchks)
|
2019-01-02 08:48:42 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Equals(t, explset, lset)
|
|
|
|
testutil.Equals(t, expchks, chks)
|
2017-03-29 16:18:41 -07:00
|
|
|
}
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Assert(t, expp.Next() == false, "")
|
|
|
|
testutil.Ok(t, gotp.Err())
|
2017-03-14 07:24:08 -07:00
|
|
|
}
|
|
|
|
|
2017-04-08 08:42:04 -07:00
|
|
|
for k, v := range mi.labelIndex {
|
2017-12-21 02:55:58 -08:00
|
|
|
tplsExp, err := NewStringTuples(v, 1)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-04-08 08:42:04 -07:00
|
|
|
|
|
|
|
tplsRes, err := ir.LabelValues(k)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-03-14 07:24:08 -07:00
|
|
|
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Equals(t, tplsExp.Len(), tplsRes.Len())
|
2017-04-08 08:42:04 -07:00
|
|
|
for i := 0; i < tplsExp.Len(); i++ {
|
|
|
|
strsExp, err := tplsExp.At(i)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-04-08 08:42:04 -07:00
|
|
|
|
|
|
|
strsRes, err := tplsRes.At(i)
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, err)
|
2017-04-08 08:42:04 -07:00
|
|
|
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Equals(t, strsExp, strsRes)
|
2017-04-08 08:42:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 17:06:14 -08:00
|
|
|
testutil.Ok(t, ir.Close())
|
2017-03-14 07:24:08 -07:00
|
|
|
}
|
2018-06-25 02:25:22 -07:00
|
|
|
|
|
|
|
func TestReaderWithInvalidBuffer(t *testing.T) {
|
|
|
|
b := realByteSlice([]byte{0x81, 0x81, 0x81, 0x81, 0x81, 0x81})
|
|
|
|
r := &Reader{b: b}
|
|
|
|
|
|
|
|
db := r.decbufUvarintAt(0)
|
|
|
|
testutil.NotOk(t, db.err())
|
|
|
|
}
|