main: add flags for new storage

This commit is contained in:
Fabian Reinartz 2017-02-05 18:22:06 +01:00
parent 87bea50b85
commit ea3ba338dd
3 changed files with 19 additions and 9 deletions

View file

@ -31,6 +31,7 @@ import (
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/notifier"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage/tsdb"
"github.com/prometheus/prometheus/web"
)
@ -48,6 +49,7 @@ var cfg = struct {
notifierTimeout time.Duration
queryEngine promql.EngineOptions
web web.Options
tsdb tsdb.Options
alertmanagerURLs stringset
prometheusURL string
@ -116,6 +118,18 @@ func init() {
&cfg.localStoragePath, "storage.local.path", "data",
"Base path for metrics storage.",
)
cfg.fs.DurationVar(
&cfg.tsdb.MinBlockDuration, "storage.tsdb.min-block-duration", 2*time.Hour,
"Minimum duration of a data block before being persisted.",
)
cfg.fs.DurationVar(
&cfg.tsdb.MaxBlockDuration, "storage.tsdb.max-block-duration", 36*time.Hour,
"Maximum duration compacted blocks may span.",
)
cfg.fs.IntVar(
&cfg.tsdb.AppendableBlocks, "storage.tsdb.AppendableBlocks", 2,
"Number of head blocks that can be appended to.",
)
// Alertmanager.
cfg.fs.IntVar(

View file

@ -78,11 +78,7 @@ func Main() int {
reloadables []Reloadable
)
localStorage, err := tsdb.Open(cfg.localStoragePath, &tsdb.Options{
MinBlockDuration: 2 * 60 * 60 * 1000,
MaxBlockDuration: 24 * 60 * 60 * 1000,
AppendableBlocks: 2,
})
localStorage, err := tsdb.Open(cfg.localStoragePath, &cfg.tsdb)
if err != nil {
log.Errorf("Opening storage failed: %s", err)
return 1

View file

@ -22,10 +22,10 @@ type Options struct {
// The timestamp range of head blocks after which they get persisted.
// It's the minimum duration of any persisted block.
MinBlockDuration uint64
MinBlockDuration time.Duration
// The maximum timestamp range of compacted blocks.
MaxBlockDuration uint64
MaxBlockDuration time.Duration
// Number of head blocks that can be appended to.
// Should be two or higher to prevent write errors in general scenarios.
@ -39,8 +39,8 @@ type Options struct {
func Open(path string, opts *Options) (storage.Storage, error) {
db, err := tsdb.OpenPartitioned(path, 1, nil, &tsdb.Options{
WALFlushInterval: 10 * time.Second,
MinBlockDuration: opts.MinBlockDuration,
MaxBlockDuration: opts.MaxBlockDuration,
MinBlockDuration: uint64(opts.MinBlockDuration.Seconds() * 1000),
MaxBlockDuration: uint64(opts.MaxBlockDuration.Seconds() * 1000),
AppendableBlocks: opts.AppendableBlocks,
})
if err != nil {