diff --git a/cmd/tsdb/main.go b/cmd/tsdb/main.go index 8c0494510e..d4fdc6251f 100644 --- a/cmd/tsdb/main.go +++ b/cmd/tsdb/main.go @@ -107,7 +107,9 @@ func main() { } dumpSamples(db, *dumpMinTime, *dumpMaxTime) } - flag.CommandLine.Set("log.level", "debug") + if err := flag.CommandLine.Set("log.level", "debug"); err != nil { + exitWithError(err) + } } type writeBenchmark struct { diff --git a/compact_test.go b/compact_test.go index 90819bcf92..2580478569 100644 --- a/compact_test.go +++ b/compact_test.go @@ -27,7 +27,6 @@ import ( "github.com/go-kit/kit/log" "github.com/pkg/errors" prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" - dto "github.com/prometheus/client_model/go" "github.com/prometheus/tsdb/chunks" "github.com/prometheus/tsdb/fileutil" "github.com/prometheus/tsdb/labels" @@ -744,7 +743,7 @@ func TestCompaction_populateBlock(t *testing.T) { if ok := t.Run(tc.title, func(t *testing.T) { blocks := make([]BlockReader, 0, len(tc.inputSeriesSamples)) for _, b := range tc.inputSeriesSamples { - ir, cr, mint, maxt := createIdxChkReaders(b) + ir, cr, mint, maxt := createIdxChkReaders(t, b) blocks = append(blocks, &mockBReader{ir: ir, cr: cr, mint: mint, maxt: maxt}) } @@ -890,16 +889,14 @@ func TestDisableAutoCompactions(t *testing.T) { default: } - m := &dto.Metric{} for x := 0; x < 10; x++ { - db.metrics.compactionsSkipped.Write(m) - if *m.Counter.Value > float64(0) { + if prom_testutil.ToFloat64(db.metrics.compactionsSkipped) > 0.0 { break } time.Sleep(10 * time.Millisecond) } - testutil.Assert(t, *m.Counter.Value > float64(0), "No compaction was skipped after the set timeout.") + testutil.Assert(t, prom_testutil.ToFloat64(db.metrics.compactionsSkipped) > 0.0, "No compaction was skipped after the set timeout.") testutil.Equals(t, 0, len(db.blocks)) // Enable the compaction, trigger it and check that the block is persisted. diff --git a/go.mod b/go.mod index df0015df3a..02f3cf9e78 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/pkg/errors v0.8.0 github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v0.9.1 - github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 + github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce // indirect github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d // indirect github.com/stretchr/testify v1.2.2 // indirect diff --git a/head_test.go b/head_test.go index 4fbdec03af..9e78b6b624 100644 --- a/head_test.go +++ b/head_test.go @@ -859,7 +859,7 @@ func TestGCChunkAccess(t *testing.T) { _, err = cr.Chunk(chunks[1].Ref) testutil.Ok(t, err) - h.Truncate(1500) // Remove a chunk. + testutil.Ok(t, h.Truncate(1500)) // Remove a chunk. _, err = cr.Chunk(chunks[0].Ref) testutil.Equals(t, ErrNotFound, err) @@ -899,7 +899,7 @@ func TestGCSeriesAccess(t *testing.T) { _, err = cr.Chunk(chunks[1].Ref) testutil.Ok(t, err) - h.Truncate(2000) // Remove the series. + testutil.Ok(t, h.Truncate(2000)) // Remove the series. testutil.Equals(t, (*memSeries)(nil), h.series.getByID(1)) diff --git a/index/index.go b/index/index.go index 9e5ceccecc..6b333fa584 100644 --- a/index/index.go +++ b/index/index.go @@ -53,7 +53,6 @@ const ( type indexWriterSeries struct { labels labels.Labels chunks []chunks.Meta // series file offset of chunks - offset uint32 // index file offset of series reference } type indexWriterSeriesSlice []*indexWriterSeries diff --git a/index/index_test.go b/index/index_test.go index b82d07d2a2..43b737c7d1 100644 --- a/index/index_test.go +++ b/index/index_test.go @@ -295,7 +295,7 @@ func TestPersistence_index_e2e(t *testing.T) { for i, s := range input { err = iw.AddSeries(uint64(i), s.labels, s.chunks...) testutil.Ok(t, err) - mi.AddSeries(uint64(i), s.labels, s.chunks...) + testutil.Ok(t, mi.AddSeries(uint64(i), s.labels, s.chunks...)) for _, l := range s.labels { valset, ok := values[l.Name] @@ -325,7 +325,7 @@ func TestPersistence_index_e2e(t *testing.T) { } err = iw.WritePostings("", "", newListPostings(all...)) testutil.Ok(t, err) - mi.WritePostings("", "", newListPostings(all...)) + testutil.Ok(t, mi.WritePostings("", "", newListPostings(all...))) for n, e := range postings.m { for v := range e { diff --git a/labels/labels.go b/labels/labels.go index d1ba70b454..35a230f57c 100644 --- a/labels/labels.go +++ b/labels/labels.go @@ -204,9 +204,7 @@ func ReadLabels(fn string, n int) ([]Labels, error) { hashes[h] = struct{}{} i++ } - if err != nil { - return nil, err - } + if i != n { return mets, errors.Errorf("requested %d metrics but found %d", n, i) } diff --git a/querier_test.go b/querier_test.go index 3b70032829..d190840fd8 100644 --- a/querier_test.go +++ b/querier_test.go @@ -194,7 +194,7 @@ type seriesSamples struct { // Index: labels -> postings -> chunkMetas -> chunkRef // ChunkReader: ref -> vals -func createIdxChkReaders(tc []seriesSamples) (IndexReader, ChunkReader, int64, int64) { +func createIdxChkReaders(t *testing.T, tc []seriesSamples) (IndexReader, ChunkReader, int64, int64) { sort.Slice(tc, func(i, j int) bool { return labels.Compare(labels.FromMap(tc[i].lset), labels.FromMap(tc[i].lset)) < 0 }) @@ -234,7 +234,7 @@ func createIdxChkReaders(tc []seriesSamples) (IndexReader, ChunkReader, int64, i } ls := labels.FromMap(s.lset) - mi.AddSeries(uint64(i), ls, metas...) + testutil.Ok(t, mi.AddSeries(uint64(i), ls, metas...)) postings.Add(uint64(i), ls) @@ -249,12 +249,12 @@ func createIdxChkReaders(tc []seriesSamples) (IndexReader, ChunkReader, int64, i } for l, vs := range lblIdx { - mi.WriteLabelIndex([]string{l}, vs.slice()) + testutil.Ok(t, mi.WriteLabelIndex([]string{l}, vs.slice())) } - postings.Iter(func(l labels.Label, p index.Postings) error { + testutil.Ok(t, postings.Iter(func(l labels.Label, p index.Postings) error { return mi.WritePostings(l.Name, l.Value, p) - }) + })) return mi, chkReader, blockMint, blockMaxt } @@ -363,7 +363,7 @@ func TestBlockQuerier(t *testing.T) { Outer: for _, c := range cases.queries { - ir, cr, _, _ := createIdxChkReaders(cases.data) + ir, cr, _, _ := createIdxChkReaders(t, cases.data) querier := &blockQuerier{ index: ir, chunks: cr, @@ -525,7 +525,7 @@ func TestBlockQuerierDelete(t *testing.T) { Outer: for _, c := range cases.queries { - ir, cr, _, _ := createIdxChkReaders(cases.data) + ir, cr, _, _ := createIdxChkReaders(t, cases.data) querier := &blockQuerier{ index: ir, chunks: cr, @@ -630,7 +630,7 @@ func TestBaseChunkSeries(t *testing.T) { for _, tc := range cases { mi := newMockIndex() for _, s := range tc.series { - mi.AddSeries(s.ref, s.lset, s.chunks...) + testutil.Ok(t, mi.AddSeries(s.ref, s.lset, s.chunks...)) } bcs := &baseChunkSeries{ @@ -1884,7 +1884,7 @@ func TestPostingsForMatchers(t *testing.T) { for p.Next() { lbls := labels.Labels{} - ir.Series(p.At(), &lbls, &[]chunks.Meta{}) + testutil.Ok(t, ir.Series(p.At(), &lbls, &[]chunks.Meta{})) if _, ok := exp[lbls.String()]; !ok { t.Errorf("Evaluating %v, unexpected result %s", c.matchers, lbls.String()) } else { diff --git a/repair_test.go b/repair_test.go index 19b663fea5..15e85ff64a 100644 --- a/repair_test.go +++ b/repair_test.go @@ -69,7 +69,7 @@ func TestRepairBadIndexVersion(t *testing.T) { testutil.NotOk(t, err) // Touch chunks dir in block. - os.MkdirAll(filepath.Join(dbDir, "chunks"), 0777) + testutil.Ok(t, os.MkdirAll(filepath.Join(dbDir, "chunks"), 0777)) defer func() { testutil.Ok(t, os.RemoveAll(filepath.Join(dbDir, "chunks"))) }() diff --git a/tombstones_test.go b/tombstones_test.go index 80d5ef2040..d60ef832dd 100644 --- a/tombstones_test.go +++ b/tombstones_test.go @@ -139,7 +139,8 @@ func TestMemTombstonesConcurrency(t *testing.T) { }() go func() { for x := 0; x < totalRuns; x++ { - tomb.Get(uint64(x)) + _, err := tomb.Get(uint64(x)) + testutil.Ok(t, err) } wg.Done() }() diff --git a/wal_test.go b/wal_test.go index 7b9f965269..7f07a63b9b 100644 --- a/wal_test.go +++ b/wal_test.go @@ -146,9 +146,9 @@ func TestSegmentWAL_Truncate(t *testing.T) { var readSeries []RefSeries r := w.Reader() - r.Read(func(s []RefSeries) { + testutil.Ok(t, r.Read(func(s []RefSeries) { readSeries = append(readSeries, s...) - }, nil, nil) + }, nil, nil)) testutil.Equals(t, expected, readSeries) }