From ef94c388dbf3b47d6ccd114cba93116366340688 Mon Sep 17 00:00:00 2001 From: Brett Jones Date: Tue, 7 Jan 2020 18:53:03 -0600 Subject: [PATCH] sidecar: allow custom http con pool size fix #1953 --- CHANGELOG.md | 1 + cmd/thanos/sidecar.go | 7 ++++++- pkg/store/prometheus.go | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 134714a9c69..abc62fa2ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel ### Fixed +- [#1955](https://github.com/thanos-io/thanos/pull/1955) Sidecar: enable command line flag to set http connection pool size `--prometheus.connection-pool-size` - [#1919](https://github.com/thanos-io/thanos/issues/1919) Compactor: Fixed potential data loss when uploading older blocks, or upload taking long time while compactor is running. - [#1937](https://github.com/thanos-io/thanos/pull/1937) Compactor: Improved synchronization of meta JSON files. diff --git a/cmd/thanos/sidecar.go b/cmd/thanos/sidecar.go index f6961e9766b..54667ed7c81 100644 --- a/cmd/thanos/sidecar.go +++ b/cmd/thanos/sidecar.go @@ -65,6 +65,9 @@ func registerSidecar(m map[string]setupFunc, app *kingpin.Application) { minTime := thanosmodel.TimeOrDuration(cmd.Flag("min-time", "Start of time range limit to serve. Thanos sidecar will serve only metrics, which happened later than this value. Option can be a constant time in RFC3339 format or time duration relative to current time, such as -1d or 2h45m. Valid duration units are ms, s, m, h, d, w, y."). Default("0000-01-01T00:00:00Z")) + connectionPoolSize := cmd.Flag("prometheus.connection-pool-size", "sets the MaxIdleConnsPerHost and MaxIdleConns when connecting to prometheus"). + Default("100").Int() + m[component.Sidecar.String()] = func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, _ bool) error { rl := reloader.New( log.With(logger, "component", "reloader"), @@ -95,6 +98,7 @@ func registerSidecar(m map[string]setupFunc, app *kingpin.Application) { *ignoreBlockSize, component.Sidecar, *minTime, + *connectionPoolSize, ) } } @@ -120,6 +124,7 @@ func runSidecar( ignoreBlockSize bool, comp component.Component, limitMinTime thanosmodel.TimeOrDurationValue, + connectionPoolSize int, ) error { var m = &promMetadata{ promURL: promURL, @@ -244,7 +249,7 @@ func runSidecar( { promStore, err := store.NewPrometheusStore( - logger, nil, promURL, component.Sidecar, m.Labels, m.Timestamps) + logger, nil, promURL, component.Sidecar, m.Labels, m.Timestamps, connectionPoolSize) if err != nil { return errors.Wrap(err, "create Prometheus store") } diff --git a/pkg/store/prometheus.go b/pkg/store/prometheus.go index 4012eceb9c8..74f4eace9d7 100644 --- a/pkg/store/prometheus.go +++ b/pkg/store/prometheus.go @@ -73,13 +73,18 @@ func NewPrometheusStore( component component.StoreAPI, externalLabels func() labels.Labels, timestamps func() (mint int64, maxt int64), + connectionPoolSize int, ) (*PrometheusStore, error) { if logger == nil { logger = log.NewNopLogger() } if client == nil { + t := http.DefaultTransport.(*http.Transport) + t.MaxIdleConnsPerHost = connectionPoolSize + t.MaxIdleConns = connectionPoolSize + client = &http.Client{ - Transport: tracing.HTTPTripperware(logger, http.DefaultTransport), + Transport: tracing.HTTPTripperware(logger, t), } } p := &PrometheusStore{