From 3aed8f33b6e4f473e97c721bb522be954e267f56 Mon Sep 17 00:00:00 2001 From: Michael Okoko <10512379+idoqo@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:26:06 +0100 Subject: [PATCH] PMM-12619: Make PMM environment variables more consistent (#2857) * refactored environment variables * update migration doc * replace test line * drop no lint rule * fix parser tests * re-order table values * remove deprecated env variables * fix tests * use singluar advisor * introduce PMM_DEV_ prefix for dev-related variables * clean up environment variables * drop printf * drop unused variable * update tests * add notes for removed variable * update oauth variables * update changed variable list * update variable check validation * refactor tests * surpress linter error --- .github/workflows/api-tests.yml | 5 +- .github/workflows/managed.yml | 4 +- agent/docker-compose.yml | 7 +- api-tests/docker-compose.yml | 7 +- .../management/alerting/alerting_test.go | 2 +- .../roles/grafana/files/datasources.yml | 20 +-- build/docker/server/README.md | 31 ++-- docker-compose.yml | 165 +++++++++--------- docs/process/best_practices.md | 8 + .../process/v2_to_v3_environment_variables.md | 57 ++++++ managed/CONTRIBUTING.md | 34 ++-- managed/cmd/pmm-managed-init/main.go | 4 +- managed/cmd/pmm-managed-starlark/main.go | 2 +- managed/cmd/pmm-managed/main.go | 22 +-- .../models/percona_sso_model_helpers_test.go | 8 +- managed/services/checks/checks.go | 4 +- managed/services/checks/checks_test.go | 4 +- managed/services/config/config.go | 2 +- .../management/alerting/service_test.go | 8 +- managed/services/server/server.go | 16 +- managed/services/server/server_test.go | 42 ++--- managed/services/supervisord/supervisord.go | 40 ++--- managed/services/telemetry/config.default.yml | 4 +- managed/services/telemetry/config.go | 10 +- managed/testdata/supervisord.d/grafana.ini | 22 +-- managed/testdata/supervisord.d/qan-api2.ini | 4 +- managed/utils/envvars/parser.go | 84 ++++----- managed/utils/envvars/parser_test.go | 96 ++++------ managed/utils/interceptors/interceptors.go | 2 +- qan-api2/main.go | 8 +- 30 files changed, 379 insertions(+), 343 deletions(-) create mode 100644 docs/process/v2_to_v3_environment_variables.md diff --git a/.github/workflows/api-tests.yml b/.github/workflows/api-tests.yml index ee856a59e6..3d560b0264 100644 --- a/.github/workflows/api-tests.yml +++ b/.github/workflows/api-tests.yml @@ -94,9 +94,8 @@ jobs: container_name: pmm-agent_pmm-server environment: - PMM_DEBUG=1 - - PERCONA_TEST_CHECKS_INTERVAL=10s - - PERCONA_TEST_PLATFORM_ADDRESS=https://check-dev.percona.com - - PERCONA_TEST_PLATFORM_PUBLIC_KEY=RWTg+ZmCCjt7O8eWeAmTLAqW+1ozUbpRSKSwNTmO+exlS5KEIPYWuYdX + - PMM_DEV_PERCONA_PLATFORM_ADDRESS=https://check-dev.percona.com + - PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY=RWTg+ZmCCjt7O8eWeAmTLAqW+1ozUbpRSKSwNTmO+exlS5KEIPYWuYdX ports: - 80:8080 - 443:8443 diff --git a/.github/workflows/managed.yml b/.github/workflows/managed.yml index 120d538409..e79ce022c4 100644 --- a/.github/workflows/managed.yml +++ b/.github/workflows/managed.yml @@ -29,8 +29,8 @@ jobs: PMM_SERVER_IMAGE: perconalab/pmm-server:3-dev-latest AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} - OAUTH_PMM_CLIENT_ID: ${{ secrets.OAUTH_PMM_CLIENT_ID }} - OAUTH_PMM_CLIENT_SECRET: ${{ secrets.OAUTH_PMM_CLIENT_SECRET }} + PMM_DEV_OAUTH_CLIENT_ID: ${{ secrets.OAUTH_PMM_CLIENT_ID }} + PMM_DEV_OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_PMM_CLIENT_SECRET }} DEVCONTAINER_CACHE_ENABLED: false steps: diff --git a/agent/docker-compose.yml b/agent/docker-compose.yml index 1d0bc80557..a8f7aecb78 100644 --- a/agent/docker-compose.yml +++ b/agent/docker-compose.yml @@ -10,12 +10,11 @@ services: - "127.0.0.1:443:8443" environment: - PMM_DEBUG=1 - - PERCONA_TEST_CHECKS_INTERVAL=10s # for local development - - PERCONA_TEST_CHECKS_FILE=/srv/checks/custom-checks.yml + - PMM_DEV_ADVISOR_CHECKS_FILE=/srv/checks/custom-checks.yml # for check-dev - # - PERCONA_TEST_SAAS_HOST=check-dev.percona.com:443 - # - PERCONA_TEST_CHECKS_PUBLIC_KEY=RWTg+ZmCCjt7O8eWeAmTLAqW+1ozUbpRSKSwNTmO+exlS5KEIPYWuYdX + # - PMM_DEV_PERCONA_PLATFORM_ADDRESS=check-dev.percona.com:443 + # - PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY=RWTg+ZmCCjt7O8eWeAmTLAqW+1ozUbpRSKSwNTmO+exlS5KEIPYWuYdX volumes: - ./testdata/checks:/srv/checks diff --git a/api-tests/docker-compose.yml b/api-tests/docker-compose.yml index b3452357cd..ea21aff444 100644 --- a/api-tests/docker-compose.yml +++ b/api-tests/docker-compose.yml @@ -10,12 +10,11 @@ services: - 127.0.0.1:443:8443 environment: - PMM_DEBUG=1 - - PERCONA_TEST_CHECKS_INTERVAL=10s # for local development - # - PERCONA_TEST_CHECKS_FILE=/srv/checks/custom-checks.yml + # - PMM_DEV_ADVISOR_CHECKS_FILE=/srv/checks/custom-checks.yml # for check-dev - - PERCONA_TEST_SAAS_HOST=check-dev.percona.com - - PERCONA_TEST_CHECKS_PUBLIC_KEY=RWTg+ZmCCjt7O8eWeAmTLAqW+1ozUbpRSKSwNTmO+exlS5KEIPYWuYdX + - PMM_DEV_PERCONA_PLATFORM_ADDRESS=check-dev.percona.com + - PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY=RWTg+ZmCCjt7O8eWeAmTLAqW+1ozUbpRSKSwNTmO+exlS5KEIPYWuYdX volumes: - ./testdata/checks:/srv/checks diff --git a/api-tests/management/alerting/alerting_test.go b/api-tests/management/alerting/alerting_test.go index 80657c5369..3a26e37518 100644 --- a/api-tests/management/alerting/alerting_test.go +++ b/api-tests/management/alerting/alerting_test.go @@ -41,7 +41,7 @@ import ( // Note: Even though the Alerting service checks for alerting enabled or disabled before returning results // we don't enable or disable Alerting explicit in our tests since it is enabled by default through -// DISABLE_ALERTING env var. +// PMM_DISABLE_ALERTING env var. func TestRulesAPI(t *testing.T) { t.Parallel() client := alertingClient.Default.Alerting diff --git a/build/ansible/roles/grafana/files/datasources.yml b/build/ansible/roles/grafana/files/datasources.yml index ce5e7e2f1f..f6b50d2e30 100644 --- a/build/ansible/roles/grafana/files/datasources.yml +++ b/build/ansible/roles/grafana/files/datasources.yml @@ -19,17 +19,17 @@ datasources: orgId: 1 type: postgres access: proxy - url: ${PERCONA_TEST_POSTGRES_ADDR} - user: ${PERCONA_TEST_POSTGRES_USERNAME} - database: ${PERCONA_TEST_POSTGRES_DBNAME} + url: ${PMM_POSTGRES_ADDR} + user: ${PMM_POSTGRES_USERNAME} + database: ${PMM_POSTGRES_DBNAME} jsonData: - sslRootCertFile: ${PERCONA_TEST_POSTGRES_SSL_CA_PATH} - sslKeyFile: ${PERCONA_TEST_POSTGRES_SSL_KEY_PATH} - sslCertFile: ${PERCONA_TEST_POSTGRES_SSL_CERT_PATH} + sslRootCertFile: ${PMM_POSTGRES_SSL_CA_PATH} + sslKeyFile: ${PMM_POSTGRES_SSL_KEY_PATH} + sslCertFile: ${PMM_POSTGRES_SSL_CERT_PATH} postgresVersion: "1100" - sslmode: ${PERCONA_TEST_POSTGRES_SSL_MODE} + sslmode: ${PMM_POSTGRES_SSL_MODE} secureJsonData: - password: ${PERCONA_TEST_POSTGRES_DBPASSWORD} + password: ${PMM_POSTGRES_DBPASSWORD} - name: PTSummary version: 2 orgId: 1 @@ -40,6 +40,6 @@ datasources: version: 2 type: grafana-clickhouse-datasource jsonData: - port: ${PERCONA_TEST_PMM_CLICKHOUSE_PORT} - server: ${PERCONA_TEST_PMM_CLICKHOUSE_HOST} + port: ${PMM_CLICKHOUSE_PORT} + server: ${PMM_CLICKHOUSE_HOST} tlsSkipVerify: false \ No newline at end of file diff --git a/build/docker/server/README.md b/build/docker/server/README.md index d49a8136c2..e5ceb49a49 100644 --- a/build/docker/server/README.md +++ b/build/docker/server/README.md @@ -23,22 +23,21 @@ This example uses the tag `:3` to pull the latest PMM 3.x version, but other, [m You can use these environment variables (-e VAR) when running the Docker image. -| Variable | Description | -|--------------------------|-----------------------------------------------------------------------------------------------------------------------------| -| DISABLE_UPDATES | Disable automatic updates | -| DISABLE_TELEMETRY | Disable built-in telemetry and disable STT if telemetry is disabled | -| DISABLE_ALERTING | Disable percona alerting | -| METRICS_RESOLUTION | High metrics resolution in seconds | -| METRICS_RESOLUTION_HR | High metrics resolution (same as above) | -| METRICS_RESOLUTION_MR | Medium metrics resolution in seconds | -| METRICS_RESOLUTION_LR | Low metrics resolution in seconds | -| DATA_RETENTION | How long to keep time-series data in ClickHouse. This variable accepts golang style duration format, example: 24h, 30m, 10s | -| ENABLE_VM_CACHE | Enable cache in VM | -| ENABLE_AZUREDISCOVER | Enable support for discovery of Azure databases | -| ENABLE_BACKUP_MANAGEMENT | Enable integrated backup tools | -| PMM_PUBLIC_ADDRESS | External IP address or the DNS name on which PMM server is running. | -| PMM_DEBUG | Enables a more verbose log level | -| PMM_TRACE | Enables a more verbose log level including traceback information | +| Variable | Description | +|------------------------------|-----------------------------------------------------------------------------------------------------------------------------| +| PMM_DISABLE_UPDATES | Disable automatic updates | +| PMM_DISABLE_TELEMETRY | Disable built-in telemetry and disable STT if telemetry is disabled | +| PMM_DISABLE_ALERTING | Disable Percona alerting | +| PMM_METRICS_RESOLUTION | High metrics resolution in seconds | +| PMM_METRICS_RESOLUTION_HR | High metrics resolution (same as above) | +| PMM_METRICS_RESOLUTION_MR | Medium metrics resolution in seconds | +| PMM_METRICS_RESOLUTION_LR | Low metrics resolution in seconds | +| PMM_DATA_RETENTION | How long to keep time-series data in ClickHouse. This variable accepts golang style duration format, example: 24h, 30m, 10s | +| PMM_ENABLE_VM_CACHE | Enable cache in VM | +| PMM_ENABLE_AZURE_DISCOVER | Enable support for discovery of Azure databases | +| PMM_PUBLIC_ADDRESS | External IP address or the DNS name on which PMM server is running. | +| PMM_DEBUG | Enables a more verbose log level | +| PMM_TRACE | Enables a more verbose log level including traceback information | ## For more information please visit: diff --git a/docker-compose.yml b/docker-compose.yml index 0195e96f9f..7317df4e0f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,36 +16,36 @@ services: networks: - ${NETWORK:-default} environment: - - PMM_RELEASE_PATH=/root/go/bin - - REVIEWDOG_GITHUB_API_TOKEN=${REVIEWDOG_GITHUB_API_TOKEN} - AWS_ACCESS_KEY=${AWS_ACCESS_KEY} - AWS_SECRET_KEY=${AWS_SECRET_KEY} - - ENABLE_RBAC=${ENABLE_RBAC:-0} - - LESS_LOG_NOISE=1 - - PERCONA_TEST_VERSION_SERVICE_URL=${PERCONA_TEST_VERSION_SERVICE_URL} + - REVIEWDOG_GITHUB_API_TOKEN=${REVIEWDOG_GITHUB_API_TOKEN} + - PMM_LESS_LOG_NOISE=1 + - PMM_RELEASE_PATH=/root/go/bin + - PMM_ENABLE_ACCESS_CONTROL=${PMM_ENABLE_ACCESS_CONTROL:-0} + - PMM_DEV_VERSION_SERVICE_URL=${PMM_DEV_VERSION_SERVICE_URL} - PMM_WATCHTOWER_HOST=${PMM_WATCHTOWER_HOST:-http://watchtower:8080} - PMM_WATCHTOWER_TOKEN=${PMM_WATCHTOWER_TOKEN:-INSECURE_TOKEN} - # - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost - # - PERCONA_TEST_PLATFORM_INSECURE=1 - # - PERCONA_TEST_PLATFORM_PUBLIC_KEY= - # - PERCONA_TEST_TELEMETRY_INTERVAL=10s - # - PERCONA_TEST_TELEMETRY_DISABLE_START_DELAY=1 - # - PERCONA_TEST_TELEMETRY_RETRY_BACKOFF=10s - # - PERCONA_TEST_PMM_CLICKHOUSE_ADDR=127.0.0.1:9000 - # - PERCONA_TEST_PMM_CLICKHOUSE_DATABASE=pmm - # - PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE=10000 - # - PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE=2 + # - PMM_DEV_PERCONA_PLATFORM_ADDRESS=https://check.localhost + # - PMM_DEV_PERCONA_PLATFORM_INSECURE=1 + # - PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY= + # - PMM_DEV_TELEMETRY_INTERVAL=10s + # - PMM_DEV_TELEMETRY_DISABLE_START_DELAY=1 + # - PMM_DEV_TELEMETRY_RETRY_BACKOFF=10s + # - PMM_CLICKHOUSE_ADDR=127.0.0.1:9000 + # - PMM_CLICKHOUSE_DATABASE=pmm + # - PMM_CLICKHOUSE_BLOCK_SIZE=10000 + # - PMM_CLICKHOUSE_POOL_SIZE=2 # - PMM_DEBUG=1 - # - PERCONA_TEST_CHECKS_FILE=/srv/checks/local-checks.yml - # - PERCONA_TEST_POSTGRES_ADDR=pg - # - PERCONA_TEST_POSTGRES_DBNAME=pmm-managed - # - PERCONA_TEST_POSTGRES_USERNAME=pmm-managed - # - PERCONA_TEST_POSTGRES_DBPASSWORD=pmm-managed - # - PERCONA_TEST_POSTGRES_SSL_MODE=verify-full - # - PERCONA_TEST_POSTGRES_SSL_CA_PATH=/tmp/certs/root.crt - # - PERCONA_TEST_POSTGRES_SSL_KEY_PATH=/tmp/certs/pmm-managed.key - # - PERCONA_TEST_POSTGRES_SSL_CERT_PATH=/tmp/certs/pmm-managed.crt - # - PERCONA_TEST_PMM_DISABLE_BUILTIN_POSTGRES=1 + # - PMM_DEV_ADVISOR_CHECKS_FILE=/srv/checks/local-checks.yml + # - PMM_POSTGRES_ADDR=pg + # - PMM_POSTGRES_DBNAME=pmm-managed + # - PMM_POSTGRES_USERNAME=pmm-managed + # - PMM_POSTGRES_DBPASSWORD=pmm-managed + # - PMM_POSTGRES_SSL_MODE=verify-full + # - PMM_POSTGRES_SSL_CA_PATH=/tmp/certs/root.crt + # - PMM_POSTGRES_SSL_KEY_PATH=/tmp/certs/pmm-managed.key + # - PMM_POSTGRES_SSL_CERT_PATH=/tmp/certs/pmm-managed.crt + # - PMM_DISABLE_BUILTIN_POSTGRES=1 # - GF_DATABASE_SSL_MODE=verify-full # - GF_DATABASE_CA_CERT_PATH=/tmp/certs/root.crt # - GF_DATABASE_CLIENT_KEY_PATH=/tmp/certs/grafana.key @@ -224,26 +224,25 @@ services: - REVIEWDOG_GITHUB_API_TOKEN=${REVIEWDOG_GITHUB_API_TOKEN} - AWS_ACCESS_KEY=${AWS_ACCESS_KEY} - AWS_SECRET_KEY=${AWS_SECRET_KEY} - - ENABLE_BACKUP_MANAGEMENT=1 - # - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost - # - PERCONA_TEST_PLATFORM_INSECURE=1 - # - PERCONA_TEST_PLATFORM_PUBLIC_KEY= - # - PERCONA_TEST_TELEMETRY_INTERVAL=10s - # - PERCONA_TEST_TELEMETRY_RETRY_BACKOFF=10s - # - PERCONA_TEST_TELEMETRY_DISABLE_START_DELAY=1 - - PERCONA_TEST_PMM_CLICKHOUSE_ADDR=${CH_HOSTNAME:-ch}:9000 - - PERCONA_TEST_PMM_CLICKHOUSE_DATABASE=pmm - - PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE=10000 - - PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE=2 - - PERCONA_TEST_PMM_DISABLE_BUILTIN_CLICKHOUSE=1 - - PERCONA_TEST_POSTGRES_ADDR=pg:5432 - - PERCONA_TEST_POSTGRES_USERNAME=pmm-managed - - PERCONA_TEST_POSTGRES_DBPASSWORD=pmm-managed - - PERCONA_TEST_PMM_DISABLE_BUILTIN_POSTGRES=1 - # - PERCONA_TEST_POSTGRES_SSL_MODE=require - # - PERCONA_TEST_POSTGRES_SSL_CA_PATH=/certs/root.crt - # - PERCONA_TEST_POSTGRES_SSL_KEY_PATH=/certs/pmm-managed.key - # - PERCONA_TEST_POSTGRES_SSL_CERT_PATH=/certs/pmm-managed.crt + # - PMM_DEV_PERCONA_PLATFORM_ADDRESS=https://check.localhost + # - PMM_DEV_PERCONA_PLATFORM_INSECURE=1 + # - PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY= + # - PMM_DEV_TELEMETRY_INTERVAL=10s + # - PMM_DEV_TELEMETRY_RETRY_BACKOFF=10s + # - PMM_DEV_TELEMETRY_DISABLE_START_DELAY=1 + - PMM_CLICKHOUSE_ADDR=${CH_HOSTNAME:-ch}:9000 + - PMM_CLICKHOUSE_DATABASE=pmm + - PMM_CLICKHOUSE_BLOCK_SIZE=10000 + - PMM_CLICKHOUSE_POOL_SIZE=2 + - PMM_DISABLE_BUILTIN_CLICKHOUSE=1 + - PMM_POSTGRES_ADDR=pg:5432 + - PMM_POSTGRES_USERNAME=pmm-managed + - PMM_POSTGRES_DBPASSWORD=pmm-managed + - PMM_DISABLE_BUILTIN_POSTGRES=1 + # - PMM_POSTGRES_SSL_MODE=require + # - PMM_POSTGRES_SSL_CA_PATH=/certs/root.crt + # - PMM_POSTGRES_SSL_KEY_PATH=/certs/pmm-managed.key + # - PMM_POSTGRES_SSL_CERT_PATH=/certs/pmm-managed.crt - GF_DATABASE_URL=postgres://grafana:grafana@pg:5432/grafana # - GF_DATABASE_SSL_MODE=require # - PMM_DEBUG=1 @@ -308,25 +307,25 @@ services: - REVIEWDOG_GITHUB_API_TOKEN=${REVIEWDOG_GITHUB_API_TOKEN} - AWS_ACCESS_KEY=${AWS_ACCESS_KEY} - AWS_SECRET_KEY=${AWS_SECRET_KEY} - # - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost - # - PERCONA_TEST_PLATFORM_INSECURE=1 - # - PERCONA_TEST_PLATFORM_PUBLIC_KEY= - # - PERCONA_TEST_TELEMETRY_INTERVAL=10s - # - PERCONA_TEST_TELEMETRY_RETRY_BACKOFF=10s - # - PERCONA_TEST_TELEMETRY_DISABLE_START_DELAY=1 - - PERCONA_TEST_PMM_CLICKHOUSE_ADDR=${CH_HOSTNAME:-ch}:9000 - - PERCONA_TEST_PMM_CLICKHOUSE_DATABASE=pmm - - PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE=10000 - - PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE=2 - - PERCONA_TEST_PMM_DISABLE_BUILTIN_CLICKHOUSE=1 - - PERCONA_TEST_POSTGRES_ADDR=pg:5432 - - PERCONA_TEST_POSTGRES_USERNAME=pmm-managed - - PERCONA_TEST_POSTGRES_DBPASSWORD=pmm-managed - - PERCONA_TEST_PMM_DISABLE_BUILTIN_POSTGRES=1 - # - PERCONA_TEST_POSTGRES_SSL_MODE=require - # - PERCONA_TEST_POSTGRES_SSL_CA_PATH=/certs/root.crt - # - PERCONA_TEST_POSTGRES_SSL_KEY_PATH=/certs/pmm-managed.key - # - PERCONA_TEST_POSTGRES_SSL_CERT_PATH=/certs/pmm-managed.crt + # - PMM_DEV_PERCONA_PLATFORM_ADDRESS=https://check.localhost + # - PMM_DEV_PERCONA_PLATFORM_INSECURE=1 + # - PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY= + # - PMM_DEV_TELEMETRY_INTERVAL=10s + # - PMM_DEV_TELEMETRY_RETRY_BACKOFF=10s + # - PMM_DEV_TELEMETRY_DISABLE_START_DELAY=1 + - PMM_CLICKHOUSE_ADDR=${CH_HOSTNAME:-ch}:9000 + - PMM_CLICKHOUSE_DATABASE=pmm + - PMM_CLICKHOUSE_BLOCK_SIZE=10000 + - PMM_CLICKHOUSE_POOL_SIZE=2 + - PMM_DISABLE_BUILTIN_CLICKHOUSE=1 + - PMM_POSTGRES_ADDR=pg:5432 + - PMM_POSTGRES_USERNAME=pmm-managed + - PMM_POSTGRES_DBPASSWORD=pmm-managed + - PMM_DISABLE_BUILTIN_POSTGRES=1 + # - PMM_POSTGRES_SSL_MODE=require + # - PMM_POSTGRES_SSL_CA_PATH=/certs/root.crt + # - PMM_POSTGRES_SSL_KEY_PATH=/certs/pmm-managed.key + # - PMM_POSTGRES_SSL_CERT_PATH=/certs/pmm-managed.crt - GF_DATABASE_URL=postgres://grafana:grafana@pg:5432/grafana # - GF_DATABASE_SSL_MODE=require # - PMM_DEBUG=1 @@ -390,25 +389,25 @@ services: - REVIEWDOG_GITHUB_API_TOKEN=${REVIEWDOG_GITHUB_API_TOKEN} - AWS_ACCESS_KEY=${AWS_ACCESS_KEY} - AWS_SECRET_KEY=${AWS_SECRET_KEY} - # - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost - # - PERCONA_TEST_PLATFORM_INSECURE=1 - # - PERCONA_TEST_PLATFORM_PUBLIC_KEY= - # - PERCONA_TEST_TELEMETRY_INTERVAL=10s - # - PERCONA_TEST_TELEMETRY_RETRY_BACKOFF=10s - # - PERCONA_TEST_TELEMETRY_DISABLE_START_DELAY=1 - - PERCONA_TEST_PMM_CLICKHOUSE_ADDR=${CH_HOSTNAME:-ch}:9000 - - PERCONA_TEST_PMM_CLICKHOUSE_DATABASE=pmm - - PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE=10000 - - PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE=2 - - PERCONA_TEST_PMM_DISABLE_BUILTIN_CLICKHOUSE=1 - - PERCONA_TEST_POSTGRES_ADDR=pg:5432 - - PERCONA_TEST_POSTGRES_USERNAME=pmm-managed - - PERCONA_TEST_POSTGRES_DBPASSWORD=pmm-managed - - PERCONA_TEST_PMM_DISABLE_BUILTIN_POSTGRES=1 - # - PERCONA_TEST_POSTGRES_SSL_MODE=require - # - PERCONA_TEST_POSTGRES_SSL_CA_PATH=/certs/root.crt - # - PERCONA_TEST_POSTGRES_SSL_KEY_PATH=/certs/pmm-managed.key - # - PERCONA_TEST_POSTGRES_SSL_CERT_PATH=/certs/pmm-managed.crt + # - PMM_DEV_PERCONA_PLATFORM_ADDRESS=https://check.localhost + # - PMM_DEV_PERCONA_PLATFORM_INSECURE=1 + # - PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY= + # - PMM_DEV_TELEMETRY_INTERVAL=10s + # - PMM_DEV_TELEMETRY_RETRY_BACKOFF=10s + # - PMM_DEV_TELEMETRY_DISABLE_START_DELAY=1 + - PMM_CLICKHOUSE_ADDR=${CH_HOSTNAME:-ch}:9000 + - PMM_CLICKHOUSE_DATABASE=pmm + - PMM_CLICKHOUSE_BLOCK_SIZE=10000 + - PMM_CLICKHOUSE_POOL_SIZE=2 + - PMM_DISABLE_BUILTIN_CLICKHOUSE=1 + - PMM_POSTGRES_ADDR=pg:5432 + - PMM_POSTGRES_USERNAME=pmm-managed + - PMM_POSTGRES_DBPASSWORD=pmm-managed + - PMM_DISABLE_BUILTIN_POSTGRES=1 + # - PMM_POSTGRES_SSL_MODE=require + # - PMM_POSTGRES_SSL_CA_PATH=/certs/root.crt + # - PMM_POSTGRES_SSL_KEY_PATH=/certs/pmm-managed.key + # - PMM_POSTGRES_SSL_CERT_PATH=/certs/pmm-managed.crt - GF_DATABASE_URL=postgres://grafana:grafana@pg:5432/grafana # - GF_DATABASE_SSL_MODE=require # - PMM_DEBUG=1 diff --git a/docs/process/best_practices.md b/docs/process/best_practices.md index f93fa188cd..62f666a745 100644 --- a/docs/process/best_practices.md +++ b/docs/process/best_practices.md @@ -26,6 +26,14 @@ - Supervisor-level dependencies between services are not strictly required (due to restarts everything will work eventually), but are nice to have: they help avoid scarry errors in logs. - The big exception is exporters: we should follow practices established by the Prometheus community and not fail if the system under monitoring is not available. Other startup errors, like a missing certificate file, should still terminate the exporter. +### Environment Variables +For consistency, environment variables should keep to the following suggestions: +- Use the `PMM_DEV_` prefix for any environment variable that is to be used for *only* development/test purposes i.e., +variables that are not meant for end-users in any circumstance e.g., `PMM_DEV_PERCONA_PLATFORM_ADDRESS` +- Use the `PMM_TEST_` prefix for any variable that is not part of PMM GA functionality. +- Use the `PMM_` prefix for variables that is part of PMM GA functionality. +- Use a sub-prefix if a number of env vars relate to one component, e.g., `PMM_TEST_HA_` +- The use of PERCONA_ prefix is prohibited (exception: PMM_PERCONA_PLATFORM_URL, since it's part of a proper name, not a prefix) ## Code style - `gofumpt -s ` (note the `-s`) diff --git a/docs/process/v2_to_v3_environment_variables.md b/docs/process/v2_to_v3_environment_variables.md new file mode 100644 index 0000000000..f059f978da --- /dev/null +++ b/docs/process/v2_to_v3_environment_variables.md @@ -0,0 +1,57 @@ +## Migrating PMM v2 environment variables to v3 +We've renamed some environment variables used by PMM for consistency. +Below is a list of affected variables and their new names. + +| PMM 2 | PMM 3 | Comments | +|-----------------------------------------------|--------------------------------------------|--------------------------------------------------------------| +| `DATA_RETENTION` | `PMM_DATA_RETENTION` | | +| `DISABLE_ALERTING` | `PMM_DISABLE_ALERTING` | | +| `DISABLE_UPDATES` | `PMM_DISABLE_UPDATES` | | +| `DISABLE_TELEMETRY` | `PMM_DISABLE_TELEMETRY` | | +| `PERCONA_PLATFORM_API_TIMEOUT` | `PMM_DEV_PERCONA_PLATFORM_API_TIMEOUT` | | +| `DISABLE_BACKUP_MANAGEMENT` | `PMM_DISABLE_BACKUP_MANAGEMENT` | | +| `ENABLE_AZUREDISCOVER` | `PMM_ENABLE_AZURE_DISCOVER` | | +| `ENABLE_RBAC` | `PMM_ENABLE_ACCESS_CONTROL` | | +| `LESS_LOG_NOISE` | `PMM_LESS_LOG_NOISE` | | +| `METRICS_RESOLUTION` | `PMM_METRICS_RESOLUTION` | | +| `METRICS_RESOLUTION_HR` | `PMM_METRICS_RESOLUTION_HR` | | +| `METRICS_RESOLUTION_LR` | `PMM_METRICS_RESOLUTION_LR` | | +| `METRICS_RESOLUTION_MR` | `PMM_METRICS_RESOLUTION_MR` | | +| `OAUTH_PMM_CLIENT_ID` | `PMM_DEV_OAUTH_CLIENT_ID` | | +| `OAUTH_PMM_CLIENT_SECRET` | `PMM_DEV_OAUTH_CLIENT_SECRET` | | +| `PERCONA_TEST_AUTH_HOST` | | Removed in PMM v3, use `PMM_DEV_PERCONA_PLATFORM_ADDRESS` | +| `PERCONA_TEST_CHECKS_FILE` | `PMM_DEV_ADVISOR_CHECKS_FILE` | | +| `PERCONA_TEST_CHECKS_HOST` | | Removed in PMM v3, use `PMM_DEV_PERCONA_PLATFORM_ADDRESS` | +| `PERCONA_TEST_CHECKS_INTERVAL` | | Removed in PMM v3 as it wasn't actually used. | +| `PERCONA_TEST_CHECKS_PUBLIC_KEY` | | Removed in PMM v3, use `PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY` | +| `PERCONA_TEST_NICER_API` | `PMM_NICER_API` | | +| `PERCONA_TEST_PMM_CLICKHOUSE_ADDR` | `PMM_CLICKHOUSE_ADDR` | | +| `PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE` | `PMM_CLICKHOUSE_BLOCK_SIZE` | | +| `PERCONA_TEST_PMM_CLICKHOUSE_DATABASE` | `PMM_CLICKHOUSE_DATABASE` | | +| `PERCONA_TEST_PMM_CLICKHOUSE_DATASOURCE` | `PMM_CLICKHOUSE_DATASOURCE` | | +| `PERCONA_TEST_PMM_CLICKHOUSE_HOST` | `PMM_CLICKHOUSE_HOST` | | +| `PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE` | `PMM_CLICKHOUSE_POOL_SIZE` | | +| `PERCONA_TEST_PMM_CLICKHOUSE_PORT` | `PMM_CLICKHOUSE_PORT` | | +| `PERCONA_TEST_PMM_DISABLE_BUILTIN_CLICKHOUSE` | `PMM_DISABLE_BUILTIN_CLICKHOUSE` | | +| `PERCONA_TEST_PMM_DISABLE_BUILTIN_POSTGRES` | `PMM_DISABLE_BUILTIN_POSTGRES` | | +| `PERCONA_TEST_INTERFACE_TO_BIND` | `PMM_INTERFACE_TO_BIND` | | +| `PERCONA_TEST_PLATFORM_ADDRESS` | `PMM_DEV_PERCONA_PLATFORM_ADDRESS` | | +| `PERCONA_TEST_PLATFORM_INSECURE` | `PMM_DEV_PERCONA_PLATFORM_INSECURE` | | +| `PERCONA_TEST_PLATFORM_PUBLIC_KEY` | `PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY` | | +| `PERCONA_TEST_POSTGRES_ADDR` | `PMM_POSTGRES_ADDR` | | +| `PERCONA_TEST_POSTGRES_DBNAME` | `PMM_POSTGRES_DBNAME` | | +| `PERCONA_TEST_POSTGRES_SSL_CA_PATH` | `PMM_POSTGRES_SSL_CA_PATH` | | +| `PERCONA_TEST_POSTGRES_SSL_CERT_PATH` | `PMM_POSTGRES_SSL_CERT_PATH` | | +| `PERCONA_TEST_POSTGRES_SSL_KEY_PATH` | `PMM_POSTGRES_SSL_KEY_PATH` | | +| `PERCONA_TEST_POSTGRES_SSL_MODE` | `PMM_POSTGRES_SSL_MODE` | | +| `PERCONA_TEST_POSTGRES_DBPASSWORD` | `PMM_POSTGRES_DBPASSWORD` | | +| `PERCONA_TEST_SAAS_HOST` | | Removed in PMM v3, use `PMM_DEV_PERCONA_PLATFORM_ADDRESS` | +| `PERCONA_TEST_POSTGRES_USERNAME` | `PMM_POSTGRES_USERNAME` | | +| `PERCONA_TEST_STARLARK_ALLOW_RECURSION` | `PMM_DEV_ADVISOR_STARLARK_ALLOW_RECURSION` | | +| `PMM_TEST_TELEMETRY_DISABLE_SEND` | `PMM_DEV_TELEMETRY_DISABLE_SEND` | | +| `PERCONA_TEST_TELEMETRY_DISABLE_START_DELAY` | `PMM_DEV_TELEMETRY_DISABLE_START_DELAY` | | +| `PMM_TEST_TELEMETRY_FILE` | `PMM_DEV_TELEMETRY_FILE` | | +| `PERCONA_TEST_TELEMETRY_HOST` | `PMM_DEV_TELEMETRY_HOST` | | +| `PERCONA_TEST_TELEMETRY_INTERVAL` | `PMM_DEV_TELEMETRY_INTERVAL` | | +| `PERCONA_TEST_TELEMETRY_RETRY_BACKOFF` | `PMM_DEV_TELEMETRY_RETRY_BACKOFF` | | +| `PERCONA_TEST_VERSION_SERVICE_URL` | `PMM_DEV_VERSION_SERVICE_URL` | | diff --git a/managed/CONTRIBUTING.md b/managed/CONTRIBUTING.md index ddbafd1018..bebeceb0a3 100644 --- a/managed/CONTRIBUTING.md +++ b/managed/CONTRIBUTING.md @@ -53,25 +53,21 @@ go test -timeout=30s -p 1 ./... ## Available test environment variables: -| Variable | Description | Default | -| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | -| PERCONA_TEST_PMM_CLICKHOUSE_ADDR | Sets Clickhouse address | 127.0.0.1:9000 | -| PERCONA_TEST_PMM_CLICKHOUSE_DATABASE | Sets Clickhouse database | pmm | -| PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE | Sets Clickhouse connections pool size | none | -| PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE | Sets Clickhouse block size | none | -| PERCONA_TEST_STARLARK_ALLOW_RECURSION | Allows recursive functions in checks scripts | false | -| PERCONA_TEST_NICER_API | Enables nicer API with default/zero values in response. | false | -| PERCONA_TEST_VERSION_SERVICE_URL | Sets versions service URL | https://check.percona.com/versions/v1 | -| PERCONA_TEST_CHECKS_FILE | Specifies path to local checks file and disables downlading checks files from Percona Platform | none | -| PERCONA_TEST_CHECKS_DISABLE_START_DELAY | Disables checks service startup delay | false | -| PERCONA_TEST_TELEMETRY_INTERVAL | Sets telemetry reporting interval | 24h | -| PERCONA_TEST_TELEMETRY_DISABLE_SEND | Disables sending of telemetry data to SaaS. This param doesn't affect telemetry data gathering from the datasources | false | -| PERCONA_TEST_TELEMETRY_FILE | Sets path for telemetry config file | | -| PERCONA_TEST_TELEMETRY_DISABLE_START_DELAY | Disable the default telemetry execution start delay, so that telemetry gathering is run immediately upon system | false | -| PERCONA_TEST_TELEMETRY_RETRY_BACKOFF | Sets telemetry reporting retry backoff time | 1h | -| PERCONA_TEST_PLATFORM_ADDRESS | Sets Percona Platform address | https://check.percona.com | -| PERCONA_TEST_PLATFORM_INSECURE | Allows insecure TLS connections to Percona Platform | false | -| PERCONA_TEST_PLATFORM_PUBLIC_KEY | Sets Percona Platform public key (Minisign) | set of keys embedded into managed binary | +| Variable | Description | Default | +|------------------------------------------|---------------------------------------------------------------------------------------------------------------------|------------------------------------------| +| PMM_DEV_ADVISOR_STARLARK_ALLOW_RECURSION | Allows recursive functions in checks scripts | false | +| PMM_NICER_API | Enables nicer API with default/zero values in response. | false | +| PMM_DEV_VERSION_SERVICE_URL | Sets versions service URL | https://check.percona.com/versions/v1 | +| PMM_DEV_ADVISOR_CHECKS_FILE | Specifies path to local checks file and disables downlading checks files from Percona Platform | none | +| PMM_ADVISORS_CHECKS_DISABLE_START_DELAY | Disables checks service startup delay | false | +| PMM_DEV_TELEMETRY_INTERVAL | Sets telemetry reporting interval | 24h | +| PMM_DEV_TELEMETRY_DISABLE_SEND | Disables sending of telemetry data to SaaS. This param doesn't affect telemetry data gathering from the datasources | false | +| PMM_DEV_TELEMETRY_FILE | Sets path for telemetry config file | | +| PMM_DEV_TELEMETRY_DISABLE_START_DELAY | Disable the default telemetry execution start delay, so that telemetry gathering is run immediately upon system | false | +| PMM_DEV_TELEMETRY_RETRY_BACKOFF | Sets telemetry reporting retry backoff time | 1h | +| PMM_DEV_PERCONA_PLATFORM_ADDRESS | Sets Percona Platform address | https://check.percona.com | +| PMM_DEV_PERCONA_PLATFORM_INSECURE | Allows insecure TLS connections to Percona Platform | false | +| PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY | Sets Percona Platform public key (Minisign) | set of keys embedded into managed binary | ## Add instances for monitoring diff --git a/managed/cmd/pmm-managed-init/main.go b/managed/cmd/pmm-managed-init/main.go index 2a3a076ea7..4934ef1401 100644 --- a/managed/cmd/pmm-managed-init/main.go +++ b/managed/cmd/pmm-managed-init/main.go @@ -53,8 +53,8 @@ func main() { } pmmConfigParams := make(map[string]any) - pmmConfigParams["DisableInternalDB"], _ = strconv.ParseBool(os.Getenv("PERCONA_TEST_PMM_DISABLE_BUILTIN_POSTGRES")) - pmmConfigParams["DisableInternalClickhouse"], _ = strconv.ParseBool(os.Getenv("PERCONA_TEST_PMM_DISABLE_BUILTIN_CLICKHOUSE")) + pmmConfigParams["DisableInternalDB"], _ = strconv.ParseBool(os.Getenv("PMM_DISABLE_BUILTIN_POSTGRES")) + pmmConfigParams["DisableInternalClickhouse"], _ = strconv.ParseBool(os.Getenv("PMM_DISABLE_BUILTIN_CLICKHOUSE")) if err := supervisord.SavePMMConfig(pmmConfigParams); err != nil { logrus.Errorf("PMM Server configuration error: %s.", err) os.Exit(1) diff --git a/managed/cmd/pmm-managed-starlark/main.go b/managed/cmd/pmm-managed-starlark/main.go index b574e8db9c..e9c7ecf1bc 100644 --- a/managed/cmd/pmm-managed-starlark/main.go +++ b/managed/cmd/pmm-managed-starlark/main.go @@ -42,7 +42,7 @@ const ( memoryLimitBytes = 1024 * 1024 * 1024 // Only used for testing. - starlarkRecursionFlag = "PERCONA_TEST_STARLARK_ALLOW_RECURSION" + starlarkRecursionFlag = "PMM_DEV_ADVISOR_STARLARK_ALLOW_RECURSION" // Warning messages. cpuUsageWarning = "Failed to limit CPU usage" diff --git a/managed/cmd/pmm-managed/main.go b/managed/cmd/pmm-managed/main.go index a5a5cf3c0c..c6b4a85b70 100644 --- a/managed/cmd/pmm-managed/main.go +++ b/managed/cmd/pmm-managed/main.go @@ -357,7 +357,7 @@ func runHTTP1Server(ctx context.Context, deps *http1ServerDeps) { } // FIXME make that a default behavior: https://jira.percona.com/browse/PMM-6722 - if nicer, _ := strconv.ParseBool(os.Getenv("PERCONA_TEST_NICER_API")); nicer { + if nicer, _ := strconv.ParseBool(os.Getenv("PMM_NICER_API")); nicer { l.Warn("Enabling nicer API with default/zero values in response.") marshaller.EmitUnpopulated = true } @@ -658,32 +658,32 @@ func main() { //nolint:cyclop,maintidx postgresAddrF := kingpin.Flag("postgres-addr", "PostgreSQL address"). Default(models.DefaultPostgreSQLAddr). - Envar("PERCONA_TEST_POSTGRES_ADDR"). + Envar("PMM_POSTGRES_ADDR"). String() postgresDBNameF := kingpin.Flag("postgres-name", "PostgreSQL database name"). Default("pmm-managed"). - Envar("PERCONA_TEST_POSTGRES_DBNAME"). + Envar("PMM_POSTGRES_DBNAME"). String() postgresDBUsernameF := kingpin.Flag("postgres-username", "PostgreSQL database username"). Default("pmm-managed"). - Envar("PERCONA_TEST_POSTGRES_USERNAME"). + Envar("PMM_POSTGRES_USERNAME"). String() postgresSSLModeF := kingpin.Flag("postgres-ssl-mode", "PostgreSQL SSL mode"). Default(models.DisableSSLMode). - Envar("PERCONA_TEST_POSTGRES_SSL_MODE"). + Envar("PMM_POSTGRES_SSL_MODE"). Enum(models.DisableSSLMode, models.RequireSSLMode, models.VerifyCaSSLMode, models.VerifyFullSSLMode) postgresSSLCAPathF := kingpin.Flag("postgres-ssl-ca-path", "PostgreSQL SSL CA root certificate path"). - Envar("PERCONA_TEST_POSTGRES_SSL_CA_PATH"). + Envar("PMM_POSTGRES_SSL_CA_PATH"). String() postgresDBPasswordF := kingpin.Flag("postgres-password", "PostgreSQL database password"). Default("pmm-managed"). - Envar("PERCONA_TEST_POSTGRES_DBPASSWORD"). + Envar("PMM_POSTGRES_DBPASSWORD"). String() postgresSSLKeyPathF := kingpin.Flag("postgres-ssl-key-path", "PostgreSQL SSL key path"). - Envar("PERCONA_TEST_POSTGRES_SSL_KEY_PATH"). + Envar("PMM_POSTGRES_SSL_KEY_PATH"). String() postgresSSLCertPathF := kingpin.Flag("postgres-ssl-cert-path", "PostgreSQL SSL certificate path"). - Envar("PERCONA_TEST_POSTGRES_SSL_CERT_PATH"). + Envar("PMM_POSTGRES_SSL_CERT_PATH"). String() haEnabled := kingpin.Flag("ha-enable", "Enable HA"). @@ -720,8 +720,8 @@ func main() { //nolint:cyclop,maintidx debugF := kingpin.Flag("debug", "Enable debug logging").Envar("PMM_DEBUG").Bool() traceF := kingpin.Flag("trace", "[DEPRECATED] Enable trace logging (implies debug)").Envar("PMM_TRACE").Bool() - clickHouseDatabaseF := kingpin.Flag("clickhouse-name", "Clickhouse database name").Default("pmm").Envar("PERCONA_TEST_PMM_CLICKHOUSE_DATABASE").String() - clickhouseAddrF := kingpin.Flag("clickhouse-addr", "Clickhouse database address").Default("127.0.0.1:9000").Envar("PERCONA_TEST_PMM_CLICKHOUSE_ADDR").String() + clickHouseDatabaseF := kingpin.Flag("clickhouse-name", "Clickhouse database name").Default("pmm").Envar("PMM_CLICKHOUSE_DATABASE").String() + clickhouseAddrF := kingpin.Flag("clickhouse-addr", "Clickhouse database address").Default("127.0.0.1:9000").Envar("PMM_CLICKHOUSE_ADDR").String() watchtowerHostF := kingpin.Flag("watchtower-host", "Watchtower host").Default("http://watchtower:8080").Envar("PMM_WATCHTOWER_HOST").URL() diff --git a/managed/models/percona_sso_model_helpers_test.go b/managed/models/percona_sso_model_helpers_test.go index 23f59c2d7d..663a4661b6 100644 --- a/managed/models/percona_sso_model_helpers_test.go +++ b/managed/models/percona_sso_model_helpers_test.go @@ -47,9 +47,9 @@ func TestPerconaSSODetails(t *testing.T) { orgID := uuid.NewString() t.Run("CorrectCredentials", func(t *testing.T) { - clientID, clientSecret := os.Getenv("OAUTH_PMM_CLIENT_ID"), os.Getenv("OAUTH_PMM_CLIENT_SECRET") + clientID, clientSecret := os.Getenv("PMM_DEV_OAUTH_CLIENT_ID"), os.Getenv("PMM_DEV_OAUTH_CLIENT_SECRET") if clientID == "" || clientSecret == "" { - t.Skip("Environment variables OAUTH_PMM_CLIENT_ID / OAUTH_PMM_CLIENT_SECRET are not defined, skipping test") + t.Skip("Environment variables PMM_DEV_OAUTH_CLIENT_ID / PMM_DEV_OAUTH_CLIENT_SECRET are not defined, skipping test") } db, cleanup := setupDB(t) @@ -117,9 +117,9 @@ func TestPerconaSSODetails(t *testing.T) { }) t.Run("WrongURL", func(t *testing.T) { - clientID, clientSecret := os.Getenv("OAUTH_PMM_CLIENT_ID"), os.Getenv("OAUTH_PMM_CLIENT_SECRET") + clientID, clientSecret := os.Getenv("PMM_DEV_OAUTH_CLIENT_ID"), os.Getenv("PMM_DEV_OAUTH_CLIENT_SECRET") if clientID == "" || clientSecret == "" { - t.Skip("Environment variables OAUTH_PMM_CLIENT_ID / OAUTH_PMM_CLIENT_SECRET are not defined, skipping test") + t.Skip("Environment variables PMM_DEV_OAUTH_CLIENT_ID / PMM_DEV_OAUTH_CLIENT_SECRET are not defined, skipping test") } db, cleanup := setupDB(t) diff --git a/managed/services/checks/checks.go b/managed/services/checks/checks.go index cced2f6a86..64f4dfd749 100644 --- a/managed/services/checks/checks.go +++ b/managed/services/checks/checks.go @@ -56,8 +56,8 @@ const ( defaultStartDelay = time.Minute // Environment variables that affect checks service; only for testing. - envCheckFile = "PERCONA_TEST_CHECKS_FILE" //nolint:gosec - envDisableStartDelay = "PERCONA_TEST_CHECKS_DISABLE_START_DELAY" + envCheckFile = "PMM_DEV_ADVISOR_CHECKS_FILE" + envDisableStartDelay = "PMM_ADVISORS_CHECKS_DISABLE_START_DELAY" checkExecutionTimeout = 5 * time.Minute // limits execution time for every single check platformRequestTimeout = 2 * time.Minute // time limit to get checks list from the portal diff --git a/managed/services/checks/checks_test.go b/managed/services/checks/checks_test.go index b38f0b1d4e..feeb983d69 100644 --- a/managed/services/checks/checks_test.go +++ b/managed/services/checks/checks_test.go @@ -54,9 +54,9 @@ var ( ) func TestDownloadAdvisors(t *testing.T) { - clientID, clientSecret := os.Getenv("OAUTH_PMM_CLIENT_ID"), os.Getenv("OAUTH_PMM_CLIENT_SECRET") + clientID, clientSecret := os.Getenv("PMM_DEV_OAUTH_CLIENT_ID"), os.Getenv("PMM_DEV_OAUTH_CLIENT_SECRET") if clientID == "" || clientSecret == "" { - t.Skip("Environment variables OAUTH_PMM_CLIENT_ID / OAUTH_PMM_CLIENT_SECRET are not defined, skipping test") + t.Skip("Environment variables PMM_DEV_OAUTH_CLIENT_ID / PMM_DEV_OAUTH_CLIENT_SECRET are not defined, skipping test") } setupClients(t) diff --git a/managed/services/config/config.go b/managed/services/config/config.go index fd4cedf7b5..0ae7ecc672 100644 --- a/managed/services/config/config.go +++ b/managed/services/config/config.go @@ -30,7 +30,7 @@ import ( ) const ( - envConfigPath = "PERCONA_PMM_CONFIG_PATH" + envConfigPath = "PMM_TEST_CONFIG_PATH" defaultConfigPath = "/etc/percona/pmm/pmm-managed.yml" ) diff --git a/managed/services/management/alerting/service_test.go b/managed/services/management/alerting/service_test.go index 08bc38d10d..0e1d7de3e5 100644 --- a/managed/services/management/alerting/service_test.go +++ b/managed/services/management/alerting/service_test.go @@ -43,9 +43,9 @@ const ( func TestCollect(t *testing.T) { t.Parallel() - clientID, clientSecret := os.Getenv("OAUTH_PMM_CLIENT_ID"), os.Getenv("OAUTH_PMM_CLIENT_SECRET") + clientID, clientSecret := os.Getenv("PMM_DEV_OAUTH_CLIENT_ID"), os.Getenv("PMM_DEV_OAUTH_CLIENT_SECRET") if clientID == "" || clientSecret == "" { - t.Skip("Environment variables OAUTH_PMM_CLIENT_ID / OAUTH_PMM_CLIENT_SECRET are not defined, skipping test") + t.Skip("Environment variables PMM_DEV_OAUTH_CLIENT_ID / PMM_DEV_OAUTH_CLIENT_SECRET are not defined, skipping test") } ctx := context.Background() @@ -110,9 +110,9 @@ func TestCollect(t *testing.T) { } func TestDownloadTemplates(t *testing.T) { - clientID, clientSecret := os.Getenv("OAUTH_PMM_CLIENT_ID"), os.Getenv("OAUTH_PMM_CLIENT_SECRET") + clientID, clientSecret := os.Getenv("PMM_DEV_OAUTH_CLIENT_ID"), os.Getenv("PMM_DEV_OAUTH_CLIENT_SECRET") if clientID == "" || clientSecret == "" { - t.Skip("Environment variables OAUTH_PMM_CLIENT_ID / OAUTH_PMM_CLIENT_SECRET are not defined, skipping test") + t.Skip("Environment variables PMM_DEV_OAUTH_CLIENT_ID / PMM_DEV_OAUTH_CLIENT_SECRET are not defined, skipping test") } sqlDB := testdb.Open(t, models.SkipFixtures, nil) diff --git a/managed/services/server/server.go b/managed/services/server/server.go index dc4d9634d1..0a18699ecb 100644 --- a/managed/services/server/server.go +++ b/managed/services/server/server.go @@ -295,7 +295,7 @@ func (s *Server) StartUpdate(ctx context.Context, req *serverpb.StartUpdateReque s.envRW.RUnlock() if updatesDisabled { - return nil, status.Error(codes.FailedPrecondition, "Updates are disabled via DISABLE_UPDATES environment variable.") + return nil, status.Error(codes.FailedPrecondition, "Updates are disabled via PMM_DISABLE_UPDATES environment variable.") } err := s.updater.StartUpdate(ctx, req.GetNewImage()) @@ -469,12 +469,12 @@ func (s *Server) validateChangeSettingsRequest(ctx context.Context, req *serverp // check request parameters compatibility with environment variables if req.EnableUpdates && s.envSettings.DisableUpdates { - return status.Error(codes.FailedPrecondition, "Updates are disabled via DISABLE_UPDATES environment variable.") + return status.Error(codes.FailedPrecondition, "Updates are disabled via PMM_DISABLE_UPDATES environment variable.") } // ignore req.DisableTelemetry and req.DisableStt even if they are present since that will not change anything if req.EnableTelemetry && s.envSettings.DisableTelemetry { - return status.Error(codes.FailedPrecondition, "Telemetry is disabled via DISABLE_TELEMETRY environment variable.") + return status.Error(codes.FailedPrecondition, "Telemetry is disabled via PMM_DISABLE_TELEMETRY environment variable.") } // ignore req.EnableAlerting even if they are present since that will not change anything @@ -484,23 +484,23 @@ func (s *Server) validateChangeSettingsRequest(ctx context.Context, req *serverp // ignore req.DisableAzurediscover even if they are present since that will not change anything if req.DisableAzurediscover && s.envSettings.EnableAzurediscover { - return status.Error(codes.FailedPrecondition, "Azure Discover is enabled via ENABLE_AZUREDISCOVER environment variable.") + return status.Error(codes.FailedPrecondition, "Azure Discover is enabled via PMM_ENABLE_AZURE_DISCOVER environment variable.") } if !canUpdateDurationSetting(metricsRes.GetHr().AsDuration(), s.envSettings.MetricsResolutions.HR) { - return status.Error(codes.FailedPrecondition, "High resolution for metrics is set via METRICS_RESOLUTION_HR (or METRICS_RESOLUTION) environment variable.") + return status.Error(codes.FailedPrecondition, "High resolution for metrics is set via PMM_METRICS_RESOLUTION_HR (or PMM_METRICS_RESOLUTION) environment variable.") //nolint:lll } if !canUpdateDurationSetting(metricsRes.GetMr().AsDuration(), s.envSettings.MetricsResolutions.MR) { - return status.Error(codes.FailedPrecondition, "Medium resolution for metrics is set via METRICS_RESOLUTION_MR environment variable.") + return status.Error(codes.FailedPrecondition, "Medium resolution for metrics is set via PMM_METRICS_RESOLUTION_MR environment variable.") } if !canUpdateDurationSetting(metricsRes.GetLr().AsDuration(), s.envSettings.MetricsResolutions.LR) { - return status.Error(codes.FailedPrecondition, "Low resolution for metrics is set via METRICS_RESOLUTION_LR environment variable.") + return status.Error(codes.FailedPrecondition, "Low resolution for metrics is set via PMM_METRICS_RESOLUTION_LR environment variable.") } if !canUpdateDurationSetting(req.DataRetention.AsDuration(), s.envSettings.DataRetention) { - return status.Error(codes.FailedPrecondition, "Data retention for queries is set via DATA_RETENTION environment variable.") + return status.Error(codes.FailedPrecondition, "Data retention for queries is set via PMM_DATA_RETENTION environment variable.") } return nil diff --git a/managed/services/server/server_test.go b/managed/services/server/server_test.go index 82a67d3cb6..5d6e83f78f 100644 --- a/managed/services/server/server_test.go +++ b/managed/services/server/server_test.go @@ -90,12 +90,12 @@ func TestServer(t *testing.T) { t.Run("Typical", func(t *testing.T) { s := newServer(t) errs := s.UpdateSettingsFromEnv([]string{ - "DISABLE_UPDATES=true", - "DISABLE_TELEMETRY=1", - "METRICS_RESOLUTION_HR=1s", - "METRICS_RESOLUTION_MR=2s", - "METRICS_RESOLUTION_LR=3s", - "DATA_RETENTION=240h", + "PMM_DISABLE_UPDATES=true", + "PMM_DISABLE_TELEMETRY=1", + "PMM_METRICS_RESOLUTION_HR=1s", + "PMM_METRICS_RESOLUTION_MR=2s", + "PMM_METRICS_RESOLUTION_LR=3s", + "PMM_DATA_RETENTION=240h", "PMM_PUBLIC_ADDRESS=1.2.3.4:5678", }) require.Empty(t, errs) @@ -111,9 +111,9 @@ func TestServer(t *testing.T) { t.Run("Untypical", func(t *testing.T) { s := newServer(t) errs := s.UpdateSettingsFromEnv([]string{ - "DISABLE_TELEMETRY=TrUe", - "METRICS_RESOLUTION=3S", - "DATA_RETENTION=360H", + "PMM_DISABLE_TELEMETRY=TrUe", + "PMM_METRICS_RESOLUTION=3S", + "PMM_DATA_RETENTION=360H", }) require.Empty(t, errs) assert.Equal(t, true, s.envSettings.DisableTelemetry) @@ -124,27 +124,27 @@ func TestServer(t *testing.T) { t.Run("NoValue", func(t *testing.T) { s := newServer(t) errs := s.UpdateSettingsFromEnv([]string{ - "DISABLE_TELEMETRY", + "PMM_DISABLE_TELEMETRY", }) require.Len(t, errs, 1) - require.EqualError(t, errs[0], `failed to parse environment variable "DISABLE_TELEMETRY"`) + require.EqualError(t, errs[0], `failed to parse environment variable "PMM_DISABLE_TELEMETRY"`) assert.False(t, s.envSettings.DisableTelemetry) }) t.Run("InvalidValue", func(t *testing.T) { s := newServer(t) errs := s.UpdateSettingsFromEnv([]string{ - "DISABLE_TELEMETRY=", + "PMM_DISABLE_TELEMETRY=", }) require.Len(t, errs, 1) - require.EqualError(t, errs[0], `invalid value "" for environment variable "DISABLE_TELEMETRY"`) + require.EqualError(t, errs[0], `invalid value "" for environment variable "PMM_DISABLE_TELEMETRY"`) assert.False(t, s.envSettings.DisableTelemetry) }) t.Run("MetricsLessThenMin", func(t *testing.T) { s := newServer(t) errs := s.UpdateSettingsFromEnv([]string{ - "METRICS_RESOLUTION=5ns", + "PMM_METRICS_RESOLUTION=5ns", }) require.Len(t, errs, 1) var errInvalidArgument *models.InvalidArgumentError @@ -156,7 +156,7 @@ func TestServer(t *testing.T) { t.Run("DataRetentionLessThenMin", func(t *testing.T) { s := newServer(t) errs := s.UpdateSettingsFromEnv([]string{ - "DATA_RETENTION=12h", + "PMM_DATA_RETENTION=12h", }) require.Len(t, errs, 1) var errInvalidArgument *models.InvalidArgumentError @@ -168,7 +168,7 @@ func TestServer(t *testing.T) { t.Run("Data retention is not a natural number of days", func(t *testing.T) { s := newServer(t) errs := s.UpdateSettingsFromEnv([]string{ - "DATA_RETENTION=30h", + "PMM_DATA_RETENTION=30h", }) require.Len(t, errs, 1) var errInvalidArgument *models.InvalidArgumentError @@ -180,10 +180,10 @@ func TestServer(t *testing.T) { t.Run("Data retention without suffix", func(t *testing.T) { s := newServer(t) errs := s.UpdateSettingsFromEnv([]string{ - "DATA_RETENTION=30", + "PMM_DATA_RETENTION=30", }) require.Len(t, errs, 1) - require.EqualError(t, errs[0], `environment variable "DATA_RETENTION=30" has invalid duration 30`) + require.EqualError(t, errs[0], `environment variable "PMM_DATA_RETENTION=30" has invalid duration 30`) assert.Zero(t, s.envSettings.DataRetention) }) }) @@ -194,7 +194,7 @@ func TestServer(t *testing.T) { ctx := context.TODO() s.envSettings.DisableUpdates = true - expected := status.New(codes.FailedPrecondition, "Updates are disabled via DISABLE_UPDATES environment variable.") + expected := status.New(codes.FailedPrecondition, "Updates are disabled via PMM_DISABLE_UPDATES environment variable.") tests.AssertGRPCError(t, expected, s.validateChangeSettingsRequest(ctx, &serverpb.ChangeSettingsRequest{ EnableUpdates: true, })) @@ -203,7 +203,7 @@ func TestServer(t *testing.T) { })) s.envSettings.DisableTelemetry = true - expected = status.New(codes.FailedPrecondition, "Telemetry is disabled via DISABLE_TELEMETRY environment variable.") + expected = status.New(codes.FailedPrecondition, "Telemetry is disabled via PMM_DISABLE_TELEMETRY environment variable.") tests.AssertGRPCError(t, expected, s.validateChangeSettingsRequest(ctx, &serverpb.ChangeSettingsRequest{ EnableTelemetry: true, })) @@ -224,7 +224,7 @@ func TestServer(t *testing.T) { server.UpdateSettingsFromEnv([]string{ "ENABLE_ALERTING=1", - "ENABLE_AZUREDISCOVER=1", + "PMM_ENABLE_AZURE_DISCOVER=1", }) ctx := context.TODO() diff --git a/managed/services/supervisord/supervisord.go b/managed/services/supervisord/supervisord.go index 2d94414418..41c0f5bf19 100644 --- a/managed/services/supervisord/supervisord.go +++ b/managed/services/supervisord/supervisord.go @@ -422,11 +422,11 @@ func getValueFromENV(envName string, defaultValue string) string { // marshalConfig marshals supervisord program configuration. func (s *Service) marshalConfig(tmpl *template.Template, settings *models.Settings, ssoDetails *models.PerconaSSODetails) ([]byte, error) { - clickhouseDatabase := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_DATABASE", defaultClickhouseDatabase) - clickhouseAddr := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_ADDR", defaultClickhouseAddr) - clickhouseDataSourceAddr := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_DATASOURCE_ADDR", defaultClickhouseDataSourceAddr) - clickhousePoolSize := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE", "") - clickhouseBlockSize := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE", "") + clickhouseDatabase := getValueFromENV("PMM_CLICKHOUSE_DATABASE", defaultClickhouseDatabase) + clickhouseAddr := getValueFromENV("PMM_CLICKHOUSE_ADDR", defaultClickhouseAddr) + clickhouseDataSourceAddr := getValueFromENV("PMM_CLICKHOUSE_DATASOURCE_ADDR", defaultClickhouseDataSourceAddr) + clickhousePoolSize := getValueFromENV("PMM_CLICKHOUSE_POOL_SIZE", "") + clickhouseBlockSize := getValueFromENV("PMM_CLICKHOUSE_BLOCK_SIZE", "") clickhouseAddrPair := strings.SplitN(clickhouseAddr, ":", 2) vmSearchDisableCache := getValueFromENV("VM_search_disableCache", strconv.FormatBool(!settings.VictoriaMetrics.CacheEnabled)) vmSearchMaxQueryLen := getValueFromENV("VM_search_maxQueryLen", defaultVMSearchMaxQueryLen) @@ -725,10 +725,10 @@ command = /usr/sbin/percona-qan-api2 --data-retention={{ .DataRetentionDays }} environment = - PERCONA_TEST_PMM_CLICKHOUSE_ADDR="{{ .ClickhouseAddr }}", - PERCONA_TEST_PMM_CLICKHOUSE_DATABASE="{{ .ClickhouseDatabase }}", -{{ if .ClickhousePoolSize }} PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE={{ .ClickhousePoolSize }},{{- end}} -{{ if .ClickhouseBlockSize }} PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE={{ .ClickhouseBlockSize }}{{- end}} + PMM_CLICKHOUSE_ADDR="{{ .ClickhouseAddr }}", + PMM_CLICKHOUSE_DATABASE="{{ .ClickhouseDatabase }}", +{{ if .ClickhousePoolSize }} PMM_CLICKHOUSE_POOL_SIZE={{ .ClickhousePoolSize }},{{- end}} +{{ if .ClickhouseBlockSize }} PMM_CLICKHOUSE_BLOCK_SIZE={{ .ClickhouseBlockSize }}{{- end}} user = pmm autorestart = true autostart = true @@ -765,17 +765,17 @@ command = cfg:default.auth.oauth_allow_insecure_email_lookup="true" {{- end}} environment = - PERCONA_TEST_POSTGRES_ADDR="{{ .PostgresAddr }}", - PERCONA_TEST_POSTGRES_DBNAME="{{ .PostgresDBName }}", - PERCONA_TEST_POSTGRES_USERNAME="{{ .PostgresDBUsername }}", - PERCONA_TEST_POSTGRES_DBPASSWORD="{{ .PostgresDBPassword }}", - PERCONA_TEST_POSTGRES_SSL_MODE="{{ .PostgresSSLMode }}", - PERCONA_TEST_POSTGRES_SSL_CA_PATH="{{ .PostgresSSLCAPath }}", - PERCONA_TEST_POSTGRES_SSL_KEY_PATH="{{ .PostgresSSLKeyPath }}", - PERCONA_TEST_POSTGRES_SSL_CERT_PATH="{{ .PostgresSSLCertPath }}", - PERCONA_TEST_PMM_CLICKHOUSE_DATASOURCE_ADDR="{{ .ClickhouseDataSourceAddr }}", - PERCONA_TEST_PMM_CLICKHOUSE_HOST="{{ .ClickhouseHost }}", - PERCONA_TEST_PMM_CLICKHOUSE_PORT="{{ .ClickhousePort }}", + PMM_POSTGRES_ADDR="{{ .PostgresAddr }}", + PMM_POSTGRES_DBNAME="{{ .PostgresDBName }}", + PMM_POSTGRES_USERNAME="{{ .PostgresDBUsername }}", + PMM_POSTGRES_DBPASSWORD="{{ .PostgresDBPassword }}", + PMM_POSTGRES_SSL_MODE="{{ .PostgresSSLMode }}", + PMM_POSTGRES_SSL_CA_PATH="{{ .PostgresSSLCAPath }}", + PMM_POSTGRES_SSL_KEY_PATH="{{ .PostgresSSLKeyPath }}", + PMM_POSTGRES_SSL_CERT_PATH="{{ .PostgresSSLCertPath }}", + PMM_CLICKHOUSE_DATASOURCE_ADDR="{{ .ClickhouseDataSourceAddr }}", + PMM_CLICKHOUSE_HOST="{{ .ClickhouseHost }}", + PMM_CLICKHOUSE_PORT="{{ .ClickhousePort }}", {{- if .PerconaSSODetails}} GF_AUTH_SIGNOUT_REDIRECT_URL="https://{{ .IssuerDomain }}/login/signout?fromURI=https://{{ .PMMServerAddress }}/graph/login" {{- end}} diff --git a/managed/services/telemetry/config.default.yml b/managed/services/telemetry/config.default.yml index 4e9aae6820..ed7bf76dd1 100644 --- a/managed/services/telemetry/config.default.yml +++ b/managed/services/telemetry/config.default.yml @@ -965,8 +965,8 @@ telemetry: summary: "Use of External DBs" data: - metric_name: "pmm_server_ha_clickhouse_address" - column: "PERCONA_TEST_PMM_CLICKHOUSE_ADDR" + column: "PMM_CLICKHOUSE_ADDR" - metric_name: "pmm_server_ha_postgres_address" - column: "PERCONA_TEST_POSTGRES_ADDR" + column: "PMM_POSTGRES_ADDR" - metric_name: "pmm_server_ha_vm_url" column: "PMM_VM_URL" diff --git a/managed/services/telemetry/config.go b/managed/services/telemetry/config.go index 006d0fb3ba..53ccf7d42c 100644 --- a/managed/services/telemetry/config.go +++ b/managed/services/telemetry/config.go @@ -30,11 +30,11 @@ import ( ) const ( - envDisableSend = "PERCONA_TEST_TELEMETRY_DISABLE_SEND" - envConfigFile = "PERCONA_TEST_TELEMETRY_FILE" - envDisableStartDelay = "PERCONA_TEST_TELEMETRY_DISABLE_START_DELAY" - envReportingInterval = "PERCONA_TEST_TELEMETRY_INTERVAL" - envReportingRetryBackoff = "PERCONA_TEST_TELEMETRY_RETRY_BACKOFF" + envDisableSend = "PMM_DEV_TELEMETRY_DISABLE_SEND" + envConfigFile = "PMM_DEV_TELEMETRY_FILE" + envDisableStartDelay = "PMM_DEV_TELEMETRY_DISABLE_START_DELAY" + envReportingInterval = "PMM_DEV_TELEMETRY_INTERVAL" + envReportingRetryBackoff = "PMM_DEV_TELEMETRY_RETRY_BACKOFF" ) const ( diff --git a/managed/testdata/supervisord.d/grafana.ini b/managed/testdata/supervisord.d/grafana.ini index ba5408a3f4..107cdf2661 100644 --- a/managed/testdata/supervisord.d/grafana.ini +++ b/managed/testdata/supervisord.d/grafana.ini @@ -8,17 +8,17 @@ command = --config=/etc/grafana/grafana.ini cfg:default.server.domain="192.168.0.42:8443" environment = - PERCONA_TEST_POSTGRES_ADDR="127.0.0.1:5432", - PERCONA_TEST_POSTGRES_DBNAME="postgres", - PERCONA_TEST_POSTGRES_USERNAME="db_username", - PERCONA_TEST_POSTGRES_DBPASSWORD="db_password", - PERCONA_TEST_POSTGRES_SSL_MODE="verify", - PERCONA_TEST_POSTGRES_SSL_CA_PATH="path-to-CA-cert", - PERCONA_TEST_POSTGRES_SSL_KEY_PATH="path-to-key", - PERCONA_TEST_POSTGRES_SSL_CERT_PATH="path-to-cert", - PERCONA_TEST_PMM_CLICKHOUSE_DATASOURCE_ADDR="127.0.0.1:8123", - PERCONA_TEST_PMM_CLICKHOUSE_HOST="127.0.0.1", - PERCONA_TEST_PMM_CLICKHOUSE_PORT="9000", + PMM_POSTGRES_ADDR="127.0.0.1:5432", + PMM_POSTGRES_DBNAME="postgres", + PMM_POSTGRES_USERNAME="db_username", + PMM_POSTGRES_DBPASSWORD="db_password", + PMM_POSTGRES_SSL_MODE="verify", + PMM_POSTGRES_SSL_CA_PATH="path-to-CA-cert", + PMM_POSTGRES_SSL_KEY_PATH="path-to-key", + PMM_POSTGRES_SSL_CERT_PATH="path-to-cert", + PMM_CLICKHOUSE_DATASOURCE_ADDR="127.0.0.1:8123", + PMM_CLICKHOUSE_HOST="127.0.0.1", + PMM_CLICKHOUSE_PORT="9000", user = pmm directory = /usr/share/grafana autorestart = true diff --git a/managed/testdata/supervisord.d/qan-api2.ini b/managed/testdata/supervisord.d/qan-api2.ini index 94124e5afb..3422475cb7 100644 --- a/managed/testdata/supervisord.d/qan-api2.ini +++ b/managed/testdata/supervisord.d/qan-api2.ini @@ -6,8 +6,8 @@ command = /usr/sbin/percona-qan-api2 --data-retention=30 environment = - PERCONA_TEST_PMM_CLICKHOUSE_ADDR="127.0.0.1:9000", - PERCONA_TEST_PMM_CLICKHOUSE_DATABASE="pmm", + PMM_CLICKHOUSE_ADDR="127.0.0.1:9000", + PMM_CLICKHOUSE_DATABASE="pmm", user = pmm diff --git a/managed/utils/envvars/parser.go b/managed/utils/envvars/parser.go index 9e9ad2e0f8..35adf8fa2c 100644 --- a/managed/utils/envvars/parser.go +++ b/managed/utils/envvars/parser.go @@ -32,12 +32,12 @@ import ( const ( defaultPlatformAddress = "https://check.percona.com" - envPlatformAddress = "PERCONA_TEST_PLATFORM_ADDRESS" - envPlatformInsecure = "PERCONA_TEST_PLATFORM_INSECURE" - envPlatformPublicKey = "PERCONA_TEST_PLATFORM_PUBLIC_KEY" - evnInterfaceToBind = "PERCONA_TEST_INTERFACE_TO_BIND" - envEnableAccessControl = "ENABLE_RBAC" - envPlatformAPITimeout = "PERCONA_PLATFORM_API_TIMEOUT" + envPlatformAddress = "PMM_DEV_PERCONA_PLATFORM_ADDRESS" + envPlatformInsecure = "PMM_DEV_PERCONA_PLATFORM_INSECURE" + envPlatformPublicKey = "PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY" + evnInterfaceToBind = "PMM_INTERFACE_TO_BIND" + envEnableAccessControl = "PMM_ENABLE_ACCESS_CONTROL" + envPlatformAPITimeout = "PMM_DEV_PERCONA_PLATFORM_API_TIMEOUT" defaultPlatformAPITimeout = 30 * time.Second // ENVvmAgentPrefix is the prefix for environment variables related to the VM agent. ENVvmAgentPrefix = "VMAGENT_" @@ -56,13 +56,13 @@ func (e InvalidDurationError) Error() string { return string(e) } // In case of error, the docker run terminates. // Short description of environment variables: // - PATH, HOSTNAME, TERM, HOME are default environment variables that will be ignored; -// - DISABLE_UPDATES is a boolean flag to enable or disable pmm-server update; -// - DISABLE_TELEMETRY is a boolean flag to enable or disable pmm telemetry (and disable STT if telemetry is disabled); -// - DISABLE_ALERTING disables Percona Alerting; -// - METRICS_RESOLUTION, METRICS_RESOLUTION_MR, METRICS_RESOLUTION_HR, METRICS_RESOLUTION_LR are durations of metrics resolution; -// - DATA_RETENTION is the duration of how long keep time-series data in ClickHouse; -// - ENABLE_AZUREDISCOVER enables Azure Discover; -// - ENABLE_RBAC enables Access control; +// - PMM_DISABLE_UPDATES is a boolean flag to enable or disable pmm-server update; +// - PMM_DISABLE_TELEMETRY is a boolean flag to enable or disable pmm telemetry (and disable STT if telemetry is disabled); +// - PMM_DISABLE_ALERTING disables Percona Alerting; +// - PMM_METRICS_RESOLUTION, PMM_METRICS_RESOLUTION_MR, PMM_METRICS_RESOLUTION_HR, PMM_METRICS_RESOLUTION_LR are durations of metrics resolution; +// - PMM_DATA_RETENTION is the duration of how long keep time-series data in ClickHouse; +// - PMM_ENABLE_AZURE_DISCOVER enables Azure Discover; +// - PMM_ENABLE_ACCESS_CONTROL enables Access control; // - the environment variables prefixed with GF_ passed as related to Grafana. // - the environment variables relating to proxies // - the environment variable set by podman @@ -87,42 +87,47 @@ func ParseEnvVars(envs []string) (*models.ChangeSettingsParams, []error, []strin case "_", "HOME", "HOSTNAME", "LANG", "PATH", "PWD", "SHLVL", "TERM", "LC_ALL", "SHELL", "LOGNAME", "USER", "PS1": // skip default environment variables continue + case "NO_PROXY", "HTTP_PROXY", "HTTPS_PROXY": + continue + + case "CONTAINER": + continue case "PMM_DEBUG", "PMM_TRACE": // skip cross-component environment variables that are already handled by kingpin continue - case "PERCONA_TEST_VERSION_SERVICE_URL": + case "PMM_DEV_VERSION_SERVICE_URL": // skip pmm-managed environment variables that are already handled by kingpin continue - case "PERCONA_TEST_PMM_CLICKHOUSE_DATABASE", "PERCONA_TEST_PMM_CLICKHOUSE_ADDR", "PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE", "PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE": //nolint:lll + case "PMM_CLICKHOUSE_DATABASE", "PMM_CLICKHOUSE_ADDR", "PMM_CLICKHOUSE_BLOCK_SIZE", "PMM_CLICKHOUSE_POOL_SIZE": // skip env variables for external clickhouse continue - case "DISABLE_UPDATES": + case "PMM_DISABLE_UPDATES": envSettings.DisableUpdates, err = strconv.ParseBool(v) if err != nil { err = fmt.Errorf("invalid value %q for environment variable %q", v, k) } - case "DISABLE_TELEMETRY": + case "PMM_DISABLE_TELEMETRY": envSettings.DisableTelemetry, err = strconv.ParseBool(v) if err != nil { err = fmt.Errorf("invalid value %q for environment variable %q", v, k) } - case "METRICS_RESOLUTION", "METRICS_RESOLUTION_HR": + case "PMM_METRICS_RESOLUTION", "PMM_METRICS_RESOLUTION_HR": if envSettings.MetricsResolutions.HR, err = parseStringDuration(v); err != nil { err = formatEnvVariableError(err, env, v) } - case "METRICS_RESOLUTION_MR": + case "PMM_METRICS_RESOLUTION_MR": if envSettings.MetricsResolutions.MR, err = parseStringDuration(v); err != nil { err = formatEnvVariableError(err, env, v) } - case "METRICS_RESOLUTION_LR": + case "PMM_METRICS_RESOLUTION_LR": if envSettings.MetricsResolutions.LR, err = parseStringDuration(v); err != nil { err = formatEnvVariableError(err, env, v) } - case "DATA_RETENTION": + case "PMM_DATA_RETENTION": if envSettings.DataRetention, err = parseStringDuration(v); err != nil { err = formatEnvVariableError(err, env, v) } - case "ENABLE_VM_CACHE": + case "PMM_ENABLE_VM_CACHE": envSettings.EnableVMCache, err = strconv.ParseBool(v) if err != nil { err = fmt.Errorf("invalid value %q for environment variable %q", v, k) @@ -131,28 +136,22 @@ func ParseEnvVars(envs []string) (*models.ChangeSettingsParams, []error, []strin // disable cache explicitly envSettings.DisableVMCache = true } - case "DISABLE_ALERTING": + case "PMM_DISABLE_ALERTING": envSettings.DisableAlerting, err = strconv.ParseBool(v) if err != nil { err = fmt.Errorf("invalid value %q for environment variable %q", v, k) } - case "ENABLE_AZUREDISCOVER": + case "PMM_ENABLE_AZURE_DISCOVER": envSettings.EnableAzurediscover, err = strconv.ParseBool(v) if err != nil { err = fmt.Errorf("invalid value %q for environment variable %q", v, k) } - case "DISABLE_BACKUP_MANAGEMENT": + case "PMM_DISABLE_BACKUP_MANAGEMENT": envSettings.DisableBackupManagement, err = strconv.ParseBool(v) if err != nil { err = fmt.Errorf("invalid value %q for environment variable %q", v, k) } - case "PERCONA_TEST_AUTH_HOST", "PERCONA_TEST_CHECKS_HOST", "PERCONA_TEST_TELEMETRY_HOST", "PERCONA_TEST_SAAS_HOST": - warns = append(warns, fmt.Sprintf("environment variable %q is removed and replaced by %q", k, envPlatformAddress)) - - case "PERCONA_TEST_CHECKS_PUBLIC_KEY": - warns = append(warns, fmt.Sprintf("environment variable %q is removed and replaced by %q", k, envPlatformPublicKey)) - case "PMM_PUBLIC_ADDRESS": envSettings.PMMPublicAddress = v @@ -162,12 +161,6 @@ func ParseEnvVars(envs []string) (*models.ChangeSettingsParams, []error, []strin err = fmt.Errorf("invalid value %q for environment variable %q", v, k) } - case "NO_PROXY", "HTTP_PROXY", "HTTPS_PROXY": - continue - - case "CONTAINER": - continue - case "PMM_INSTALL_METHOD": continue @@ -217,12 +210,23 @@ func ParseEnvVars(envs []string) (*models.ChangeSettingsParams, []error, []strin continue } - if !strings.HasPrefix(k, "PERCONA_TEST_") { - warns = append(warns, fmt.Sprintf("unknown environment variable %q", env)) + // skip PMM development environment variables + if strings.HasPrefix(k, "PMM_DEV_") { + continue + } + + // skip PMM test environment variables + if strings.HasPrefix(k, "PMM_TEST_") { + warns = append(warns, fmt.Sprintf("environment variable %q may be removed or replaced in the future", env)) + continue + } + + if strings.HasPrefix(k, "PERCONA_") { + warns = append(warns, "PERCONA_* env variables IS NOT SUPPORTED, please use PMM_* env variables, for details please check our documentation") continue } - warns = append(warns, fmt.Sprintf("environment variable %q IS NOT SUPPORTED and WILL BE REMOVED IN THE FUTURE", k)) + warns = append(warns, fmt.Sprintf("unknown environment variable %q", env)) } if err != nil { diff --git a/managed/utils/envvars/parser_test.go b/managed/utils/envvars/parser_test.go index 2d823ea055..2e1c910f8d 100644 --- a/managed/utils/envvars/parser_test.go +++ b/managed/utils/envvars/parser_test.go @@ -33,12 +33,12 @@ func TestEnvVarValidator(t *testing.T) { t.Parallel() envs := []string{ - "DISABLE_UPDATES=True", - "DISABLE_TELEMETRY=True", - "METRICS_RESOLUTION=5m", - "METRICS_RESOLUTION_MR=5s", - "METRICS_RESOLUTION_LR=1h", - "DATA_RETENTION=72h", + "PMM_DISABLE_UPDATES=True", + "PMM_DISABLE_TELEMETRY=True", + "PMM_METRICS_RESOLUTION=5m", + "PMM_METRICS_RESOLUTION_MR=5s", + "PMM_METRICS_RESOLUTION_LR=1h", + "PMM_DATA_RETENTION=72h", } expectedEnvVars := &models.ChangeSettingsParams{ DataRetention: 72 * time.Hour, @@ -117,26 +117,26 @@ func TestEnvVarValidator(t *testing.T) { t.Parallel() envs := []string{ - "DISABLE_UPDATES", - "DISABLE_TELEMETRY", - "DISABLE_UPDATES=5", - "DISABLE_TELEMETRY=X", - "METRICS_RESOLUTION=5f", - "METRICS_RESOLUTION_MR=s5", - "METRICS_RESOLUTION_LR=1hour", - "DATA_RETENTION=keep one week", + "PMM_DISABLE_UPDATES", + "PMM_DISABLE_TELEMETRY", + "PMM_DISABLE_UPDATES=5", + "PMM_DISABLE_TELEMETRY=X", + "PMM_METRICS_RESOLUTION=5f", + "PMM_METRICS_RESOLUTION_MR=s5", + "PMM_METRICS_RESOLUTION_LR=1hour", + "PMM_DATA_RETENTION=keep one week", } expectedEnvVars := &models.ChangeSettingsParams{} expectedErrs := []error{ - fmt.Errorf(`failed to parse environment variable "DISABLE_UPDATES"`), - fmt.Errorf(`failed to parse environment variable "DISABLE_TELEMETRY"`), - fmt.Errorf(`invalid value "5" for environment variable "DISABLE_UPDATES"`), - fmt.Errorf(`invalid value "x" for environment variable "DISABLE_TELEMETRY"`), - fmt.Errorf(`environment variable "METRICS_RESOLUTION=5f" has invalid duration 5f`), - fmt.Errorf(`environment variable "METRICS_RESOLUTION_MR=s5" has invalid duration s5`), - fmt.Errorf(`environment variable "METRICS_RESOLUTION_LR=1hour" has invalid duration 1hour`), - fmt.Errorf(`environment variable "DATA_RETENTION=keep one week" has invalid duration keep one week`), + fmt.Errorf(`failed to parse environment variable "PMM_DISABLE_UPDATES"`), + fmt.Errorf(`failed to parse environment variable "PMM_DISABLE_TELEMETRY"`), + fmt.Errorf(`invalid value "5" for environment variable "PMM_DISABLE_UPDATES"`), + fmt.Errorf(`invalid value "x" for environment variable "PMM_DISABLE_TELEMETRY"`), + fmt.Errorf(`environment variable "PMM_METRICS_RESOLUTION=5f" has invalid duration 5f`), + fmt.Errorf(`environment variable "PMM_METRICS_RESOLUTION_MR=s5" has invalid duration s5`), + fmt.Errorf(`environment variable "PMM_METRICS_RESOLUTION_LR=1hour" has invalid duration 1hour`), + fmt.Errorf(`environment variable "PMM_DATA_RETENTION=keep one week" has invalid duration keep one week`), } gotEnvVars, gotErrs, gotWarns := ParseEnvVars(envs) @@ -145,57 +145,33 @@ func TestEnvVarValidator(t *testing.T) { assert.Nil(t, gotWarns) }) - t.Run("PERCONA_TEST_PLATFORM_ADDRESS env vars with warnings", func(t *testing.T) { + t.Run("v2 valid env vars with 'PERCONA_*' prefix show warnings", func(t *testing.T) { t.Parallel() envs := []string{ "PERCONA_TEST_PLATFORM_ADDRESS=https://host:333", - } - expectedEnvVars := &models.ChangeSettingsParams{} - expectedWarns := []string{ - `environment variable "PERCONA_TEST_PLATFORM_ADDRESS" IS NOT SUPPORTED and WILL BE REMOVED IN THE FUTURE`, - } - - gotEnvVars, gotErrs, gotWarns := ParseEnvVars(envs) - assert.Nil(t, gotErrs) - assert.Equal(t, expectedEnvVars, gotEnvVars) - assert.Equal(t, expectedWarns, gotWarns) - }) - - t.Run("PERCONA_TEST_CHECKS_PUBLIC_KEY env vars with warnings", func(t *testing.T) { - t.Parallel() - - envs := []string{ "PERCONA_TEST_CHECKS_PUBLIC_KEY=some key", + "PERCONA_TEST_AUTH_HOST=host:333", + "PERCONA_TEST_CHECKS_HOST=host:333", + "PERCONA_TEST_TELEMETRY_HOST=host:333", + "PERCONA_TEST_SAAS_HOST=host:333", } expectedEnvVars := &models.ChangeSettingsParams{} expectedWarns := []string{ - `environment variable "PERCONA_TEST_CHECKS_PUBLIC_KEY" is removed and replaced by "PERCONA_TEST_PLATFORM_PUBLIC_KEY"`, + `PERCONA_* env variables IS NOT SUPPORTED, please use PMM_* env variables, for details please check our documentation`, + `PERCONA_* env variables IS NOT SUPPORTED, please use PMM_* env variables, for details please check our documentation`, + `PERCONA_* env variables IS NOT SUPPORTED, please use PMM_* env variables, for details please check our documentation`, + `PERCONA_* env variables IS NOT SUPPORTED, please use PMM_* env variables, for details please check our documentation`, + `PERCONA_* env variables IS NOT SUPPORTED, please use PMM_* env variables, for details please check our documentation`, + `PERCONA_* env variables IS NOT SUPPORTED, please use PMM_* env variables, for details please check our documentation`, } - gotEnvVars, gotErrs, gotWarns := ParseEnvVars(envs) - assert.Nil(t, gotErrs) + gotEnvVars, _, gotWarns := ParseEnvVars(envs) + // assert.Nil(t, gotErrs) assert.Equal(t, expectedEnvVars, gotEnvVars) assert.Equal(t, expectedWarns, gotWarns) }) - t.Run("SAAS env vars with errors", func(t *testing.T) { - t.Parallel() - - for _, k := range []string{ - "PERCONA_TEST_AUTH_HOST", - "PERCONA_TEST_CHECKS_HOST", - "PERCONA_TEST_TELEMETRY_HOST", - "PERCONA_TEST_SAAS_HOST", - } { - expected := fmt.Sprintf(`environment variable %q is removed and replaced by "PERCONA_TEST_PLATFORM_ADDRESS"`, k) - envs := []string{k + "=host:333"} - _, gotErrs, gotWarns := ParseEnvVars(envs) - assert.Equal(t, []string{expected}, gotWarns) - assert.Nil(t, gotErrs) - } - }) - t.Run("Parse Platform API Timeout", func(t *testing.T) { t.Parallel() @@ -206,7 +182,7 @@ func TestEnvVarValidator(t *testing.T) { }{ { value: "", respVal: time.Second * 30, - msg: "Environment variable \"PERCONA_PLATFORM_API_TIMEOUT\" is not set, using \"30s\" as a default timeout for platform API.", + msg: "Environment variable \"PMM_DEV_PERCONA_PLATFORM_API_TIMEOUT\" is not set, using \"30s\" as a default timeout for platform API.", }, { value: "10s", respVal: time.Second * 10, diff --git a/managed/utils/interceptors/interceptors.go b/managed/utils/interceptors/interceptors.go index 8a3a4e7173..a246c7c8bd 100644 --- a/managed/utils/interceptors/interceptors.go +++ b/managed/utils/interceptors/interceptors.go @@ -94,7 +94,7 @@ func Unary(interceptor grpc.UnaryServerInterceptor) UnaryInterceptorType { l := logrus.WithField("request", logger.MakeRequestID()) ctx = logger.SetEntry(ctx, l) - if info.FullMethod == "/server.Server/Readiness" && os.Getenv("LESS_LOG_NOISE") != "" { + if info.FullMethod == "/server.Server/Readiness" && os.Getenv("PMM_LESS_LOG_NOISE") != "" { l = logrus.NewEntry(logrus.New()) l.Logger.SetOutput(io.Discard) } diff --git a/qan-api2/main.go b/qan-api2/main.go index df5457964d..c1496b1e76 100644 --- a/qan-api2/main.go +++ b/qan-api2/main.go @@ -262,12 +262,12 @@ func main() { debugBindF := kingpin.Flag("listen-debug-addr", "Debug server listen address").Default("127.0.0.1:9933").String() dataRetentionF := kingpin.Flag("data-retention", "QAN data Retention (in days)").Default("30").Uint() dsnF := kingpin.Flag("dsn", "ClickHouse database DSN. Can be override with database/host/port options").Default(defaultDsnF).String() - clickHouseDatabaseF := kingpin.Flag("clickhouse-name", "Clickhouse database name").Default("pmm").Envar("PERCONA_TEST_PMM_CLICKHOUSE_DATABASE").String() - clickhouseAddrF := kingpin.Flag("clickhouse-addr", "Clickhouse database address").Default("127.0.0.1:9000").Envar("PERCONA_TEST_PMM_CLICKHOUSE_ADDR").String() + clickHouseDatabaseF := kingpin.Flag("clickhouse-name", "Clickhouse database name").Default("pmm").Envar("PMM_CLICKHOUSE_DATABASE").String() + clickhouseAddrF := kingpin.Flag("clickhouse-addr", "Clickhouse database address").Default("127.0.0.1:9000").Envar("PMM_CLICKHOUSE_ADDR").String() clickhouseBlockSizeF := kingpin.Flag("clickhouse-block-size", "Number of rows that can be load from table in one cycle"). - Default("10000").Envar("PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE").String() + Default("10000").Envar("PMM_CLICKHOUSE_BLOCK_SIZE").String() clickhousePoolSizeF := kingpin.Flag("clickhouse-pool-size", "Controls how much queries can be run simultaneously"). - Default("2").Envar("PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE").String() + Default("2").Envar("PMM_CLICKHOUSE_POOL_SIZE").String() debugF := kingpin.Flag("debug", "Enable debug logging").Bool() traceF := kingpin.Flag("trace", "Enable trace logging (implies debug)").Bool()