From ab7d3bbc711e12b7318aba96d4f2c073d167f4d5 Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Fri, 16 Apr 2021 14:02:20 -0400 Subject: [PATCH] Add metrics for requests forwarded by standbys. (#11366) --- changelog/11366.txt | 3 +++ vault/request_forwarding.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelog/11366.txt diff --git a/changelog/11366.txt b/changelog/11366.txt new file mode 100644 index 0000000000000..b1d9eb17ed60c --- /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 a69ba68593dcc..bdd31a54f1733 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") }