055434cca9
Implement a metric for RPC requests with labels on the identity, so that administrators can monitor the source of requests within the cluster. This changeset demonstrates the change with the new `ACL.WhoAmI` RPC, and we'll wire up the remaining RPCs once we've threaded the new pre-forwarding authentication through the all. Note that metrics are measured after we forward but before we return any authentication error. This ensures that we only emit metrics on the server that actually serves the request. We'll perform rate limiting at the same place. Includes telemetry configuration to omit identity labels.
24 lines
781 B
Go
24 lines
781 B
Go
package nomad
|
|
|
|
import (
|
|
"github.com/armon/go-metrics"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
)
|
|
|
|
// MeasureRPCRate increments the appropriate rate metric for this endpoint,
|
|
// with a label from the identity
|
|
func (srv *Server) MeasureRPCRate(endpoint, op string, args structs.RequestWithIdentity) {
|
|
identity := args.GetIdentity()
|
|
|
|
if !srv.config.ACLEnabled || identity == nil || srv.config.DisableRPCRateMetricsLabels {
|
|
// If ACLs aren't enabled, we never have a sensible identity.
|
|
// Or the administrator may have disabled the identity labels.
|
|
metrics.IncrCounter([]string{"nomad", "rpc", endpoint, op}, 1)
|
|
} else {
|
|
metrics.IncrCounterWithLabels(
|
|
[]string{"nomad", "rpc", endpoint, op}, 1,
|
|
[]metrics.Label{{Name: "identity", Value: identity.String()}})
|
|
}
|
|
}
|