mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Allow tombstone file to not exist
This commit is contained in:
parent
7087f68647
commit
da9614fa54
|
@ -20,6 +20,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/prometheus/tsdb/index"
|
"github.com/prometheus/tsdb/index"
|
||||||
|
"github.com/prometheus/tsdb/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSetCompactionFailed(t *testing.T) {
|
func TestSetCompactionFailed(t *testing.T) {
|
||||||
|
|
|
@ -20,10 +20,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prometheus/prometheus/pkg/textparse"
|
|
||||||
"github.com/prometheus/tsdb/chunkenc"
|
"github.com/prometheus/tsdb/chunkenc"
|
||||||
"github.com/prometheus/tsdb/chunks"
|
"github.com/prometheus/tsdb/chunks"
|
||||||
"github.com/prometheus/tsdb/labels"
|
"github.com/prometheus/tsdb/labels"
|
||||||
|
@ -382,41 +380,3 @@ func TestPersistence_index_e2e(t *testing.T) {
|
||||||
|
|
||||||
testutil.Ok(t, ir.Close())
|
testutil.Ok(t, ir.Close())
|
||||||
}
|
}
|
||||||
|
|
||||||
func readPrometheusLabels(fn string, n int) ([]labels.Labels, error) {
|
|
||||||
f, err := os.Open(fn)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(f)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
p := textparse.New(b)
|
|
||||||
i := 0
|
|
||||||
var mets []labels.Labels
|
|
||||||
hashes := map[uint64]struct{}{}
|
|
||||||
|
|
||||||
for p.Next() && i < n {
|
|
||||||
m := make(labels.Labels, 0, 10)
|
|
||||||
p.Metric((*promlabels.Labels)(unsafe.Pointer(&m)))
|
|
||||||
|
|
||||||
h := m.Hash()
|
|
||||||
if _, ok := hashes[h]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
mets = append(mets, m)
|
|
||||||
hashes[h] = struct{}{}
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
if err := p.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if i != n {
|
|
||||||
return mets, errors.Errorf("requested %d metrics but found %d", n, i)
|
|
||||||
}
|
|
||||||
return mets, nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -109,7 +109,9 @@ type Stone struct {
|
||||||
|
|
||||||
func readTombstones(dir string) (memTombstones, error) {
|
func readTombstones(dir string) (memTombstones, error) {
|
||||||
b, err := ioutil.ReadFile(filepath.Join(dir, tombstoneFilename))
|
b, err := ioutil.ReadFile(filepath.Join(dir, tombstoneFilename))
|
||||||
if err != nil {
|
if os.IsNotExist(err) {
|
||||||
|
return memTombstones{}, nil
|
||||||
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue