Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Add deprecation warning for startup.dataset.config
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrodnm committed Nov 15, 2022
1 parent adcdc49 commit 0156836
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 10 deletions.
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
startup.dataset:
metrics:
default_chunk_interval: 1d
23 changes: 14 additions & 9 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Promscale accepts configuration via command-line flags, environment variables, or via a `config.yml` file. The basis for environment variable and file-based configuration are the command-line flags.

The only exception is the `startup.dataset` configuration options which can
only be set in the `config.yml` file. For more information on the dataset
config refer to [its documentation](dataset.md).

Should the same configuration parameter be provided by multiple methods, the precedence rules (from highest to lowest) are as follows:
- CLI flag value
- environment variable value
Expand Down Expand Up @@ -140,15 +144,16 @@ The following subsections cover all CLI flags which promscale supports. You can

### Startup process flags

| Flag | Type | Default | Description |
|---------------------------------------|:-------:|:-------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| startup.dataset.config | string | "" (disabled) | Dataset configuration in YAML format for Promscale. It is used for setting various dataset configuration like default metric chunk interval. For more information, please consult the following resources: [dataset](dataset.md) |
| startup.install-extensions | boolean | true | Install TimescaleDB & Promscale extensions. |
| startup.only | boolean | false | Only run startup configuration with Promscale (i.e. migrate) and exit. Can be used to run promscale as an init container for HA setups. |
| startup.skip-migrate | boolean | false | Skip migrating Promscale SQL schema to latest version on startup. |
| startup.upgrade-extensions | boolean | true | Upgrades TimescaleDB & Promscale extensions. |
| startup.upgrade-prerelease-extensions | boolean | false | Upgrades to pre-release TimescaleDB, Promscale extensions. |
| startup.use-schema-version-lease | boolean | true | Use schema version lease to prevent race conditions during migration. |
| Flag | Type | Default | Description |
|---------------------------------------|:-------:|:-------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| startup.dataset.config | string | "" (disabled) | **DEPRECATION NOTICE**: *this flag is going to be removed in a future version, please follow the [upgrade guide](dataset.md#upgrading-from-startupdatasetconfig)*. Dataset configuration in YAML format for Promscale. It is used for setting various dataset configuration like default metric chunk interval. For more information, please consult the following resources: [dataset](dataset.md) |
| startup.dataset *(config.yaml only)* | yaml | "" (disabled) | Dataset configuration in YAML format for Promscale. It is used for setting various dataset configuration like default metric chunk interval. For more information, please consult the following resources: [dataset](dataset.md) |
| startup.install-extensions | boolean | true | Install TimescaleDB & Promscale extensions. |
| startup.only | boolean | false | Only run startup configuration with Promscale (i.e. migrate) and exit. Can be used to run promscale as an init container for HA setups. |
| startup.skip-migrate | boolean | false | Skip migrating Promscale SQL schema to latest version on startup. |
| startup.upgrade-extensions | boolean | true | Upgrades TimescaleDB & Promscale extensions. |
| startup.upgrade-prerelease-extensions | boolean | false | Upgrades to pre-release TimescaleDB, Promscale extensions. |
| startup.use-schema-version-lease | boolean | true | Use schema version lease to prevent race conditions during migration. |

### Web server flags

Expand Down
36 changes: 36 additions & 0 deletions docs/dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,39 @@ Note: Any configuration omitted from the configuration structure will be set to
| metrics | ha_lease_timeout | duration | 1m | High availability lease timeout duration, period after which the lease will be lost in case it wasn't refreshed |
| metrics | default_retention_period | duration | 90d | Retention period for metric data, all data older than this period will be dropped |
| traces | default_retention_period | duration | 90d | Retention period for tracing data, all data older than this period will be dropped |
## Upgrading from startup.dataset.config
In previous releases the dataset config was defined as a YAML string. This was
so that it could be used not only in the config file, but also as a command
line flag or environment variable.
In config file:
```yaml
startup.dataset.config: |
metrics:
default_chunk_interval: 8h
```
As command line flag:
```bash
./promscale -startup.dataset.config="metrics:\n default_chunk_interval: 8h"
```
This was deprecated in favor of `startup.dataset` which is a YAML mapping node
instead of a string:

```yaml
# Deprecated config
startup.dataset.config: |
metrics:
default_chunk_interval: 8h
# Newer dataset config as YAML mapping
startup:
dataset:
metrics:
default_chunk_interval: 8h
```
3 changes: 3 additions & 0 deletions pkg/runner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ func CreateClient(r prometheus.Registerer, cfg *Config) (*pgclient.Client, error
}

if (cfg.DatasetCfg != dataset.Config{}) {
if cfg.DatasetConfig != "" {
log.Warn("msg", "Ignoring `startup.dataset.config` in favor of the newer `startup.dataset` config option since both were set.")
}
err = cfg.DatasetCfg.Apply(conn)
} else if cfg.DatasetConfig != "" {
err = applyDatasetConfig(conn, cfg.DatasetConfig)
Expand Down
25 changes: 24 additions & 1 deletion pkg/runner/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ var (
removedEnvVarError = fmt.Errorf("using removed environmental variables, please update your configuration to new variable names to proceed")
removedFlagsError = fmt.Errorf("using removed flags, please update to new flag names to proceed")
removedConfigVarError = fmt.Errorf("using removed configuration file variables, please update to new variable names to proceed")
flagAliases = map[string]string{
toBeDeprecated = map[string]string{
"startup.dataset.config": "The config option `startup.dataset.config` and environment variable PROMETHEUS_STARTUP_DATASET_CONFIG are going to be deprecated in an upcoming release. Update your config.yaml as in https://github.com/timescale/promscale/blob/master/docs/dataset.md to use the new dataset config",
}
flagAliases = map[string]string{
"auth.tls-cert-file": "tls-cert-file",
"auth.tls-key-file": "tls-key-file",
"cache.memory-target": "memory-target",
Expand Down Expand Up @@ -185,6 +188,8 @@ func ParseFlags(cfg *Config, args []string) (*Config, error) {
return nil, fmt.Errorf("configuration error when parsing flags: %w", err)
}

handleToBeDeprecated(fs, toBeDeprecated)

// Checking if TLS files are not both set or both empty.
if (cfg.TLSCertFile != "") != (cfg.TLSKeyFile != "") {
return nil, fmt.Errorf("both TLS Ceriticate File and TLS Key File need to be provided for a valid TLS configuration")
Expand Down Expand Up @@ -419,3 +424,21 @@ argloop:
}
return result
}

func handleToBeDeprecated(fs *flag.FlagSet, toBeDeprecated map[string]string) {

if len(toBeDeprecated) == 0 {
return
}

setFlags := getFlagsThatHaveBeenSet(fs)

for key, message := range toBeDeprecated {
_, ok := setFlags[key]
if !ok {
continue
}

log.Warn("msg", message)
}
}

0 comments on commit 0156836

Please sign in to comment.