dolthub / dolt

Dolt – Git for Data
Apache License 2.0
17.96k stars 513 forks source link

Establish configuration hierarchy. CLI args override `config.yaml` #2755

Open max-hoffman opened 2 years ago

max-hoffman commented 2 years ago

generating a new server config has a hard switch between args or a static file:

func GetServerConfig(dEnv *env.DoltEnv, apr *argparser.ArgParseResults) (ServerConfig, error) {
    if cfgFile, ok := apr.GetValue(configFileFlag); ok {
        return getYAMLServerConfig(dEnv.FS, cfgFile)
    }
    return getCommandLineServerConfig(dEnv, apr)
}

If the config file is passed and cli args aren't empty, apply the overrides to the server config.

max-hoffman commented 2 years ago

https://github.com/dolthub/dolt/issues/2753

timsehn commented 2 years ago

Right now, if you specify a config.yaml, all command line arguments to dolt sql-server are ignored.

For instance, in the server shell:

dolt_new $ cat config.yaml 
log_level: info

behavior:
  read_only: false
  autocommit: true

user:
  name: timsehn
  password: fuck

listener:
  host: localhost
  port: 3306
  max_connections: 100
  read_timeout_millis: 28800000
  write_timeout_millis: 28800000

performance:
  query_parallelism: null
dolt_new $ dolt sql-server -u root --config=config.yaml
Starting server with Config HP="localhost:3306"|T="28800000"|R="false"|L="info"
2022-08-30T16:29:30-07:00 INFO [conn 1] NewConnection {DisableClientMultiStatements=false}
2022-08-30T16:29:30-07:00 INFO [conn 1] ConnectionClosed {}
2022-08-30T16:29:38-07:00 INFO [conn 2] NewConnection {DisableClientMultiStatements=false}

Note the config.yaml has user timsehn defined and I try and establish a user root using -u root.

Now client shell:

test-unique-reorder $ mysql -h 127.0.0.1 -uroot
ERROR 1045 (28000): User not found 'root'
test-unique-reorder $ mysql -h 127.0.0.1 -utimsehn -pfuck
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.9-Vitess 

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

I can connect with timsehn but not as root.

We need to establish a configuration hierarchy and which values override and which values are additive.