Skip to content

Commit

Permalink
sidecar: allow custom http con pool size fix thanos-io#1953
Browse files Browse the repository at this point in the history
  • Loading branch information
blockloop committed Jan 8, 2020
1 parent 9c84435 commit ef94c38
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion cmd/thanos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -95,6 +98,7 @@ func registerSidecar(m map[string]setupFunc, app *kingpin.Application) {
*ignoreBlockSize,
component.Sidecar,
*minTime,
*connectionPoolSize,
)
}
}
Expand All @@ -120,6 +124,7 @@ func runSidecar(
ignoreBlockSize bool,
comp component.Component,
limitMinTime thanosmodel.TimeOrDurationValue,
connectionPoolSize int,
) error {
var m = &promMetadata{
promURL: promURL,
Expand Down Expand Up @@ -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")
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/store/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit ef94c38

Please sign in to comment.