introduce EmptyReadRequest for status_endpoint (#12653)

Co-authored-by: Daniel Nephin <dnephin@hashicorp.com>
This commit is contained in:
FFMMM 2022-03-29 18:05:45 -07:00 committed by GitHub
parent 885edde8c1
commit bbab030beb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -5,11 +5,12 @@ import (
"net" "net"
"sync" "sync"
"github.com/hashicorp/consul/agent/pool"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/go-hclog" "github.com/hashicorp/go-hclog"
"github.com/hashicorp/raft" "github.com/hashicorp/raft"
autopilot "github.com/hashicorp/raft-autopilot" autopilot "github.com/hashicorp/raft-autopilot"
"github.com/hashicorp/consul/agent/pool"
"github.com/hashicorp/consul/agent/structs"
) )
// StatsFetcher has two functions for autopilot. First, lets us fetch all the // StatsFetcher has two functions for autopilot. First, lets us fetch all the
@ -42,7 +43,7 @@ func NewStatsFetcher(logger hclog.Logger, pool *pool.ConnPool, datacenter string
// RPC to each server, so we let it finish and then clean up the in-flight // RPC to each server, so we let it finish and then clean up the in-flight
// tracking. // tracking.
func (f *StatsFetcher) fetch(server *autopilot.Server, replyCh chan *autopilot.ServerStats) { func (f *StatsFetcher) fetch(server *autopilot.Server, replyCh chan *autopilot.ServerStats) {
var args struct{} var args EmptyReadRequest
var reply structs.RaftStats var reply structs.RaftStats
// defer some cleanup to notify everything else that the fetching is no longer occurring // defer some cleanup to notify everything else that the fetching is no longer occurring

View File

@ -13,7 +13,7 @@ type Status struct {
} }
// Ping is used to just check for connectivity // Ping is used to just check for connectivity
func (s *Status) Ping(args struct{}, reply *struct{}) error { func (s *Status) Ping(args EmptyReadRequest, reply *struct{}) error {
return nil return nil
} }
@ -55,8 +55,16 @@ func (s *Status) Peers(args *structs.DCSpecificRequest, reply *[]string) error {
return nil return nil
} }
// Used by Autopilot to query the raft stats of the local server. // EmptyReadRequest implements the interface used by middleware.RequestRecorder
func (s *Status) RaftStats(args struct{}, reply *structs.RaftStats) error { // to communicate properties of requests.
type EmptyReadRequest struct{}
func (e EmptyReadRequest) IsRead() bool {
return true
}
// RaftStats is used by Autopilot to query the raft stats of the local server.
func (s *Status) RaftStats(args EmptyReadRequest, reply *structs.RaftStats) error {
stats := s.server.raft.Stats() stats := s.server.raft.Stats()
var err error var err error