Skip to content

Commit

Permalink
Add metrics for requests forwarded by standbys. (#11366)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncabatoff authored Apr 16, 2021
1 parent 74bd3ee commit 4157ed4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/11366.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
core: Add metrics for standby node forwarding.
```
5 changes: 4 additions & 1 deletion vault/request_forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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")
}
Expand Down

0 comments on commit 4157ed4

Please sign in to comment.