mirror of https://github.com/prometheus/prometheus
Moved tsdbconfig to main.
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>pull/6777/head
parent
a20bebf7eb
commit
48ead578a0
|
@ -32,6 +32,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"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"
|
||||||
|
@ -41,7 +42,6 @@ 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"
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ func main() {
|
||||||
outageTolerance model.Duration
|
outageTolerance model.Duration
|
||||||
resendDelay model.Duration
|
resendDelay model.Duration
|
||||||
web web.Options
|
web web.Options
|
||||||
tsdb tsdbconfig.Options
|
tsdb tsdbOptions
|
||||||
lookbackDelta model.Duration
|
lookbackDelta model.Duration
|
||||||
webTimeout model.Duration
|
webTimeout model.Duration
|
||||||
queryTimeout model.Duration
|
queryTimeout model.Duration
|
||||||
|
@ -384,12 +384,13 @@ func main() {
|
||||||
|
|
||||||
cfg.web.Context = ctxWeb
|
cfg.web.Context = ctxWeb
|
||||||
cfg.web.TSDB = localStorage.Get
|
cfg.web.TSDB = localStorage.Get
|
||||||
|
cfg.web.TSDBRetentionDuration = cfg.tsdb.RetentionDuration
|
||||||
|
cfg.web.TSDBMaxBytes = cfg.tsdb.MaxBytes
|
||||||
cfg.web.Storage = fanoutStorage
|
cfg.web.Storage = fanoutStorage
|
||||||
cfg.web.QueryEngine = queryEngine
|
cfg.web.QueryEngine = queryEngine
|
||||||
cfg.web.ScrapeManager = scrapeManager
|
cfg.web.ScrapeManager = scrapeManager
|
||||||
cfg.web.RuleManager = ruleManager
|
cfg.web.RuleManager = ruleManager
|
||||||
cfg.web.Notifier = notifierManager
|
cfg.web.Notifier = notifierManager
|
||||||
cfg.web.TSDBCfg = cfg.tsdb
|
|
||||||
cfg.web.LookbackDelta = time.Duration(cfg.lookbackDelta)
|
cfg.web.LookbackDelta = time.Duration(cfg.lookbackDelta)
|
||||||
|
|
||||||
cfg.web.Version = &web.PrometheusVersion{
|
cfg.web.Version = &web.PrometheusVersion{
|
||||||
|
@ -977,3 +978,31 @@ func (s *readyStorage) Close() 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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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),
|
|
||||||
}
|
|
||||||
}
|
|
41
web/web.go
41
web/web.go
|
@ -38,6 +38,7 @@ 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"
|
||||||
|
@ -51,7 +52,6 @@ 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"
|
||||||
|
@ -211,17 +211,18 @@ func (h *Handler) ApplyConfig(conf *config.Config) error {
|
||||||
|
|
||||||
// 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 tsdbconfig.Options
|
TSDBRetentionDuration model.Duration
|
||||||
Storage storage.Storage
|
TSDBMaxBytes units.Base2Bytes
|
||||||
QueryEngine *promql.Engine
|
Storage storage.Storage
|
||||||
LookbackDelta time.Duration
|
QueryEngine *promql.Engine
|
||||||
ScrapeManager *scrape.Manager
|
LookbackDelta time.Duration
|
||||||
RuleManager *rules.Manager
|
ScrapeManager *scrape.Manager
|
||||||
Notifier *notifier.Manager
|
RuleManager *rules.Manager
|
||||||
Version *PrometheusVersion
|
Notifier *notifier.Manager
|
||||||
Flags map[string]string
|
Version *PrometheusVersion
|
||||||
|
Flags map[string]string
|
||||||
|
|
||||||
ListenAddress string
|
ListenAddress string
|
||||||
CORSOrigin *regexp.Regexp
|
CORSOrigin *regexp.Regexp
|
||||||
|
@ -757,14 +758,14 @@ func (h *Handler) status(w http.ResponseWriter, r *http.Request) {
|
||||||
GODEBUG: os.Getenv("GODEBUG"),
|
GODEBUG: os.Getenv("GODEBUG"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.options.TSDBCfg.RetentionDuration != 0 {
|
if h.options.TSDBRetentionDuration != 0 {
|
||||||
status.StorageRetention = h.options.TSDBCfg.RetentionDuration.String()
|
status.StorageRetention = h.options.TSDBRetentionDuration.String()
|
||||||
}
|
}
|
||||||
if h.options.TSDBCfg.MaxBytes != 0 {
|
if h.options.TSDBMaxBytes != 0 {
|
||||||
if status.StorageRetention != "" {
|
if status.StorageRetention != "" {
|
||||||
status.StorageRetention = status.StorageRetention + " or "
|
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()
|
metrics, err := h.gatherer.Gather()
|
||||||
|
@ -807,14 +808,14 @@ func (h *Handler) runtimeInfo() (api_v1.RuntimeInfo, error) {
|
||||||
GODEBUG: os.Getenv("GODEBUG"),
|
GODEBUG: os.Getenv("GODEBUG"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.options.TSDBCfg.RetentionDuration != 0 {
|
if h.options.TSDBRetentionDuration != 0 {
|
||||||
status.StorageRetention = h.options.TSDBCfg.RetentionDuration.String()
|
status.StorageRetention = h.options.TSDBRetentionDuration.String()
|
||||||
}
|
}
|
||||||
if h.options.TSDBCfg.MaxBytes != 0 {
|
if h.options.TSDBMaxBytes != 0 {
|
||||||
if status.StorageRetention != "" {
|
if status.StorageRetention != "" {
|
||||||
status.StorageRetention = status.StorageRetention + " or "
|
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()
|
metrics, err := h.gatherer.Gather()
|
||||||
|
|
Loading…
Reference in New Issue