Create default logger for DB
This commit is contained in:
parent
f734773214
commit
a3b47c4929
|
@ -50,7 +50,7 @@ type writeBenchmark struct {
|
||||||
cleanup bool
|
cleanup bool
|
||||||
numMetrics int
|
numMetrics int
|
||||||
|
|
||||||
storage *tsdb.PartitionedDB
|
storage *tsdb.DB
|
||||||
|
|
||||||
cpuprof *os.File
|
cpuprof *os.File
|
||||||
memprof *os.File
|
memprof *os.File
|
||||||
|
@ -90,7 +90,7 @@ func (b *writeBenchmark) run(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
dir := filepath.Join(b.outPath, "storage")
|
dir := filepath.Join(b.outPath, "storage")
|
||||||
|
|
||||||
st, err := tsdb.OpenPartitioned(dir, 1, nil, &tsdb.Options{
|
st, err := tsdb.Open(dir, nil, &tsdb.Options{
|
||||||
WALFlushInterval: 200 * time.Millisecond,
|
WALFlushInterval: 200 * time.Millisecond,
|
||||||
RetentionDuration: 1 * 24 * 60 * 60 * 1000, // 1 days in milliseconds
|
RetentionDuration: 1 * 24 * 60 * 60 * 1000, // 1 days in milliseconds
|
||||||
MinBlockDuration: 3 * 60 * 60 * 1000, // 2 hours in milliseconds
|
MinBlockDuration: 3 * 60 * 60 * 1000, // 2 hours in milliseconds
|
||||||
|
|
|
@ -158,12 +158,11 @@ func (c *compactor) compact(dir string, blocks ...Block) (err error) {
|
||||||
c.metrics.duration.Observe(time.Since(start).Seconds())
|
c.metrics.duration.Observe(time.Since(start).Seconds())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if fileutil.Exist(dir) {
|
if err = os.RemoveAll(dir); err != nil {
|
||||||
if err = os.RemoveAll(dir); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err = os.MkdirAll(dir, 0755); err != nil {
|
|
||||||
|
if err = os.MkdirAll(dir, 0777); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
db.go
13
db.go
|
@ -131,7 +131,7 @@ func newDBMetrics(r prometheus.Registerer) *dbMetrics {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open returns a new DB in the given directory.
|
// Open returns a new DB in the given directory.
|
||||||
func Open(dir string, logger log.Logger, opts *Options) (db *DB, err error) {
|
func Open(dir string, l log.Logger, opts *Options) (db *DB, err error) {
|
||||||
if err := os.MkdirAll(dir, 0777); err != nil {
|
if err := os.MkdirAll(dir, 0777); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -148,8 +148,13 @@ func Open(dir string, logger log.Logger, opts *Options) (db *DB, err error) {
|
||||||
return nil, errors.Wrapf(err, "open DB in %s", dir)
|
return nil, errors.Wrapf(err, "open DB in %s", dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// var r prometheus.Registerer
|
if l == nil {
|
||||||
r := prometheus.DefaultRegisterer
|
l = log.NewLogfmtLogger(os.Stdout)
|
||||||
|
l = log.NewContext(l).With("ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller)
|
||||||
|
}
|
||||||
|
|
||||||
|
var r prometheus.Registerer
|
||||||
|
// r := prometheus.DefaultRegisterer
|
||||||
|
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
opts = DefaultOptions
|
opts = DefaultOptions
|
||||||
|
@ -161,7 +166,7 @@ func Open(dir string, logger log.Logger, opts *Options) (db *DB, err error) {
|
||||||
db = &DB{
|
db = &DB{
|
||||||
dir: dir,
|
dir: dir,
|
||||||
lockf: lockf,
|
lockf: lockf,
|
||||||
logger: logger,
|
logger: l,
|
||||||
metrics: newDBMetrics(r),
|
metrics: newDBMetrics(r),
|
||||||
opts: opts,
|
opts: opts,
|
||||||
compactc: make(chan struct{}, 1),
|
compactc: make(chan struct{}, 1),
|
||||||
|
|
Loading…
Reference in New Issue