From 8a775bc468b3cc862871d8d1adf275ddcde52229 Mon Sep 17 00:00:00 2001 From: Bartlomiej Plotka Date: Mon, 17 Feb 2020 10:19:53 +0000 Subject: [PATCH] Moved unit agnostic options to separate pkg. Signed-off-by: Bartlomiej Plotka --- cmd/prometheus/main.go | 3 ++- tsdb/config/config.go | 50 ++++++++++++++++++++++++++++++++++++++++++ web/web.go | 32 ++------------------------- 3 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 tsdb/config/config.go diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 0acbc0ace..888e2a977 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -40,6 +40,7 @@ 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" @@ -106,7 +107,7 @@ func main() { outageTolerance model.Duration resendDelay model.Duration web web.Options - tsdb web.TSDBOptions + tsdb tsdbconfig.Options lookbackDelta model.Duration webTimeout model.Duration queryTimeout model.Duration diff --git a/tsdb/config/config.go b/tsdb/config/config.go new file mode 100644 index 000000000..13f56d924 --- /dev/null +++ b/tsdb/config/config.go @@ -0,0 +1,50 @@ +// 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 e5b269675..5dbe7f7bf 100644 --- a/web/web.go +++ b/web/web.go @@ -38,7 +38,6 @@ 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" @@ -52,6 +51,7 @@ 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" @@ -209,39 +209,11 @@ func (h *Handler) ApplyConfig(conf *config.Config) 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), - } -} - // Options for the web Handler. type Options struct { Context context.Context TSDB func() *tsdb.DB - TSDBCfg TSDBOptions + TSDBCfg tsdbconfig.Options Storage storage.Storage QueryEngine *promql.Engine LookbackDelta time.Duration