Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce ReachableDialer interface to easily allow grpc.Dial #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions checkers/reachable.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ var (
ReachableDefaultTimeout = time.Duration(3) * time.Second
)

// Closer is a closeable resource like net.Conn
type Closer interface {
Close() error
}

// ReachableDialer is the signature for a function that checks if an address is reachable
type ReachableDialer func(network, address string, timeout time.Duration) (net.Conn, error)
type ReachableDialer func(network, address string, timeout time.Duration) (Closer, error)

// ReachableDatadogIncrementer is any datadog client that has the Incr method for tracking metrics
type ReachableDatadogIncrementer interface {
Expand Down Expand Up @@ -67,7 +72,7 @@ func NewReachableChecker(cfg *ReachableConfig) (*ReachableChecker, error) {
if cfg.Timeout != 0 {
t = cfg.Timeout
}
d := net.DialTimeout
d := defaultDialer
if cfg.Dialer != nil {
d = cfg.Dialer
}
Expand All @@ -86,6 +91,11 @@ func NewReachableChecker(cfg *ReachableConfig) (*ReachableChecker, error) {
return r, nil
}

func defaultDialer(network, address string, timeout time.Duration) (Closer, error) {
conn, err := net.DialTimeout(network, address, timeout)
return conn, err
}

// Status checks if the endpoint is reachable
func (r *ReachableChecker) Status() (interface{}, error) {
// We must provide a port so when a port is not set in the URL provided use
Expand Down