Create default logger for DB

This commit is contained in:
Fabian Reinartz 2017-02-19 16:04:37 +01:00
parent f734773214
commit a3b47c4929
3 changed files with 15 additions and 11 deletions

View File

@ -50,7 +50,7 @@ type writeBenchmark struct {
cleanup bool
numMetrics int
storage *tsdb.PartitionedDB
storage *tsdb.DB
cpuprof *os.File
memprof *os.File
@ -90,7 +90,7 @@ func (b *writeBenchmark) run(cmd *cobra.Command, args []string) {
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,
RetentionDuration: 1 * 24 * 60 * 60 * 1000, // 1 days in milliseconds
MinBlockDuration: 3 * 60 * 60 * 1000, // 2 hours in milliseconds

View File

@ -158,12 +158,11 @@ func (c *compactor) compact(dir string, blocks ...Block) (err error) {
c.metrics.duration.Observe(time.Since(start).Seconds())
}()
if fileutil.Exist(dir) {
if err = os.RemoveAll(dir); err != nil {
return err
}
if err = os.RemoveAll(dir); err != nil {
return err
}
if err = os.MkdirAll(dir, 0755); err != nil {
if err = os.MkdirAll(dir, 0777); err != nil {
return err
}

13
db.go
View File

@ -131,7 +131,7 @@ func newDBMetrics(r prometheus.Registerer) *dbMetrics {
}
// 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 {
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)
}
// var r prometheus.Registerer
r := prometheus.DefaultRegisterer
if l == nil {
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 {
opts = DefaultOptions
@ -161,7 +166,7 @@ func Open(dir string, logger log.Logger, opts *Options) (db *DB, err error) {
db = &DB{
dir: dir,
lockf: lockf,
logger: logger,
logger: l,
metrics: newDBMetrics(r),
opts: opts,
compactc: make(chan struct{}, 1),