-
Notifications
You must be signed in to change notification settings - Fork 168
Allow config options in file as yaml mappings #1737
Conversation
deb1c6b
to
c5afb5f
Compare
ChunkInterval DayDuration `mapstructure:"default_chunk_interval" yaml:"default_chunk_interval"` | ||
Compression *bool `mapstructure:"compress_data" yaml:"compress_data"` // Using pointer to check if the the value was set. | ||
HALeaseRefresh DayDuration `mapstructure:"ha_lease_refresh" yaml:"ha_lease_refresh"` | ||
HALeaseTimeout DayDuration `mapstructure:"ha_lease_timeout" yaml:"ha_lease_timeout"` | ||
RetentionPeriod DayDuration `mapstructure:"default_retention_period" yaml:"default_retention_period"` | ||
} | ||
|
||
// Traces contains dataset configuration options for traces data. | ||
type Traces struct { | ||
RetentionPeriod DayDuration `yaml:"default_retention_period"` | ||
RetentionPeriod DayDuration `mapstructure:"default_retention_period" yaml:"default_retention_period"` |
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.
These can be exposed as command line flags, is there a reason why they're not?
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.
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.
These can be exposed as command line flags, is there a reason why they're not?
I think we see dataset config as a place for those flags that are purely related to DB (hence dataset), which is why these are not kept as flags.
803c9cc
to
6829137
Compare
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.
Overall LGTM. I want to ask @antekresic to review as well.
6829137
to
b7c40eb
Compare
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.
Looks good overall, some minor tweak suggestions and a test case to add.
f2ebbaa
to
57662ae
Compare
cc @paulfantom this is the PR to allow a yaml mapping instead of a string for the dataset config |
e040fc6
to
b5dca9a
Compare
Replaces the `ff` package with a custom implementation that uses Viper to parse the config file and sets the values for the `flag.Flag`s. By design the ff package doesn't allow flag subsets or nested maps inside the config yaml and all config options must be explicitely defined as `flag.Flag`. This limits the ability to specify more dynamic config options like lists or maps of user defined rules (Ex: metric rollups). Viper provides the flexibility we require for parsing the config file, and unmarshaling directly into more complex datastructures. To define how to unmarshal a subtree of the configuration into a datastructure via unmarshalRule. An unmarshalRule for the dataset config was added as: ``` withUnmarshalRules( []unmarshalRule{{"startup.dataset", &dataset.Config}} ) ``` Given a config file that contains the subtree: ``` startup: dataset: metrics: ... traces: ... ``` The subtree `startup.dataset` will be unmarshal into `&dataset.Config` by Viper using the github.com/mitchellh/mapstructure package. Viper can access a nested field by passing a `.` delimited path of keys. This change also allows us to format our configuration files to use yaml mappings instead of long key names with `.`, thus maintaining backwards compatibility: ``` web.listen-address: localhost:9201 web.auth.password: my-password web.auth.username: promscale ``` Can be rewritten as: ``` web: listen-address: localhost:9201 auth: password: my-password username: promscale ```
b5dca9a
to
ed4d8da
Compare
ed4d8da
to
0156836
Compare
Replaces the
ff
package with a custom implementation that uses Viper to parse the config file and sets the values for theflag.Flag
s.By design the ff package doesn't allow flag subsets or nested maps inside the config yaml and all config options must be explicitely defined as
flag.Flag
. This limits the ability to specify more dynamic config options like lists or maps of user defined rules (Ex: metric rollups).Viper provides the flexibility we require for parsing the config file, and unmarshaling directly into more complex datastructures. To define how to unmarshal a subtree of the configuration into a datastructure via unmarshalRule:
Given the the config file contains the subtree:
Viper can access a nested field by passing a
.
delimited path of keys. In this scenario, the subtreestartup.dataset
will be unmarshal into&dataset.Config
by Viper using the github.com/mitchellh/mapstructure package.This change also allows us to format our configuration files to use yaml mappings instead of long key names with
.
, thus maintaining backwards compatibility:Can be rewritten as:
Merge requirements
Please take into account the following non-code changes that you may need to make with your PR: