-
Notifications
You must be signed in to change notification settings - Fork 163
/
config.go
85 lines (78 loc) · 2.31 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package scyllaclient
import (
"net/http"
"time"
"github.com/pkg/errors"
"github.com/scylladb/scylla-operator/pkg/util/network"
"go.uber.org/multierr"
)
// Config specifies the Client configuration.
type Config struct {
// Hosts specifies all the cluster hosts that for a pool of hosts for the
// client.
Hosts []string
// Port specifies the default Scylla Manager agent port.
Port string
// Transport scheme HTTP or HTTPS.
Scheme string
// AuthToken specifies the authentication token.
AuthToken string `yaml:"auth_token"`
// Timeout specifies time to complete a single request to Scylla REST API
// possibly including opening a TCP connection.
Timeout time.Duration `yaml:"timeout"`
// PoolDecayDuration specifies size of time window to measure average
// request time in Epsilon-Greedy host pool.
Backoff BackoffConfig
// InteractiveBackoff specifies backoff for interactive requests i.e.
// originating from API / sctool.
InteractiveBackoff BackoffConfig
// How many seconds to wait for the job to finish before returning
// the info response.
LongPollingSeconds int64
PoolDecayDuration time.Duration
// Transport allows for setting a custom round tripper to send HTTP
// requests over not standard connections i.e. over SSH tunnel.
Transport http.RoundTripper
}
// BackoffConfig specifies request exponential backoff parameters.
type BackoffConfig struct {
WaitMin time.Duration
WaitMax time.Duration
MaxRetries uint64
Multiplier float64
Jitter float64
}
// DefaultConfig returns a Config initialized with default values.
func DefaultConfig() Config {
host, _ := network.FindFirstNonLocalIP()
return Config{
Hosts: []string{host.String()},
Port: "10001",
Scheme: "https",
Timeout: 15 * time.Second,
Backoff: BackoffConfig{
WaitMin: 1 * time.Second,
WaitMax: 30 * time.Second,
MaxRetries: 9,
Multiplier: 2,
Jitter: 0.2,
},
InteractiveBackoff: BackoffConfig{
WaitMin: time.Second,
MaxRetries: 1,
},
LongPollingSeconds: 10,
PoolDecayDuration: 30 * time.Minute,
}
}
// Validate checks if all the fields are properly set.
func (c Config) Validate() error {
var err error
if len(c.Hosts) == 0 {
err = multierr.Append(err, errors.New("missing hosts"))
}
if c.Port == "" {
err = multierr.Append(err, errors.New("missing port"))
}
return err
}