mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #17427 from ivanvc/release-3.5-implement-etcd-process-go-fail-client-timeout
[3.5] Implement etcd process go fail client timeout
This commit is contained in:
commit
b795a8f662
@ -138,12 +138,13 @@ type EtcdProcessCluster struct {
|
||||
}
|
||||
|
||||
type EtcdProcessClusterConfig struct {
|
||||
ExecPath string
|
||||
DataDirPath string
|
||||
KeepDataDir bool
|
||||
GoFailEnabled bool
|
||||
PeerProxy bool
|
||||
EnvVars map[string]string
|
||||
ExecPath string
|
||||
DataDirPath string
|
||||
KeepDataDir bool
|
||||
GoFailEnabled bool
|
||||
GoFailClientTimeout time.Duration
|
||||
PeerProxy bool
|
||||
EnvVars map[string]string
|
||||
|
||||
ClusterSize int
|
||||
|
||||
@ -400,21 +401,22 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfigs(tb testing.TB) []*
|
||||
}
|
||||
|
||||
etcdCfgs[i] = &EtcdServerProcessConfig{
|
||||
lg: lg,
|
||||
ExecPath: cfg.ExecPath,
|
||||
Args: args,
|
||||
EnvVars: envVars,
|
||||
TlsArgs: cfg.TlsArgs(),
|
||||
DataDirPath: dataDirPath,
|
||||
KeepDataDir: cfg.KeepDataDir,
|
||||
Name: name,
|
||||
Purl: peerAdvertiseUrl,
|
||||
Acurl: curl,
|
||||
Murl: murl,
|
||||
InitialToken: cfg.InitialToken,
|
||||
ClientHttpUrl: clientHttpUrl,
|
||||
GoFailPort: gofailPort,
|
||||
Proxy: proxyCfg,
|
||||
lg: lg,
|
||||
ExecPath: cfg.ExecPath,
|
||||
Args: args,
|
||||
EnvVars: envVars,
|
||||
TlsArgs: cfg.TlsArgs(),
|
||||
DataDirPath: dataDirPath,
|
||||
KeepDataDir: cfg.KeepDataDir,
|
||||
Name: name,
|
||||
Purl: peerAdvertiseUrl,
|
||||
Acurl: curl,
|
||||
Murl: murl,
|
||||
InitialToken: cfg.InitialToken,
|
||||
ClientHttpUrl: clientHttpUrl,
|
||||
GoFailPort: gofailPort,
|
||||
GoFailClientTimeout: cfg.GoFailClientTimeout,
|
||||
Proxy: proxyCfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,10 +94,11 @@ type EtcdServerProcessConfig struct {
|
||||
Murl string
|
||||
ClientHttpUrl string
|
||||
|
||||
InitialToken string
|
||||
InitialCluster string
|
||||
GoFailPort int
|
||||
Proxy *proxy.ServerConfig
|
||||
InitialToken string
|
||||
InitialCluster string
|
||||
GoFailPort int
|
||||
GoFailClientTimeout time.Duration
|
||||
Proxy *proxy.ServerConfig
|
||||
}
|
||||
|
||||
func NewEtcdServerProcess(cfg *EtcdServerProcessConfig) (*EtcdServerProcess, error) {
|
||||
@ -111,7 +112,10 @@ func NewEtcdServerProcess(cfg *EtcdServerProcessConfig) (*EtcdServerProcess, err
|
||||
}
|
||||
ep := &EtcdServerProcess{cfg: cfg, donec: make(chan struct{})}
|
||||
if cfg.GoFailPort != 0 {
|
||||
ep.failpoints = &BinaryFailpoints{member: ep}
|
||||
ep.failpoints = &BinaryFailpoints{
|
||||
member: ep,
|
||||
clientTimeout: cfg.GoFailClientTimeout,
|
||||
}
|
||||
}
|
||||
return ep, nil
|
||||
}
|
||||
@ -258,6 +262,7 @@ func (ep *EtcdServerProcess) Etcdctl(connType ClientConnType, isAutoTLS, v2 bool
|
||||
type BinaryFailpoints struct {
|
||||
member EtcdProcess
|
||||
availableCache map[string]string
|
||||
clientTimeout time.Duration
|
||||
}
|
||||
|
||||
func (f *BinaryFailpoints) SetupEnv(failpoint, payload string) error {
|
||||
@ -279,6 +284,12 @@ func (f *BinaryFailpoints) SetupHTTP(ctx context.Context, failpoint, payload str
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
httpClient := http.Client{
|
||||
Timeout: 1 * time.Second,
|
||||
}
|
||||
if f.clientTimeout != 0 {
|
||||
httpClient.Timeout = f.clientTimeout
|
||||
}
|
||||
resp, err := httpClient.Do(r)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -301,6 +312,12 @@ func (f *BinaryFailpoints) DeactivateHTTP(ctx context.Context, failpoint string)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
httpClient := http.Client{
|
||||
Timeout: 1 * time.Second,
|
||||
}
|
||||
if f.clientTimeout != 0 {
|
||||
httpClient.Timeout = f.clientTimeout
|
||||
}
|
||||
resp, err := httpClient.Do(r)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -312,10 +329,6 @@ func (f *BinaryFailpoints) DeactivateHTTP(ctx context.Context, failpoint string)
|
||||
return nil
|
||||
}
|
||||
|
||||
var httpClient = http.Client{
|
||||
Timeout: 1 * time.Second,
|
||||
}
|
||||
|
||||
func (f *BinaryFailpoints) Enabled() bool {
|
||||
_, err := failpoints(f.member)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user