Repository navigation
Allow configuring syslog program name for ClickHouse logs - #98789
Conversation
9f2d5c2 to
70ac6ab
Compare
|
@mstetsyuk or @bharatnc Would you be interested in reviewing this PR? |
|
Workflow [PR], commit [82a31a8] Summary: ✅
AI ReviewSummaryThis PR has been simplified down to the explicit PR Metadata
Findings
💡 Nits
Final Verdict
LLVM Coverage ReportMeasured on commit 82a31a8.
Changed lines: Changed C/C++ lines covered: 2/28 (7.14%) · Uncovered code |
|
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. |
|
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. |
70ac6ab to
a3ac6d9
Compare
cddd84b to
bd922aa
Compare
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
bd922aa to
512e67f
Compare
| | `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`. | |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8b4edce to
abecf53
Compare
abecf53 to
6abe650
Compare
6abe650 to
4d6ab03
Compare
|
@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:
CI status on
The keeper one is also ruled out by mechanism: that test enables no syslog, so the modified block never executes,
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 Everything that exercises this change is green, including all six unit test jobs (asan_ubsan, msan, tsan), |
|
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. |
Algunenano
left a comment
There was a problem hiding this comment.
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. | |
There was a problem hiding this comment.
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.
Thanks a lot! |
Changelog category (leave one):
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 5424APP-NAMEand now sends the command name (for exampleclickhouse-server), and the multi-purpose binary started asclickhouse serverorclickhouse keepernow usesclickhouse-server/clickhouse-keeperinstead ofclickhousefor local syslog.Documentation entry for user-facing changes
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-serverorclickhouse-keeper).logger.syslog.format: Withformat=syslog,programnameis used as RFC 5424APP-NAME. Withformat=bsd,programnamehas no effect.Example use:
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! :)
programname:Poco::SyslogChannel::PROP_NAME(local syslog) andPoco::Net::RemoteSyslogChannel::PROP_NAME(remote syslog).logger.syslog.programnamedefaults tocmd_nameinbuildLoggers, which maps to the ClickHouse command name used to start the process.clickhouse.clickhouse-server,clickhouse-keeper, etc.) are more informative.programnamedocs section. Remote syslog never setPROP_NAMEbefore, soPocoleft its"-"default and every RFC 5424 record carried-asAPP-NAME; those records now carryclickhouse-server/clickhouse-keeper. Local syslog already usedcmd_name, but for the multi-purpose binary that wasclickhouse, and it is now the subcommand-specific name. Users who filter on the old values can pin them with an explicitprogramname.virtual std::string BaseDaemon::getCommandName()(defaulting to Poco'scommandName()), overridden byServerandKeeper, used byBaseDaemon::initializeon the firstbuildLoggerscall.buildLoggerscall sites inServer.cpp/Keeper.cpp, or includecmd_namein theconfig_loggercache key.buildLoggerscalls early-return on theconfig_loggerguard, 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, becauseprograms/main.cpperases the subcommand argument, soclickhouse serverreportsclickhouse.clickhouse, viaBaseDaemon::disambiguateCommandName, which delegates to the free functiondisambiguateClickHouseCommandName(executable_file_name, command_name, subcommand_name). The decision deliberately uses Poco'sapplication.namerather thancommandName():commandName()isapplication.baseName, andPoco::Path::getBaseNametruncates at the last dot, so a binary namedclickhouse.prodreportscommandName() == "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 anyPoco::Util::Applicationasserts that it is the only instance in the process and installs process-wide signal handlers, which is not acceptable inside the sharedunit_tests_dbmsbinary.src/Daemon/tests/gtest_daemon_command_name.cppcovers 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.LoggerStateGuardsnapshots the root channel/level plus the channel and level of every pre-existing logger, holding each channel through a sharedPoco::AutoPtrso it stays alive, and restores them exactly.buildLoggersrepoints every already-created logger at a channel owned by the test'sLoggersinstance, 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.format=bsdbehavior:programname.APP-NAMEdirectly and avoid legacyTAGwording.APP-NAME/tag or explain RFC 3164TAGdecomposition.logger.syslog.options:logger.syslog.options.programname.programname:APP-NAMEtokens (empty, longer than 48 characters, or containing bytes outside printable ASCII%d33-126), raisingBAD_ARGUMENTSat startup.format=syslog.RemoteSyslogChannel::logwrites the name verbatim betweenHOSTNAMEandPROCID, 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 unrelatedformatoraddresschange.cmd_namefallback is deliberately never rejected, since it derives from the binary name and refusing to start because of an unusualargv[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_NAMEis only assigned when the derived value is a validAPP-NAME, so an unusual binary name leaves Poco's-default in place. Local syslog keeps receivingcmd_nameunchecked, which is exactly what it received before this PR.Testing
Targeted unit-test validation ran locally (not full suite):
ninja unit_tests_dbms(inbuild_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.mdxsource fragment is edited. The generated pagedocs/reference/settings/server-settings/settings/other.mdxis deliberately left alone, because theNo direct edits to generated or read-only docscheck rejects edits inside autogenerated regions unless the PR carries thepr-autogenerated-docslabel. 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.optionsis already implemented inLoggers::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
26.10.1.1275-master(included in26.10and later)