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).
This commit is contained in:
parent
3b8bdf0f62
commit
8dd3476921
|
@ -23,8 +23,8 @@ type Win32_Processor struct {
|
||||||
MaxClockSpeed uint32
|
MaxClockSpeed uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Win32_PerfFormattedData_Counters_ProcessorInformation stores instance value of the perf counters
|
// win32_PerfFormattedData_Counters_ProcessorInformation stores instance value of the perf counters
|
||||||
type Win32_PerfFormattedData_Counters_ProcessorInformation struct {
|
type win32_PerfFormattedData_Counters_ProcessorInformation struct {
|
||||||
Name string
|
Name string
|
||||||
PercentDPCTime uint64
|
PercentDPCTime uint64
|
||||||
PercentIdleTime uint64
|
PercentIdleTime uint64
|
||||||
|
@ -51,7 +51,7 @@ func Times(percpu bool) ([]TimesStat, error) {
|
||||||
|
|
||||||
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
|
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
|
||||||
if percpu {
|
if percpu {
|
||||||
return perCPUTimes()
|
return perCPUTimesWithContext(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret []TimesStat
|
var ret []TimesStat
|
||||||
|
@ -119,17 +119,13 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
|
||||||
|
|
||||||
// PerfInfo returns the performance counter's instance value for ProcessorInformation.
|
// 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.
|
// Name property is the key by which overall, per cpu and per core metric is known.
|
||||||
func PerfInfo() ([]Win32_PerfFormattedData_Counters_ProcessorInformation, error) {
|
func perfInfoWithContext(ctx context.Context) ([]win32_PerfFormattedData_Counters_ProcessorInformation, error) {
|
||||||
return PerfInfoWithContext(context.Background())
|
var ret []win32_PerfFormattedData_Counters_ProcessorInformation
|
||||||
}
|
|
||||||
|
|
||||||
func PerfInfoWithContext(ctx context.Context) ([]Win32_PerfFormattedData_Counters_ProcessorInformation, error) {
|
q := wmi.CreateQuery(&ret, "WHERE NOT Name LIKE '%_Total'")
|
||||||
var ret []Win32_PerfFormattedData_Counters_ProcessorInformation
|
|
||||||
|
|
||||||
q := wmi.CreateQuery(&ret, "")
|
|
||||||
err := common.WMIQueryWithContext(ctx, q, &ret)
|
err := common.WMIQueryWithContext(ctx, q, &ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []Win32_PerfFormattedData_Counters_ProcessorInformation{}, err
|
return []win32_PerfFormattedData_Counters_ProcessorInformation{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, 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
|
// 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
|
var ret []TimesStat
|
||||||
stats, err := PerfInfo()
|
stats, err := perfInfoWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,10 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sysProductUUID := common.HostSys("class/dmi/id/product_uuid")
|
sysProductUUID := common.HostSys("class/dmi/id/product_uuid")
|
||||||
|
machineID := common.HostEtc("machine-id")
|
||||||
switch {
|
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):
|
case common.PathExists(sysProductUUID):
|
||||||
lines, err := common.ReadLines(sysProductUUID)
|
lines, err := common.ReadLines(sysProductUUID)
|
||||||
if err == nil && len(lines) > 0 && lines[0] != "" {
|
if err == nil && len(lines) > 0 && lines[0] != "" {
|
||||||
|
@ -81,6 +84,16 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
fallthrough
|
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:
|
default:
|
||||||
values, err := common.DoSysctrl("kernel.random.boot_id")
|
values, err := common.DoSysctrl("kernel.random.boot_id")
|
||||||
if err == nil && len(values) == 1 && values[0] != "" {
|
if err == nil && len(values) == 1 && values[0] != "" {
|
||||||
|
|
|
@ -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/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/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/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","checksumSHA1":"KUrV5Esg6Wdcrv+hDc6/p0Q3/qw=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"},
|
||||||
{"path":"github.com/shirou/gopsutil/disk","checksumSHA1":"JRyOki26wb3vORGErYK95N4tAeQ=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"},
|
{"path":"github.com/shirou/gopsutil/cpu","checksumSHA1":"ZRkivbqqxTXH267b+mFAEk55HRI=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"},
|
||||||
{"path":"github.com/shirou/gopsutil/host","checksumSHA1":"WpGujRcl7wfklBc5/8JREHAQmF4=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"},
|
{"path":"github.com/shirou/gopsutil/disk","checksumSHA1":"JRyOki26wb3vORGErYK95N4tAeQ=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"},
|
||||||
{"path":"github.com/shirou/gopsutil/internal/common","checksumSHA1":"GR7l7Ez4ppxIfonl7aJayYRVPWc=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"},
|
{"path":"github.com/shirou/gopsutil/host","checksumSHA1":"j+lnhiTHzGU2/EOd2k2EceD7Mak=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"},
|
||||||
{"path":"github.com/shirou/gopsutil/mem","checksumSHA1":"ehcscnqRvxDZYb1nBDVzZi8vFi8=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"},
|
{"path":"github.com/shirou/gopsutil/internal/common","checksumSHA1":"GR7l7Ez4ppxIfonl7aJayYRVPWc=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"},
|
||||||
{"path":"github.com/shirou/gopsutil/net","checksumSHA1":"wAc1Qo6T9MTYdSog78uJfCYZPtc=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"},
|
{"path":"github.com/shirou/gopsutil/mem","checksumSHA1":"ehcscnqRvxDZYb1nBDVzZi8vFi8=","revision":"48177ef5f8809fc72b716c414435f2d4cff8e24d","revisionTime":"2018-11-07T11:16:21Z"},
|
||||||
{"path":"github.com/shirou/gopsutil/process","checksumSHA1":"eI4qh+sc46gqKAfBt2jspO2l448=","revision":"a11c78ba2c13c5b1ee59c53296ba35f92f0ce658","revisionTime":"2018-09-27T12:43:08Z"},
|
{"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/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/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"},
|
{"path":"github.com/stretchr/objx","checksumSHA1":"n+vQ7Bmp+ODWGmCp8cI5MFsaZVA=","revision":"a5cfa15c000af5f09784e5355969ba7eb66ef0de","revisionTime":"2018-04-26T10:50:06Z"},
|
||||||
|
|
Loading…
Reference in New Issue