Skip to content
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

report listener and storage types as found keys #15383

Merged
merged 2 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/15383.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
command: do not report listener and storage types as key not found warnings
```
6 changes: 6 additions & 0 deletions command/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ func ParseConfig(d, source string) (*Config, error) {
if err := ParseStorage(result, o, "storage"); err != nil {
return nil, fmt.Errorf("error parsing 'storage': %w", err)
}
result.found(result.Storage.Type, result.Storage.Type)
} else {
delete(result.UnusedKeys, "backend")
if o := list.Filter("backend"); len(o.Items) > 0 {
Expand Down Expand Up @@ -967,3 +968,8 @@ func (c *Config) Prune() {
c.Telemetry.UnusedKeys = nil
}
}

func (c *Config) found(s, k string) {
HridoyRoy marked this conversation as resolved.
Show resolved Hide resolved
delete(c.UnusedKeys, s)
c.FoundKeys = append(c.FoundKeys, k)
}
4 changes: 4 additions & 0 deletions command/server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ func TestParseSeals(t *testing.T) {
func TestUnknownFieldValidation(t *testing.T) {
testUnknownFieldValidation(t)
}

func TestUnknownFieldValidationListenerAndStorage(t *testing.T) {
testUnknownFieldValidationStorageAndListener(t)
}
10 changes: 10 additions & 0 deletions command/server/config_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,16 @@ func testUnknownFieldValidation(t *testing.T) {
}
}

func testUnknownFieldValidationStorageAndListener(t *testing.T) {
config, err := LoadConfigFile("./test-fixtures/storage-listener-config.json")
if err != nil {
t.Fatalf("err: %s", err)
}
if len(config.UnusedKeys) != 0 {
t.Fatalf("unused keys for valid config are %+v\n", config.UnusedKeys)
}
}

func testLoadConfigFile_json(t *testing.T) {
config, err := LoadConfigFile("./test-fixtures/config.hcl.json")
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions command/server/test-fixtures/storage-listener-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"api_addr": "https://localhost:8200",
"default_lease_ttl": "6h",
"disable_mlock": true,
"listener": {
"tcp": {
"address": "0.0.0.0:8200"
}
},
"log_level": "info",
"storage": {
"consul": {
"address": "127.0.0.1:8500"
}
},
"ui": true
}
1 change: 1 addition & 0 deletions internalshared/configutil/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func ParseListeners(result *SharedConfig, list *ast.ObjectList) error {
l.Type = strings.ToLower(l.Type)
switch l.Type {
case "tcp", "unix":
result.found(l.Type, l.Type)
default:
return multierror.Prefix(fmt.Errorf("unsupported listener type %q", l.Type), fmt.Sprintf("listeners.%d:", i))
}
Expand Down