From 1618d7951802e991b56419b533fe99707c57fcd7 Mon Sep 17 00:00:00 2001 From: Pierre Souchay Date: Thu, 10 Jan 2019 16:50:14 +0100 Subject: [PATCH] Allow `"disable_host_node_id": false` to work on Linux as non-root. (#4926) Bump `shirou/gopsutil` to include https://github.com/shirou/gopsutil/pull/603 This will allow to have consistent node-id even when machine is reinstalled when using `"disable_host_node_id": false` It will fix https://github.com/hashicorp/consul/issues/4914 and allow having the same node-id even when reinstalling a node from scratch. However, it is only compatible with a single OS (installing to Windows will change the node-id, but it seems acceptable). --- .../shirou/gopsutil/cpu/cpu_windows.go | 22 ++++++++----------- .../shirou/gopsutil/host/host_linux.go | 13 +++++++++++ vendor/vendor.json | 15 +++++++------ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/vendor/github.com/shirou/gopsutil/cpu/cpu_windows.go b/vendor/github.com/shirou/gopsutil/cpu/cpu_windows.go index 8aa691cf0071..975c2cb8660a 100644 --- a/vendor/github.com/shirou/gopsutil/cpu/cpu_windows.go +++ b/vendor/github.com/shirou/gopsutil/cpu/cpu_windows.go @@ -23,8 +23,8 @@ type Win32_Processor struct { MaxClockSpeed uint32 } -// Win32_PerfFormattedData_Counters_ProcessorInformation stores instance value of the perf counters -type Win32_PerfFormattedData_Counters_ProcessorInformation struct { +// win32_PerfFormattedData_Counters_ProcessorInformation stores instance value of the perf counters +type win32_PerfFormattedData_Counters_ProcessorInformation struct { Name string PercentDPCTime uint64 PercentIdleTime uint64 @@ -51,7 +51,7 @@ func Times(percpu bool) ([]TimesStat, error) { func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { if percpu { - return perCPUTimes() + return perCPUTimesWithContext(ctx) } var ret []TimesStat @@ -119,17 +119,13 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { // PerfInfo returns the performance counter's instance value for ProcessorInformation. // Name property is the key by which overall, per cpu and per core metric is known. -func PerfInfo() ([]Win32_PerfFormattedData_Counters_ProcessorInformation, error) { - return PerfInfoWithContext(context.Background()) -} - -func PerfInfoWithContext(ctx context.Context) ([]Win32_PerfFormattedData_Counters_ProcessorInformation, error) { - var ret []Win32_PerfFormattedData_Counters_ProcessorInformation +func perfInfoWithContext(ctx context.Context) ([]win32_PerfFormattedData_Counters_ProcessorInformation, error) { + var ret []win32_PerfFormattedData_Counters_ProcessorInformation - q := wmi.CreateQuery(&ret, "") + q := wmi.CreateQuery(&ret, "WHERE NOT Name LIKE '%_Total'") err := common.WMIQueryWithContext(ctx, q, &ret) if err != nil { - return []Win32_PerfFormattedData_Counters_ProcessorInformation{}, err + return []win32_PerfFormattedData_Counters_ProcessorInformation{}, err } return ret, err @@ -152,9 +148,9 @@ func ProcInfoWithContext(ctx context.Context) ([]Win32_PerfFormattedData_PerfOS_ } // perCPUTimes returns times stat per cpu, per core and overall for all CPUs -func perCPUTimes() ([]TimesStat, error) { +func perCPUTimesWithContext(ctx context.Context) ([]TimesStat, error) { var ret []TimesStat - stats, err := PerfInfo() + stats, err := perfInfoWithContext(ctx) if err != nil { return nil, err } diff --git a/vendor/github.com/shirou/gopsutil/host/host_linux.go b/vendor/github.com/shirou/gopsutil/host/host_linux.go index 7ca50897d740..2c1ac6ba723a 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_linux.go +++ b/vendor/github.com/shirou/gopsutil/host/host_linux.go @@ -73,7 +73,10 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) { } sysProductUUID := common.HostSys("class/dmi/id/product_uuid") + machineID := common.HostEtc("machine-id") switch { + // In order to read this file, needs to be supported by kernel/arch and run as root + // so having fallback is important case common.PathExists(sysProductUUID): lines, err := common.ReadLines(sysProductUUID) if err == nil && len(lines) > 0 && lines[0] != "" { @@ -81,6 +84,16 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) { break } fallthrough + // Fallback on GNU Linux systems with systemd, readable by everyone + case common.PathExists(machineID): + lines, err := common.ReadLines(machineID) + if err == nil && len(lines) > 0 && len(lines[0]) == 32 { + st := lines[0] + ret.HostID = fmt.Sprintf("%s-%s-%s-%s-%s", st[0:8], st[8:12], st[12:16], st[16:20], st[20:32]) + break + } + fallthrough + // Not stable between reboot, but better than nothing default: values, err := common.DoSysctrl("kernel.random.boot_id") if err == nil && len(values) == 1 && values[0] != "" { diff --git a/vendor/vendor.json b/vendor/vendor.json index cfa95f03d9fb..cb835892cfe9 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -258,13 +258,14 @@ {"path":"github.com/ryanuber/columnize","checksumSHA1":"ExnVEVNT8APpFTm26cUb5T09yR4=","comment":"v2.0.1-8-g983d3a5","revision":"9b3edd62028f107d7cabb19353292afd29311a4e","revisionTime":"2016-07-12T16:32:29Z"}, {"path":"github.com/ryanuber/go-glob","checksumSHA1":"6JP37UqrI0H80Gpk0Y2P+KXgn5M=","revision":"256dc444b735e061061cf46c809487313d5b0065","revisionTime":"2017-01-28T01:21:29Z"}, {"path":"github.com/sean-/seed","checksumSHA1":"A/YUMbGg1LHIeK2+NLZBt+MIAao=","revision":"3c72d44db0c567f7c901f9c5da5fe68392227750","revisionTime":"2017-02-08T16:47:21Z"}, - {"path":"github.com/shirou/gopsutil/cpu","checksumSHA1":"xnCc/S88aNcLk5ypKy35jzFWSEA=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"}, - {"path":"github.com/shirou/gopsutil/disk","checksumSHA1":"JRyOki26wb3vORGErYK95N4tAeQ=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"}, - {"path":"github.com/shirou/gopsutil/host","checksumSHA1":"WpGujRcl7wfklBc5/8JREHAQmF4=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"}, - {"path":"github.com/shirou/gopsutil/internal/common","checksumSHA1":"GR7l7Ez4ppxIfonl7aJayYRVPWc=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"}, - {"path":"github.com/shirou/gopsutil/mem","checksumSHA1":"ehcscnqRvxDZYb1nBDVzZi8vFi8=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"}, - {"path":"github.com/shirou/gopsutil/net","checksumSHA1":"wAc1Qo6T9MTYdSog78uJfCYZPtc=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"}, - {"path":"github.com/shirou/gopsutil/process","checksumSHA1":"eI4qh+sc46gqKAfBt2jspO2l448=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"}, + {"path":"github.com/shirou/gopsutil","checksumSHA1":"KUrV5Esg6Wdcrv+hDc6/p0Q3/qw=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"}, + {"path":"github.com/shirou/gopsutil/cpu","checksumSHA1":"ZRkivbqqxTXH267b+mFAEk55HRI=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"}, + {"path":"github.com/shirou/gopsutil/disk","checksumSHA1":"JRyOki26wb3vORGErYK95N4tAeQ=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"}, + {"path":"github.com/shirou/gopsutil/host","checksumSHA1":"j+lnhiTHzGU2/EOd2k2EceD7Mak=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"}, + {"path":"github.com/shirou/gopsutil/internal/common","checksumSHA1":"GR7l7Ez4ppxIfonl7aJayYRVPWc=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"}, + {"path":"github.com/shirou/gopsutil/mem","checksumSHA1":"ehcscnqRvxDZYb1nBDVzZi8vFi8=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"}, + {"path":"github.com/shirou/gopsutil/net","checksumSHA1":"wAc1Qo6T9MTYdSog78uJfCYZPtc=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"}, + {"path":"github.com/shirou/gopsutil/process","checksumSHA1":"eI4qh+sc46gqKAfBt2jspO2l448=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"}, {"path":"github.com/shirou/w32","checksumSHA1":"Nve7SpDmjsv6+rhkXAkfg/UQx94=","revision":"bb4de0191aa41b5507caa14b0650cdbddcd9280b","revisionTime":"2016-09-30T03:27:40Z"}, {"path":"github.com/spf13/pflag","checksumSHA1":"WVKhLVXQFxXwmuRX+IRzebUmxjE=","revision":"298182f68c66c05229eb03ac171abe6e309ee79a","revisionTime":"2018-08-31T15:14:32Z"}, {"path":"github.com/stretchr/objx","checksumSHA1":"n+vQ7Bmp+ODWGmCp8cI5MFsaZVA=","revision":"a5cfa15c000af5f09784e5355969ba7eb66ef0de","revisionTime":"2018-04-26T10:50:06Z"},