Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimirtool config: Add more retained old defaults #1762

Merged
merged 2 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

### Mimirtool

* [BUGFIX] `config convert`: Retain Cortex defaults for `blocks_storage.backend`, `ruler_storage.backend`, and `alertmanager_storage.backend`. #1626
* [BUGFIX] `config convert`: Retain Cortex defaults for `blocks_storage.backend`, `ruler_storage.backend`, `alertmanager_storage.backend`, `auth.type`, `activity_tracker.filepath`, `alertmanager.data_dir`, `blocks_storage.filesystem.dir`, `compactor.data_dir`, `ruler.rule_path`, `ruler_storage.filesystem.dir`, and `graphite.querier.schemas.backend`. #1626 #1762

### Tools

Expand Down
19 changes: 14 additions & 5 deletions docs/sources/operators-guide/tools/mimirtool.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,20 @@ It supports converting both CLI flags and [YAML configuration files]({{< relref
`mimirtool config convert` helps you migrate from Cortex to Grafana Mimir. There are changes to the default values of
some configuration parameters in Mimir v2.0.0 that you might not want to use as part of this migration:

- `blocks_storage.backend` - Cortex default is `s3`, Mimir default is `filesystem`
- `ruler_storage.backend` - Cortex default is `s3`, Mimir default is `filesystem`
- `alertmanager_storage.backend` - Cortex default is `s3`, Mimir default is `filesystem`
- `server.http_listen_port` - Cortex default is `80`, Mimir default is `8080`
- (GEM only) `auth.type` - GEM 1.x default is `trust`, 2.x default is `enterprise`
| Parameter | Cortex/GEM 1.7 default | Mimir/GEM 2.0 default |
| --------------------------------------------- | ------------------------ | ------------------------ |
| `blocks_storage.backend` | `s3` | `filesystem` |
| `ruler_storage.backend` | `s3` | `filesystem` |
| `alertmanager_storage.backend` | `s3` | `filesystem` |
| `server.http_listen_port` | `80` | `8080` |
| `activity_tracker.filepath` | `./active-query-tracker` | `./metrics-activity.log` |
| `alertmanager.data_dir` | `data/` | `./data-alertmanager/` |
| `blocks_storage.filesystem.dir` | `<empty>` | `blocks` |
| `compactor.data_dir` | `./data` | `./data-compactor/` |
| `ruler.rule_path` | `/rules` | `./data-ruler/` |
| `ruler_storage.filesystem.dir` | `<empty>` | `ruler` |
| (GEM only) `auth.type` | `trust` | `enterprise` |
| (GEM only) `graphite.querier.schemas.backend` | `s3` | `filesystem` |

For these parameters `mimirtool config convert` will output the Cortex default value even when the configuration parameter is not explicitly set in the input
configuration. If in the input configuration you explicitly set the Cortex default value, and you have provided
Expand Down
43 changes: 18 additions & 25 deletions pkg/mimirtool/config/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ type conversionInput struct {
dontLoadCommonOpts bool
}

func (in *conversionInput) loadCommonOpts(t *testing.T, yamlFile, flagsFile string) (commonYAML []byte, commonFlags []string) {
func (in *conversionInput) loadCommonOpts(t *testing.T, oldYAMLFile, newYAMLFile, oldFlagsFile, newFlagsFile string) (newCommonYAML []byte, newCommonFlags []string) {
if in.dontLoadCommonOpts {
return nil, nil
}
if in.yaml == nil {
in.yaml = loadFile(t, yamlFile)
commonYAML = in.yaml
in.yaml = loadFile(t, oldYAMLFile)
newCommonYAML = loadFile(t, newYAMLFile)
}
if in.flags == nil {
in.flags = loadFlags(t, flagsFile)
commonFlags = in.flags
in.flags = loadFlags(t, oldFlagsFile)
newCommonFlags = loadFlags(t, newFlagsFile)
}

return
Expand All @@ -46,7 +46,7 @@ func testConvertGEM(t *testing.T, tc conversionInput, test func(t *testing.T, ou
t.Run("gem170->gem200", func(t *testing.T) {
t.Parallel()

expectedCommonYAML, expectedCommonFlags := tc.loadCommonOpts(t, "testdata/gem/common-options-old.yaml", "testdata/gem/common-flags-old.txt")
expectedCommonYAML, expectedCommonFlags := tc.loadCommonOpts(t, "testdata/gem/common-options-old.yaml", "testdata/gem/common-options-new.yaml", "testdata/gem/common-flags-old.txt", "testdata/gem/common-flags-new.txt")
outYAML, outFlags, notices, err := Convert(tc.yaml, tc.flags, GEM170ToGEM200Mapper(), DefaultGEM170Config, DefaultGEM200COnfig, tc.useNewDefaults, tc.outputDefaults)

if expectedCommonYAML != nil {
Expand All @@ -66,7 +66,7 @@ func testConvertCortex(t *testing.T, tc conversionInput, test func(t *testing.T,
t.Run("cortex->mimir", func(t *testing.T) {
t.Parallel()

expectedCommonYAML, expectedCommonFlags := tc.loadCommonOpts(t, "testdata/common-options.yaml", "testdata/common-flags.txt")
expectedCommonYAML, expectedCommonFlags := tc.loadCommonOpts(t, "testdata/common-options-old.yaml", "testdata/common-options-new.yaml", "testdata/common-flags-old.txt", "testdata/common-flags-new.txt")
outYAML, outFlags, notices, err := Convert(tc.yaml, tc.flags, CortexToMimirMapper(), DefaultCortexConfig, DefaultMimirConfig, tc.useNewDefaults, tc.outputDefaults)

if expectedCommonYAML != nil {
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestConvert_Cortex(t *testing.T) {
inFile: "testdata/noop-old.yaml",
inFlagsFile: "testdata/flags-precedence-old.flags.txt",
outFlagsFile: "testdata/flags-precedence-new.flags.txt",
outFile: "testdata/common-options.yaml",
outFile: "testdata/common-options-new.yaml",
skipGEMTest: true, // no need to test this in GEM too; plus, output for GEM also includes GEM common opts
},
{
Expand Down Expand Up @@ -257,23 +257,23 @@ func TestConvert_Cortex(t *testing.T) {
skipGEMTest: true,
dontAddCommonOpts: true, // The common opts are in the outFile. That's the same reason why this test case doesn't work for GEM
inFile: "testdata/empty.yaml",
outFile: "testdata/old-defaults-retained-new.yaml",
outFile: "testdata/common-options-new.yaml",
},
{
name: "values where the old default should be retained are retained even with useNewDefaults=true",
skipGEMTest: true,
dontAddCommonOpts: true, // The common opts are in the outFile. That's the same reason why this test case doesn't work for GEM
useNewDefaults: true,
inFile: "testdata/old-defaults-retained-old.yaml",
outFile: "testdata/old-defaults-retained-new.yaml",
inFile: "testdata/common-options-old.yaml",
outFile: "testdata/common-options-new.yaml",
},
{
name: "values where the old default should be retained are retained with useNewDefaults=false",
skipGEMTest: true,
dontAddCommonOpts: true, // The common opts are in the outFile. That's the same reason why this test case doesn't work for GEM
useNewDefaults: true,
inFile: "testdata/old-defaults-retained-old.yaml",
outFile: "testdata/old-defaults-retained-new.yaml",
inFile: "testdata/common-options-old.yaml",
outFile: "testdata/common-options-new.yaml",
},
{
name: "values where the old default should be retained but are with random values are retained with useNewDefaults=false",
Expand Down Expand Up @@ -353,21 +353,21 @@ func TestConvert_GEM(t *testing.T) {
name: "values where the old default should be retained are printed even when implicitly using the old default",
dontAddCommonOpts: true, // The common opts are in the outFile.
inFile: "testdata/empty.yaml",
outFile: "testdata/gem/old-defaults-retained-new.yaml",
outFile: "testdata/gem/common-options-new.yaml",
},
{
name: "values where the old default should be retained are retained even with useNewDefaults=true",
dontAddCommonOpts: true, // The common opts are in the outFile.
useNewDefaults: true,
inFile: "testdata/gem/old-defaults-retained-old.yaml",
outFile: "testdata/gem/old-defaults-retained-new.yaml",
inFile: "testdata/gem/common-options-old.yaml",
outFile: "testdata/gem/common-options-new.yaml",
},
{
name: "values where the old default should be retained are retained with useNewDefaults=false",
dontAddCommonOpts: true, // The common opts are in the outFile.
useNewDefaults: true,
inFile: "testdata/gem/old-defaults-retained-old.yaml",
outFile: "testdata/gem/old-defaults-retained-new.yaml",
inFile: "testdata/gem/common-options-old.yaml",
outFile: "testdata/gem/common-options-new.yaml",
},
{
name: "values where the old default should be retained but are with random values are retained with useNewDefaults=false",
Expand Down Expand Up @@ -500,8 +500,6 @@ func TestReportDeletedFlags(t *testing.T) {
}

var changedCortexDefaults = []ChangedDefault{
{Path: "activity_tracker.filepath", OldDefault: "./active-query-tracker", NewDefault: "./metrics-activity.log"},
{Path: "alertmanager.data_dir", OldDefault: "data/", NewDefault: "./data-alertmanager/"},
{Path: "alertmanager.enable_api", OldDefault: "false", NewDefault: "true"},
{Path: "alertmanager.external_url", OldDefault: "", NewDefault: "http://localhost:8080/alertmanager"},
{Path: "alertmanager.sharding_ring.instance_interface_names", OldDefault: "eth0,en0", NewDefault: "<nil>"},
Expand All @@ -524,12 +522,10 @@ var changedCortexDefaults = []ChangedDefault{
{Path: "blocks_storage.bucket_store.metadata_cache.memcached.max_idle_connections", OldDefault: "16", NewDefault: "100"},
{Path: "blocks_storage.bucket_store.metadata_cache.memcached.timeout", OldDefault: "100ms", NewDefault: "200ms"},
{Path: "blocks_storage.bucket_store.sync_dir", OldDefault: "tsdb-sync", NewDefault: "./tsdb-sync/"},
{Path: "blocks_storage.filesystem.dir", OldDefault: "", NewDefault: "blocks"},
{Path: "blocks_storage.tsdb.close_idle_tsdb_timeout", OldDefault: "0s", NewDefault: "13h0m0s"},
{Path: "blocks_storage.tsdb.dir", OldDefault: "tsdb", NewDefault: "./tsdb/"},
{Path: "blocks_storage.tsdb.retention_period", OldDefault: "6h0m0s", NewDefault: "24h0m0s"},
{Path: "compactor.block_sync_concurrency", OldDefault: "20", NewDefault: "8"},
{Path: "compactor.data_dir", OldDefault: "./data", NewDefault: "./data-compactor/"},
{Path: "compactor.sharding_ring.instance_interface_names", OldDefault: "eth0,en0", NewDefault: "<nil>"},
{Path: "compactor.sharding_ring.kvstore.store", OldDefault: "consul", NewDefault: "memberlist"},
{Path: "compactor.sharding_ring.wait_stability_min_duration", OldDefault: "1m0s", NewDefault: "0s"},
Expand Down Expand Up @@ -570,9 +566,7 @@ var changedCortexDefaults = []ChangedDefault{
{Path: "ruler.enable_api", OldDefault: "false", NewDefault: "true"},
{Path: "ruler.ring.instance_interface_names", OldDefault: "eth0,en0", NewDefault: "<nil>"},
{Path: "ruler.ring.kvstore.store", OldDefault: "consul", NewDefault: "memberlist"},
{Path: "ruler.rule_path", OldDefault: "/rules", NewDefault: "./data-ruler/"},
{Path: "ruler.ruler_client.max_send_msg_size", OldDefault: "16777216", NewDefault: "104857600"},
{Path: "ruler_storage.filesystem.dir", OldDefault: "", NewDefault: "ruler"},
{Path: "store_gateway.sharding_ring.instance_interface_names", OldDefault: "eth0,en0", NewDefault: "<nil>"},
{Path: "store_gateway.sharding_ring.kvstore.store", OldDefault: "consul", NewDefault: "memberlist"},
{Path: "store_gateway.sharding_ring.wait_stability_min_duration", OldDefault: "1m0s", NewDefault: "0s"},
Expand Down Expand Up @@ -619,7 +613,6 @@ func TestChangedGEMDefaults(t *testing.T) {
{Path: "graphite.querier.metric_name_cache.memcached.max_idle_connections", OldDefault: "16", NewDefault: "100"},
{Path: "graphite.querier.metric_name_cache.memcached.max_item_size", OldDefault: "0", NewDefault: "1048576"},
{Path: "graphite.querier.metric_name_cache.memcached.timeout", OldDefault: "100ms", NewDefault: "200ms"},
{Path: "graphite.querier.schemas.backend", OldDefault: "s3", NewDefault: "filesystem"},
{Path: "instrumentation.enabled", OldDefault: "false", NewDefault: "true"},
{Path: "limits.compactor_split_groups", OldDefault: "4", NewDefault: "1"},
{Path: "limits.compactor_tenant_shard_size", OldDefault: "1", NewDefault: "0"},
Expand Down
24 changes: 20 additions & 4 deletions pkg/mimirtool/config/cortex.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ func CortexToMimirMapper() Mapper {
setOldDefaultExplicitly("blocks_storage.backend"),
setOldDefaultExplicitly("ruler_storage.backend"),
setOldDefaultExplicitly("alertmanager_storage.backend"),
// Prevent activity_tracker.filepath from being updates with a new default (./metrics-activity.log) implicitly and always set it to the old default (./active-query-tracker)
setOldDefaultWithNewPathExplicitly("querier.active_query_tracker_dir", "activity_tracker.filepath"),
// Prevent alertmanager.data_dir from being updates with a new default (./data-alertmanager/) implicitly and always set it to the old default (data/)
setOldDefaultExplicitly("alertmanager.data_dir"),
// Prevent blocks_storage.filesystem.dir from being updates with a new default (blocks) implicitly and always set it to the old default ("")
setOldDefaultExplicitly("blocks_storage.filesystem.dir"),
// Prevent compactor.data_dir from being updates with a new default (./data-compactor/) implicitly and always set it to the old default (./data)
setOldDefaultExplicitly("compactor.data_dir"),
// Prevent ruler.rule_path from being updates with a new default (./data-ruler/) implicitly and always set it to the old default (/rules)
setOldDefaultExplicitly("ruler.rule_path"),
// Prevent ruler_storage.filesystem.dir from being updates with a new default (ruler) implicitly and always set it to the old default ("")
setOldDefaultExplicitly("ruler_storage.filesystem.dir"),
}
}

Expand Down Expand Up @@ -521,18 +533,22 @@ func mapInstanceInterfaceNames(ifaceNames map[string]string) Mapper {
}

func setOldDefaultExplicitly(path string) Mapper {
return setOldDefaultWithNewPathExplicitly(path, path)
}

func setOldDefaultWithNewPathExplicitly(oldPath, newPath string) Mapper {
return MapperFunc(func(source, target Parameters) error {
v, err := source.GetValue(path)
v, err := source.GetValue(oldPath)
if err != nil {
return err
}

if v.IsUnset() || !differentFromDefault(source, path) {
err = target.SetValue(path, source.MustGetDefaultValue(path))
if v.IsUnset() || !differentFromDefault(source, oldPath) {
err = target.SetValue(newPath, source.MustGetDefaultValue(oldPath))
// We set the default again after the value itself because when prepareSourceDefaults is mapping defaults
// `SetValue` actually sets the default value.
// Also set the source default to Nil, so that when updating defaults this parameter isn't affected
err2 := target.SetDefaultValue(path, Nil)
err2 := target.SetDefaultValue(newPath, Nil)
return multierror.New(err, err2).Err()
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/mimirtool/config/gem.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ func GEM170ToGEM200Mapper() Mapper {
setOldDefaultExplicitly("blocks_storage.backend"),
setOldDefaultExplicitly("ruler_storage.backend"),
setOldDefaultExplicitly("alertmanager_storage.backend"),
// Prevent activity_tracker.filepath from being updates with a new default (./metrics-activity.log) implicitly and always set it to the old default (./active-query-tracker)
setOldDefaultWithNewPathExplicitly("querier.active_query_tracker_dir", "activity_tracker.filepath"),
// Prevent alertmanager.data_dir from being updates with a new default (./data-alertmanager/) implicitly and always set it to the old default (data/)
setOldDefaultExplicitly("alertmanager.data_dir"),
// Prevent blocks_storage.filesystem.dir from being updates with a new default (blocks) implicitly and always set it to the old default ("")
setOldDefaultExplicitly("blocks_storage.filesystem.dir"),
// Prevent compactor.data_dir from being updates with a new default (./data-compactor/) implicitly and always set it to the old default (./data)
setOldDefaultExplicitly("compactor.data_dir"),
// Prevent ruler.rule_path from being updates with a new default (./data-ruler/) implicitly and always set it to the old default (/rules)
setOldDefaultExplicitly("ruler.rule_path"),
// Prevent ruler_storage.filesystem.dir from being updates with a new default (ruler) implicitly and always set it to the old default ("")
setOldDefaultExplicitly("ruler_storage.filesystem.dir"),
// Prevent graphite.querier.schemas.backend from being updated with a new default (filesystem) implicitly and always set it to the old default (s3)
setOldDefaultExplicitly("graphite.querier.schemas.backend"),
}
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/mimirtool/config/testdata/common-flags-new.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-server.http-listen-port=80
-blocks-storage.backend=s3
-ruler-storage.backend=s3
-alertmanager-storage.backend=s3
-activity-tracker.filepath=./active-query-tracker
-alertmanager.storage.path=data/
-blocks-storage.filesystem.dir=
-compactor.data-dir=./data
-ruler.rule-path=/rules
-ruler-storage.filesystem.dir=
10 changes: 10 additions & 0 deletions pkg/mimirtool/config/testdata/common-flags-old.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-server.http-listen-port=80
-blocks-storage.backend=s3
-ruler-storage.backend=s3
-alertmanager-storage.backend=s3
-querier.active-query-tracker-dir=./active-query-tracker
-alertmanager.storage.path=data/
-blocks-storage.filesystem.dir=
-compactor.data-dir=./data
-ruler.rule-path=/rules
-ruler-storage.filesystem.dir=
4 changes: 0 additions & 4 deletions pkg/mimirtool/config/testdata/common-flags.txt

This file was deleted.

27 changes: 27 additions & 0 deletions pkg/mimirtool/config/testdata/common-options-new.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
server:
http_listen_port: 80

blocks_storage:
backend: s3
filesystem:
dir: ''

ruler_storage:
backend: s3
filesystem:
dir: ''

alertmanager_storage:
backend: s3

activity_tracker:
filepath: ./active-query-tracker

alertmanager:
data_dir: data/

compactor:
data_dir: ./data

ruler:
rule_path: /rules
27 changes: 27 additions & 0 deletions pkg/mimirtool/config/testdata/common-options-old.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
server:
http_listen_port: 80

blocks_storage:
backend: s3
filesystem:
dir: ''

ruler_storage:
backend: s3
filesystem:
dir: ''

alertmanager_storage:
backend: s3

querier:
active_query_tracker_dir: ./active-query-tracker

alertmanager:
data_dir: data/

compactor:
data_dir: ./data

ruler:
rule_path: /rules
11 changes: 0 additions & 11 deletions pkg/mimirtool/config/testdata/common-options.yaml

This file was deleted.

9 changes: 8 additions & 1 deletion pkg/mimirtool/config/testdata/gem/common-flags-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
-auth.type=trust
-blocks-storage.backend=s3
-ruler-storage.backend=s3
-alertmanager-storage.backend=s3
-alertmanager-storage.backend=s3
-graphite.querier.schemas.backend=s3
-activity-tracker.filepath=./active-query-tracker
-alertmanager.storage.path=data/
-blocks-storage.filesystem.dir=
-compactor.data-dir=./data
-ruler.rule-path=/rules
-ruler-storage.filesystem.dir=
9 changes: 8 additions & 1 deletion pkg/mimirtool/config/testdata/gem/common-flags-old.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
-auth.type=trust
-blocks-storage.backend=s3
-ruler-storage.backend=s3
-alertmanager-storage.backend=s3
-alertmanager-storage.backend=s3
-graphite.querier.schemas.backend=s3
-querier.active-query-tracker-dir=./active-query-tracker
-alertmanager.storage.path=data/
-blocks-storage.filesystem.dir=
-compactor.data-dir=./data
-ruler.rule-path=/rules
-ruler-storage.filesystem.dir=
Loading