Accept prometheus.Registerer in constructor

This commit is contained in:
Fabian Reinartz 2017-02-28 07:17:01 +01:00
parent 306831f151
commit b281e4e39b
2 changed files with 4 additions and 7 deletions

View 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.Open(dir, nil, &tsdb.Options{ st, err := tsdb.Open(dir, nil, 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

9
db.go
View File

@ -132,7 +132,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, l log.Logger, opts *Options) (db *DB, err error) { func Open(dir string, l log.Logger, r prometheus.Registerer, 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
} }
@ -154,9 +154,6 @@ func Open(dir string, l log.Logger, opts *Options) (db *DB, err error) {
l = log.NewContext(l).With("ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) 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
} }
@ -736,7 +733,7 @@ func isPowTwo(x int) bool {
} }
// OpenPartitioned or create a new DB. // OpenPartitioned or create a new DB.
func OpenPartitioned(dir string, n int, l log.Logger, opts *Options) (*PartitionedDB, error) { func OpenPartitioned(dir string, n int, l log.Logger, r prometheus.Registerer, opts *Options) (*PartitionedDB, error) {
if !isPowTwo(n) { if !isPowTwo(n) {
return nil, errors.Errorf("%d is not a power of two", n) return nil, errors.Errorf("%d is not a power of two", n)
} }
@ -764,7 +761,7 @@ func OpenPartitioned(dir string, n int, l log.Logger, opts *Options) (*Partition
l := log.NewContext(l).With("partition", i) l := log.NewContext(l).With("partition", i)
d := partitionDir(dir, i) d := partitionDir(dir, i)
s, err := Open(d, l, opts) s, err := Open(d, l, r, opts)
if err != nil { if err != nil {
return nil, fmt.Errorf("initializing partition %q failed: %s", d, err) return nil, fmt.Errorf("initializing partition %q failed: %s", d, err)
} }