8000 feat: allow overriding metrics-exporter log verbosity via env (#1793) by Slach · Pull Request #2131 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content

feat: allow overriding metrics-exporter log verbosity via env (#1793) - #2131

Merged
alex-zaitsev merged 5 commits into
0.28.0from
feat/1793-metrics-exporter-verbosity
Nov 6, 2026
Merged

alex-zaitsev merged 5 commits into
0.28.0from
feat/1793-metrics-exporter-verbosity

Conversation

@Slach
@Slach Slach commented Nov 1, 2026 •
Copy link
Copy Markdown
Collaborator

fixes #1793

Problem

The operator and the metrics-exporter read the same configuration file, and chop.SetupLog() applies logger.* from it via flag.Set, overwriting the -v passed on the command line. So there was no way to make the metrics-exporter quieter (or more verbose) without changing the operator's logging too, short of replacing the whole config or overriding container args.

Design

Precedence: config file logger.* value, overridden by an env var when set (non-empty). This is the first step of the config file -> env vars -> CLI params direction suggested in the issue, scoped to logger options.

  • New env vars in pkg/apis/deployment/env_vars.go, one per logger.* option:
    CHOP_LOGGER_LOGTOSTDERR, CHOP_LOGGER_ALSOLOGTOSTDERR, CHOP_LOGGER_STDERRTHRESHOLD, CHOP_LOGGER_V, CHOP_LOGGER_VMODULE, CHOP_LOGGER_LOG_BACKTRACE_AT.
  • SetupLog() is now table-driven and applies the env value over the config value. Behavior with no env vars set is unchanged.
  • The env var is read by the process of the container it is set in, so it is naturally per-container.
  • Helm: new metrics.logVerbosity value (empty by default), rendered as CHOP_LOGGER_V into the metrics-exporter container only (via a _helpers.tpl include; 0 is handled as a valid value). It is rendered before metrics.env, so an explicit metrics.env entry still wins. The generated Deployment template is produced by dev/generate_helm_chart.sh, which was updated accordingly; values.schema.json and the helm-docs README are updated.
  • Docs: new "Logging" section in docs/operator_configuration.md.

Usage

Helm:

metrics:
  logVerbosity: 0
  # any other logger option through metrics.env:
  env:
    - name: CHOP_LOGGER_VMODULE
      value: "metrics_exporter=2"

Plain manifest, in the metrics-exporter container:

env:
  - name: CHOP_LOGGER_V
    value: "0"

Tests

  • pkg/chop/setup_log_test.go: env overrides config value; options without env keep config value; env applies when config is empty; empty env does not override.
  • go build ./...
  • go test -vet=off -race -count=1 ./pkg/chop/... ./pkg/apis/... - pass
  • go vet -copylocks=false -printf=false ./pkg/chop/... ./pkg/apis/deployment/... - pass
  • helm template with no value (no env rendered), logVerbosity=0, --set-string logVerbosity=3, null, and together with metrics.env; helm lint; dev/test_helm_chart.sh - 24 checks passed.

@Slach Slach linked an issue Nov 3, 2026 that may be closed by this pull request
Add CHOP_LOGGER_* env vars (LOGTOSTDERR, ALSOLOGTOSTDERR, STDERRTHRESHOLD,
V, VMODULE, LOG_BACKTRACE_AT) that override the matching logger.* options
of the operator configuration in the process they are set for. This lets
the metrics-exporter use its own verbosity while sharing the config file
with the operator.

Helm: add metrics.logVerbosity (empty by default), rendered as CHOP_LOGGER_V
into the metrics-exporter container only.

Fixes #1793

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Slach
Slach force-pushed the feat/1793-metrics-exporter-verbosity branch from 1699d9e to 35803ee Compare November 3, 2026 05:02
@alex-zaitsev
Copy link
Copy Markdown
Member

Why is it needed? Would it be better to use operator configuration?

@Slach
Slach commented Nov 4, 2026
Copy link
Copy Markdown
Collaborator Author

@alex-zaitsev for example we need to debug metrics-exporter but don't need increase verbosity for clickhouse-operator, and invariant - debug clickhouse-operator and don't increase logs verbosiry for metrics-exporter

@Slach
Slach commented Nov 4, 2026
Copy link
Copy Markdown
Collaborator Author

@alex-zaitsev operator configuration can't do this: both clickhouse-operator and metrics-exporter containers mount the same /etc/clickhouse-operator and both call chop.SetupLog(), so logger.v from the config applies to both. Moreover, SetupLog() applies it via flag.Set after CLI parsing, so even overriding args: -v=0 on the metrics-exporter container (the workaround mentioned in #1793) gets overwritten by logger.v: "1" from the default config.

The original request in #1793 is to reduce metrics-exporter log noise (with -v=1 it dumps manifests) while keeping operator logs unchanged; the reverse case is debugging the operator without flooding exporter logs. An env var is read only by the container it's set in, so it's naturally per-container, and it follows the config file -> env vars -> CLI precedence you suggested in #1793.

@Slach
Slach commented Nov 5, 2026
Copy link
Copy Markdown
Collaborator Author

Helm example, different logging for operator and metrics-exporter:

configs:
  files:
    config.yaml:
      logger:
        v: "3"          # default for both containers
operator:
  env:
    - name: CHOP_LOGGER_VMODULE
      value: "worker*=5"
metrics:
  logVerbosity: 0       # CHOP_LOGGER_V for metrics-exporter only
  env:
    - name: CHOP_LOGGER_VMODULE
      value: "exporter=2"

Slach and others added 3 commits November 5, 2026 12:57
Render operator.logVerbosity as CHOP_LOGGER_V into the clickhouse-operator
container only, symmetric to metrics.logVerbosity, so operator and
metrics-exporter verbosity can be set independently via helm values.

Refs #1793

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alex-zaitsev
alex-zaitsev merged commit 3fb4660 into 0.28.0 Nov 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure Metrics Exporter Verbosity via Deployment Variables

2 participants

0