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
Signed-off-by: Brett Jones <[email protected]>
  • Loading branch information
blockloop committed Jan 8, 2020
1 parent 9c84435 commit c31e774
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 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 @@ -45,6 +45,9 @@ func registerSidecar(m map[string]setupFunc, app *kingpin.Application) {
promReadyTimeout := cmd.Flag("prometheus.ready_timeout", "Maximum time to wait for the Prometheus instance to start up").
Default("10m").Duration()

connectionPoolSize := cmd.Flag("prometheus.connection-pool-size", "sets the MaxIdleConnsPerHost and MaxIdleConns when connecting to prometheus").
Default("100").Int()

dataDir := cmd.Flag("tsdb.path", "Data directory of TSDB.").
Default("./data").String()

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
3 changes: 3 additions & 0 deletions docs/components/sidecar.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ Flags:
--prometheus.ready_timeout=10m
Maximum time to wait for the Prometheus
instance to start up
--prometheus.connection-pool-size=100
sets the MaxIdleConnsPerHost and MaxIdleConns
when connecting to prometheus
--tsdb.path="./data" Data directory of TSDB.
--reloader.config-file="" Config file watched by the reloader.
--reloader.config-envsubst-file=""
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
18 changes: 8 additions & 10 deletions pkg/store/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math"
"net/http"
"net/url"
"testing"
"time"
Expand Down Expand Up @@ -59,7 +60,7 @@ func testPrometheusStoreSeriesE2e(t *testing.T, prefix string) {
limitMinT := int64(0)
proxy, err := NewPrometheusStore(nil, nil, u, component.Sidecar,
func() labels.Labels { return labels.FromStrings("region", "eu-west") },
func() (int64, int64) { return limitMinT, -1 }) // Maxt does not matter.
func() (int64, int64) { return limitMinT, -1 }, http.DefaultMaxIdleConnsPerHost) // Maxt does not matter.
testutil.Ok(t, err)

// Query all three samples except for the first one. Since we round up queried data
Expand Down Expand Up @@ -211,7 +212,7 @@ func TestPrometheusStore_SeriesLabels_e2e(t *testing.T) {
limitMinT := int64(0)
proxy, err := NewPrometheusStore(nil, nil, u, component.Sidecar,
func() labels.Labels { return labels.FromStrings("region", "eu-west") },
func() (int64, int64) { return limitMinT, -1 }) // Maxt does not matter.
func() (int64, int64) { return limitMinT, -1 }, http.DefaultMaxIdleConnsPerHost) // Maxt does not matter.
testutil.Ok(t, err)

{
Expand Down Expand Up @@ -284,7 +285,7 @@ func TestPrometheusStore_LabelValues_e2e(t *testing.T) {
u, err := url.Parse(fmt.Sprintf("http://%s", p.Addr()))
testutil.Ok(t, err)

proxy, err := NewPrometheusStore(nil, nil, u, component.Sidecar, getExternalLabels, nil)
proxy, err := NewPrometheusStore(nil, nil, u, component.Sidecar, getExternalLabels, nil, http.DefaultMaxIdleConnsPerHost)
testutil.Ok(t, err)

resp, err := proxy.LabelValues(ctx, &storepb.LabelValuesRequest{
Expand Down Expand Up @@ -318,7 +319,7 @@ func TestPrometheusStore_ExternalLabelValues_e2e(t *testing.T) {
u, err := url.Parse(fmt.Sprintf("http://%s", p.Addr()))
testutil.Ok(t, err)

proxy, err := NewPrometheusStore(nil, nil, u, component.Sidecar, getExternalLabels, nil)
proxy, err := NewPrometheusStore(nil, nil, u, component.Sidecar, getExternalLabels, nil, http.DefaultMaxIdleConnsPerHost)
testutil.Ok(t, err)

resp, err := proxy.LabelValues(ctx, &storepb.LabelValuesRequest{
Expand Down Expand Up @@ -364,8 +365,7 @@ func TestPrometheusStore_Series_MatchExternalLabel_e2e(t *testing.T) {

proxy, err := NewPrometheusStore(nil, nil, u, component.Sidecar,
func() labels.Labels { return labels.FromStrings("region", "eu-west") },
func() (int64, int64) { return 0, math.MaxInt64 },
)
func() (int64, int64) { return 0, math.MaxInt64 }, http.DefaultMaxIdleConnsPerHost)
testutil.Ok(t, err)
srv := newStoreSeriesServer(ctx)

Expand Down Expand Up @@ -410,8 +410,7 @@ func TestPrometheusStore_Info(t *testing.T) {

proxy, err := NewPrometheusStore(nil, nil, nil, component.Sidecar,
func() labels.Labels { return labels.FromStrings("region", "eu-west") },
func() (int64, int64) { return 123, 456 },
)
func() (int64, int64) { return 123, 456 }, http.DefaultMaxIdleConnsPerHost)
testutil.Ok(t, err)

resp, err := proxy.Info(ctx, &storepb.InfoRequest{})
Expand Down Expand Up @@ -489,8 +488,7 @@ func TestPrometheusStore_Series_SplitSamplesIntoChunksWithMaxSizeOfUint16_e2e(t

proxy, err := NewPrometheusStore(nil, nil, u, component.Sidecar,
func() labels.Labels { return labels.FromStrings("region", "eu-west") },
func() (int64, int64) { return 0, math.MaxInt64 },
)
func() (int64, int64) { return 0, math.MaxInt64 }, http.DefaultMaxIdleConnsPerHost)
testutil.Ok(t, err)

// We build chunks only for SAMPLES method. Make sure we ask for SAMPLES only.
Expand Down

0 comments on commit c31e774

Please sign in to comment.