Merge pull request #17050 from ahrtr/gofail_client_timeout_20231201

Support setting http client timeout when enable/disable failpoint
This commit is contained in:
Benjamin Wang 2023-12-02 08:33:51 +00:00 committed by GitHub
commit 9d18fb0c6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 30 deletions

View File

@ -137,11 +137,12 @@ type EtcdProcessClusterConfig struct {
// Test config
KeepDataDir bool
Logger *zap.Logger
GoFailEnabled bool
LazyFSEnabled bool
PeerProxy bool
KeepDataDir bool
Logger *zap.Logger
GoFailEnabled bool
GoFailClientTimeout time.Duration
LazyFSEnabled bool
PeerProxy bool
// Process config
@ -326,6 +327,10 @@ func WithGoFailEnabled(enabled bool) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.GoFailEnabled = enabled }
}
func WithGoFailClientTimeout(dur time.Duration) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.GoFailClientTimeout = dur }
}
func WithLazyFSEnabled(enabled bool) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.LazyFSEnabled = enabled }
}
@ -609,23 +614,24 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
}
return &EtcdServerProcessConfig{
lg: cfg.Logger,
ExecPath: execPath,
Args: args,
EnvVars: envVars,
TlsArgs: cfg.TlsArgs(),
Client: cfg.Client,
DataDirPath: dataDirPath,
KeepDataDir: cfg.KeepDataDir,
Name: name,
PeerURL: peerAdvertiseUrl,
ClientURL: curl,
ClientHTTPURL: clientHttpUrl,
MetricsURL: murl,
InitialToken: cfg.ServerConfig.InitialClusterToken,
GoFailPort: gofailPort,
Proxy: proxyCfg,
LazyFSEnabled: cfg.LazyFSEnabled,
lg: cfg.Logger,
ExecPath: execPath,
Args: args,
EnvVars: envVars,
TlsArgs: cfg.TlsArgs(),
Client: cfg.Client,
DataDirPath: dataDirPath,
KeepDataDir: cfg.KeepDataDir,
Name: name,
PeerURL: peerAdvertiseUrl,
ClientURL: curl,
ClientHTTPURL: clientHttpUrl,
MetricsURL: murl,
InitialToken: cfg.ServerConfig.InitialClusterToken,
GoFailPort: gofailPort,
GoFailClientTimeout: cfg.GoFailClientTimeout,
Proxy: proxyCfg,
LazyFSEnabled: cfg.LazyFSEnabled,
}
}

View File

@ -95,9 +95,10 @@ type EtcdServerProcessConfig struct {
ClientHTTPURL string
MetricsURL string
InitialToken string
InitialCluster string
GoFailPort int
InitialToken string
InitialCluster string
GoFailPort int
GoFailClientTimeout time.Duration
LazyFSEnabled bool
Proxy *proxy.ServerConfig
@ -117,7 +118,10 @@ func NewEtcdServerProcess(t testing.TB, cfg *EtcdServerProcessConfig) (*EtcdServ
}
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,
}
}
if cfg.LazyFSEnabled {
ep.lazyfs = newLazyFS(cfg.lg, cfg.DataDirPath, t)
@ -337,6 +341,7 @@ func (ep *EtcdServerProcess) Failpoints() *BinaryFailpoints {
type BinaryFailpoints struct {
member EtcdProcess
availableCache map[string]string
clientTimeout time.Duration
}
func (f *BinaryFailpoints) SetupEnv(failpoint, payload string) error {
@ -358,6 +363,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
@ -380,6 +391,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
@ -391,10 +408,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 {