Skip to content
Merged
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
22 changes: 20 additions & 2 deletions checker/patroni_leader_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,29 @@ import (
// --trigger-value is used to specify the HTTP code to expect, e.g. 200.
type PatroniLeaderChecker struct {
*vipconfig.Config
*http.Client
}

// NewPatroniLeaderChecker returns a new instance
func NewPatroniLeaderChecker(conf *vipconfig.Config) (*PatroniLeaderChecker, error) {
return &PatroniLeaderChecker{conf}, nil
tlsConfig, err := getTransport(conf)
if err != nil {
return nil, err
}

transport := &http.Transport{
TLSClientConfig: tlsConfig,
}

client := &http.Client{
Transport: transport,
Timeout: time.Second,
}

return &PatroniLeaderChecker{
Config: conf,
Client: client,
}, nil
}

// GetChangeNotificationStream checks the status in the loop
Expand All @@ -29,7 +47,7 @@ func (c *PatroniLeaderChecker) GetChangeNotificationStream(ctx context.Context,
case <-ctx.Done():
return nil
case <-time.After(time.Duration(c.Interval) * time.Millisecond):
r, err := http.Get(c.Endpoints[0] + c.TriggerKey)
r, err := c.Client.Get(c.Endpoints[0] + c.TriggerKey)
if err != nil {
c.Logger.Sugar().Error("patroni REST API error:", err)
continue
Expand Down
Loading