From 349378454a4e09237af6e84b944a6075fba1d2c5 Mon Sep 17 00:00:00 2001 From: Chris Capurso Date: Fri, 9 Jul 2021 11:05:05 -0400 Subject: [PATCH] [VAULT-1836] Support kv-v1 generic mounts for vault.kv.secret.count metric (#12020) * [VAULT-1836] Support kv-v1 generic mounts for vault.kv.secret.count metric * [VAULT-1836] Add changelog entry --- changelog/12020.txt | 3 +++ vault/core_metrics.go | 2 +- vault/core_metrics_test.go | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 changelog/12020.txt diff --git a/changelog/12020.txt b/changelog/12020.txt new file mode 100644 index 000000000..c3c605dac --- /dev/null +++ b/changelog/12020.txt @@ -0,0 +1,3 @@ +```release-note:bug +core/metrics: Add generic KV mount support for vault.kv.secret.count telemetry metric +``` diff --git a/vault/core_metrics.go b/vault/core_metrics.go index 6477721ec..d5fbd7782 100644 --- a/vault/core_metrics.go +++ b/vault/core_metrics.go @@ -323,7 +323,7 @@ func (c *Core) findKvMounts() []*kvMount { } for _, entry := range c.mounts.Entries { - if entry.Type == "kv" { + if entry.Type == "kv" || entry.Type == "generic" { version, ok := entry.Options["version"] if !ok { version = "1" diff --git a/vault/core_metrics_test.go b/vault/core_metrics_test.go index 6e69859b6..7558637ef 100644 --- a/vault/core_metrics_test.go +++ b/vault/core_metrics_test.go @@ -23,15 +23,17 @@ func TestCoreMetrics_KvSecretGauge(t *testing.T) { testMounts := []struct { Path string + Type string Version string ExpectedCount int }{ - {"secret/", "2", 0}, - {"secret1/", "1", 3}, - {"secret2/", "1", 0}, - {"secret3/", "2", 4}, - {"prefix/secret3/", "2", 0}, - {"prefix/secret4/", "2", 5}, + {"secret/", "kv", "2", 0}, + {"secret1/", "kv", "1", 3}, + {"secret2/", "kv", "1", 0}, + {"secret3/", "kv", "2", 4}, + {"prefix/secret3/", "kv", "2", 0}, + {"prefix/secret4/", "kv", "2", 5}, + {"generic/", "generic", "1", 3}, } ctx := namespace.RootContext(nil) @@ -40,7 +42,7 @@ func TestCoreMetrics_KvSecretGauge(t *testing.T) { me := &MountEntry{ Table: mountTableType, Path: sanitizePath(tm.Path), - Type: "kv", + Type: tm.Type, Options: map[string]string{"version": tm.Version}, } err := core.mount(ctx, me) @@ -53,6 +55,9 @@ func TestCoreMetrics_KvSecretGauge(t *testing.T) { "secret1/a", // 3 "secret1/b", "secret1/c/d", + "generic/a", + "generic/b", + "generic/c", } v2secrets := []string{ "secret3/data/a", // 4