client: fix race accessing Node.status

* Call Node.Canonicalize once when Node is created.
 * Lock when accessing fields mutated by node update goroutine
This commit is contained in:
Michael Schurter 2020-02-06 13:37:42 -08:00
parent 351d32cd81
commit 2896f78f77
2 changed files with 10 additions and 4 deletions

View File

@ -2847,12 +2847,15 @@ func (c *Client) setGaugeForUptime(hStats *stats.HostStats, baseLabels []metrics
func (c *Client) emitHostStats() {
nodeID := c.NodeID()
hStats := c.hostStatsCollector.Stats()
node := c.Node()
node.Canonicalize()
c.configLock.RLock()
nodeStatus := c.configCopy.Node.Status
nodeEligibility := c.configCopy.Node.SchedulingEligibility
c.configLock.RUnlock()
labels := append(c.baseLabels,
metrics.Label{Name: "node_status", Value: node.Status},
metrics.Label{Name: "node_scheduling_eligibility", Value: node.SchedulingEligibility},
metrics.Label{Name: "node_status", Value: nodeStatus},
metrics.Label{Name: "node_scheduling_eligibility", Value: nodeEligibility},
)
c.setGaugeForMemoryStats(nodeID, hStats, labels)

View File

@ -521,6 +521,9 @@ func convertClientConfig(agentConfig *Config) (*clientconfig.Config, error) {
// Set up the HTTP advertise address
conf.Node.HTTPAddr = agentConfig.AdvertiseAddrs.HTTP
// Canonicalize Node struct
conf.Node.Canonicalize()
// Reserve resources on the node.
// COMPAT(0.10): Remove in 0.10
r := conf.Node.Reserved