Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Prom fork to 2.24 #378

Merged
merged 1 commit into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
68 changes: 40 additions & 28 deletions cmd/promxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path"
"regexp"

"go.uber.org/atomic"
"k8s.io/klog"

"github.com/golang/glog"
Expand All @@ -24,20 +25,19 @@ import (

_ "net/http/pprof"

"crypto/md5"

kitlog "github.com/go-kit/kit/log"
"github.com/jessevdk/go-flags"
"github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/route"
"github.com/prometheus/common/version"
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/discovery"
sd_config "github.com/prometheus/prometheus/discovery/config"
_ "github.com/prometheus/prometheus/discovery/install" // Register service discovery implementations.
"github.com/prometheus/prometheus/notifier"
"github.com/prometheus/prometheus/pkg/relabel"
"github.com/prometheus/prometheus/promql"
Expand All @@ -50,7 +50,6 @@ import (

proxyconfig "github.com/jacksontj/promxy/pkg/config"
"github.com/jacksontj/promxy/pkg/logging"
"github.com/jacksontj/promxy/pkg/noop"
"github.com/jacksontj/promxy/pkg/proxystorage"
)

Expand Down Expand Up @@ -79,10 +78,11 @@ type cliOpts struct {
ExternalURL string `long:"web.external-url" description:"The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). Used for generating relative and absolute links back to Prometheus itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived automatically."`
EnableLifecycle bool `long:"web.enable-lifecycle" description:"Enable shutdown and reload via HTTP request."`

QueryTimeout time.Duration `long:"query.timeout" description:"Maximum time a query may take before being aborted." default:"2m"`
QueryMaxConcurrency int `long:"query.max-concurrency" description:"Maximum number of queries executed concurrently." default:"1000"`
QueryMaxSamples int `long:"query.max-samples" description:"Maximum number of samples a single query can load into memory. Note that queries will fail if they would load more samples than this into memory, so this also limits the number of samples a query can return." default:"50000000"`
QueryLookbackDelta time.Duration `long:"query.lookback-delta" description:"The maximum lookback duration for retrieving metrics during expression evaluations." default:"5m"`
QueryTimeout time.Duration `long:"query.timeout" description:"Maximum time a query may take before being aborted." default:"2m"`
// TODO: REMOVE
//QueryMaxConcurrency int `long:"query.max-concurrency" description:"Maximum number of queries executed concurrently." default:"1000"`
QueryMaxSamples int `long:"query.max-samples" description:"Maximum number of samples a single query can load into memory. Note that queries will fail if they would load more samples than this into memory, so this also limits the number of samples a query can return." default:"50000000"`
QueryLookbackDelta time.Duration `long:"query.lookback-delta" description:"The maximum lookback duration for retrieving metrics during expression evaluations." default:"5m"`

RemoteReadMaxConcurrency int `long:"remote-read.max-concurrency" description:"Maximum number of concurrent remote read calls." default:"10"`

Expand All @@ -106,7 +106,7 @@ func (c *cliOpts) ToFlags() map[string]string {

var opts cliOpts

func reloadConfig(rls ...proxyconfig.Reloadable) error {
func reloadConfig(noStepSuqueryInterval *safePromQLNoStepSubqueryInterval, rls ...proxyconfig.Reloadable) error {
cfg, err := proxyconfig.ConfigFromFile(opts.ConfigFile)
if err != nil {
return fmt.Errorf("error loading cfg: %v", err)
Expand All @@ -123,7 +123,7 @@ func reloadConfig(rls ...proxyconfig.Reloadable) error {
if failed {
return fmt.Errorf("one or more errors occurred while applying new configuration")
}
promql.SetDefaultEvaluationInterval(time.Duration(cfg.PromConfig.GlobalConfig.EvaluationInterval))
noStepSuqueryInterval.Set(cfg.PromConfig.GlobalConfig.EvaluationInterval)
reloadTime.Set(float64(time.Now().Unix()))
return nil
}
Expand Down Expand Up @@ -199,17 +199,19 @@ func main() {
}
reloadables = append(reloadables, ps)
proxyStorage = ps
noStepSubqueryInterval := &safePromQLNoStepSubqueryInterval{}
noStepSubqueryInterval.Set(config.DefaultGlobalConfig.EvaluationInterval)

engine := promql.NewEngine(promql.EngineOpts{
Reg: prometheus.DefaultRegisterer,
MaxConcurrent: opts.QueryMaxConcurrency,
Timeout: opts.QueryTimeout,
MaxSamples: opts.QueryMaxSamples,
Reg: prometheus.DefaultRegisterer,
//MaxConcurrent: opts.QueryMaxConcurrency, TODO: remove
Timeout: opts.QueryTimeout,
MaxSamples: opts.QueryMaxSamples,
NoStepSubqueryIntervalFn: noStepSubqueryInterval.Get,
LookbackDelta: opts.QueryLookbackDelta,
})
engine.NodeReplacer = ps.NodeReplacer

promql.LookbackDelta = opts.QueryLookbackDelta

// TODO: rename
externalUrl, err := computeExternalURL(opts.ExternalURL, opts.BindAddr)
if err != nil {
Expand Down Expand Up @@ -237,16 +239,12 @@ func main() {
reloadables = append(reloadables, proxyconfig.WrapPromReloadable(notifierManager))

discoveryManagerNotify := discovery.NewManager(ctx, kitlog.With(logger, "component", "discovery manager notify"))

reloadables = append(reloadables,
proxyconfig.WrapPromReloadable(&proxyconfig.ApplyConfigFunc{func(cfg *config.Config) error {
c := make(map[string]sd_config.ServiceDiscoveryConfig)
for _, v := range cfg.AlertingConfig.AlertmanagerConfigs {
// AlertmanagerConfigs doesn't hold an unique identifier so we use the config hash as the identifier.
b, err := json.Marshal(v)
if err != nil {
return err
}
c[fmt.Sprintf("%x", md5.Sum(b))] = v.ServiceDiscoveryConfig
c := make(map[string]discovery.Configs)
for k, v := range cfg.AlertingConfig.AlertmanagerConfigs.ToMap() {
c[k] = v.ServiceDiscoveryConfigs
}
return discoveryManagerNotify.ApplyConfig(c)
}}),
Expand All @@ -270,7 +268,6 @@ func main() {
ExternalURL: externalUrl, // URL listed as URL for "who fired this alert"
QueryFunc: rules.EngineQueryFunc(engine, proxyStorage),
NotifyFunc: sendAlerts(notifierManager, externalUrl.String()),
TSDB: noop.NewNoopStorage(), // TODO: use remote_read?
Appendable: proxyStorage,
Logger: logger,
Registerer: prometheus.DefaultRegisterer,
Expand Down Expand Up @@ -383,7 +380,7 @@ func main() {
}
})

if err := reloadConfig(reloadables...); err != nil {
if err := reloadConfig(noStepSubqueryInterval, reloadables...); err != nil {
logrus.Fatalf("Error loading config: %s", err)
}

Expand Down Expand Up @@ -434,7 +431,7 @@ func main() {
select {
case rc := <-webHandler.Reload():
log.Infof("Reloading config")
if err := reloadConfig(reloadables...); err != nil {
if err := reloadConfig(noStepSubqueryInterval, reloadables...); err != nil {
log.Errorf("Error reloading config: %s", err)
rc <- err
} else {
Expand All @@ -444,7 +441,7 @@ func main() {
switch sig {
case syscall.SIGHUP:
log.Infof("Reloading config")
if err := reloadConfig(reloadables...); err != nil {
if err := reloadConfig(noStepSubqueryInterval, reloadables...); err != nil {
log.Errorf("Error reloading config: %s", err)
}
case syscall.SIGTERM, syscall.SIGINT:
Expand Down Expand Up @@ -550,3 +547,18 @@ func compileCORSRegexString(s string) (*regexp.Regexp, error) {
}
return r.Regexp, nil
}

type safePromQLNoStepSubqueryInterval struct {
value atomic.Int64
}

func durationToInt64Millis(d time.Duration) int64 {
return int64(d / time.Millisecond)
}
func (i *safePromQLNoStepSubqueryInterval) Set(ev model.Duration) {
i.value.Store(durationToInt64Millis(time.Duration(ev)))
}

func (i *safePromQLNoStepSubqueryInterval) Get(int64) int64 {
return i.value.Load()
}
52 changes: 13 additions & 39 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,25 @@ module github.com/jacksontj/promxy
go 1.13

require (
cloud.google.com/go v0.39.0 // indirect
github.com/Azure/azure-sdk-for-go v30.0.0+incompatible // indirect
github.com/Azure/go-autorest v11.2.8+incompatible
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 // indirect
github.com/aws/aws-sdk-go v1.34.0 // indirect
github.com/go-kit/kit v0.8.0
github.com/gogo/protobuf v1.2.1
github.com/Azure/go-autorest/autorest v0.11.15
github.com/go-kit/kit v0.10.0
github.com/gogo/protobuf v1.3.1
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/snappy v0.0.1
github.com/google/gofuzz v1.0.0 // indirect
github.com/gophercloud/gophercloud v0.1.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.9.0 // indirect
github.com/hashicorp/go-immutable-radix v1.1.0 // indirect
github.com/hashicorp/memberlist v0.1.4 // indirect
github.com/hashicorp/serf v0.8.3 // indirect
github.com/golang/snappy v0.0.2
github.com/jessevdk/go-flags v1.4.0
github.com/julienschmidt/httprouter v1.2.0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/miekg/dns v1.1.13 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/julienschmidt/httprouter v1.3.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.0.1-0.20190709205512-ff1d4e21c12e
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
github.com/prometheus/common v0.5.0
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.15.0
github.com/prometheus/prometheus v1.8.1-0.20200513230854-c784807932c2
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec // indirect
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd // indirect
github.com/sirupsen/logrus v1.4.3-0.20190518135202-2a22dbedbad1
github.com/stretchr/testify v1.5.1
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
google.golang.org/api v0.6.0 // indirect
google.golang.org/appengine v1.6.1 // indirect
google.golang.org/genproto v0.0.0-20190605220351-eb0b1bdb6ae6 // indirect
google.golang.org/grpc v1.21.1 // indirect
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
gopkg.in/yaml.v2 v2.2.3-0.20190319135612-7b8349ac747c
k8s.io/klog v0.3.2
k8s.io/utils v0.0.0-20190529001817-6999998975a7 // indirect
github.com/sirupsen/logrus v1.6.0
go.uber.org/atomic v1.7.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/klog v1.0.0
)

replace github.com/prometheus/prometheus => github.com/jacksontj/prometheus v1.8.1-0.20200513230854-c784807932c2
replace github.com/prometheus/prometheus => github.com/jacksontj/prometheus v1.8.1-0.20210128194121-21b119060d91

replace github.com/golang/glog => github.com/kubermatic/glog-gokit v0.0.0-20181129151237-8ab7e4c2d352

Expand Down
Loading