Moved unit agnostic options to separate pkg.

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
This commit is contained in:
Bartlomiej Plotka 2020-02-17 10:19:53 +00:00
parent 59c9d6ef45
commit 8a775bc468
3 changed files with 54 additions and 31 deletions

View file

@ -40,6 +40,7 @@ import (
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"github.com/prometheus/common/promlog" "github.com/prometheus/common/promlog"
"github.com/prometheus/common/version" "github.com/prometheus/common/version"
tsdbconfig "github.com/prometheus/prometheus/tsdb/config"
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
"k8s.io/klog" "k8s.io/klog"
@ -106,7 +107,7 @@ func main() {
outageTolerance model.Duration outageTolerance model.Duration
resendDelay model.Duration resendDelay model.Duration
web web.Options web web.Options
tsdb web.TSDBOptions tsdb tsdbconfig.Options
lookbackDelta model.Duration lookbackDelta model.Duration
webTimeout model.Duration webTimeout model.Duration
queryTimeout model.Duration queryTimeout model.Duration

50
tsdb/config/config.go Normal file
View file

@ -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),
}
}

View file

@ -38,7 +38,6 @@ import (
template_text "text/template" template_text "text/template"
"time" "time"
"github.com/alecthomas/units"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level" "github.com/go-kit/kit/log/level"
conntrack "github.com/mwitkow/go-conntrack" conntrack "github.com/mwitkow/go-conntrack"
@ -52,6 +51,7 @@ import (
"github.com/prometheus/common/route" "github.com/prometheus/common/route"
"github.com/prometheus/common/server" "github.com/prometheus/common/server"
"github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/tsdb"
tsdbconfig "github.com/prometheus/prometheus/tsdb/config"
"github.com/prometheus/prometheus/tsdb/index" "github.com/prometheus/prometheus/tsdb/index"
"github.com/soheilhy/cmux" "github.com/soheilhy/cmux"
"golang.org/x/net/netutil" "golang.org/x/net/netutil"
@ -209,39 +209,11 @@ func (h *Handler) ApplyConfig(conf *config.Config) error {
return nil 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. // Options for the web Handler.
type Options struct { type Options struct {
Context context.Context Context context.Context
TSDB func() *tsdb.DB TSDB func() *tsdb.DB
TSDBCfg TSDBOptions TSDBCfg tsdbconfig.Options
Storage storage.Storage Storage storage.Storage
QueryEngine *promql.Engine QueryEngine *promql.Engine
LookbackDelta time.Duration LookbackDelta time.Duration