Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VAULT-2776] Add prefix_filter option to Vault (#12025)
* [VAULT-2776] Add prefix_filter support to vault * [VAULT-2776] Add filter_default config, update docs * [VAULT-2776] Add changelog file * [VAULT-2776] Update telemetry tests and error handling * [VAULT-2776] Add test fixtures, update test * [VAULT-2776] Update gitignore hcl filter
- Loading branch information
Showing
9 changed files
with
167 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
core: Add `prefix_filter` to telemetry config | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package server | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMetricFilterConfigs(t *testing.T) { | ||
t.Parallel() | ||
cases := []struct { | ||
configFile string | ||
expectedFilterDefault *bool | ||
expectedPrefixFilter []string | ||
}{ | ||
{ | ||
"./test-fixtures/telemetry/valid_prefix_filter.hcl", | ||
nil, | ||
[]string{"-vault.expire", "-vault.audit", "+vault.expire.num_irrevocable_leases"}, | ||
}, | ||
{ | ||
"./test-fixtures/telemetry/filter_default_override.hcl", | ||
boolPointer(false), | ||
[]string(nil), | ||
}, | ||
} | ||
t.Run("validate metric filter configs", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, tc := range cases { | ||
config, err := LoadConfigFile(tc.configFile) | ||
|
||
if err != nil { | ||
t.Fatalf("Error encountered when loading config %+v", err) | ||
} | ||
|
||
assert.Equal(t, tc.expectedFilterDefault, config.SharedConfig.Telemetry.FilterDefault) | ||
assert.Equal(t, tc.expectedPrefixFilter, config.SharedConfig.Telemetry.PrefixFilter) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
command/server/test-fixtures/telemetry/filter_default_override.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
disable_mlock = true | ||
ui = true | ||
|
||
telemetry { | ||
statsd_address = "foo" | ||
filter_default = false | ||
} |
7 changes: 7 additions & 0 deletions
7
command/server/test-fixtures/telemetry/valid_prefix_filter.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
disable_mlock = true | ||
ui = true | ||
|
||
telemetry { | ||
statsd_address = "foo" | ||
prefix_filter = ["-vault.expire", "-vault.audit", "+vault.expire.num_irrevocable_leases"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package configutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParsePrefixFilters(t *testing.T) { | ||
t.Parallel() | ||
cases := []struct { | ||
inputFilters []string | ||
expectedErrStr string | ||
expectedAllowedPrefixes []string | ||
expectedBlockedPrefixes []string | ||
}{ | ||
{ | ||
[]string{""}, | ||
"Cannot have empty filter rule in prefix_filter", | ||
[]string(nil), | ||
[]string(nil), | ||
}, | ||
{ | ||
[]string{"vault.abc"}, | ||
"Filter rule must begin with either '+' or '-': \"vault.abc\"", | ||
[]string(nil), | ||
[]string(nil), | ||
}, | ||
{ | ||
[]string{"+vault.abc", "-vault.bcd"}, | ||
"", | ||
[]string{"vault.abc"}, | ||
[]string{"vault.bcd"}, | ||
}, | ||
} | ||
t.Run("validate metric filter configs", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, tc := range cases { | ||
|
||
allowedPrefixes, blockedPrefixes, err := parsePrefixFilter(tc.inputFilters) | ||
|
||
if err != nil { | ||
assert.EqualError(t, err, tc.expectedErrStr) | ||
} else { | ||
assert.Equal(t, "", tc.expectedErrStr) | ||
assert.Equal(t, tc.expectedAllowedPrefixes, allowedPrefixes) | ||
|
||
assert.Equal(t, tc.expectedBlockedPrefixes, blockedPrefixes) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters