Skip to content

Commit

Permalink
use URL labels more frequently
Browse files Browse the repository at this point in the history
  • Loading branch information
dolph committed Feb 25, 2023
1 parent 1b3733f commit 8c17a60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type Url struct {
Url string `yaml:"-"`
}

func (u Url) String() string {
return u.Label
}

var ConfigPaths = [6]string{
"connectivity.yml",
"connectivity.yaml",
Expand Down
2 changes: 1 addition & 1 deletion connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func ParseDestinations(urls []Url) []*Destination {
if idx != 0 {
dest, err := NewDestination(url)
if err != nil {
log.Printf("%v", err)
log.Printf("%s", err)
errEncountered = true
} else {
destinations = append(destinations, dest)
Expand Down
22 changes: 11 additions & 11 deletions destinations.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Destination struct {
Path string
}

func (dest *Destination) String() string {
func (dest Destination) String() string {
return fmt.Sprintf(" %s:", dest.Label)
}

Expand Down Expand Up @@ -72,16 +72,16 @@ func (dest *Destination) Timer(metric string, took time.Duration) {
Timer(metric, took, dest.tags())
}

func NewDestination(dest Url) (*Destination, error) {
url, err := url.Parse(dest.Url)
func NewDestination(u Url) (*Destination, error) {
url, err := url.Parse(u.Url)
if err != nil {
return nil, errors.New(fmt.Sprintf("%s Failed to parse URL: %s", dest, err))
return nil, errors.New(fmt.Sprintf("%v: Failed to parse URL: %v", u, err))
}

// Determine host
host := url.Hostname()
if host == "" {
return nil, errors.New(fmt.Sprintf("%s Failed to parse a host in URL: %s", dest, err))
return nil, errors.New(fmt.Sprintf("%v: Failed to parse a host in URL: %v", u, u.Url))
}

// Determine scheme
Expand All @@ -104,7 +104,7 @@ func NewDestination(dest Url) (*Destination, error) {
} else if scheme == "icmp" {
portNumber = -1
} else {
return nil, errors.New(fmt.Sprintf("%s Unsupported scheme (try specifying tcp:// or udp:// and an explicit port, or icmp:// for ping-only): %s", dest, err))
return nil, errors.New(fmt.Sprintf("%s: Unsupported scheme (try specifying tcp:// or udp:// and an explicit port, or icmp:// for ping-only): %s", u, err))
}
}
}
Expand All @@ -119,8 +119,8 @@ func NewDestination(dest Url) (*Destination, error) {
password, passwordSet := url.User.Password()

return &Destination{
Label: dest.Label,
URL: dest.Url,
Label: u.Label,
URL: u.Url,
Protocol: protocol,
Scheme: scheme,
Username: username,
Expand All @@ -138,7 +138,7 @@ func (dest *Destination) Check() bool {

dnsResults, err := Lookup(dest)
if err != nil {
log.Printf("%s%s Failed to resolve host: %v", GetLocalIPs(), dest, err)
log.Printf("%v%v Failed to resolve host: %v", GetLocalIPs(), dest, err)
reachable = false
}

Expand All @@ -149,7 +149,7 @@ func (dest *Destination) Check() bool {
// Check destination IP for routability
route, err := GetRoute(ip)
if err != nil {
log.Printf("%s Failed to route to %s: %v", dest, ip.String(), err)
log.Printf("%v%v Failed to route to %s: %v", GetLocalIPs(), dest, ip.String(), err)
return false
}

Expand All @@ -172,7 +172,7 @@ func (dest *Destination) Check() bool {
}

func (dest *Destination) Monitor() {
log.Printf("%v Monitoring connectivity to %v", dest, dest.UrlString())
log.Printf("%v%v Monitoring connectivity to %v", GetLocalIPs(), dest, dest.UrlString())

confidence := 1

Expand Down

0 comments on commit 8c17a60

Please sign in to comment.