Skip to content

Warning for nonsense variables in config#7181

Merged
stephkyou merged 5 commits intomainfrom
steph/config
Dec 19, 2023
Merged

Warning for nonsense variables in config#7181
stephkyou merged 5 commits intomainfrom
steph/config

Conversation

@stephkyou
Copy link
Copy Markdown
Contributor

Prints a warning if any nonsense variables are found in global or local config files whenever any CLI command is run. Also restricts users from adding any nonsense variables with dolt config --add or dolt config --set.

Resolves: #7165

Copy link
Copy Markdown
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a couple minor suggestions.

Comment on lines +40 to +56
var ConfigOptions = map[string]string{
config.UserEmailKey: "",
config.UserNameKey: "",
config.UserCreds: "",
config.DoltEditor: "",
config.InitBranchName: "",
config.RemotesApiHostKey: "",
config.RemotesApiHostPortKey: "",
config.AddCredsUrlKey: "",
config.DoltLabInsecureKey: "",
config.MetricsDisabled: "",
config.MetricsHost: "",
config.MetricsPort: "",
config.MetricsInsecure: "",
config.PushAutoSetupRemote: "",
config.ProfileKey: "",
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since anytime a new config value constant is added it'll need to be added to this map (i.e. high coupling), it's a good hint that these two pieces of code might benefit from being very close together. Try moving this map into the same file as where the config constants are defined.

There's another common Go trick for maps where you don't care about the values... you'll often see them written as:

var Foo = map[string]struct{}{
    "bar": {},
}

The advantage to that form is that it's unambiguous to future code readers (once you know this pattern at least) that the value of the map is ignored. If you use bool or string, then future code readers may think that the value has some meaning. It is also slightly more efficient for the runtime to store these, because there's an optimization where Go knows empty structs don't need to be allocated anywhere, as opposed to a bool or a string, which does require allocation, even if they are empty/false. It's a small efficiency gain, but worth knowing about, especially since you'll see this pattern fairly often.

}

globalConfig.Iter(func(name, val string) (stop bool) {
if _, ok := commands.ConfigOptions[name]; !ok && !strings.HasPrefix(name, env.SqlServerGlobalsPrefix) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) Might be worth running strings.ToLower on name here and for the local config section below. It does look like the current code always lowercases the names, but older versions may not have, plus people could always manually edit the config file.

@stephkyou stephkyou requested a review from fulghum December 18, 2023 23:02
@stephkyou stephkyou merged commit 2d717c6 into main Dec 19, 2023
@stephkyou stephkyou deleted the steph/config branch December 19, 2023 01:02
@github-actions
Copy link
Copy Markdown

@coffeegoddd DOLT

test_name detail row_cnt sorted mysql_time sql_mult cli_mult
batching LOAD DATA 10000 1 0.05 0.8
batching batch sql 10000 1 0.07 1.43
batching by line sql 10000 1 0.08 1.25
blob 1 blob 200000 1 0.89 3.18 3.65
blob 2 blobs 200000 1 0.87 4.17 4.78
blob no blob 200000 1 0.88 1.32 1.41
col type datetime 200000 1 0.79 1.82 2
col type varchar 200000 1 0.65 2 2.08
config width 2 cols 200000 1 0.75 1.33 1.35
config width 32 cols 200000 1 1.87 1.39 2.49
config width 8 cols 200000 1 0.96 1.83 1.63
pk type float 200000 1 0.89 1.21 1.2
pk type int 200000 1 0.75 1.31 1.37
pk type varchar 200000 1 1.53 0.99 0.96
row count 1.6mm 1600000 1 5.5 1.54 1.58
row count 400k 400000 1 1.38 1.5 1.49
row count 800k 800000 1 2.76 1.5 1.54
secondary index four index 200000 1 3.5 1.1 0.95
secondary index no secondary 200000 1 0.86 1.35 1.43
secondary index one index 200000 1 1.11 1.54 1.5
secondary index two index 200000 1 1.95 1.24 1.13
sorting shuffled 1mm 1000000 0 5.17 1.77 1.8
sorting sorted 1mm 1000000 1 5.31 1.8 1.74

@github-actions
Copy link
Copy Markdown

@coffeegoddd DOLT

name detail mean_mult
dolt_blame_basic system table 1.08
dolt_blame_commit_filter system table 2.79
dolt_commit_ancestors_commit_filter system table 0.87
dolt_commits_commit_filter system table 0.88
dolt_diff_log_join_from_commit system table 1.73
dolt_diff_log_join_to_commit system table 1.71
dolt_diff_table_from_commit_filter system table 1.1
dolt_diff_table_to_commit_filter system table 1.08
dolt_diffs_commit_filter system table 1
dolt_history_commit_filter system table 1.19
dolt_log_commit_filter system table 0.88

@github-actions
Copy link
Copy Markdown

@coffeegoddd DOLT

name add_cnt delete_cnt update_cnt latency
adds_only 60000 0 0 0.72
adds_updates_deletes 60000 60000 60000 3.75
deletes_only 0 60000 0 1.84
updates_only 0 0 60000 2.37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fail when there is nonsense in config_golbal.json

2 participants