Add metrics for requests forwarded by standbys. (#11366)

This commit is contained in:
Nick Cabatoff 2021-04-16 14:02:20 -04:00 committed by GitHub
parent 242d258e94
commit b07a10331f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

3
changelog/11366.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
core: Add metrics for standby node forwarding.
```

View File

@ -14,9 +14,9 @@ import (
"sync"
"time"
"github.com/armon/go-metrics"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/forwarding"
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/hashicorp/vault/vault/cluster"
"github.com/hashicorp/vault/vault/replication"
@ -336,6 +336,8 @@ func (c *Core) ForwardRequest(req *http.Request) (int, http.Header, []byte, erro
return 0, nil, nil, ErrCannotForward
}
defer metrics.MeasureSince([]string{"ha", "rpc", "client", "forward"}, time.Now())
origPath := req.URL.Path
defer func() {
req.URL.Path = origPath
@ -354,6 +356,7 @@ func (c *Core) ForwardRequest(req *http.Request) (int, http.Header, []byte, erro
}
resp, err := c.rpcForwardingClient.ForwardRequest(req.Context(), freq)
if err != nil {
metrics.IncrCounter([]string{"ha", "rpc", "client", "forward", "errors"}, 1)
c.logger.Error("error during forwarded RPC request", "error", err)
return 0, nil, nil, fmt.Errorf("error during forwarding RPC request")
}