diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index d3b553f39a..05d1fbd965 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -32,6 +32,7 @@ import ( "syscall" "time" + "github.com/alecthomas/units" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" conntrack "github.com/mwitkow/go-conntrack" @@ -41,7 +42,6 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/common/promlog" "github.com/prometheus/common/version" - tsdbconfig "github.com/prometheus/prometheus/tsdb/config" kingpin "gopkg.in/alecthomas/kingpin.v2" "k8s.io/klog" @@ -109,7 +109,7 @@ func main() { outageTolerance model.Duration resendDelay model.Duration web web.Options - tsdb tsdbconfig.Options + tsdb tsdbOptions lookbackDelta model.Duration webTimeout model.Duration queryTimeout model.Duration @@ -384,12 +384,13 @@ func main() { cfg.web.Context = ctxWeb cfg.web.TSDB = localStorage.Get + cfg.web.TSDBRetentionDuration = cfg.tsdb.RetentionDuration + cfg.web.TSDBMaxBytes = cfg.tsdb.MaxBytes cfg.web.Storage = fanoutStorage cfg.web.QueryEngine = queryEngine cfg.web.ScrapeManager = scrapeManager cfg.web.RuleManager = ruleManager cfg.web.Notifier = notifierManager - cfg.web.TSDBCfg = cfg.tsdb cfg.web.LookbackDelta = time.Duration(cfg.lookbackDelta) cfg.web.Version = &web.PrometheusVersion{ @@ -977,3 +978,31 @@ func (s *readyStorage) Close() error { } return nil } + +// tsdbOptions is tsdb.Option version with defined units. +// This is required as tsdb.Option fields are unit agnostic (time). +type tsdbOptions struct { + WALSegmentSize units.Base2Bytes + RetentionDuration model.Duration + MaxBytes units.Base2Bytes + NoLockfile bool + AllowOverlappingBlocks bool + WALCompression bool + StripeSize int + MinBlockDuration model.Duration + MaxBlockDuration model.Duration +} + +func (opts tsdbOptions) ToTSDBOptions() tsdb.Options { + return tsdb.Options{ + WALSegmentSize: int(opts.WALSegmentSize), + RetentionDuration: int64(time.Duration(opts.RetentionDuration) / time.Millisecond), + MaxBytes: int64(opts.MaxBytes), + NoLockfile: opts.NoLockfile, + AllowOverlappingBlocks: opts.AllowOverlappingBlocks, + WALCompression: opts.WALCompression, + StripeSize: opts.StripeSize, + MinBlockDuration: int64(time.Duration(opts.MinBlockDuration) / time.Millisecond), + MaxBlockDuration: int64(time.Duration(opts.MaxBlockDuration) / time.Millisecond), + } +} diff --git a/tsdb/config/config.go b/tsdb/config/config.go deleted file mode 100644 index 13f56d9249..0000000000 --- a/tsdb/config/config.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2020 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tsdbconfig - -import ( - "time" - - "github.com/alecthomas/units" - "github.com/prometheus/common/model" - "github.com/prometheus/prometheus/tsdb" -) - -// Options is tsdb.Option version with defined units. -// This is required as tsdb.Option fields are unit agnostic (time). -type Options struct { - WALSegmentSize units.Base2Bytes - RetentionDuration model.Duration - MaxBytes units.Base2Bytes - NoLockfile bool - AllowOverlappingBlocks bool - WALCompression bool - StripeSize int - MinBlockDuration model.Duration - MaxBlockDuration model.Duration -} - -func (opts Options) ToTSDBOptions() tsdb.Options { - return tsdb.Options{ - WALSegmentSize: int(opts.WALSegmentSize), - RetentionDuration: int64(time.Duration(opts.RetentionDuration) / time.Millisecond), - MaxBytes: int64(opts.MaxBytes), - NoLockfile: opts.NoLockfile, - AllowOverlappingBlocks: opts.AllowOverlappingBlocks, - WALCompression: opts.WALCompression, - StripeSize: opts.StripeSize, - MinBlockDuration: int64(time.Duration(opts.MinBlockDuration) / time.Millisecond), - MaxBlockDuration: int64(time.Duration(opts.MaxBlockDuration) / time.Millisecond), - } -} diff --git a/web/web.go b/web/web.go index 5dbe7f7bf7..e25878928c 100644 --- a/web/web.go +++ b/web/web.go @@ -38,6 +38,7 @@ import ( template_text "text/template" "time" + "github.com/alecthomas/units" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" conntrack "github.com/mwitkow/go-conntrack" @@ -51,7 +52,6 @@ import ( "github.com/prometheus/common/route" "github.com/prometheus/common/server" "github.com/prometheus/prometheus/tsdb" - tsdbconfig "github.com/prometheus/prometheus/tsdb/config" "github.com/prometheus/prometheus/tsdb/index" "github.com/soheilhy/cmux" "golang.org/x/net/netutil" @@ -211,17 +211,18 @@ func (h *Handler) ApplyConfig(conf *config.Config) error { // Options for the web Handler. type Options struct { - Context context.Context - TSDB func() *tsdb.DB - TSDBCfg tsdbconfig.Options - Storage storage.Storage - QueryEngine *promql.Engine - LookbackDelta time.Duration - ScrapeManager *scrape.Manager - RuleManager *rules.Manager - Notifier *notifier.Manager - Version *PrometheusVersion - Flags map[string]string + Context context.Context + TSDB func() *tsdb.DB + TSDBRetentionDuration model.Duration + TSDBMaxBytes units.Base2Bytes + Storage storage.Storage + QueryEngine *promql.Engine + LookbackDelta time.Duration + ScrapeManager *scrape.Manager + RuleManager *rules.Manager + Notifier *notifier.Manager + Version *PrometheusVersion + Flags map[string]string ListenAddress string CORSOrigin *regexp.Regexp @@ -757,14 +758,14 @@ func (h *Handler) status(w http.ResponseWriter, r *http.Request) { GODEBUG: os.Getenv("GODEBUG"), } - if h.options.TSDBCfg.RetentionDuration != 0 { - status.StorageRetention = h.options.TSDBCfg.RetentionDuration.String() + if h.options.TSDBRetentionDuration != 0 { + status.StorageRetention = h.options.TSDBRetentionDuration.String() } - if h.options.TSDBCfg.MaxBytes != 0 { + if h.options.TSDBMaxBytes != 0 { if status.StorageRetention != "" { status.StorageRetention = status.StorageRetention + " or " } - status.StorageRetention = status.StorageRetention + h.options.TSDBCfg.MaxBytes.String() + status.StorageRetention = status.StorageRetention + h.options.TSDBMaxBytes.String() } metrics, err := h.gatherer.Gather() @@ -807,14 +808,14 @@ func (h *Handler) runtimeInfo() (api_v1.RuntimeInfo, error) { GODEBUG: os.Getenv("GODEBUG"), } - if h.options.TSDBCfg.RetentionDuration != 0 { - status.StorageRetention = h.options.TSDBCfg.RetentionDuration.String() + if h.options.TSDBRetentionDuration != 0 { + status.StorageRetention = h.options.TSDBRetentionDuration.String() } - if h.options.TSDBCfg.MaxBytes != 0 { + if h.options.TSDBMaxBytes != 0 { if status.StorageRetention != "" { status.StorageRetention = status.StorageRetention + " or " } - status.StorageRetention = status.StorageRetention + h.options.TSDBCfg.MaxBytes.String() + status.StorageRetention = status.StorageRetention + h.options.TSDBMaxBytes.String() } metrics, err := h.gatherer.Gather()