2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-01-24 16:54:20 +00:00
|
|
|
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
|
2023-04-12 13:03:07 +00:00
|
|
|
func (s *Server) MeasureRPCRate(endpoint, op string, args structs.RequestWithIdentity) {
|
2023-01-24 16:54:20 +00:00
|
|
|
identity := args.GetIdentity()
|
|
|
|
|
2023-04-12 13:03:07 +00:00
|
|
|
if !s.config.ACLEnabled || identity == nil || s.config.DisableRPCRateMetricsLabels {
|
2023-01-24 16:54:20 +00:00
|
|
|
// 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()}})
|
|
|
|
}
|
|
|
|
}
|