Skip to content

Allow configuring syslog program name for ClickHouse logs - #98789

Merged
Algunenano merged 3 commits into
ClickHouse:masterfrom
martinfrancois:issue-11784
Oct 2, 2026
Merged

Algunenano merged 3 commits into
ClickHouse:masterfrom
martinfrancois:issue-11784

Conversation

@martinfrancois

@martinfrancois martinfrancois commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

You can now set a custom syslog program name for ClickHouse logs using logger.syslog.programname, making it easier to distinguish multiple ClickHouse instances in syslog. The default syslog identifier is now command-specific: remote syslog previously sent - as the RFC 5424 APP-NAME and now sends the command name (for example clickhouse-server), and the multi-purpose binary started as clickhouse server or clickhouse keeper now uses clickhouse-server / clickhouse-keeper instead of clickhouse for local syslog.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Motivation:
Allow users to set a stable, custom syslog program identifier (e.g., environment-specific identifiers) instead of relying solely on the binary command name.

Parameters:

  • logger.syslog.programname: Program name for syslog records. If not set, defaults to the name of the ClickHouse command you started (for example, clickhouse-server or clickhouse-keeper).
  • logger.syslog.format: With format=syslog, programname is used as RFC 5424 APP-NAME. With format=bsd, programname has no effect.

Example use:

<logger>
    <use_syslog>1</use_syslog>
    <syslog>
        <programname>clickhouse-production-scc</programname>
        <address>syslog.remote:10514</address>
        <format>syslog</format>
    </syslog>
</logger>

Design decisions and alternatives considered

