Skip to content

CI: collect Build profile telemetry for a subset of builds - #108294

Merged
maxknv merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-build-profile-hook-upload-best-effort
Jun 27, 2026
Merged

maxknv merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-build-profile-hook-upload-best-effort

Conversation

@groeneai

@groeneai groeneai commented Jun 23, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #84159

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

build_profile_hook runs on every master Build variant and uploads compile-time-trace telemetry to a shared remote analytics DB. The ~25 variants of a master push finish and upload at roughly the same time, so the per-user INSERTs cross that DB's memory limit and one is killed with Code: 241 MEMORY_LIMIT_EXCEEDED (While executing ParallelParsingBlockInputFormat). The hook treated that rejection as fatal (sys.exit(1)), so a successful build was reported as a failed Post Hooks check (~600/day, all variants, build-content-independent).

Reduce the workload at the source: collect build profile telemetry only for an explicit subset of two representative release builds (amd_release, arm_release) instead of all ~25 variants, so they no longer upload at once and cross the per-user limit. The other build names are listed commented-out, so re-enabling one is a one-line change.

Keep input_format_parallel_parsing=0 on the INSERT (per @nikitamikhaylov): the kill happens in ParallelParsingBlockInputFormat, whose chunk buffering is the memory peak, and single-threaded parsing keeps a single upload's peak parse memory low.

