github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/structs/autopilot.go (about)

     1  package structs
     2  
     3  import (
     4  	"time"
     5  
     6  	autopilot "github.com/hashicorp/raft-autopilot"
     7  	"github.com/hashicorp/serf/serf"
     8  )
     9  
    10  // OperatorHealthReply is a representation of the overall health of the cluster
    11  type OperatorHealthReply struct {
    12  	// Healthy is true if all the servers in the cluster are healthy.
    13  	Healthy bool
    14  
    15  	// FailureTolerance is the number of healthy servers that could be lost without
    16  	// an outage occurring.
    17  	FailureTolerance int
    18  
    19  	// Servers holds the health of each server.
    20  	Servers []ServerHealth
    21  }
    22  
    23  // ServerHealth is the health (from the leader's point of view) of a server.
    24  type ServerHealth struct {
    25  	// ID is the raft ID of the server.
    26  	ID string
    27  
    28  	// Name is the node name of the server.
    29  	Name string
    30  
    31  	// Address is the address of the server.
    32  	Address string
    33  
    34  	// The status of the SerfHealth check for the server.
    35  	SerfStatus serf.MemberStatus
    36  
    37  	// Version is the Nomad version of the server.
    38  	Version string
    39  
    40  	// Leader is whether this server is currently the leader.
    41  	Leader bool
    42  
    43  	// LastContact is the time since this node's last contact with the leader.
    44  	LastContact time.Duration
    45  
    46  	// LastTerm is the highest leader term this server has a record of in its Raft log.
    47  	LastTerm uint64
    48  
    49  	// LastIndex is the last log index this server has a record of in its Raft log.
    50  	LastIndex uint64
    51  
    52  	// Healthy is whether or not the server is healthy according to the current
    53  	// Autopilot config.
    54  	Healthy bool
    55  
    56  	// Voter is whether this is a voting server.
    57  	Voter bool
    58  
    59  	// StableSince is the last time this server's Healthy value changed.
    60  	StableSince time.Time
    61  }
    62  
    63  // RaftStats holds miscellaneous Raft metrics for a server, used by autopilot.
    64  type RaftStats struct {
    65  	// LastContact is the time since this node's last contact with the leader.
    66  	LastContact string
    67  
    68  	// LastTerm is the highest leader term this server has a record of in its Raft log.
    69  	LastTerm uint64
    70  
    71  	// LastIndex is the last log index this server has a record of in its Raft log.
    72  	LastIndex uint64
    73  }
    74  
    75  func (s *RaftStats) ToAutopilotServerStats() *autopilot.ServerStats {
    76  	duration, _ := time.ParseDuration(s.LastContact)
    77  	return &autopilot.ServerStats{
    78  		LastContact: duration,
    79  		LastTerm:    s.LastTerm,
    80  		LastIndex:   s.LastIndex,
    81  	}
    82  }