open-nomad/nomad/client_stats_endpoint.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.5 KiB
Go
Raw Normal View History

2018-01-11 23:58:59 +00:00
package nomad
import (
"time"
metrics "github.com/armon/go-metrics"
2018-09-15 23:23:13 +00:00
log "github.com/hashicorp/go-hclog"
2018-01-11 23:58:59 +00:00
nstructs "github.com/hashicorp/nomad/nomad/structs"
2018-09-15 23:23:13 +00:00
"github.com/hashicorp/nomad/client/structs"
2018-01-11 23:58:59 +00:00
)
// ClientStats is used to forward RPC requests to the targed Nomad client's
// ClientStats endpoint.
type ClientStats struct {
2018-09-15 23:23:13 +00:00
srv *Server
logger log.Logger
2018-01-11 23:58:59 +00:00
}
func NewClientStatsEndpoint(srv *Server) *ClientStats {
return &ClientStats{srv: srv, logger: srv.logger.Named("client_stats")}
}
2018-02-06 01:20:42 +00:00
func (s *ClientStats) Stats(args *nstructs.NodeSpecificRequest, reply *structs.ClientStatsResponse) error {
2018-01-11 23:58:59 +00:00
// We only allow stale reads since the only potentially stale information is
// the Node registration and the cost is fairly high for adding another hope
// in the forwarding chain.
args.QueryOptions.AllowStale = true
authErr := s.srv.Authenticate(nil, args)
2018-01-11 23:58:59 +00:00
// Potentially forward to a different region.
if done, err := s.srv.forward("ClientStats.Stats", args, args, reply); done {
return err
}
s.srv.MeasureRPCRate("client_stats", nstructs.RateMetricRead, args)
if authErr != nil {
return nstructs.ErrPermissionDenied
}
2018-01-11 23:58:59 +00:00
defer metrics.MeasureSince([]string{"nomad", "client_stats", "stats"}, time.Now())
// Check node read permissions
if aclObj, err := s.srv.ResolveACL(args); err != nil {
2018-01-11 23:58:59 +00:00
return err
} else if aclObj != nil && !aclObj.AllowNodeRead() {
return nstructs.ErrPermissionDenied
}
return s.srv.forwardClientRPC("ClientStats.Stats", args.NodeID, args, reply)
2018-01-11 23:58:59 +00:00
}