Upload errors are no longer swallowed. With the workload reduced, a genuine INSERT rejection means a real lost upload and now fails the hook loudly instead of being reported as success. The empty-artifact skip (#84159, builds that produce no profile data) is unrelated to error handling and stays.

Example failure (master Build (amd_release), 2026-06-23): https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=4dde9a6abaa86ed9c3897525f053b02a284f6a67&name_0=MasterCI&name_1=Build%20%28amd_release%29

Regression tests in ci/tests/test_build_profile_hook.py: telemetry is collected only for the allow-listed release builds; the INSERT runs with input_format_parallel_parsing=0; an upload rejection propagates rather than being swallowed. Each fails against the un-fixed code and passes with this change.

Version info

  • Merged into: 26.7.1.156 (included in 26.7 and later)

The build_profile_hook post-hook runs on every master Build variant and
uploads compile-time-trace telemetry to a shared remote analytics DB. The
~25 variants of a master push finish and upload at once, so the per-user
INSERTs routinely cross the DB's memory limit and one is killed with
Code: 241 MEMORY_LIMIT_EXCEEDED (during ParallelParsingBlockInputFormat).
insert_* turns that rejection into an AssertionError, which the hook treated
as fatal (sys.exit 1), so a successful build was reported as a failed
"Post Hooks" check.

This telemetry is observability-only and has no bearing on the produced
binaries, so a rejected upload must not fail the build. Catch upload errors
per artifact in _upload_profile_artifacts, log them, and continue. Genuine
build/producer errors still fail loudly: they surface earlier, in
prepare-time-trace.sh under strict Shell.check and in local file assembly,
outside the upload loop.

PR ClickHouse#107117 guarded the missing/empty-artifact case (ClickHouse#84159) but left the
remote-rejection case fatal; this addresses that remaining mechanism, which
is the dominant cause of the chronic master Build Post Hooks failures across
all variants (~600/day, build-content-independent).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. The failing path is deterministic given a rejected upload: _upload_profile_artifacts -> insert_profile_data -> log_cluster.py assert self._log_cluster.do_query(...) raises AssertionError, which the old check() except turned into sys.exit(1). Reproduced as a unit test by injecting a failing_insert that raises AssertionError (the exact exception insert_* raises on a rejected INSERT). In CI it fires whenever the shared LogCluster DB rejects the INSERT (Code: 241 MEMORY_LIMIT_EXCEEDED), which the ~25 simultaneous master Build uploads routinely trigger.
b Root cause explained? build_profile_hook runs master-only on every Build variant and uploads compile-time-trace telemetry to a shared remote analytics DB. ~25 variants of one master push finish and upload at roughly the same time -> the per-user INSERTs cross that DB's memory limit -> one is killed with Code: 241 MEMORY_LIMIT_EXCEEDED (While executing ParallelParsingBlockInputFormat). log_cluster.py asserts do_query(...) succeeded, so the rejection becomes an AssertionError; the hook's broad except treated that as fatal (sys.exit(1)), so a successful build was reported as a failed Post Hooks check. Build-content-independent, all variants, master-only -> exactly the chronic signature (~600/day). PR #107117 fixed the missing/empty-artifact mechanism (#84159) but left this remote-rejection mechanism fatal.
c Fix matches root cause? Yes. The upload is observability-only and has no bearing on the produced binaries, so a rejected upload must not fail the build. _upload_profile_artifacts now catches the per-artifact upload exception, logs it (WARNING + traceback), and continues. This directly targets mechanism (b): the rejection no longer escapes to the fatal except. Not a band-aid: genuine producer errors (prepare-time-trace.sh crash, local file assembly) still fail loudly because they surface earlier, outside the upload loop.
d Test intent preserved / new tests added? New tests added in ci/tests/test_build_profile_hook.py: test_remote_upload_rejection_is_best_effort (a raised AssertionError from insert must not propagate) and test_one_artifact_rejection_does_not_block_the_rest (one rejected artifact must not stop the others). The existing #107117 coverage (_has_data, LTO/cross-arch/native artifact selection, producer empty-output) is retained, so the missing/empty-artifact intent is preserved.
e Both directions demonstrated? Yes. Pytest unavailable locally, so validated with a standalone runner. NEW logic: 9/9 tests pass (rejection swallowed, build succeeds). OLD logic (the _has_data guard from #107117 but no try/except around insert): the injected AssertionError propagates -> would hit the fatal except -> sys.exit(1) -> Post Hooks FAIL. Fails-without-fix / passes-with-fix confirmed.
f Fix is general, not a narrow patch? Yes. The guard is in the shared _upload_profile_artifacts loop, so it covers all three artifacts (profile.json, binary_sizes.txt, binary_symbols.txt) and every Build variant uniformly, not one call site. It catches Exception (not just AssertionError), so transient connectivity rejections are covered too. Combined with #107117's _has_data guard, both non-fatal upload failure modes (artifact-absent and remote-rejection) are now handled in one place. This is the source-level fix (make telemetry upload best-effort), not a symptom guard.

Session id: cron:clickhouse-worker-slot-3:20260623-130300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv — follow-up to #107117 (which you approved). That guarded the missing/empty build-profile artifact case; this makes the telemetry INSERT itself best-effort so a Code: 241 MEMORY_LIMIT_EXCEEDED rejection from the shared LogCluster DB (the ~25 master Build variants upload at once) no longer turns a successful build into a failed Post Hooks check. This is the dominant remaining mechanism of the chronic master Build Post Hooks failures (~600/day, all variants).

@nikitamikhaylov

Copy link
Copy Markdown
Member

@groeneai you can just disable the parallel parsing.

The shared LogCluster analytics DB rejects the build_profile_hook INSERT
with Code 241 MEMORY_LIMIT_EXCEEDED while executing
ParallelParsingBlockInputFormat when the ~25 master Build variants finish
and upload at once. The per-user limit is fixed server-side, so the
existing max_memory_usage_for_user override does not help; the only lever
is lowering the INSERT's peak parse memory.

Parallel parsing buffers many chunks at once, and that peak is what
crosses the limit. Send input_format_parallel_parsing=0 on the telemetry
INSERT (LogCluster.do_query, used only by the three build-profile
uploads) so the INSERT is accepted and the telemetry is kept rather than
dropped. The best-effort catch from the prior commit stays as a guard for
transient connectivity rejections, without masking genuine producer
errors (those surface earlier under strict Shell.check).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done. Pushed input_format_parallel_parsing=0 on the telemetry INSERT (in LogCluster.do_query, used only by the three build-profile uploads).

The INSERT is killed While executing ParallelParsingBlockInputFormat, so the peak is the parallel parser buffering many chunks at once. The per-user limit is fixed server-side (the existing max_memory_usage_for_user=0 override is clamped, the rejection still shows maximum: 29.80 GiB), so single-threaded parsing is the lever that keeps the INSERT under the limit. This keeps the telemetry rather than dropping it. Kept the best-effort catch as a guard for transient connectivity rejections; it does not mask producer errors, which surface earlier under strict Shell.check.

Regression test added: do_query sends input_format_parallel_parsing=0 (fails on the prior params, passes now).

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a53bf73]

Summary: ❌

job_name test_name status info comment
Stress test (arm_asan_ubsan, s3) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue

AI Review

Summary

This PR limits build_profile_hook telemetry collection to amd_release and arm_release, keeps LogCluster inserts on single-threaded input parsing, and leaves upload failures visible now that the upload fan-out is reduced. The implementation matches the maintainer discussion, the PR metadata category is appropriate, and I did not find a correctness or reliability issue that warrants an inline review comment.

Missing context / blind spots
  • ⚠️ The real upload path only runs when Info().pr_number == 0, so PR CI cannot exercise the master-push LogCluster upload under production credentials. The next MasterCI push running Build (amd_release) and Build (arm_release) would close that live-capacity check.
  • ⚠️ I could not run ci/tests/test_build_profile_hook.py locally because /usr/bin/python3 has no pytest module in this environment. The attempted run failed before collecting tests; the log is in ci/tmp/test_build_profile_hook.log.
Final Verdict

Status: ✅ Approve

No required changes.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 23, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 5e66c70

Every failure below links a fixing PR (ours or external). Only CH Inc sync is exempt.

Check / test Reason Fixing PR
Stress test (amd_asan_ubsan) trunk-crash (NOT PR-caused: this PR only touches ci/jobs/scripts/log_cluster.py, a CI telemetry path, and cannot affect query execution) #108128 (ours, open)
Mergeable Check / PR aggregators reflecting the stress red n/a (aggregator)
CH Inc sync — CH Inc sync (private, not actionable)

The stress red is Logical error: 'Unexpected return type from if. Expected UInt64. Got String' on SELECT sum(b) FROM t_overwrite_then_prewhere PREWHERE v > 50, aborting in MergeTreeRangeReader::executePrewhereActionsAndFilterColumns (STID 1611-483a). This is the on-fly-mutation if(cond, expr, col) keep-old fallback type-mismatch fixed by #108128 (open, on review). It is a chronic trunk crash (35 hits / 26 distinct PRs / 4 master in 30d, ongoing since 2026-06-17), unrelated to this CI-only change. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108294&sha=5e66c708202a5fd5c5340130ab403fb9eae0f1d8&name_0=PR&name_1=Stress%20test%20%28amd_asan_ubsan%29

Session id: cron:our-pr-ci-monitor:20260624-033000

@maxknv

maxknv commented Jun 24, 2026

Copy link
Copy Markdown
Member

Thanks for digging into this — the root-cause analysis (parallel-parsing buffer crossing the per-user limit) is solid and well-explained. I do want to push back on the failure model the fix relies on, though.

1. The framing of "fatal" overstates it. The post hook failing doesn't fail the build itself — the Build job stays green and only the separate Post Hooks check goes red. So we're not turning a successful build into a failed build; we're losing the signal on a standalone telemetry step. That changes the cost/benefit of the fix.

2. Reporting a failed operation as success doesn't sit right with me. Making the upload best-effort means a non-trivial operation can fail and we'll never know. Today's failure is loud and annoying, but it's at least visible. Swallowing it trades a noisy-but-honest signal for a silent one, and we can end up doing real work that quietly fails.

3. If the workload is too heavy for the cluster, let's reduce the workload. The real problem is ~25 variants uploading simultaneously on every master push. That points at scheduling/throttling — e.g. don't profile every variant, or every commit — rather than at suppressing the error. Fixing the parse memory helps, but it's treating the symptom of "too much at once."

4. If a failed profile upload is genuinely fine to ignore, do we need it at all? These two positions are in tension: either the telemetry matters (then losing it should be visible and we should fix the capacity), or it doesn't (then dropping the check entirely is cleaner than catching-and-logging).

5. Overall this feels like sweeping the dust under the rug. The input_format_parallel_parsing=0 change is a reasonable improvement on its own. But pairing it with "errors are now best-effort" hides the underlying capacity issue instead of resolving it.

Concretely, I'd suggest splitting this: keep the parallel-parsing fix (it's a clear win), and instead of making failures best-effort, address the contention directly — throttle/stagger uploads or reduce how often we profile. If we decide the telemetry is expendable, let's say so explicitly and drop it rather than keep a check that's green regardless of outcome.

