diff --git a/changelog/11366.txt b/changelog/11366.txt new file mode 100644 index 000000000000..b1d9eb17ed60 --- /dev/null +++ b/changelog/11366.txt @@ -0,0 +1,3 @@ +```release-note:improvement +core: Add metrics for standby node forwarding. +``` diff --git a/vault/request_forwarding.go b/vault/request_forwarding.go index a69ba68593dc..bdd31a54f173 100644 --- a/vault/request_forwarding.go +++ b/vault/request_forwarding.go @@ -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") }