scrape: fallback to hostname if lookup fails (#5366)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2019-03-15 13:02:16 +01:00 committed by Brian Brazil
parent 4397916cb2
commit 23069b87dc

View file

@ -241,7 +241,7 @@ func (m *Manager) TargetsDropped() map[string][]*Target {
return targets
}
// getFqdn returns a fqdn if it's possible, otherwise falls back a hostname.
// getFqdn returns a FQDN if it's possible, otherwise falls back to hostname.
func getFqdn() (string, error) {
hostname, err := os.Hostname()
if err != nil {
@ -250,7 +250,8 @@ func getFqdn() (string, error) {
ips, err := net.LookupIP(hostname)
if err != nil {
return hostname, err
// Return the system hostname if we can't look up the IP address.
return hostname, nil
}
lookup := func(ipStr encoding.TextMarshaler) (string, error) {