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

Log network device name during fingerprinting #11184

Merged
merged 2 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 8 additions & 5 deletions client/fingerprint/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,21 @@ func (f *NetworkFingerprint) Fingerprint(req *FingerprintRequest, resp *Fingerpr
return nil
}

// Create a sub-logger with common values to help with debugging
logger := f.logger.With("interface", intf.Name)

// Record the throughput of the interface
var mbits int
throughput := f.linkSpeed(intf.Name)
if cfg.NetworkSpeed != 0 {
mbits = cfg.NetworkSpeed
f.logger.Debug("setting link speed to user configured speed", "mbits", mbits)
logger.Debug("setting link speed to user configured speed", "mbits", mbits)
} else if throughput != 0 {
mbits = throughput
f.logger.Debug("link speed detected", "interface", intf.Name, "mbits", mbits)
logger.Debug("link speed detected", "mbits", mbits)
} else {
mbits = defaultNetworkSpeed
f.logger.Debug("link speed could not be detected and no speed specified by user, falling back to default speed", "mbits", defaultNetworkSpeed)
logger.Debug("link speed could not be detected and no speed specified by user, falling back to default speed", "mbits", defaultNetworkSpeed)
}

// Create the network resources from the interface
Expand All @@ -109,7 +112,7 @@ func (f *NetworkFingerprint) Fingerprint(req *FingerprintRequest, resp *Fingerpr
}

for _, nwResource := range nwResources {
f.logger.Debug("detected interface IP", "interface", intf.Name, "IP", nwResource.IP)
logger.Debug("detected interface IP", "IP", nwResource.IP)
}

// Deprecated, setting the first IP as unique IP for the node
Expand Down Expand Up @@ -138,7 +141,7 @@ func (f *NetworkFingerprint) createNodeNetworkResources(ifaces []net.Interface,
speed := f.linkSpeed(iface.Name)
if speed == 0 {
speed = defaultNetworkSpeed
f.logger.Debug("link speed could not be detected, falling back to default speed", "mbits", defaultNetworkSpeed)
f.logger.Debug("link speed could not be detected, falling back to default speed", "interface", iface.Name, "mbits", defaultNetworkSpeed)
}

newNetwork := &structs.NodeNetworkResource{
Expand Down
4 changes: 2 additions & 2 deletions client/fingerprint/network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ func (f *NetworkFingerprint) linkSpeedSys(device string) int {
// Read contents of the device/speed file
content, err := ioutil.ReadFile(path)
if err != nil {
f.logger.Debug("unable to read link speed", "path", path)
f.logger.Debug("unable to read link speed", "path", path, "device", device)
return 0
}

lines := strings.Split(string(content), "\n")
mbs, err := strconv.Atoi(lines[0])
if err != nil || mbs <= 0 {
f.logger.Debug("unable to parse link speed", "path", path)
f.logger.Debug("unable to parse link speed", "path", path, "device", device)
return 0
}

Expand Down
10 changes: 5 additions & 5 deletions client/fingerprint/network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ func (f *NetworkFingerprint) linkSpeed(device string) int {
outBytes, err := exec.Command(path, command).Output()

if err != nil {
f.logger.Warn("failed to detect link speed", "path", path, "command", command, "error", err)
f.logger.Warn("failed to detect link speed", "device", device, "path", path, "command", command, "error", err)
return 0
}

output := strings.TrimSpace(string(outBytes))

return f.parseLinkSpeed(output)
return f.parseLinkSpeed(device, output)
}

func (f *NetworkFingerprint) parseLinkSpeed(commandOutput string) int {
func (f *NetworkFingerprint) parseLinkSpeed(device, commandOutput string) int {
args := strings.Split(commandOutput, " ")
if len(args) != 2 {
f.logger.Warn("couldn't split LinkSpeed output", "output", commandOutput)
f.logger.Warn("couldn't split LinkSpeed output", "device", device, "output", commandOutput)
return 0
}

unit := strings.Replace(args[1], "\r\n", "", -1)
value, err := strconv.Atoi(args[0])
if err != nil {
f.logger.Warn("unable to parse LinkSpeed value", "value", commandOutput)
f.logger.Warn("unable to parse LinkSpeed value", "device", device, "value", commandOutput, "error", err)
return 0
}

Expand Down