Add metrics for requests forwarded by standbys. (#11366)
This commit is contained in:
parent
242d258e94
commit
b07a10331f
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
core: Add metrics for standby node forwarding.
|
||||||
|
```
|
|
@ -14,9 +14,9 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/armon/go-metrics"
|
||||||
log "github.com/hashicorp/go-hclog"
|
log "github.com/hashicorp/go-hclog"
|
||||||
"github.com/hashicorp/vault/helper/forwarding"
|
"github.com/hashicorp/vault/helper/forwarding"
|
||||||
|
|
||||||
"github.com/hashicorp/vault/sdk/helper/consts"
|
"github.com/hashicorp/vault/sdk/helper/consts"
|
||||||
"github.com/hashicorp/vault/vault/cluster"
|
"github.com/hashicorp/vault/vault/cluster"
|
||||||
"github.com/hashicorp/vault/vault/replication"
|
"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
|
return 0, nil, nil, ErrCannotForward
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer metrics.MeasureSince([]string{"ha", "rpc", "client", "forward"}, time.Now())
|
||||||
|
|
||||||
origPath := req.URL.Path
|
origPath := req.URL.Path
|
||||||
defer func() {
|
defer func() {
|
||||||
req.URL.Path = origPath
|
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)
|
resp, err := c.rpcForwardingClient.ForwardRequest(req.Context(), freq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
metrics.IncrCounter([]string{"ha", "rpc", "client", "forward", "errors"}, 1)
|
||||||
c.logger.Error("error during forwarded RPC request", "error", err)
|
c.logger.Error("error during forwarded RPC request", "error", err)
|
||||||
return 0, nil, nil, fmt.Errorf("error during forwarding RPC request")
|
return 0, nil, nil, fmt.Errorf("error during forwarding RPC request")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue