How to deal with flags in Dgraph

Some ideas thrown around to see if we can decrease the number of flags in Dgraph and make things more obvious.

      --vault-addr string                Vault server's address in the form http://ip:port. (default "http://localhost:8200")
      --vault-field string               Vault kv store field whose value is the Base64 encoded encryption key. (default "enc_key")
      --vault-format string              Vault field format. raw or base64 (default "base64")
      --vault-path string                Vault kv store path. e.g. secret/data/dgraph for kv-v2, kv/dgraph for kv-v1. (default "secret/data/dgraph")
      --vault-roleid-file string         File containing Vault role-id used for approle auth.
      --vault-secretid-file string       File containing Vault secret-id used for approle auth.

--graphql string
--tls string
--vault string    This flag can be used to configure Dgraph's integration with Vault. It supports these options:
      - addr: http://localhost:8200 ;
      - field: enc_key;
      - format: base64;
      - path: secret/data/dgraph;
      - roleid-file: <filepath>;
      - secretid-file: <filepath>;
      - field: a,b,c;
      You don't need double quotes. Each option is separated by a semicolon. Perhaps single quotes if needed.

dgraph alpha --collector string "jaeger.addr: <addr>; datadog.addr: <addr>; ... something else"
dgraph alpha --vault="addr: http://localhost:8200; field: enc_key; format: base64"

// PostingListCache,PstoreBlockCache,PstoreIndexCache,WAL). (default "0,65,35,0")

--cache-posting = 0.10
--cache-block = 0.55
--cache-index = 0.25
--cache-wal = 0.10

dgraph alpha --cache-block=0.65 --cache-index=0.35 # --cache-wal=0.0 --cache-posting=0.0

dgraph alpha --cache "size: 2G; block: 0.65; index: 0.35"

dgraph alpha --cache "size: 2 MB; block: 0.65; index: 0.35" // OK
dgraph alpha --cache "size: 2MB; ......................"
             --cache "block: 0.65;"

CC: @dmai, @ajeet

first , how about load flags from config file ?

dgraph alpha -c config.yml  


dgraph alpha -c config.json 

then overwrite it with command line input --k1.c1.v=abc and environment

dgraph alpha -c config.json --cache.block=0.8 


cache_block=0.9 dgraph alpha -c config.json 

If the config is too long, just put it into one file.
and then they can share most config info and make it much easier and simple to setup a cluster.

and also add a sub-command

dgraph config > sample.yaml

It output a sample config with all default settings and help documents as comment for each settings elements.

His proposal is another. It is to condense configs into a single flag per category of the flags itself.
Loading from the config file won’t be different.


--vault = All about Vault
--collector = All about Jaeger
--cache = All about cache configs

This should come from Viber\Cobra lib. But I think it is already possible.

Not sure, dumping flags would make the user’s head boil. Several configs aren’t necessarily needed to use. The user would freeze thinking that he has to understand the whole thing to get up and running.


Oh, sorry, I must misunderstand something.

I just want to pass all my necessary parameters in one line.
neither --vault = All about Vault nor --vault-key1=v1 --vault-key2=v2 can make it short.
If it support load it from config file,
then I can just start it with dgraph alpha -c config.yml

In the config file,we can support all format we like.

vault {
  key1: val1
  key2: val2


vault.key1 = val1
vault.key2 = val2



If I have a config file named sample.yml like this

    # list of Dgraph zero addresses of the form IP_ADDRESS:PORT. (default "localhost:5080")
       - localhost:5080
       - zero1:5080
   #port_offset int                  Value added to all listening port numbers. [Internal=7080, HTTP=8080, Grpc=9080]
   #      it is suggest to pass from command-line when you setup your alpha cluster
   #      dgraph alpha -c config.yml --alpha.port_offset=1  
       # grpc:9080
       # http: 8080
       # internal: 7080
       offset: 0
       # string Vault server's address in the form http://ip:port. (default "http://localhost:8200")
       addr: "http://localhost:8200"
       # Vault kv store field whose value is the Base64 encoded encryption key. (default "enc_key")
       field:  "enc_key"

The comment for each field makes it more clear .
The struct like

      addr: v1
      field: v2

is more obvious than --vault.addr=v1 or --vault= addr:v1; field:v2;

I don’t like have too many command-line flags in one command. you can’t edit it as simple as in your editor.
If it longer than one line, I often make a shell script to run it.

dgraph alpha command has almost 60 flags.
I don’t need to care it now for the number is not too big. However, if it keep growing, it matters.

@BlankRain Config files are already supported for Dgraph commands using the --config option. e.g.,

dgraph alpha --config config.yaml


DGRAPH_ALPHA_CONFIG=config.yaml dgraph alpha

The precedence rules for applying a config value follow the ordering from Viper:

  1. Flags
  2. Environment variables
  3. Config file.