Skip to content
This repository was archived by the owner on Aug 13, 2019. It is now read-only.

Commit 288f67e

Browse files
fix some unchecked errors and remove unused vars. (#592)
Signed-off-by: Krasi Georgiev <[email protected]>
1 parent a10c001 commit 288f67e

11 files changed

+26
-29
lines changed

cmd/tsdb/main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ func main() {
107107
}
108108
dumpSamples(db, *dumpMinTime, *dumpMaxTime)
109109
}
110-
flag.CommandLine.Set("log.level", "debug")
110+
if err := flag.CommandLine.Set("log.level", "debug"); err != nil {
111+
exitWithError(err)
112+
}
111113
}
112114

113115
type writeBenchmark struct {

compact_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/go-kit/kit/log"
2828
"github.com/pkg/errors"
2929
prom_testutil "github.com/prometheus/client_golang/prometheus/testutil"
30-
dto "github.com/prometheus/client_model/go"
3130
"github.com/prometheus/tsdb/chunks"
3231
"github.com/prometheus/tsdb/fileutil"
3332
"github.com/prometheus/tsdb/labels"
@@ -744,7 +743,7 @@ func TestCompaction_populateBlock(t *testing.T) {
744743
if ok := t.Run(tc.title, func(t *testing.T) {
745744
blocks := make([]BlockReader, 0, len(tc.inputSeriesSamples))
746745
for _, b := range tc.inputSeriesSamples {
747-
ir, cr, mint, maxt := createIdxChkReaders(b)
746+
ir, cr, mint, maxt := createIdxChkReaders(t, b)
748747
blocks = append(blocks, &mockBReader{ir: ir, cr: cr, mint: mint, maxt: maxt})
749748
}
750749

@@ -890,16 +889,14 @@ func TestDisableAutoCompactions(t *testing.T) {
890889
default:
891890
}
892891

893-
m := &dto.Metric{}
894892
for x := 0; x < 10; x++ {
895-
db.metrics.compactionsSkipped.Write(m)
896-
if *m.Counter.Value > float64(0) {
893+
if prom_testutil.ToFloat64(db.metrics.compactionsSkipped) > 0.0 {
897894
break
898895
}
899896
time.Sleep(10 * time.Millisecond)
900897
}
901898

902-
testutil.Assert(t, *m.Counter.Value > float64(0), "No compaction was skipped after the set timeout.")
899+
testutil.Assert(t, prom_testutil.ToFloat64(db.metrics.compactionsSkipped) > 0.0, "No compaction was skipped after the set timeout.")
903900
testutil.Equals(t, 0, len(db.blocks))
904901

905902
// Enable the compaction, trigger it and check that the block is persisted.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/pkg/errors v0.8.0
1919
github.com/pmezard/go-difflib v1.0.0 // indirect
2020
github.com/prometheus/client_golang v0.9.1
21-
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
21+
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect
2222
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce // indirect
2323
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d // indirect
2424
github.com/stretchr/testify v1.2.2 // indirect

head_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ func TestGCChunkAccess(t *testing.T) {
859859
_, err = cr.Chunk(chunks[1].Ref)
860860
testutil.Ok(t, err)
861861

862-
h.Truncate(1500) // Remove a chunk.
862+
testutil.Ok(t, h.Truncate(1500)) // Remove a chunk.
863863

864864
_, err = cr.Chunk(chunks[0].Ref)
865865
testutil.Equals(t, ErrNotFound, err)
@@ -899,7 +899,7 @@ func TestGCSeriesAccess(t *testing.T) {
899899
_, err = cr.Chunk(chunks[1].Ref)
900900
testutil.Ok(t, err)
901901

902-
h.Truncate(2000) // Remove the series.
902+
testutil.Ok(t, h.Truncate(2000)) // Remove the series.
903903

904904
testutil.Equals(t, (*memSeries)(nil), h.series.getByID(1))
905905

index/index.go

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const (
5353
type indexWriterSeries struct {
5454
labels labels.Labels
5555
chunks []chunks.Meta // series file offset of chunks
56-
offset uint32 // index file offset of series reference
5756
}
5857

5958
type indexWriterSeriesSlice []*indexWriterSeries

index/index_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func TestPersistence_index_e2e(t *testing.T) {
295295
for i, s := range input {
296296
err = iw.AddSeries(uint64(i), s.labels, s.chunks...)
297297
testutil.Ok(t, err)
298-
mi.AddSeries(uint64(i), s.labels, s.chunks...)
298+
testutil.Ok(t, mi.AddSeries(uint64(i), s.labels, s.chunks...))
299299

300300
for _, l := range s.labels {
301301
valset, ok := values[l.Name]
@@ -325,7 +325,7 @@ func TestPersistence_index_e2e(t *testing.T) {
325325
}
326326
err = iw.WritePostings("", "", newListPostings(all...))
327327
testutil.Ok(t, err)
328-
mi.WritePostings("", "", newListPostings(all...))
328+
testutil.Ok(t, mi.WritePostings("", "", newListPostings(all...)))
329329

330330
for n, e := range postings.m {
331331
for v := range e {

labels/labels.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ func ReadLabels(fn string, n int) ([]Labels, error) {
204204
hashes[h] = struct{}{}
205205
i++
206206
}
207-
if err != nil {
208-
return nil, err
209-
}
207+
210208
if i != n {
211209
return mets, errors.Errorf("requested %d metrics but found %d", n, i)
212210
}

querier_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ type seriesSamples struct {
194194

195195
// Index: labels -> postings -> chunkMetas -> chunkRef
196196
// ChunkReader: ref -> vals
197-
func createIdxChkReaders(tc []seriesSamples) (IndexReader, ChunkReader, int64, int64) {
197+
func createIdxChkReaders(t *testing.T, tc []seriesSamples) (IndexReader, ChunkReader, int64, int64) {
198198
sort.Slice(tc, func(i, j int) bool {
199199
return labels.Compare(labels.FromMap(tc[i].lset), labels.FromMap(tc[i].lset)) < 0
200200
})
@@ -234,7 +234,7 @@ func createIdxChkReaders(tc []seriesSamples) (IndexReader, ChunkReader, int64, i
234234
}
235235

236236
ls := labels.FromMap(s.lset)
237-
mi.AddSeries(uint64(i), ls, metas...)
237+
testutil.Ok(t, mi.AddSeries(uint64(i), ls, metas...))
238238

239239
postings.Add(uint64(i), ls)
240240

@@ -249,12 +249,12 @@ func createIdxChkReaders(tc []seriesSamples) (IndexReader, ChunkReader, int64, i
249249
}
250250

251251
for l, vs := range lblIdx {
252-
mi.WriteLabelIndex([]string{l}, vs.slice())
252+
testutil.Ok(t, mi.WriteLabelIndex([]string{l}, vs.slice()))
253253
}
254254

255-
postings.Iter(func(l labels.Label, p index.Postings) error {
255+
testutil.Ok(t, postings.Iter(func(l labels.Label, p index.Postings) error {
256256
return mi.WritePostings(l.Name, l.Value, p)
257-
})
257+
}))
258258

259259
return mi, chkReader, blockMint, blockMaxt
260260
}
@@ -363,7 +363,7 @@ func TestBlockQuerier(t *testing.T) {
363363

364364
Outer:
365365
for _, c := range cases.queries {
366-
ir, cr, _, _ := createIdxChkReaders(cases.data)
366+
ir, cr, _, _ := createIdxChkReaders(t, cases.data)
367367
querier := &blockQuerier{
368368
index: ir,
369369
chunks: cr,
@@ -525,7 +525,7 @@ func TestBlockQuerierDelete(t *testing.T) {
525525

526526
Outer:
527527
for _, c := range cases.queries {
528-
ir, cr, _, _ := createIdxChkReaders(cases.data)
528+
ir, cr, _, _ := createIdxChkReaders(t, cases.data)
529529
querier := &blockQuerier{
530530
index: ir,
531531
chunks: cr,
@@ -630,7 +630,7 @@ func TestBaseChunkSeries(t *testing.T) {
630630
for _, tc := range cases {
631631
mi := newMockIndex()
632632
for _, s := range tc.series {
633-
mi.AddSeries(s.ref, s.lset, s.chunks...)
633+
testutil.Ok(t, mi.AddSeries(s.ref, s.lset, s.chunks...))
634634
}
635635

636636
bcs := &baseChunkSeries{
@@ -1884,7 +1884,7 @@ func TestPostingsForMatchers(t *testing.T) {
18841884

18851885
for p.Next() {
18861886
lbls := labels.Labels{}
1887-
ir.Series(p.At(), &lbls, &[]chunks.Meta{})
1887+
testutil.Ok(t, ir.Series(p.At(), &lbls, &[]chunks.Meta{}))
18881888
if _, ok := exp[lbls.String()]; !ok {
18891889
t.Errorf("Evaluating %v, unexpected result %s", c.matchers, lbls.String())
18901890
} else {

repair_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestRepairBadIndexVersion(t *testing.T) {
6969
testutil.NotOk(t, err)
7070

7171
// Touch chunks dir in block.
72-
os.MkdirAll(filepath.Join(dbDir, "chunks"), 0777)
72+
testutil.Ok(t, os.MkdirAll(filepath.Join(dbDir, "chunks"), 0777))
7373
defer func() {
7474
testutil.Ok(t, os.RemoveAll(filepath.Join(dbDir, "chunks")))
7575
}()

tombstones_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ func TestMemTombstonesConcurrency(t *testing.T) {
139139
}()
140140
go func() {
141141
for x := 0; x < totalRuns; x++ {
142-
tomb.Get(uint64(x))
142+
_, err := tomb.Get(uint64(x))
143+
testutil.Ok(t, err)
143144
}
144145
wg.Done()
145146
}()

wal_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ func TestSegmentWAL_Truncate(t *testing.T) {
146146
var readSeries []RefSeries
147147
r := w.Reader()
148148

149-
r.Read(func(s []RefSeries) {
149+
testutil.Ok(t, r.Read(func(s []RefSeries) {
150150
readSeries = append(readSeries, s...)
151-
}, nil, nil)
151+
}, nil, nil))
152152

153153
testutil.Equals(t, expected, readSeries)
154154
}

0 commit comments

Comments
 (0)