Skip to content

Commit

Permalink
Fix tsdb code and tests to work on Windows.
Browse files Browse the repository at this point in the history
Add back Windows CI, we lost it when tsdb was merged into the prometheus
repo. There's many tests failing outside tsdb, so only test tsdb for
now.

Fixes #6513

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
  • Loading branch information
brian-brazil committed Jan 3, 2020
1 parent a9ed3b9 commit c3d6784
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
12 changes: 12 additions & 0 deletions .circleci/config.yml
Expand Up @@ -4,6 +4,7 @@ version: 2.1
orbs:
prometheus: prometheus/prometheus@0.3.0
go: circleci/go@0.2.0
win: circleci/windows@2.3.0

executors:
# Whenever the Go version is updated here, .promu.yml
Expand Down Expand Up @@ -49,6 +50,13 @@ jobs:
key: v1-npm-deps-{{ checksum "web/ui/react-app/yarn.lock" }}
paths:
- web/ui/react-app/node_modules
test_windows:
executor: win/default
working_directory: /go/src/github.com/prometheus/prometheus
steps:
- checkout
# TSDB is where the most risk is Windows wise, so only test there for now.
- run: go test ./tsdb/...
fuzzit_regression:
executor: fuzzit
working_directory: /go/src/github.com/prometheus/prometheus
Expand Down Expand Up @@ -78,6 +86,10 @@ workflows:
filters:
tags:
only: /.*/
- test_windows:
filters:
tags:
only: /.*/
- fuzzit_regression:
filters:
tags:
Expand Down
2 changes: 2 additions & 0 deletions tsdb/block_test.go
Expand Up @@ -197,9 +197,11 @@ func TestCorruptedChunk(t *testing.T) {
testutil.Equals(t, test.openErr.Error(), err.Error())
return
}
defer func() { testutil.Ok(t, b.Close()) }()

querier, err := NewBlockQuerier(b, 0, 1)
testutil.Ok(t, err)
defer func() { testutil.Ok(t, querier.Close()) }()
set, err := querier.Select(labels.MustNewMatcher(labels.MatchEqual, "a", "b"))
testutil.Ok(t, err)

Expand Down
2 changes: 2 additions & 0 deletions tsdb/db_test.go
Expand Up @@ -2655,6 +2655,7 @@ func TestChunkWriter_ReadAfterWrite(t *testing.T) {
// Check the content of the chunks.
r, err := chunks.NewDirReader(tempDir, nil)
testutil.Ok(t, err)
defer func() { testutil.Ok(t, r.Close()) }()

for _, chks := range test.chks {
for _, chkExp := range chks {
Expand Down Expand Up @@ -2705,4 +2706,5 @@ func TestChunkReader_ConcurrentReads(t *testing.T) {
}
wg.Wait()
}
testutil.Ok(t, r.Close())
}
25 changes: 18 additions & 7 deletions tsdb/index/index.go
Expand Up @@ -511,11 +511,11 @@ func (w *Writer) finishSymbols() error {
return err
}

var err error
w.symbolFile, err = fileutil.OpenMmapFile(w.f.name)
sf, err := fileutil.OpenMmapFile(w.f.name)
if err != nil {
return err
}
w.symbolFile = sf
hash := crc32.Checksum(w.symbolFile.Bytes()[w.toc.Symbols+4:hashPos], castagnoliTable)
w.buf1.Reset()
w.buf1.PutBE32(hash)
Expand Down Expand Up @@ -700,7 +700,11 @@ func (w *Writer) writePostingsOffsetTable() error {
if err != nil {
return err
}
defer f.Close()
defer func() {
if f != nil {
f.Close()
}
}()
d := encoding.NewDecbufRaw(realByteSlice(f.Bytes()), int(w.fPO.pos))
cnt := w.cntPO
for d.Err() == nil && cnt > 0 {
Expand All @@ -720,6 +724,10 @@ func (w *Writer) writePostingsOffsetTable() error {
}

// Cleanup temporary file.
if err := f.Close(); err != nil {
return err
}
f = nil
if err := w.fPO.close(); err != nil {
return err
}
Expand Down Expand Up @@ -962,9 +970,9 @@ type labelIndexHashEntry struct {
}

func (w *Writer) Close() error {
if err := w.ensureStage(idxStageDone); err != nil {
return err
}
// Even if this fails, we need to close all the files.
ensureErr := w.ensureStage(idxStageDone)

if w.symbolFile != nil {
if err := w.symbolFile.Close(); err != nil {
return err
Expand All @@ -980,7 +988,10 @@ func (w *Writer) Close() error {
return err
}
}
return w.f.close()
if err := w.f.close(); err != nil {
return err
}
return ensureErr
}

// StringTuples provides access to a sorted list of string tuples.
Expand Down
1 change: 1 addition & 0 deletions tsdb/index/index_test.go
Expand Up @@ -280,6 +280,7 @@ func TestPostingsMany(t *testing.T) {

ir, err := NewFileReader(fn)
testutil.Ok(t, err)
defer func() { testutil.Ok(t, ir.Close()) }()

cases := []struct {
in []string
Expand Down
1 change: 1 addition & 0 deletions tsdb/wal/watcher_test.go
Expand Up @@ -427,6 +427,7 @@ func TestReadCheckpointMultipleSegments(t *testing.T) {
}
}
}
testutil.Ok(t, w.Close())

// At this point we should have at least 6 segments, lets create a checkpoint dir of the first 5.
checkpointDir := dir + "/wal/checkpoint.000004"
Expand Down

0 comments on commit c3d6784

Please sign in to comment.