diff --git a/cmd/prometheus/config.go b/cmd/prometheus/config.go index f5c0015126..5e5f45c15b 100644 --- a/cmd/prometheus/config.go +++ b/cmd/prometheus/config.go @@ -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( diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index b89d9c23a8..ae5998eff6 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -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 diff --git a/storage/tsdb/tsdb.go b/storage/tsdb/tsdb.go index b6552a7c66..c0dc0f96bf 100644 --- a/storage/tsdb/tsdb.go +++ b/storage/tsdb/tsdb.go @@ -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 {