From eb816dca166a28219df827e693cb28c0b52d4385 Mon Sep 17 00:00:00 2001 From: Shantanu Gadgil Date: Tue, 31 May 2022 20:14:18 +0530 Subject: [PATCH 1/9] add arch_classic as a new fingerprint variable --- client/fingerprint/arch.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/fingerprint/arch.go b/client/fingerprint/arch.go index 5d309a1c0e3..bfeac82a8e7 100644 --- a/client/fingerprint/arch.go +++ b/client/fingerprint/arch.go @@ -20,6 +20,15 @@ func NewArchFingerprint(logger log.Logger) Fingerprint { func (f *ArchFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error { resp.AddAttribute("cpu.arch", runtime.GOARCH) + + if (runtime.GOARCH == "amd64") { + resp.AddAttribute("cpu.arch_classic", "x86_64") + } else if (runtime.GOARCH == "386") { + resp.AddAttribute("cpu.arch_classic", "i386") + } else if (runtime.GOARCH == "arm64") { + resp.AddAttribute("cpu.arch_classic", "aarch64") + } + resp.Detected = true return nil } From f5c5ff410b792b5902a7fab40bdbcb4a4f62336b Mon Sep 17 00:00:00 2001 From: Shantanu Gadgil Date: Tue, 31 May 2022 20:46:07 +0530 Subject: [PATCH 2/9] gofmt -s --- client/fingerprint/arch.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/fingerprint/arch.go b/client/fingerprint/arch.go index bfeac82a8e7..0d35b48d131 100644 --- a/client/fingerprint/arch.go +++ b/client/fingerprint/arch.go @@ -21,11 +21,11 @@ func NewArchFingerprint(logger log.Logger) Fingerprint { func (f *ArchFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error { resp.AddAttribute("cpu.arch", runtime.GOARCH) - if (runtime.GOARCH == "amd64") { + if runtime.GOARCH == "amd64" { resp.AddAttribute("cpu.arch_classic", "x86_64") - } else if (runtime.GOARCH == "386") { + } else if runtime.GOARCH == "386" { resp.AddAttribute("cpu.arch_classic", "i386") - } else if (runtime.GOARCH == "arm64") { + } else if runtime.GOARCH == "arm64" { resp.AddAttribute("cpu.arch_classic", "aarch64") } From 6461cca17957e16e502c4067a270ec6f9dbb8a8e Mon Sep 17 00:00:00 2001 From: Shantanu Gadgil Date: Wed, 1 Jun 2022 13:12:55 +0530 Subject: [PATCH 3/9] add the changelog entry --- .changelog/13182.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/13182.txt diff --git a/.changelog/13182.txt b/.changelog/13182.txt new file mode 100644 index 00000000000..de5956bb687 --- /dev/null +++ b/.changelog/13182.txt @@ -0,0 +1,3 @@ +```release-note:improvement +fingerprint: add support for detecting 'classic' names of CPU architectures (`x86_64`, `aarch64`, etc.) +``` From 23f2d3aa99c7ef4b05e122fa06f788589ea54cb0 Mon Sep 17 00:00:00 2001 From: Shantanu Gadgil Date: Wed, 1 Jun 2022 22:06:38 +0530 Subject: [PATCH 4/9] limit 'cpu.machine' to linux. make it fingerprint 'uname -m' --- client/fingerprint/arch.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/client/fingerprint/arch.go b/client/fingerprint/arch.go index 0d35b48d131..3bea3b7085f 100644 --- a/client/fingerprint/arch.go +++ b/client/fingerprint/arch.go @@ -1,7 +1,9 @@ package fingerprint import ( + "os/exec" "runtime" + "strings" log "github.com/hashicorp/go-hclog" ) @@ -21,12 +23,16 @@ func NewArchFingerprint(logger log.Logger) Fingerprint { func (f *ArchFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error { resp.AddAttribute("cpu.arch", runtime.GOARCH) - if runtime.GOARCH == "amd64" { - resp.AddAttribute("cpu.arch_classic", "x86_64") - } else if runtime.GOARCH == "386" { - resp.AddAttribute("cpu.arch_classic", "i386") - } else if runtime.GOARCH == "arm64" { - resp.AddAttribute("cpu.arch_classic", "aarch64") + if runtime.GOOS == "linux" { + unameOutput, err := exec.Command("uname", "-m").Output() + + if err != nil { + f.logger.Warn("error calling 'uname -m'") + resp.AddAttribute("cpu.machine", "undefined") + } else { + output := strings.TrimSpace(string(unameOutput)) + resp.AddAttribute("cpu.machine", output) + } } resp.Detected = true From 2a4e542a34625596f0b98a24fcd8a356f9d5413b Mon Sep 17 00:00:00 2001 From: Shantanu Gadgil Date: Wed, 1 Jun 2022 22:08:32 +0530 Subject: [PATCH 5/9] limit 'cpu.machine' to linux. make it fingerprint 'uname -m' --- .changelog/13182.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/13182.txt b/.changelog/13182.txt index de5956bb687..75dac2ca13a 100644 --- a/.changelog/13182.txt +++ b/.changelog/13182.txt @@ -1,3 +1,3 @@ ```release-note:improvement -fingerprint: add support for detecting 'classic' names of CPU architectures (`x86_64`, `aarch64`, etc.) +fingerprint: add support for detecting 'uname -m' for Linux (attribute `cpu.machine`) ``` From 130c0f2487a6364e499d64110379a0f9c3924634 Mon Sep 17 00:00:00 2001 From: Shantanu Gadgil Date: Wed, 1 Jun 2022 22:09:39 +0530 Subject: [PATCH 6/9] better English --- .changelog/13182.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/13182.txt b/.changelog/13182.txt index 75dac2ca13a..5940e722e8a 100644 --- a/.changelog/13182.txt +++ b/.changelog/13182.txt @@ -1,3 +1,3 @@ ```release-note:improvement -fingerprint: add support for detecting 'uname -m' for Linux (attribute `cpu.machine`) +fingerprint: add support for detecting 'uname -m' on Linux clients. (attribute `cpu.machine`) ``` From 56af2c18e78381bead6710526fcf17669550c4c6 Mon Sep 17 00:00:00 2001 From: Shantanu Gadgil Date: Thu, 2 Jun 2022 13:41:36 +0530 Subject: [PATCH 7/9] kernel architecture (kernel.arch) using gopsutil --- .changelog/13182.txt | 2 +- client/fingerprint/arch.go | 13 ------------- client/fingerprint/host.go | 1 + website/content/docs/runtime/interpolation.mdx | 8 ++++++++ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.changelog/13182.txt b/.changelog/13182.txt index 5940e722e8a..31d0e9d03d4 100644 --- a/.changelog/13182.txt +++ b/.changelog/13182.txt @@ -1,3 +1,3 @@ ```release-note:improvement -fingerprint: add support for detecting 'uname -m' on Linux clients. (attribute `cpu.machine`) +fingerprint: add support for detecting kernel architecture of clients. (attribute: `kernel.arch`) ``` diff --git a/client/fingerprint/arch.go b/client/fingerprint/arch.go index 3bea3b7085f..ab09a21e7ee 100644 --- a/client/fingerprint/arch.go +++ b/client/fingerprint/arch.go @@ -22,19 +22,6 @@ func NewArchFingerprint(logger log.Logger) Fingerprint { func (f *ArchFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error { resp.AddAttribute("cpu.arch", runtime.GOARCH) - - if runtime.GOOS == "linux" { - unameOutput, err := exec.Command("uname", "-m").Output() - - if err != nil { - f.logger.Warn("error calling 'uname -m'") - resp.AddAttribute("cpu.machine", "undefined") - } else { - output := strings.TrimSpace(string(unameOutput)) - resp.AddAttribute("cpu.machine", output) - } - } - resp.Detected = true return nil } diff --git a/client/fingerprint/host.go b/client/fingerprint/host.go index f7b82982dea..4d37d091d07 100644 --- a/client/fingerprint/host.go +++ b/client/fingerprint/host.go @@ -30,6 +30,7 @@ func (f *HostFingerprint) Fingerprint(req *FingerprintRequest, resp *Fingerprint 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) diff --git a/website/content/docs/runtime/interpolation.mdx b/website/content/docs/runtime/interpolation.mdx index 3c211412471..a8fa29b912b 100644 --- a/website/content/docs/runtime/interpolation.mdx +++ b/website/content/docs/runtime/interpolation.mdx @@ -220,6 +220,14 @@ Below is a table documenting common node properties: Kernel of the client (e.g. linux, darwin) + + + {'${attr.kernel.arch}'} + + + Kernel architecture of the client (e.g. x86_64, aarch64) + + {'${attr.kernel.version}'} From 3425e51da293a17e185dc67da3374e1958349889 Mon Sep 17 00:00:00 2001 From: Shantanu Gadgil Date: Thu, 2 Jun 2022 13:48:18 +0530 Subject: [PATCH 8/9] remove unwanted imports --- client/fingerprint/arch.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/fingerprint/arch.go b/client/fingerprint/arch.go index ab09a21e7ee..5d309a1c0e3 100644 --- a/client/fingerprint/arch.go +++ b/client/fingerprint/arch.go @@ -1,9 +1,7 @@ package fingerprint import ( - "os/exec" "runtime" - "strings" log "github.com/hashicorp/go-hclog" ) From 07643cce3b41acc024086d68db946dbd9f15a29d Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Thu, 2 Jun 2022 15:48:52 -0400 Subject: [PATCH 9/9] docs: list node attributes in alphabetical order --- website/content/docs/runtime/interpolation.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/content/docs/runtime/interpolation.mdx b/website/content/docs/runtime/interpolation.mdx index a8fa29b912b..b9f852258e5 100644 --- a/website/content/docs/runtime/interpolation.mdx +++ b/website/content/docs/runtime/interpolation.mdx @@ -214,18 +214,18 @@ Below is a table documenting common node properties: - {'${attr.kernel.name}'} + {'${attr.kernel.arch}'} - Kernel of the client (e.g. linux, darwin) + Kernel architecture of the client (e.g. x86_64, aarch64) - {'${attr.kernel.arch}'} + {'${attr.kernel.name}'} - Kernel architecture of the client (e.g. x86_64, aarch64) + Kernel of the client (e.g. linux, darwin)