diff --git a/build/ansible/roles/clickhouse/files/default-config.xml b/build/ansible/roles/clickhouse/files/default-config.xml index 4579bc7a229..ac1608b3e78 100644 --- a/build/ansible/roles/clickhouse/files/default-config.xml +++ b/build/ansible/roles/clickhouse/files/default-config.xml @@ -590,7 +590,7 @@ - users.xml + default-users.xml diff --git a/build/ansible/roles/clickhouse/files/low-memory-config.xml b/build/ansible/roles/clickhouse/files/low-memory-config.xml index 0ea4102545d..d2a950f2477 100644 --- a/build/ansible/roles/clickhouse/files/low-memory-config.xml +++ b/build/ansible/roles/clickhouse/files/low-memory-config.xml @@ -590,7 +590,7 @@ - users.xml + low-memory-users.xml diff --git a/build/ansible/roles/clickhouse/files/switch-config.sh b/build/ansible/roles/clickhouse/files/switch-config.sh index 156e1911c41..f1b536342f7 100755 --- a/build/ansible/roles/clickhouse/files/switch-config.sh +++ b/build/ansible/roles/clickhouse/files/switch-config.sh @@ -1,55 +1,7 @@ #!/bin/bash -# Usage: switch-config.sh [low|default] -# Switches /etc/clickhouse-server/config.xml +# switch-config.sh is deprecated and will be removed in a future PMM release. +# Use the PMM_CLICKHOUSE_CONFIG environment variable instead. -set -e -CONFIG_DIR="/etc/clickhouse-server" -PROFILE="$1" - -if [ -z "$PROFILE" ]; then - echo "Usage: $0 [low|default]" >&2 - exit 1 -fi - -case "$PROFILE" in - low) - CONFIG_TARGET="low-memory-config.xml" - USERS_TARGET="low-memory-users.xml" - ;; - default) - CONFIG_TARGET="default-config.xml" - USERS_TARGET="default-users.xml" - ;; - *) - echo "Usage: $0 [low|default]" >&2 - exit 1 - ;; -esac - -if [ ! -e "$CONFIG_DIR/$CONFIG_TARGET" ]; then - echo "Config profile $CONFIG_TARGET does not exist in $CONFIG_DIR." >&2 - exit 2 -fi -if [ ! -e "$CONFIG_DIR/$USERS_TARGET" ]; then - echo "Users profile $USERS_TARGET does not exist in $CONFIG_DIR." >&2 - exit 2 -fi - -echo "Stopping clickhouse..." -if ! supervisorctl stop clickhouse; then - echo "Failed to stop clickhouse!" >&2 - exit 3 -fi - -ln -sf "$CONFIG_TARGET" "$CONFIG_DIR/config.xml" -ln -sf "$USERS_TARGET" "$CONFIG_DIR/users.xml" -echo "Switched config.xml to $CONFIG_TARGET." -echo "Switched users.xml to $USERS_TARGET." - -echo "Starting clickhouse..." -if ! supervisorctl start clickhouse; then - echo "Failed to start clickhouse!" >&2 - exit 4 -fi - -exit 0 +echo "switch-config.sh is deprecated and will be removed in a future PMM release." >&2 +echo "Set PMM_CLICKHOUSE_CONFIG=default|low-memory" >&2 +exit 1 diff --git a/build/ansible/roles/supervisord/files/pmm.ini b/build/ansible/roles/supervisord/files/pmm.ini index 49ea2e4d834..d3ded8fd388 100644 --- a/build/ansible/roles/supervisord/files/pmm.ini +++ b/build/ansible/roles/supervisord/files/pmm.ini @@ -51,7 +51,7 @@ redirect_stderr = true [program:clickhouse] priority = 2 -command = /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/config.xml +command = /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/default-config.xml autorestart = true autostart = true startretries = 10 diff --git a/documentation/docs/install-pmm/install-pmm-server/deployment-options/docker/env_var.md b/documentation/docs/install-pmm/install-pmm-server/deployment-options/docker/env_var.md index 94b46cff0ed..4157168a730 100644 --- a/documentation/docs/install-pmm/install-pmm-server/deployment-options/docker/env_var.md +++ b/documentation/docs/install-pmm/install-pmm-server/deployment-options/docker/env_var.md @@ -25,6 +25,17 @@ Fine-tune data retention and collection intervals to balance monitoring detail w !!! tip "Performance impact" Higher resolution (lower values) provides more detailed metrics but increases storage requirements and system load. For high-traffic production environments, consider increasing these values. +### Built-in ClickHouse configuration +Select the configuration profile for the built-in ClickHouse instance + +| Variable | Default | Description | Example | +|----------|---------|-------------|----------| +| `PMM_CLICKHOUSE_CONFIG` | `default` | Use `low-memory` for PMM Server environments with less than 16 GB RAM. | `low-memory` | + +!!! note "low-memory config" + While this configuration attempts to optimize ClickHouse for low-memory environments, we highly recommend users to follow our configuration guide. + For details, see [ClickHouse memory issues](../../../../troubleshoot/qan_issues.md#clickhouse-memory-issues-in-low-memory-environments). + ### Feature controls Enable or disable specific PMM features: @@ -262,4 +273,4 @@ docker run \ ``` ## Related topic -[Preview environment variables](../docker/preview_env_var.md) \ No newline at end of file +[Preview environment variables](../docker/preview_env_var.md) diff --git a/documentation/docs/troubleshoot/qan_issues.md b/documentation/docs/troubleshoot/qan_issues.md index 13107fcb9c5..a15f27a1944 100644 --- a/documentation/docs/troubleshoot/qan_issues.md +++ b/documentation/docs/troubleshoot/qan_issues.md @@ -92,32 +92,17 @@ PMM includes two ClickHouse profiles: ### Switch to low-memory configuration -```bash -docker exec -it -u pmm pmm-server ./switch-config.sh low -``` +Select the profile with the `PMM_CLICKHOUSE_CONFIG` environment variable when you create the container: -To switch back: ```bash -docker exec -it -u pmm pmm-server ./switch-config.sh default +docker run -e PMM_CLICKHOUSE_CONFIG=low-memory ... percona/pmm-server:3 ``` -The script stops ClickHouse, updates the configuration, and restarts the service. - -### Persistent configuration - -If you run PMM Server with the `--rm` flag, run the switch script each time the container starts. For systemd, add to your unit file: -```ini -ExecStartPost=/usr/bin/docker exec -u pmm pmm-server ./switch-config.sh low -``` - -See [Install PMM Server with Podman](../install-pmm/install-pmm-server/deployment-options/podman/index.md) for systemd configuration examples. - !!! note "Configuration details" Both configuration files are located in `/etc/clickhouse-server/` inside the PMM Server container: - `default-config.xml`: default profile - `low-memory-config.xml`: low-memory profile - The script is available at `/etc/clickhouse-server/switch-config.sh` or `/opt/switch-config.sh`. - - When switching profiles, both `config.xml` and `users.xml` are updated to point to the selected profile. \ No newline at end of file + +The `switch-config.sh` script is deprecated and will be removed in a future PMM release; use `PMM_CLICKHOUSE_CONFIG` instead. diff --git a/managed/AGENTS.md b/managed/AGENTS.md index 3db47cf875e..957566a3cd8 100644 --- a/managed/AGENTS.md +++ b/managed/AGENTS.md @@ -150,6 +150,7 @@ PMM supports HA via **Raft consensus** (`services/ha/`): - Don't skip `make gen` after proto/model changes - Don't comment on every line — only where clarity is needed - Don't inline comments (`code // comment`) — put comments on separate lines +- Don't inline `err != nil` checks (`if err := f(); err != nil`) — assign on one line, check on the next - Don't use named return values in functions - Don't commit test binaries or artifacts - Don't create subshells in Makefiles without reason diff --git a/managed/cmd/pmm-managed-init/main.go b/managed/cmd/pmm-managed-init/main.go index ea4ed7f9042..d964adb4075 100644 --- a/managed/cmd/pmm-managed-init/main.go +++ b/managed/cmd/pmm-managed-init/main.go @@ -22,7 +22,9 @@ import ( "github.com/sirupsen/logrus" "github.com/percona/pmm/managed/models" + "github.com/percona/pmm/managed/services/clickhouse" "github.com/percona/pmm/managed/services/supervisord" + "github.com/percona/pmm/managed/utils/env" "github.com/percona/pmm/managed/utils/envvars" "github.com/percona/pmm/utils/logger" ) @@ -36,6 +38,10 @@ func main() { logrus.SetLevel(logrus.TraceLevel) } envSettings, errs, warns := envvars.ParseEnvVars(os.Environ()) + clickHouseConfig, err := clickhouse.GetClickHouseConfig(os.Getenv(env.ClickHouseConfig)) + if err != nil { + errs = append(errs, err) + } for _, warn := range warns { logrus.Warnf("Configuration warning: %s", warn) } @@ -46,8 +52,7 @@ func main() { os.Exit(1) } - err := models.ValidateSettings(envSettings) - if err != nil { + if err := models.ValidateSettings(envSettings); err != nil { logrus.Errorf("Configuration error: %s.", err) os.Exit(1) } @@ -56,6 +61,7 @@ func main() { pmmConfigParams["DisableInternalDB"], _ = strconv.ParseBool(os.Getenv("PMM_DISABLE_BUILTIN_POSTGRES")) pmmConfigParams["DisableInternalClickhouse"], _ = strconv.ParseBool(os.Getenv("PMM_DISABLE_BUILTIN_CLICKHOUSE")) pmmConfigParams["AgentConfigFilePath"] = models.AgentConfigFilePath + pmmConfigParams["ClickHouseConfig"] = clickHouseConfig isHAEnabled, _ := strconv.ParseBool(os.Getenv("PMM_HA_ENABLE")) if isHAEnabled { diff --git a/managed/services/clickhouse/config.go b/managed/services/clickhouse/config.go new file mode 100644 index 00000000000..859a071bc2a --- /dev/null +++ b/managed/services/clickhouse/config.go @@ -0,0 +1,80 @@ +// Copyright (C) 2023 Percona LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Package clickhouse provides facilities for working with clickhouse. +package clickhouse + +import ( + "errors" + "fmt" + "os" + "path/filepath" + "sort" + "strings" +) + +const ( + defaultClickHouseConfig = "default" + clickHouseConfigDir = "/etc/clickhouse-server" +) + +// GetClickHouseConfig returns the config name if the matching +// -config.xml files exist on disk. +// Empty input falls back to defaultClickHouseConfig. +func GetClickHouseConfig(config string) (string, error) { + if config == "" { + return defaultClickHouseConfig, nil + } + + return config, validateClickHouseConfigAt(config, clickHouseConfigDir) +} + +// validateClickHouseConfigAt returns an error if configuration files are missing for given config +func validateClickHouseConfigAt(config, dir string) error { + availableConfigs, err := availableClickHouseConfigs(dir) + if err != nil { + return fmt.Errorf("unable to get available ClickHouse configs: %w", err) + } + + path := filepath.Join(dir, config+"-config.xml") + if _, err := os.Stat(path); err != nil { + if errors.Is(err, os.ErrNotExist) { + return fmt.Errorf( + "invalid PMM_CLICKHOUSE_CONFIG=%s: %s not found; available configs: %v", + config, path, availableConfigs, + ) + } + return fmt.Errorf("cannot stat %s: %w", path, err) + } + + return nil +} + +// availableClickHouseConfigs lists config names that are present in the dir +func availableClickHouseConfigs(dir string) ([]string, error) { + var configs []string + + matches, err := filepath.Glob(filepath.Join(dir, "*-config.xml")) + if err != nil { + return nil, err + } + for _, m := range matches { + name := strings.TrimSuffix(filepath.Base(m), "-config.xml") + configs = append(configs, name) + } + + sort.Strings(configs) + return configs, nil +} diff --git a/managed/services/clickhouse/config_test.go b/managed/services/clickhouse/config_test.go new file mode 100644 index 00000000000..bbfa7e7e999 --- /dev/null +++ b/managed/services/clickhouse/config_test.go @@ -0,0 +1,128 @@ +// Copyright (C) 2023 Percona LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package clickhouse + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// writeConfigFiles creates the given files in dir with placeholder content. +func writeConfigFiles(t *testing.T, dir string, names ...string) { + t.Helper() + for _, name := range names { + require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte(""), 0o600)) + } +} + +func TestGetClickHouseConfig(t *testing.T) { + t.Parallel() + + // Empty input falls back to the default config. + got, err := GetClickHouseConfig("") + require.NoError(t, err) + assert.Equal(t, defaultClickHouseConfig, got) +} + +func TestValidateClickHouseConfigAt(t *testing.T) { + t.Parallel() + + dir := t.TempDir() + // A config is valid as long as -config.xml exists. + writeConfigFiles( + t, dir, + "default-config.xml", + "low-memory-config.xml", + ) + + tests := []struct { + name string + config string + errContains []string + }{ + {name: "default", config: "default"}, + {name: "low-memory", config: "low-memory"}, + { + name: "missing", + config: "nonexistent", + errContains: []string{ + `invalid PMM_CLICKHOUSE_CONFIG=nonexistent`, + "available configs:", + "default", "low-memory", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + err := validateClickHouseConfigAt(tt.config, dir) + if tt.errContains == nil { + require.NoError(t, err) + return + } + require.Error(t, err) + for _, substr := range tt.errContains { + assert.Contains(t, err.Error(), substr) + } + }) + } + + t.Run("invalid config dir", func(t *testing.T) { + t.Parallel() + + base := t.TempDir() + // "notdir" is a regular file; using it as the config dir makes os.Stat fail + require.NoError(t, os.WriteFile(filepath.Join(base, "notdir"), nil, 0o600)) + + err := validateClickHouseConfigAt("default", filepath.Join(base, "notdir")) + require.Error(t, err) + assert.Contains(t, err.Error(), "cannot stat") + assert.NotContains(t, err.Error(), "available configs:") + }) +} + +func TestAvailableClickHouseConfigs(t *testing.T) { + t.Parallel() + + t.Run("empty dir", func(t *testing.T) { + t.Parallel() + + got, err := availableClickHouseConfigs(t.TempDir()) + require.NoError(t, err) + assert.Empty(t, got) + }) + + t.Run("lists config names sorted, ignoring non-config files", func(t *testing.T) { + t.Parallel() + + dir := t.TempDir() + writeConfigFiles( + t, dir, + "low-memory-config.xml", + "default-config.xml", + "dhparam.pem", // not a *-config.xml, must be ignored + ) + + got, err := availableClickHouseConfigs(dir) + require.NoError(t, err) + assert.Equal(t, []string{"default", "low-memory"}, got) + }) +} diff --git a/managed/services/supervisord/pmm_config.go b/managed/services/supervisord/pmm_config.go index 56b88d38cce..6ceb388fd93 100644 --- a/managed/services/supervisord/pmm_config.go +++ b/managed/services/supervisord/pmm_config.go @@ -134,7 +134,7 @@ redirect_stderr = true [program:clickhouse] priority = 2 -command = /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/config.xml +command = /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/{{ .ClickHouseConfig }}-config.xml autorestart = true autostart = true startretries = 10 diff --git a/managed/services/supervisord/pmm_config_test.go b/managed/services/supervisord/pmm_config_test.go index 652f946e4f3..e639d38b4b4 100644 --- a/managed/services/supervisord/pmm_config_test.go +++ b/managed/services/supervisord/pmm_config_test.go @@ -34,14 +34,19 @@ func TestSavePMMConfig(t *testing.T) { }{ { description: "disable internal postgresql db", - params: map[string]any{"DisableInternalDB": true, "DisableSupervisor": false, "DisableInternalClickhouse": false, "AgentConfigFilePath": "/usr/local/percona/pmm/config/pmm-agent.yaml"}, + params: map[string]any{"DisableInternalDB": true, "DisableSupervisor": false, "DisableInternalClickhouse": false, "AgentConfigFilePath": "/usr/local/percona/pmm/config/pmm-agent.yaml", "ClickHouseConfig": "default"}, file: "pmm-db_disabled", }, { description: "enable internal postgresql db", - params: map[string]any{"DisableInternalDB": false, "DisableSupervisor": false, "DisableInternalClickhouse": false, "AgentConfigFilePath": "/usr/local/percona/pmm/config/pmm-agent.yaml"}, + params: map[string]any{"DisableInternalDB": false, "DisableSupervisor": false, "DisableInternalClickhouse": false, "AgentConfigFilePath": "/usr/local/percona/pmm/config/pmm-agent.yaml", "ClickHouseConfig": "default"}, file: "pmm-db_enabled", }, + { + description: "low-memory clickhouse profile", + params: map[string]any{"DisableInternalDB": false, "DisableSupervisor": false, "DisableInternalClickhouse": false, "AgentConfigFilePath": "/usr/local/percona/pmm/config/pmm-agent.yaml", "ClickHouseConfig": "low-memory"}, + file: "pmm-ch_low_memory", + }, } for _, test := range tests { t.Run(test.description, func(t *testing.T) { diff --git a/managed/testdata/supervisord.d/pmm-ch_low_memory.ini b/managed/testdata/supervisord.d/pmm-ch_low_memory.ini new file mode 100644 index 00000000000..84a017d44b7 --- /dev/null +++ b/managed/testdata/supervisord.d/pmm-ch_low_memory.ini @@ -0,0 +1,109 @@ +[unix_http_server] +chmod = 0700 +username = dummy +password = dummy + +[supervisorctl] +username = dummy +password = dummy + +[program:pmm-init] +command = /usr/bin/ansible-playbook /opt/ansible/pmm-docker/init.yml +directory = / +autorestart = unexpected +priority=-1 +exitcodes = 0 +autostart = true +startretries = 3 +startsecs = 1 +stopsignal = TERM +stopwaitsecs = 300 +stdout_logfile = /srv/logs/pmm-init.log +stdout_logfile_maxbytes = 20MB +stdout_logfile_backups = 3 +redirect_stderr = true +environment = ANSIBLE_CONFIG="/opt/ansible/ansible.cfg" + +[program:postgresql] +priority = 1 +command = + /usr/pgsql-14/bin/postgres + -D /srv/postgres14 + -c shared_preload_libraries=pg_stat_statements + -c pg_stat_statements.max=10000 + -c pg_stat_statements.track=all + -c pg_stat_statements.save=off + -c logging_collector=off +autorestart = true +autostart = true +startretries = 10 +startsecs = 1 +stopsignal = INT ; Fast Shutdown mode +stopwaitsecs = 300 +; postgresql.conf contains settings to log to stdout, +; so we delegate logfile management to supervisord +stdout_logfile = /srv/logs/postgresql14.log +stdout_logfile_maxbytes = 30MB +stdout_logfile_backups = 2 +redirect_stderr = true + +[program:clickhouse] +priority = 2 +command = /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/low-memory-config.xml +autorestart = true +autostart = true +startretries = 10 +startsecs = 1 +stopsignal = TERM +stopwaitsecs = 300 +; config.xml contains settings to log to stdout (console), +; so we delegate logfile managemenet to supervisord +stdout_logfile = /srv/logs/clickhouse-server.log +stdout_logfile_maxbytes = 50MB +stdout_logfile_backups = 2 +redirect_stderr = true + +[program:nginx] +priority = 4 +command = nginx +autorestart = true +autostart = true +startretries = 10 +startsecs = 1 +stopsignal = TERM +stopwaitsecs = 10 +stdout_logfile = /srv/logs/nginx.log +stdout_logfile_maxbytes = 50MB +stdout_logfile_backups = 2 +redirect_stderr = true + +[program:pmm-managed] +priority = 14 +command = + /usr/sbin/pmm-managed + --victoriametrics-config=/etc/victoriametrics-promscrape.yml + --supervisord-config-dir=/etc/supervisord.d +autorestart = true +autostart = true +startretries = 1000 +startsecs = 1 +stopsignal = TERM +stopwaitsecs = 300 +stdout_logfile = /srv/logs/pmm-managed.log +stdout_logfile_maxbytes = 50MB +stdout_logfile_backups = 2 +redirect_stderr = true + +[program:pmm-agent] +priority = 15 +command = /usr/sbin/pmm-agent --config-file=/usr/local/percona/pmm/config/pmm-agent.yaml --paths-tempdir=/srv/pmm-agent/tmp --paths-nomad-data-dir=/srv/nomad/data +autorestart = true +autostart = false +startretries = 1000 +startsecs = 1 +stopsignal = TERM +stopwaitsecs = 10 +stdout_logfile = /srv/logs/pmm-agent.log +stdout_logfile_maxbytes = 50MB +stdout_logfile_backups = 2 +redirect_stderr = true diff --git a/managed/testdata/supervisord.d/pmm-db_disabled.ini b/managed/testdata/supervisord.d/pmm-db_disabled.ini index 01ce3c3a7fd..be1256c78c8 100644 --- a/managed/testdata/supervisord.d/pmm-db_disabled.ini +++ b/managed/testdata/supervisord.d/pmm-db_disabled.ini @@ -26,7 +26,7 @@ environment = ANSIBLE_CONFIG="/opt/ansible/ansible.cfg" [program:clickhouse] priority = 2 -command = /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/config.xml +command = /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/default-config.xml autorestart = true autostart = true startretries = 10 diff --git a/managed/testdata/supervisord.d/pmm-db_enabled.ini b/managed/testdata/supervisord.d/pmm-db_enabled.ini index 54d70f365c2..ebecab8effc 100644 --- a/managed/testdata/supervisord.d/pmm-db_enabled.ini +++ b/managed/testdata/supervisord.d/pmm-db_enabled.ini @@ -49,7 +49,7 @@ redirect_stderr = true [program:clickhouse] priority = 2 -command = /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/config.xml +command = /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/default-config.xml autorestart = true autostart = true startretries = 10 diff --git a/managed/utils/env/env.go b/managed/utils/env/env.go index 8adb81768a3..12d6cdf7cba 100644 --- a/managed/utils/env/env.go +++ b/managed/utils/env/env.go @@ -43,6 +43,9 @@ const ( // ClickHouseNodes is used to store the ClickHouse nodes. ClickHouseNodes = "PMM_CLICKHOUSE_NODES" + + // ClickHouseConfig specifies the configuration for ClickHouse. + ClickHouseConfig = "PMM_CLICKHOUSE_CONFIG" ) // GetBool returns the boolean value of the environment variable. diff --git a/managed/utils/envvars/parser.go b/managed/utils/envvars/parser.go index 4c9bc27edeb..5988b39fc3f 100644 --- a/managed/utils/envvars/parser.go +++ b/managed/utils/envvars/parser.go @@ -106,8 +106,8 @@ func ParseEnvVars(envs []string) (*models.ChangeSettingsParams, []error, []strin "PMM_CLICKHOUSE_USER", "PMM_CLICKHOUSE_PASSWORD", "PMM_CLICKHOUSE_HOST", "PMM_CLICKHOUSE_PORT", "PMM_CLICKHOUSE_IS_CLUSTER", "PMM_CLICKHOUSE_CLUSTER_NAME", - "PMM_CLICKHOUSE_NODES", "PMM_DISABLE_BUILTIN_CLICKHOUSE": - // skip env variables for external clickhouse + "PMM_CLICKHOUSE_NODES", "PMM_DISABLE_BUILTIN_CLICKHOUSE", + pkgenv.ClickHouseConfig: continue case "PMM_POSTGRES_ADDR", "PMM_POSTGRES_DBNAME", diff --git a/managed/utils/envvars/parser_test.go b/managed/utils/envvars/parser_test.go index 24f5ae4c142..45dbb964edc 100644 --- a/managed/utils/envvars/parser_test.go +++ b/managed/utils/envvars/parser_test.go @@ -114,6 +114,30 @@ func TestEnvVarValidator(t *testing.T) { assert.Nil(t, gotWarns) }) + t.Run("Skipped clickhouse env vars", func(t *testing.T) { + t.Parallel() + + envs := []string{ + "PMM_CLICKHOUSE_DATABASE=pmm", + "PMM_CLICKHOUSE_ADDR=127.0.0.1:9000", + "PMM_CLICKHOUSE_USER=default", + "PMM_CLICKHOUSE_PASSWORD=secret", + "PMM_CLICKHOUSE_HOST=127.0.0.1", + "PMM_CLICKHOUSE_PORT=9000", + "PMM_CLICKHOUSE_IS_CLUSTER=true", + "PMM_CLICKHOUSE_CLUSTER_NAME=cluster1", + "PMM_CLICKHOUSE_NODES=n1,n2", + "PMM_CLICKHOUSE_CONFIG=low-memory", + "PMM_DISABLE_BUILTIN_CLICKHOUSE=1", + } + expectedEnvVars := &models.ChangeSettingsParams{} + + gotEnvVars, gotErrs, gotWarns := ParseEnvVars(envs) + assert.Equal(t, expectedEnvVars, gotEnvVars) + assert.Nil(t, gotErrs) + assert.Nil(t, gotWarns) + }) + t.Run("Invalid env variables values", func(t *testing.T) { t.Parallel()