github.com/hernad/nomad@v1.6.112/nomad/structs/autopilot.go (about)

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