It's been a long time since I last wrote C++ code. I hope the code is decent; otherwise, let me know, and I'll happily make changes! :)

  1. Where to apply programname:
  • Chosen: set both Poco::SyslogChannel::PROP_NAME (local syslog) and Poco::Net::RemoteSyslogChannel::PROP_NAME (remote syslog).
  • Alternative: apply only to local syslog or only to remote syslog.
  • Why not: issue scope and user expectation are the same setting for syslog output regardless of transport.
  1. Default value strategy:
  • Chosen: logger.syslog.programname defaults to cmd_name in buildLoggers, which maps to the ClickHouse command name used to start the process.
  • Alternative: default to a hardcoded constant like clickhouse.
  • Why not: command-specific defaults (clickhouse-server, clickhouse-keeper, etc.) are more informative.
  • Note that this does change the default identifier in two ways, both documented in the programname docs section. Remote syslog never set PROP_NAME before, so Poco left its "-" default and every RFC 5424 record carried - as APP-NAME; those records now carry clickhouse-server / clickhouse-keeper. Local syslog already used cmd_name, but for the multi-purpose binary that was clickhouse, and it is now the subcommand-specific name. Users who filter on the old values can pin them with an explicit programname.
  1. Where the subcommand-specific default is supplied:
  • Chosen: a protected virtual std::string BaseDaemon::getCommandName() (defaulting to Poco's commandName()), overridden by Server and Keeper, used by BaseDaemon::initialize on the first buildLoggers call.
  • Alternative: pass the command name at the later buildLoggers call sites in Server.cpp / Keeper.cpp, or include cmd_name in the config_logger cache key.
  • Why not: the later buildLoggers calls early-return on the config_logger guard, so passing the name there is dead code; and widening the cache key would rebuild every channel (file, error log, console, syslog) a second time on each startup, which is a far larger behavior change than this feature needs. commandName() alone is also not enough, because programs/main.cpp erases the subcommand argument, so clickhouse server reports clickhouse.
  • The substitution is applied only when the executable's full file name is exactly clickhouse, via BaseDaemon::disambiguateCommandName, which delegates to the free function disambiguateClickHouseCommandName(executable_file_name, command_name, subcommand_name). The decision deliberately uses Poco's application.name rather than commandName(): commandName() is application.baseName, and Poco::Path::getBaseName truncates at the last dot, so a binary named clickhouse.prod reports commandName() == "clickhouse" without being the multi-purpose binary. Deciding on the base name would silently rewrite that deployment's syslog identifier. The mapping lives in a free function so it can be unit-tested directly: constructing any Poco::Util::Application asserts that it is the only instance in the process and installs process-wide signal handlers, which is not acceptable inside the shared unit_tests_dbms binary. src/Daemon/tests/gtest_daemon_command_name.cpp covers the multi-purpose binary, dedicated binaries and symlinks, renamed binaries, and near-miss names. Symlinks and dedicated binaries (clickhouse-server, clickhouse-keeper) already report an unambiguous name, and every other executable keeps the identifier it reported before this change, so no existing syslog identifier changes except in the genuinely ambiguous multi-tool case.
  1. Test cleanup of global logger state:
  • Chosen: LoggerStateGuard snapshots the root channel/level plus the channel and level of every pre-existing logger, holding each channel through a shared Poco::AutoPtr so it stays alive, and restores them exactly.
  • Alternative: restore only levels and repoint every pre-existing logger at the root channel.
  • Why not: buildLoggers repoints every already-created logger at a channel owned by the test's Loggers instance, so the channels do have to be restored to avoid dangling pointers. Falling back to the root channel is not a safe substitute, because the root channel is null in a fresh process and that would silently mute loggers created by earlier tests in the same binary, which is an order-dependent side effect under --gtest_shuffle. Taking a shared reference makes exact restoration safe, since the saved channel cannot be destroyed while the guard holds it.
  1. format=bsd behavior:
  • Chosen: document that remote BSD format has no effect on programname.
  • Alternative: synthesize a custom identifier in the message body for BSD mode.
  • Why not: out of scope for this issue and would diverge from current channel semantics.
  1. Terminology in documentation:
  • Chosen: use RFC 5424 term APP-NAME directly and avoid legacy TAG wording.
  • Alternative: describe it as APP-NAME/tag or explain RFC 3164 TAG decomposition.
  • Why not: this issue is about current behavior and config semantics; adding legacy terminology increases ambiguity without improving user outcomes.
  1. Document pre-existing logger.syslog.options:
  • Chosen: add a dedicated docs row for logger.syslog.options.
  • Alternative: keep it undocumented or mention it only indirectly under programname.
  • Why not: while implementing this issue, I noticed this setting already exists in code but was missing from docs. Documenting it now aligns docs with existing behavior and makes local syslog configuration easier to discover.
  1. Validation of programname:
  • Chosen: reject explicitly configured values that are not valid RFC 5424 APP-NAME tokens (empty, longer than 48 characters, or containing bytes outside printable ASCII %d33-126), raising BAD_ARGUMENTS at startup.
  • Alternative: accept anything and let the value reach the channel, sanitize silently, or validate only for remote syslog with format=syslog.
  • Why not: RemoteSyslogChannel::log writes the name verbatim between HOSTNAME and PROCID, so whitespace shifts every following header field and produces a malformed record; silent sanitization would hide the misconfiguration. Validating only in the remote/non-BSD case would mean a config that validates today starts failing after an unrelated format or address change.
  • The cmd_name fallback is deliberately never rejected, since it derives from the binary name and refusing to start because of an unusual argv[0] would punish deployments that never touched this setting. It is still not allowed to produce a malformed header: on the remote path, where the name was previously never set at all, PROP_NAME is only assigned when the derived value is a valid APP-NAME, so an unusual binary name leaves Poco's - default in place. Local syslog keeps receiving cmd_name unchecked, which is exactly what it received before this PR.

Testing

Targeted unit-test validation ran locally (not full suite):

  • ninja unit_tests_dbms (in build_min)
  • ./build_min/src/unit_tests_dbms --gtest_filter='Loggers.RemoteSyslogProgramName*'
  • ./build_min/src/unit_tests_dbms --gtest_filter='AccessRights.Radix:Loggers.RemoteSyslogProgramName*'

Only the _server_settings_outside_source.mdx source fragment is edited. The generated page docs/reference/settings/server-settings/settings/other.mdx is deliberately left alone, because the No direct edits to generated or read-only docs check rejects edits inside autogenerated regions unless the PR carries the pr-autogenerated-docs label. The nightly autogen job regenerates that page from this fragment. Maintainers who want the generated page refreshed within this PR can add the label and I will commit the regenerated output.

Closes: #11784

Additional note:
While working on this change, I noticed that logger.syslog.options is already implemented in Loggers::buildLoggers, but it was not documented as a dedicated key in the syslog settings table. I added explicit documentation for it in this PR to match existing behavior and improve discoverability.


Workflow [PR]
Sync PR [sync-upstream/pr/98789]

Version info

  • Merged into: 26.10.1.1275-master (included in 26.10 and later)

@martinfrancois
martinfrancois force-pushed the issue-11784 branch 3 times, most recently from 9f2d5c2 to 70ac6ab Compare March 4, 2026 22:00
@rschu1ze

Copy link
Copy Markdown
Member

@mstetsyuk or @bharatnc Would you be interested in reviewing this PR?

@mstetsyuk mstetsyuk self-assigned this Mar 24, 2026
@mstetsyuk
mstetsyuk self-requested a review March 24, 2026 12:15
@clickhouse-gh

clickhouse-gh Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [82a31a8]

Summary: ✅


AI Review

Summary

This PR has been simplified down to the explicit logger.syslog.programname setting in src/Loggers/Loggers.cpp and the matching prose update in the server-settings source fragment. The code change itself looks reasonable, but the generated server-settings page is no longer in sync with that source fragment, and the PR metadata/changelog text still promises the earlier default-identifier behavior that is no longer in the diff.

PR Metadata
  • Changelog category: New Feature is correct for adding logger.syslog.programname.
  • Changelog entry: required, but the current text overstates the shipped behavior. The implementation in src/Loggers/Loggers.cpp:239 only uses logger.syslog.programname when it is configured explicitly; it does not make remote syslog default to the command name, and this PR no longer changes the multi-purpose binary's default local ident either.
  • Exact replacement text: You can now set a custom syslog program name for ClickHouse logs with the logger.syslog.programname server setting.
  • The PR body should also drop the motivation/design text about changing the default identifiers for remote syslog and for clickhouse server / clickhouse keeper, because those code paths are no longer part of the current change.
Findings

⚠️ Majors

  • [docs/reference/settings/server-settings/settings/other.mdx:724] The checked-in generated server-settings page is still out of sync with the updated source fragment in docs/reference/settings/server-settings/_server_settings_outside_source.mdx:847 and docs/reference/settings/server-settings/_server_settings_outside_source.mdx:864: the published example still omits <programname>, and the table still has no programname row. If this merges as-is, the user-facing settings page will not document the new setting.
    Suggested fix: rerun the server-settings autogeneration and include the refreshed docs/reference/settings/server-settings/settings/other.mdx output from the updated fragment through the generated-docs workflow (for example with the pr-autogenerated-docs label).

💡 Nits

  • [docs/reference/settings/server-settings/_server_settings_outside_source.mdx:863] The format row still documents the literal as syslog. with the period inside the code span. Regenerating the output page without fixing the source fragment will keep reintroducing that typo.
    Suggested fix: change the literal to syslog.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    1. Regenerate docs/reference/settings/server-settings/settings/other.mdx from the updated fragment and land that generated update through the generated-docs workflow so the published docs pick up programname.
    2. Trim the PR description/changelog entry so it matches the simplified implementation that only adds the explicit logger.syslog.programname setting.
    3. Fix the syslog. typo in the source fragment before regenerating the docs page.

LLVM Coverage Report

Measured on commit 82a31a8.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 2/28 (7.14%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Apr 2, 2026
@mstetsyuk mstetsyuk added the can be tested Allows running workflows for external contributors label Apr 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Dear @mstetsyuk, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@mstetsyuk mstetsyuk self-assigned this Jun 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Dear @mstetsyuk, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

Comment thread programs/server/Server.cpp Resolved
Comment thread src/Loggers/Loggers.cpp Resolved
@martinfrancois
martinfrancois force-pushed the issue-11784 branch 2 times, most recently from cddd84b to bd922aa Compare August 8, 2026 02:10
Comment thread programs/server/Server.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 82a31a8b5 with master 728262641 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline.

Job report

Comment thread src/Loggers/Loggers.cpp Resolved
| `facility` | The syslog [facility keyword](https://en.wikipedia.org/wiki/Syslog#Facility). Must be specified uppercase with a "LOG_" prefix, e.g. `LOG_USER`, `LOG_DAEMON`, `LOG_LOCAL3`, etc. Default: `LOG_USER` if `address` is specified, `LOG_DAEMON` otherwise. |
| `format` | Log message format. Possible values: `bsd` and `syslog.` |
| `format` | Log message format. Possible values: `bsd` and `syslog` |
| `programname` | Program name used to identify ClickHouse in syslog messages. For remote syslog with `format=syslog` (RFC 5424), this is sent as `APP-NAME`. With `format=bsd` (RFC 3164), `programname` has no effect. Must be 1 to 48 printable ASCII characters without spaces, as required for RFC 5424 `APP-NAME`; other values are rejected at startup. Default: name of the ClickHouse command you started, for example `clickhouse-server` or `clickhouse-keeper`. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fragment feeds the generated server-settings page, but the checked-in output page is still stale: docs/reference/settings/server-settings/settings/other.mdx still shows the old syslog table without programname/options and still has the old syslog. typo.

ci/jobs/scripts/docs/autogenerate/autogenerate_docs.py stages _server_settings_outside_source.mdx and rewrites the generated settings pages, so the user-facing docs are not actually updated until that autogen step is run and the resulting page is committed. Since this PR is marked as a documented new feature, please regenerate the server-settings docs (or include the generated settings/other.mdx update in the same change) so the published page matches this source fragment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in e52faaf.

docs/reference/settings/server-settings/settings/other.mdx:729 did still carry the old table, without programname and options and with the syslog. typo, so the published page would not have matched this fragment. The autogen runs as a nightly job rather than on PR CI, so it would not have been reconciled before this PR merged.

I cannot run autogenerate_docs.py --write here, because the settings generators execute SQL against a running ClickHouse instance and there is no build toolchain in this environment. Since the syslog block is copied verbatim from this fragment into the generated page, I took the option you offered and committed the generated settings/other.mdx update in the same change, replacing its **syslog** through **Log formats** section with the identical section from this file. The two are now byte-identical, so the next autogen run is a no-op for this block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction to my previous reply: I had to revert the generated-page part of this.

Committing settings/other.mdx fails the Docs check (Mintlify) job, specifically its No direct edits to generated or read-only docs step:

Direct edits inside AUTOGENERATED regions detected:

  docs/reference/settings/server-settings/settings/other.mdx

Edit the generator's source data instead. Intentional generated-docs updates must carry the 'pr-autogenerated-docs' label.

So the option you suggested is gated on a label that I cannot apply as an external contributor, and applying it would be a maintainer decision about bypassing that check rather than mine to make. Reverted in abecf53; the PR now touches only the _server_settings_outside_source.mdx source fragment, which is the "edit the generator's source data" path the check asks for.

Your underlying observation stands, and I am not claiming it is resolved: the published page is stale until the autogen runs, and that job is nightly rather than per-PR. What I can say is that the source of truth is correct now, so the next autogen run picks the change up with no further action. If a maintainer would rather have the regenerated page inside this PR, add the pr-autogenerated-docs label and I will commit the regenerated output.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs/reference/settings/server-settings/settings/other.mdx:724 is back to the pre-fix generated text on the current branch: the example still has no <programname> line, and the table still ends at format on docs/reference/settings/server-settings/settings/other.mdx:745, while the source fragment now documents programname at docs/reference/settings/server-settings/_server_settings_outside_source.mdx:847 and docs/reference/settings/server-settings/_server_settings_outside_source.mdx:864.

Also, the source fragment itself still spells the format literal as syslog. at docs/reference/settings/server-settings/_server_settings_outside_source.mdx:863, so rerunning the autogen needs that fix as well.

@martinfrancois
martinfrancois force-pushed the issue-11784 branch 4 times, most recently from 8b4edce to abecf53 Compare August 8, 2026 12:13
Comment thread src/Daemon/BaseDaemon.cpp Resolved
@martinfrancois

martinfrancois commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor Author

@mstetsyuk this is ready for another look when you have time.

All review bot comments are now addressed, each with a reply in its thread. Summary of what changed in response:

  • Subcommand default never applied. BaseDaemon::initialize runs buildLoggers first and the later calls in Server.cpp / Keeper.cpp early-return on the config_logger guard, so the name passed there was dead code. Moved onto the first initialization path via a virtual getCommandName().
  • Renamed binaries losing their identifier. The override is now applied only for the genuinely ambiguous multi-tool case, via disambiguateClickHouseCommandName.
  • Dotted binary names. Poco::Path::getBaseName truncates at the last dot, so clickhouse.prod reached that code as clickhouse and was being rewritten. The ambiguity check now uses the full executable file name (application.name) instead of commandName().
  • RFC 5424 validation. An explicitly configured programname is validated and rejected at startup if it is not a valid APP-NAME. The cmd_name fallback is never rejected, but on the remote path it is only used when valid, so Poco's - default is preserved rather than emitting a malformed header.
  • Documented behavior changes. Remote syslog previously sent - as APP-NAME and the multi-purpose binary previously used the ident clickhouse; both are now called out explicitly in the docs.
  • Test fixes. Fixed a Poco::AutoPtr use-after-free in the new test's logger state guard, and two pre-existing clang-tidy errors that had been causing the builds to be dropped, which meant the unit test jobs had never actually run on this PR.

CI status on 4d6ab03: 149 passed, 4 failed. All four failures are pre-existing on master and unrelated to this change, which only touches syslog program-name plumbing, the daemon command-name helper, docs and tests:

Check Failure Also seen on
AST fuzzer (arm_asan_ubsan) Can't determine table for parallel replicas 23 PRs in 14 days, including master
AST fuzzer (amd_debug) Cannot add step Limit to QueryPlan ... incompatible header (vector search) 3 PRs, 2 of them predate this branch
Stress test (amd_asan_ubsan) IColumn::assertTypeEquality in HashJoinMethodsImpl.h 156 PRs, 199 occurrences in 14 days
Integration (amd_msan 4/8) test_keeper_dynamic_log_level::test_adjust_log_level 58 PRs since 2026-08-05

The keeper one is also ruled out by mechanism: that test enables no syslog, so the modified block never executes, cmd_name is used nowhere else in Loggers.cpp, and updateLevels (which handles the dynamic level change it asserts on) is untouched by this PR.

Mergeable Check and PR are roll-ups of those four, so the PR shows as blocked. Reruns of the flaky jobs would need someone with write access.

On conflicts: this PR had gone stale and was showing as conflicted. The original commit dates from 2026-03-04 and master had moved on by roughly 48k commits since, with changes landing in Loggers.cpp, BaseDaemon.cpp and the server settings docs in the meantime. It was rebased onto 8a14c7c2a17 on 2026-08-07, which resolved that. The branch is conflict-free and mergeable against master as of now.

Everything that exercises this change is green, including all six unit test jobs (asan_ubsan, msan, tsan), Build (arm_tidy), Fast test, Style check and Docs check.

@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Dear @mstetsyuk, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@abashkeev abashkeev added the comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). label Sep 3, 2026
@Algunenano Algunenano self-assigned this Oct 1, 2026

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've simplified the PR to the essentials. Will merge soon

| `hostname` | The name of the host from which logs are send (optional). |
| `facility` | The syslog [facility keyword](https://en.wikipedia.org/wiki/Syslog#Facility). Must be specified uppercase with a "LOG_" prefix, e.g. `LOG_USER`, `LOG_DAEMON`, `LOG_LOCAL3`, etc. Default: `LOG_USER` if `address` is specified, `LOG_DAEMON` otherwise. |
| `format` | Log message format. Possible values: `bsd` and `syslog.` |
| `programname` | Program name used in syslog messages: the local syslog ident, or the `APP-NAME` for remote syslog with `format=syslog`. No effect with `format=bsd`. 1 to 48 printable ASCII characters without spaces. Default: the command name for local syslog, unset for remote syslog. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format row just above this new programname entry still documents the literal as syslog. with the period inside the code span. Even after the generated page is refreshed, that will keep publishing the wrong format name.

Please change the documented value to syslog in the source fragment before rerunning the generated-docs flow.

@martinfrancois

Copy link
Copy Markdown
Contributor Author

I've simplified the PR to the essentials. Will merge soon

Thanks a lot!

@Algunenano
Algunenano added this pull request to the merge queue Oct 2, 2026
Merged via the queue into ClickHouse:master with commit 49a47ff Oct 2, 2026
149 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to set custom programname for syslog logger

6 participants