@groeneai

Copy link
Copy Markdown
Collaborator Author

@maxknv Agreed on the core point: making the upload best-effort reports a failed operation as success, which is the wrong trade. I'll drop that half and keep only input_format_parallel_parsing=0. That removes the parse-memory rejection at its source and leaves any other upload failure loud again, which is the honest baseline you and Nikita both want.

One caveat so the call is informed: I can't verify from this PR that single-threaded parsing alone keeps all ~25 variants under the per-user limit. The hook only runs on master (the pr_number == 0 guard), so it never executes on a PR run, and the cap that triggered the rejection is fixed server-side. The parse fix lowers peak memory but I have no master-side measurement of by how much under full concurrency, so the Code 241 rejection could recur once best-effort is gone. If it does, your point 3 (reduce the workload) is the real fix.

That part is a capacity/scheduling decision I don't want to make on my own. Which would you prefer, and in this PR or a follow-up?

  • stagger/serialize uploads (CI-level, since the contention is across 25 separate jobs, not within one)
  • profile a subset of variants, or not every commit
  • drop the telemetry upload entirely if it is expendable

I'll remove best-effort now and implement whichever you pick. I won't build throttling speculatively.

@maxknv

maxknv commented Jun 26, 2026

Copy link
Copy Markdown
Member

