f61f801e77
Upcoming work to instrument the rate of RPC requests by consumer (and eventually rate limit) requires that we thread the `RPCContext` through all RPC handlers so that we can access the underlying connection. This changeset adds the context to everywhere we intend to initially support it and intentionally excludes streaming RPCs and client RPCs. To improve the ergonomics of adding the context everywhere its needed and to clarify the requirements of dynamic vs static handlers, I've also done a good bit of refactoring here: * canonicalized the RPC handler fields so they're as close to identical as possible without introducing unused fields (i.e. I didn't add loggers if the handler doesn't use them already). * canonicalized the imports in the handler files. * added a `NewExampleEndpoint` function for each handler that ensures we're constructing the handlers with the required arguments. * reordered the registration in server.go to match the order of the files (to make it easier to see if we've missed one), and added a bunch of commentary there as to what the difference between static and dynamic handlers is.
27 lines
670 B
Go
27 lines
670 B
Go
package nomad
|
|
|
|
import (
|
|
"github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
)
|
|
|
|
// Region is used to query and list the known regions
|
|
type Region struct {
|
|
srv *Server
|
|
ctx *RPCContext
|
|
logger hclog.Logger
|
|
}
|
|
|
|
func NewRegionEndpoint(srv *Server, ctx *RPCContext) *Region {
|
|
return &Region{srv: srv, ctx: ctx, logger: srv.logger.Named("region")}
|
|
}
|
|
|
|
// List is used to list all of the known regions. No leader forwarding is
|
|
// required for this endpoint because memberlist is used to populate the
|
|
// peers list we read from.
|
|
func (r *Region) List(args *structs.GenericRequest, reply *[]string) error {
|
|
*reply = r.srv.Regions()
|
|
return nil
|
|
}
|