Fix providing correct last_contact value for node

This commit is contained in:
Ingo Oppermann 2023-07-17 20:55:29 +02:00
parent cd31893286
commit 8123b09dcf
No known key found for this signature in database
GPG Key ID: 2AB32426E9DD229E
4 changed files with 27 additions and 25 deletions

View File

@ -294,7 +294,7 @@ WAIT:
}
func (c *cluster) establishLeadership(ctx context.Context, emergency bool) error {
c.logger.Debug().WithField("emergency", emergency).Log("Establishing leadership")
c.logger.Info().WithField("emergency", emergency).Log("Establishing leadership")
ctx, cancel := context.WithCancel(ctx)
c.cancelLeaderShip = cancel
@ -309,7 +309,7 @@ func (c *cluster) establishLeadership(ctx context.Context, emergency bool) error
}
func (c *cluster) revokeLeadership() {
c.logger.Debug().Log("Revoking leadership")
c.logger.Info().Log("Revoking leadership")
if c.cancelLeaderShip != nil {
c.cancelLeaderShip()
@ -665,6 +665,8 @@ func (c *cluster) doSynchronize(emergency bool) {
have := c.proxy.ListProxyProcesses()
nodes := c.proxy.ListNodes()
c.logger.Debug().WithField("emergency", emergency).Log("Synchronizing")
nodesMap := map[string]proxy.NodeAbout{}
for _, node := range nodes {
@ -734,6 +736,8 @@ func (c *cluster) doRebalance(emergency bool) {
return
}
c.logger.Debug().WithField("emergency", emergency).Log("Rebalancing")
have := c.proxy.ListProxyProcesses()
nodes := c.proxy.ListNodes()

View File

@ -514,12 +514,21 @@ func (n *node) AboutPeer() (clientapi.About, error) {
func (n *node) About() NodeAbout {
about, err := n.AboutPeer()
n.stateLock.RLock()
defer n.stateLock.RUnlock()
if err != nil {
return NodeAbout{
ID: n.id,
Address: n.address,
State: stateDisconnected.String(),
Error: err,
ID: n.id,
Address: n.address,
State: stateDisconnected.String(),
Error: err,
LastContact: n.lastContact,
Resources: NodeResources{
IsThrottling: true,
NCPU: 1,
},
}
}
@ -528,9 +537,6 @@ func (n *node) About() NodeAbout {
createdAt = time.Now()
}
n.stateLock.RLock()
defer n.stateLock.RUnlock()
state := n.state
if time.Since(n.lastContact) > 3*time.Second {
state = stateDisconnected
@ -559,25 +565,17 @@ func (n *node) About() NodeAbout {
if state == stateDisconnected {
nodeAbout.Uptime = 0
nodeAbout.Latency = 0
nodeAbout.Resources.IsThrottling = true
nodeAbout.Resources.NCPU = 1
}
return nodeAbout
}
func (n *node) Resources() NodeResources {
n.stateLock.RLock()
defer n.stateLock.RUnlock()
about := n.About()
r := NodeResources{
IsThrottling: n.resources.throttling,
NCPU: n.resources.ncpu,
CPU: n.resources.cpu,
CPULimit: n.resources.cpuLimit,
Mem: n.resources.mem,
MemLimit: n.resources.memLimit,
}
return r
return about.Resources
}
func (n *node) Version() NodeVersion {

View File

@ -6,7 +6,7 @@ type About struct {
Auths []string `json:"auths"`
Name string `json:"name"`
ID string `json:"id"`
CreatedAt string `json:"created_at"`
CreatedAt string `json:"created_at"` // RFC3339
Uptime uint64 `json:"uptime_seconds"`
Version Version `json:"version"`
}
@ -16,7 +16,7 @@ type Version struct {
Number string `json:"number"`
Commit string `json:"repository_commit"`
Branch string `json:"repository_branch"`
Build string `json:"build_date"`
Build string `json:"build_date"` // RFC3339
Arch string `json:"arch"`
Compiler string `json:"compiler"`
}

View File

@ -25,8 +25,8 @@ type ClusterNodeCore struct {
Address string `json:"address"`
Status string `json:"status"`
Error string `json:"error"`
LastContact float64 `json:"last_contact_ms"`
Latency float64 `json:"latency_ms"`
LastContact float64 `json:"last_contact_ms"` // milliseconds
Latency float64 `json:"latency_ms"` // milliseconds
}
type ClusterNodeResources struct {