Backport of improve client RPC metrics consistency into release/1.16.x (#19842)

* backport of commit 06507fe053f8777b12c8a0a54e062df1fb111a52

* backport of commit 14e160573dbc9d644cb045af7eda5da0d03447d0

* backport of commit 088ec70f902e79a101669fbb76830fe356b23982

---------

Co-authored-by: Jared Kirschner <85913323+jkirschner-hashicorp@users.noreply.github.com>
This commit is contained in:
hc-github-team-consul-core 2023-12-06 13:05:34 -06:00 committed by GitHub
parent fa9de6f8b4
commit 236ceb3b40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

6
.changelog/19721.txt Normal file
View File

@ -0,0 +1,6 @@
```release-note:improvement
metrics: modify consul.client.rpc metric to exclude internal retries for consistency with consul.client.rpc.exceeded and consul.client.rpc.failed
```
```release-note:improvement
metrics: increment consul.client.rpc.failed if RPC fails because no servers are accessible
```

View File

@ -277,15 +277,17 @@ func (c *Client) RPC(ctx context.Context, method string, args interface{}, reply
firstCheck := time.Now()
retryCount := 0
previousJitter := time.Duration(0)
metrics.IncrCounter([]string{"client", "rpc"}, 1)
TRY:
retryCount++
manager, server := c.router.FindLANRoute()
if server == nil {
metrics.IncrCounter([]string{"client", "rpc", "failed"}, 1)
return structs.ErrNoServers
}
// Enforce the RPC limit.
metrics.IncrCounter([]string{"client", "rpc"}, 1)
if !c.rpcLimiter.Load().(*rate.Limiter).Allow() {
metrics.IncrCounter([]string{"client", "rpc", "exceeded"}, 1)
return structs.ErrRPCRateExceeded