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

Do not keep alive http connection #3878

Merged
merged 2 commits into from
Nov 28, 2022
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
- **General:** Add explicit seccompProfile type to securityContext config ([#3561](https://github.com/kedacore/keda/issues/3561))
- **General:** Add `Min` column to ScaledJob visualization ([#3689](https://github.com/kedacore/keda/issues/3689))
- **General:** Add support to use pod identities for authentication in Azure Key Vault ([#3813](https://github.com/kedacore/keda/issues/3813)
- **General:** Support disable keep http connection alive([#3874](https://github.com/kedacore/keda/issues/3874)
- **General:** Improve the function used to normalize metric names ([#3789](https://github.com/kedacore/keda/issues/3789)
- **Apache Kafka Scaler:** SASL/OAuthbearer Implementation ([#3681](https://github.com/kedacore/keda/issues/3681))
- **Azure AD Pod Identity Authentication:** Improve error messages to emphasize problems around the integration with aad-pod-identity itself ([#3610](https://github.com/kedacore/keda/issues/3610))
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/env_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ func ResolveOsEnvDuration(envName string) (*time.Duration, error) {

return nil, nil
}

func ResolveOsEnvBool(envName string, defaultValue bool) (bool, error) {
valueStr, found := os.LookupEnv(envName)

if found && valueStr != "" {
return strconv.ParseBool(valueStr)
}

return defaultValue, nil
}
27 changes: 21 additions & 6 deletions pkg/util/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ import (
"time"
)

var disableKeepAlives bool

func init() {
var err error
disableKeepAlives, err = ResolveOsEnvBool("KEDA_HTTP_DISABLE_KEEP_ALIVE", false)
if err != nil {
disableKeepAlives = false
}
}

// HTTPDoer is an interface that matches the Do method on
// (net/http).Client. It should be used in function signatures
// instead of raw *http.Clients wherever possible
Expand All @@ -37,13 +47,18 @@ func CreateHTTPClient(timeout time.Duration, unsafeSsl bool) *http.Client {
if timeout <= 0 {
timeout = 300 * time.Millisecond
}
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: unsafeSsl},
Proxy: http.ProxyFromEnvironment,
}
if disableKeepAlives {
// disable keep http connection alive
transport.DisableKeepAlives = true
transport.IdleConnTimeout = 100 * time.Second
}
httpClient := &http.Client{
Timeout: timeout,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: unsafeSsl},
Proxy: http.ProxyFromEnvironment,
},
Timeout: timeout,
Transport: transport,
}

return httpClient
}