Skip to content

Commit

Permalink
16591: added windows os.build attribute to host fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuJin committed Jun 21, 2023
1 parent 8e2cb4c commit 1da185c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/17576.txt
@@ -0,0 +1,3 @@
```release-note:improvement
runtime: Added 'os.build' attribute to node fingerprint on windows os
```
16 changes: 13 additions & 3 deletions client/fingerprint/host.go
Expand Up @@ -5,6 +5,7 @@ package fingerprint

import (
"runtime"
"strings"

log "github.com/hashicorp/go-hclog"
"github.com/shirou/gopsutil/v3/host"
Expand All @@ -29,12 +30,21 @@ func (f *HostFingerprint) Fingerprint(req *FingerprintRequest, resp *Fingerprint
return err
}

if runtime.GOOS == "windows" {
platformVersion := strings.Split(hostInfo.PlatformVersion, "Build")
if len(platformVersion) == 2 {
resp.AddAttribute("os.version", strings.TrimSpace(platformVersion[0]))
resp.AddAttribute("os.build", strings.TrimSpace(platformVersion[1]))
} else {
f.logger.Warn("unable to retrieve 'os.build' attribute", "platform_version", hostInfo.PlatformVersion)
}
} else {
resp.AddAttribute("os.version", hostInfo.PlatformVersion)
resp.AddAttribute("kernel.version", hostInfo.KernelVersion)
}
resp.AddAttribute("os.name", hostInfo.Platform)
resp.AddAttribute("os.version", hostInfo.PlatformVersion)

resp.AddAttribute("kernel.name", runtime.GOOS)
resp.AddAttribute("kernel.arch", hostInfo.KernelArch)
resp.AddAttribute("kernel.version", hostInfo.KernelVersion)

resp.AddAttribute("unique.hostname", hostInfo.Hostname)
resp.Detected = true
Expand Down
12 changes: 11 additions & 1 deletion client/fingerprint/host_test.go
Expand Up @@ -4,6 +4,7 @@
package fingerprint

import (
"runtime"
"testing"

"github.com/hashicorp/nomad/ci"
Expand Down Expand Up @@ -35,8 +36,17 @@ func TestHostFingerprint(t *testing.T) {
t.Fatalf("should generate a diff of node attributes")
}

commonAttributes := []string{"os.name", "os.version", "unique.hostname", "kernel.name"}
nonWindowsAttributes := append(commonAttributes, "kernel.version")
windowsAttributes := append(commonAttributes, "os.build")

expectedAttributes := nonWindowsAttributes
if runtime.GOOS == "windows" {
expectedAttributes = windowsAttributes
}

// Host info
for _, key := range []string{"os.name", "os.version", "unique.hostname", "kernel.name"} {
for _, key := range expectedAttributes {
assertNodeAttributeContains(t, response.Attributes, key)
}
}
1 change: 1 addition & 0 deletions website/content/docs/runtime/interpolation.mdx
Expand Up @@ -122,6 +122,7 @@ Below is a table documenting common node properties.
| `${attr.platform.aws.placement.availability-zone}` | Availability Zone of the client (if on AWS EC2) |
| `${attr.os.name}` | Operating system of the client (e.g. `ubuntu`, `windows`, `darwin`) |
| `${attr.os.version}` | Version of the client OS |
| `${attr.os.build}` | Build number (e.g `14393.5501`) of the client OS (if on Windows) |

The full list of node attributes can be obtained by running `nomad node status -verbose [node]`.

Expand Down

0 comments on commit 1da185c

Please sign in to comment.