Let's upload profiling for a smaller subset of builds: amd_release and arm_release. Make it an explicit list; other builds may be commented out. Add a brief comment explaining why a small subset was used.

@maxknv
maxknv self-requested a review June 26, 2026 11:31
The build_profile_hook telemetry upload contends for the shared LogCluster
analytics DB: on a master push ~25 Build variants finish and upload at
once, and the combined load crosses the cluster's per-user memory limit
(Code 241 MEMORY_LIMIT_EXCEEDED). Restrict the upload to an explicit
subset of two representative release builds (amd_release, arm_release) so
the contention is removed at the source rather than its symptom suppressed.
The other build names are listed commented-out so re-enabling one is a
one-line change. input_format_parallel_parsing=0 on the INSERT is kept.

With the workload reduced, drop the best-effort catch-and-log of upload
failures: a genuine INSERT rejection now means a real lost upload and must
stay visible (the hook fails loudly) instead of being reported as success.
The empty-artifact skip (ClickHouse#84159, builds that produce no profile data) is
unrelated to error handling and stays.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai groeneai changed the title CI: make Build profile telemetry upload best-effort CI: collect Build profile telemetry for a subset of builds Jun 26, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@maxknv done, pushed in a53bf73.

  • Restricted the upload to an explicit {amd_release, arm_release} allow-list (_PROFILED_BUILDS in build_profile_hook.py); the other build names are listed commented-out with a comment explaining why only a subset is profiled. The non-profiled builds short-circuit before prepare-time-trace.sh runs, so ~25 simultaneous uploads drop to 2 and the per-user-limit contention is gone at the source.
  • Dropped the best-effort catch-and-log. With the workload reduced, a genuine upload rejection now propagates and fails the hook loudly rather than being reported as success.
  • Kept input_format_parallel_parsing=0.

Tests updated: assert the subset gate, assert an upload rejection propagates (was: swallowed), keep the parallel-parsing assertion.

One caveat for the record: the hook is master-only (if Info().pr_number == 0), so this PR's CI does not exercise the upload path; the subset behavior will first be visible on the next master push.

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jun 26, 2026
@maxknv
maxknv enabled auto-merge June 27, 2026 11:29
@maxknv
maxknv added this pull request to the merge queue Jun 27, 2026
Merged via the queue into ClickHouse:master with commit 996192e Jun 27, 2026
165 of 167 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 27, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…hook-upload-best-effort

CI: collect Build profile telemetry for a subset of builds
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 manual approve Manual approve required to run CI pr-ci 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.

5 participants