Skip to content

Commit

Permalink
Merge pull request #1615 from tnozicka/limit-manager-calls
Browse files Browse the repository at this point in the history
Limit scylla manager API calls duration
  • Loading branch information
scylla-operator-bot[bot] authored Dec 1, 2023
2 parents cfdec29 + d980d33 commit 60f7824
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
7 changes: 6 additions & 1 deletion pkg/cmd/operator/manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ func (o *ManagerControllerOptions) Complete() error {

// TODO: Use https and wire certs.
url := fmt.Sprintf("http://%s/api/v1", naming.ScyllaManagerServiceName)
managerClient, err := mermaidclient.NewClient(url, &http.Transport{})
managerClient, err := mermaidclient.NewClient(url, &http.Client{
// Limit manager calls by default to a higher bound.
// Individual calls can still be further limited using context.
// Manager is prone to extremely long calls because it (unfortunately) retries errors internally.
Timeout: 15 * time.Second,
})
if err != nil {
return fmt.Errorf("can't build manager client: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/manager/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ const (
ControllerName = "ScyllaManagerController"
// maxSyncDuration enforces preemption. Do not raise the value! Controllers shouldn't actively wait,
// but rather use the queue.
maxSyncDuration = 30 * time.Second
// Unfortunately, Scylla Manager calls are synchronous, internally retried and can take ages.
// Contrary to what it should be, this needs to be quite high.
// Given we reconcile tasks individually with an API call,
// this may not be enough for N tasks but should eventually make it.
maxSyncDuration = 2 * time.Minute
)

var (
Expand Down
23 changes: 2 additions & 21 deletions pkg/mermaidclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package mermaidclient

import (
"context"
"crypto/tls"
"net/http"
"net/url"
"os"
Expand All @@ -30,15 +29,7 @@ type Client struct {
operations *operations.Client
}

// DefaultTLSConfig specifies default TLS configuration used when creating a new
// client.
var DefaultTLSConfig = func() *tls.Config {
return &tls.Config{
InsecureSkipVerify: true,
}
}

func NewClient(rawURL string, transport http.RoundTripper) (Client, error) {
func NewClient(rawURL string, client *http.Client) (Client, error) {
u, err := url.Parse(rawURL)
if err != nil {
return Client{}, err
Expand All @@ -48,17 +39,7 @@ func NewClient(rawURL string, transport http.RoundTripper) (Client, error) {
middleware.Debug = false
})

if transport == nil {
transport = &http.Transport{
TLSClientConfig: DefaultTLSConfig(),
}
}

httpClient := &http.Client{
Transport: transport,
}

r := api.NewWithClient(u.Host, u.Path, []string{u.Scheme}, httpClient)
r := api.NewWithClient(u.Host, u.Path, []string{u.Scheme}, client)
// debug can be turned on by SWAGGER_DEBUG or DEBUG env variable
// we change that to SCTOOL_DUMP_HTTP
r.Debug, _ = strconv.ParseBool(os.Getenv("SCTOOL_DUMP_HTTP"))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func GetManagerClient(ctx context.Context, client corev1client.CoreV1Interface)
Path: "/api/v1",
}).String()

manager, err := mermaidclient.NewClient(apiAddress, &http.Transport{})
manager, err := mermaidclient.NewClient(apiAddress, &http.Client{})
if err != nil {
return nil, fmt.Errorf("create manager client, %w", err)
}
Expand Down

0 comments on commit 60f7824

Please sign in to comment.