rename forward func, add comment for why we forward
This commit is contained in:
parent
9a80938fb1
commit
31c0aca10a
|
@ -29,13 +29,15 @@ func (a *Agent) register() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) Profile(args *structs.AgentPprofRequest, reply *structs.AgentPprofResponse) error {
|
func (a *Agent) Profile(args *structs.AgentPprofRequest, reply *structs.AgentPprofResponse) error {
|
||||||
// handle when serverID does not exist for requested region
|
// Forward to different region if necessary
|
||||||
|
// this would typically be done in a.srv.forward() but since
|
||||||
|
// we are targeting a specific server, not just the leader
|
||||||
|
// we must manually handle region forwarding here.
|
||||||
region := args.RequestRegion()
|
region := args.RequestRegion()
|
||||||
if region == "" {
|
if region == "" {
|
||||||
return fmt.Errorf("missing target RPC")
|
return fmt.Errorf("missing target RPC")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle region forwarding
|
|
||||||
if region != a.srv.config.Region {
|
if region != a.srv.config.Region {
|
||||||
// Mark that we are forwarding
|
// Mark that we are forwarding
|
||||||
args.SetForwarded()
|
args.SetForwarded()
|
||||||
|
@ -49,7 +51,7 @@ func (a *Agent) Profile(args *structs.AgentPprofRequest, reply *structs.AgentPpr
|
||||||
|
|
||||||
// Handle serverID not equal to ours
|
// Handle serverID not equal to ours
|
||||||
if args.ServerID != "" {
|
if args.ServerID != "" {
|
||||||
serverToFwd, err := a.serverFor(args.ServerID, region)
|
serverToFwd, err := a.forwardFor(args.ServerID, region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -260,7 +262,7 @@ OUTER:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) serverFor(serverID, region string) (*serverParts, error) {
|
func (a *Agent) forwardFor(serverID, region string) (*serverParts, error) {
|
||||||
var target *serverParts
|
var target *serverParts
|
||||||
|
|
||||||
if serverID == "leader" {
|
if serverID == "leader" {
|
||||||
|
@ -467,13 +469,13 @@ func (a *Agent) forwardProfileClient(args *structs.AgentPprofRequest, reply *str
|
||||||
|
|
||||||
rpcErr := a.srv.forwardServer(srv, "Agent.Profile", args, reply)
|
rpcErr := a.srv.forwardServer(srv, "Agent.Profile", args, reply)
|
||||||
if rpcErr != nil {
|
if rpcErr != nil {
|
||||||
return structs.NewErrRPCCoded(500, err.Error())
|
return rpcErr
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// NodeRpc
|
// NodeRpc
|
||||||
rpcErr := NodeRpc(state.Session, "Agent.Profile", args, reply)
|
rpcErr := NodeRpc(state.Session, "Agent.Profile", args, reply)
|
||||||
if rpcErr != nil {
|
if rpcErr != nil {
|
||||||
return structs.NewErrRPCCoded(500, err.Error())
|
return rpcErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue