New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VAULT-2776] Add prefix_filter option to Vault #12025
Changes from 5 commits
7305528
6447939
73d3e97
6a28af2
6c2ad99
beae728
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
core: Add `prefix_filter` to telemetry config | ||
``` |
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", | ||
ncabatoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
} | ||
}) | ||
} |
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 | ||
} |
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"] | ||
} |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine with the cases you have now, but I consider it best practice when you have an expected error field in your test case type to do something like if err != nil { compare with expected error } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah that makes sense! added that here 6c2ad99 |
||
assert.EqualError(t, err, tc.expectedErrStr) | ||
} else { | ||
assert.Equal(t, "", tc.expectedErrStr) | ||
assert.Equal(t, tc.expectedAllowedPrefixes, allowedPrefixes) | ||
|
||
assert.Equal(t, tc.expectedBlockedPrefixes, blockedPrefixes) | ||
} | ||
} | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
**/*.hcl
instead of*/*.hcl
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should! beae728