diff --git a/.gitignore b/.gitignore index b018aa636..6cab0072a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,8 @@ sha256sum.txt # Test binary, build with `go test -c` *.test .coverprofile -prometheus-data +prometheus-data/ +redis-data/ trickster-data trips_*.gz diff --git a/Makefile b/Makefile index aefe09a6a..a4f911175 100644 --- a/Makefile +++ b/Makefile @@ -290,11 +290,11 @@ developer-stop: .PHONY: developer-delete developer-delete: - @cd docs/developer/environment && docker compose down + @cd docs/developer/environment && docker compose down -v --remove-orphans -.PHONY: developer-restart -developer-restart: - @cd docs/developer/environment && docker compose down && docker compose up -d +.PHONY: developer-recreate +developer-recreate: developer-delete + @cd docs/developer/environment && docker compose up -d .PHONY: developer-seed-data developer-seed-data: diff --git a/docs/developer/environment/docker-compose-data/grafana-config/provisioning/datasources/datasource.yaml b/docs/developer/environment/docker-compose-data/grafana-config/provisioning/datasources/datasource.yaml index ff16e0bb7..de6ee0027 100644 --- a/docs/developer/environment/docker-compose-data/grafana-config/provisioning/datasources/datasource.yaml +++ b/docs/developer/environment/docker-compose-data/grafana-config/provisioning/datasources/datasource.yaml @@ -63,6 +63,16 @@ datasources: editable: true jsonData: httpMethod: POST +- name: "7: Trickster | ALB 1" + type: prometheus + access: proxy + orgId: 1 + uid: ds_prom_trickster_alb_1 + url: http://host.docker.internal:8480/alb1 + version: 1 + editable: true + jsonData: + httpMethod: POST # Mockster (Prom API Simulator) - name: sim-direct diff --git a/docs/developer/environment/docker-compose-data/prometheus-data/.gitkeep b/docs/developer/environment/docker-compose-data/prometheus-data/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/docs/developer/environment/docker-compose-data/redis-data/.gitkeep b/docs/developer/environment/docker-compose-data/redis-data/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/docs/developer/environment/docker-compose.yml b/docs/developer/environment/docker-compose.yml index f99073bd4..a3336f8aa 100644 --- a/docs/developer/environment/docker-compose.yml +++ b/docs/developer/environment/docker-compose.yml @@ -11,7 +11,7 @@ services: ports: - 6379:6379 volumes: - - redis-data:/data + - ./docker-compose-data/redis-data:/data command: redis-server --appendonly yes --stop-writes-on-bgsave-error no # ui's @@ -40,6 +40,7 @@ services: image: prom/prometheus:v3.2.1 volumes: - ./docker-compose-data/prometheus-config:/etc/prometheus + - ./docker-compose-data/prometheus-data:/prometheus command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' @@ -153,4 +154,3 @@ services: volumes: influxdbv2: - redis-data: diff --git a/examples/conf/example.full.yaml b/examples/conf/example.full.yaml index d110c411d..305c0b9f4 100644 --- a/examples/conf/example.full.yaml +++ b/examples/conf/example.full.yaml @@ -308,9 +308,13 @@ backends: # keep_alive_timeout: 120s # # max_idle_conns set the maximum concurrent keep-alive connections Trickster may have opened to this backend -# # additional requests will be queued. Default: 20 +# # while no clients are being served. Default: 20 # max_idle_conns: 20 +# # max_concurrent_conns set the maximum number of concurrent connections Trickster may have opened to this backend +# # additional requests will be queued. Default: 20 +# max_concurrent_conns: 20 + # # max_ttl defines the maximum allowed TTL for any object cached for this backend. default is 24 hours # max_ttl: 24h diff --git a/pkg/backends/healthcheck/target.go b/pkg/backends/healthcheck/target.go index 34d683991..c85358015 100644 --- a/pkg/backends/healthcheck/target.go +++ b/pkg/backends/healthcheck/target.go @@ -297,9 +297,17 @@ func newHTTPClient(timeout time.Duration) *http.Client { return http.ErrUseLastResponse }, Transport: &http.Transport{ - Dial: (&net.Dialer{KeepAlive: 5 * time.Second}).Dial, - MaxIdleConns: 32, - MaxIdleConnsPerHost: 32, + Dial: (&net.Dialer{ + Timeout: timeout, + KeepAlive: time.Second * 30, + }).Dial, + MaxIdleConns: 1, + MaxIdleConnsPerHost: 1, + MaxConnsPerHost: 1, + IdleConnTimeout: time.Second * 30, + TLSHandshakeTimeout: timeout, + ExpectContinueTimeout: timeout, + ResponseHeaderTimeout: timeout, }, } } diff --git a/pkg/backends/options/defaults.go b/pkg/backends/options/defaults.go index 1e73e3000..5692f5ee3 100644 --- a/pkg/backends/options/defaults.go +++ b/pkg/backends/options/defaults.go @@ -57,6 +57,8 @@ const ( DefaultKeepAliveTimeout = 2 * time.Minute // DefaultMaxIdleConns is the default number of Idle Connections in Backends' upstream client pools DefaultMaxIdleConns = 20 + // DefaultMaxConcurrentConns is the default max number of concurrent connections to the origin the Backend can use + DefaultMaxConcurrentConns = 20 // DefaultForwardedHeaders defines which class of 'Forwarded' headers are attached to upstream requests DefaultForwardedHeaders = "standard" // DefaultALBMechanismName defines the default ALB Mechanism Name diff --git a/pkg/backends/options/options.go b/pkg/backends/options/options.go index b4a3958b7..0b6407f84 100644 --- a/pkg/backends/options/options.go +++ b/pkg/backends/options/options.go @@ -69,6 +69,8 @@ type Options struct { Timeout time.Duration `yaml:"timeout,omitempty"` // KeepAliveTimeout defines how long an open keep-alive HTTP connection remains idle before closing KeepAliveTimeout time.Duration `yaml:"keep_alive_timeout,omitempty"` + // MaxConcurrentConns defines maximum number of open concurrent connections to maintain to the backend + MaxConcurrentConns int `yaml:"max_concurrent_conns,omitempty"` // MaxIdleConns defines maximum number of open keep-alive connections to maintain MaxIdleConns int `yaml:"max_idle_conns,omitempty"` // CacheName provides the name of the configured cache where the backend client will store it's cache data @@ -237,6 +239,7 @@ func New() *Options { HealthCheck: ho.New(), KeepAliveTimeout: DefaultKeepAliveTimeout, MaxIdleConns: DefaultMaxIdleConns, + MaxConcurrentConns: DefaultMaxConcurrentConns, MaxObjectSizeBytes: DefaultMaxObjectSizeBytes, MaxTTL: DefaultMaxTTL, NegativeCache: make(map[int]time.Duration), diff --git a/pkg/config/testdata/example.alb.yaml b/pkg/config/testdata/example.alb.yaml index 324d4a6af..fec915483 100644 --- a/pkg/config/testdata/example.alb.yaml +++ b/pkg/config/testdata/example.alb.yaml @@ -4,6 +4,7 @@ backends: default: timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default chunk_read_concurrency_limit: 16 @@ -37,6 +38,7 @@ backends: origin_url: https://origin1/ timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: origin1 @@ -73,6 +75,7 @@ backends: origin_url: http://origin2 timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: origin2 @@ -109,6 +112,7 @@ backends: origin_url: http://prom1:9090 timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: prom1:9090 @@ -144,6 +148,7 @@ backends: origin_url: http://prom2:9090 timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: prom2:9090 @@ -178,6 +183,7 @@ backends: provider: alb timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default chunk_read_concurrency_limit: 16 @@ -216,6 +222,7 @@ backends: provider: alb timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default chunk_read_concurrency_limit: 16 diff --git a/pkg/config/testdata/example.auth.yaml b/pkg/config/testdata/example.auth.yaml index 2b6a792dc..05d7d77d2 100644 --- a/pkg/config/testdata/example.auth.yaml +++ b/pkg/config/testdata/example.auth.yaml @@ -6,6 +6,7 @@ backends: origin_url: https://example.com/ timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: example.com @@ -41,6 +42,7 @@ backends: origin_url: https://example.com/ timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: example.com @@ -76,6 +78,7 @@ backends: origin_url: https://example.com/ timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: example.com @@ -109,6 +112,7 @@ backends: default: timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default chunk_read_concurrency_limit: 16 diff --git a/pkg/config/testdata/example.full.yaml b/pkg/config/testdata/example.full.yaml index 81720be65..cb5a6e634 100644 --- a/pkg/config/testdata/example.full.yaml +++ b/pkg/config/testdata/example.full.yaml @@ -6,6 +6,7 @@ backends: origin_url: http://prometheus:9090 timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: prometheus:9090 diff --git a/pkg/config/testdata/exmple.sharding.yaml b/pkg/config/testdata/exmple.sharding.yaml index 936b3334d..7855204cc 100644 --- a/pkg/config/testdata/exmple.sharding.yaml +++ b/pkg/config/testdata/exmple.sharding.yaml @@ -6,6 +6,7 @@ backends: origin_url: http://prometheus:9090 timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: prometheus:9090 diff --git a/pkg/config/testdata/simple.prometheus.yaml b/pkg/config/testdata/simple.prometheus.yaml index 7db4901b8..17a35b2ec 100644 --- a/pkg/config/testdata/simple.prometheus.yaml +++ b/pkg/config/testdata/simple.prometheus.yaml @@ -6,6 +6,7 @@ backends: origin_url: http://prometheus:9090 timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: prometheus:9090 diff --git a/pkg/config/testdata/simple.reverseproxycache.yaml b/pkg/config/testdata/simple.reverseproxycache.yaml index 3887c226b..24eb36a7d 100644 --- a/pkg/config/testdata/simple.reverseproxycache.yaml +++ b/pkg/config/testdata/simple.reverseproxycache.yaml @@ -6,6 +6,7 @@ backends: origin_url: https://www.example.com timeout: 1m0s keep_alive_timeout: 2m0s + max_concurrent_conns: 20 max_idle_conns: 20 cache_name: default cache_key_prefix: www.example.com diff --git a/pkg/proxy/proxy.go b/pkg/proxy/proxy.go index 3fa074055..1612e5322 100644 --- a/pkg/proxy/proxy.go +++ b/pkg/proxy/proxy.go @@ -90,6 +90,7 @@ func NewHTTPClient(o *bo.Options) (*http.Client, error) { }).Dial, MaxIdleConns: o.MaxIdleConns, MaxIdleConnsPerHost: o.MaxIdleConns, + MaxConnsPerHost: o.MaxConcurrentConns, IdleConnTimeout: o.KeepAliveTimeout, TLSHandshakeTimeout: connectTimeout, ExpectContinueTimeout: o.Timeout,