feat(config,server,cli,watch): support global general.callback_url (#1481) - #1482
Conversation
Provide a shared callback dispatcher with config fallback so one-shot CLI commands and each watch iteration can notify external systems without changing the existing API callback JSON contract.
ValidateConfig now errors on durations <= 0 (e.g: 0s) CallbackTimeoutDuration is always positive after a successful load
API server already notifies via pkg/server dispatchCLICallback now returns early when --command-id is set Also extract applyCLICallbacks add allowlist coverage, and drop unused GetOperationId
`startWatchIteration` no longer registers a `status.Current` row per cycle (AsyncStatus.commands is append-only) preventing unbounded memory growth in long-running watch processes The iteration `operation_id` is now a bare UUID and finish is made idempotent via sync Once the top-level watch commandId is passed to `CreateToRemote/Rebase` again
`parseCallback` now builds each POST from `context.WithoutCancel` plus `general.callback_timeout` Canceled caller context cannot kill the notification and callbacks no longer hang without a deadline
Signed-off-by: slach <bloodjazman@gmail.com>
…into feature/general-callback-url
|
@Slach the failing Test (21.8–26.3) jobs look fixed on master (object-disk streaming fallback). please approve the CI? Thanks! |
…eature/general-callback-url # Conflicts: # test/testflows/clickhouse_backup/tests/snapshots/cli.py.cli.snapshot
|
Thanks for the work — the feature itself is useful and the config part is fine. But the code structure needs rework before merge, so I will implement this myself in 1. Callback dispatch is duplicated in 3 placesOnly the low-level HTTP POST was shared (
2. The CLI wiring is fragile
3. The approach I will take instead
4. About the watch memory concern
5. Smaller points
|
|
i will fix review comments from my side |
Summary
Fixes #1481
This PR introduces
general.callback_urlandgeneral.callback_timeoutconfiguration options to enable backup completion webhooks across all execution paths: API, CLI, and Watch Mode.Currently, completion callbacks are only available via the API query parameter (
POST /backup/create?callback=...). This PR unifies callback handling into a sharedpkg/statusdispatcher while preserving strict backward compatibility for existing API consumers.Changes
pkg/config): Addedgeneral.callback_urlandgeneral.callback_timeout(default5s), with support forCALLBACK_URLandCALLBACK_TIMEOUTenvironment variables.pkg/status): CreatedSendCallback()supportingCallbackPayload(status,error,operation_id, and optionalcommand/duration).pkg/server): Updated API handler to fall back togeneral.callback_urlif the?callback=query parameter is missing or empty. Query params still take precedence when provided.cmd/clickhouse-backup): Added synchronous callback dispatch in CLI lifecycle hooks, reusing existingcommandId/operation_idtracking. Errors during dispatch are logged and swallowed so CLI exit codes are never affected by callback failures.pkg/backup/watch.go): Added per-iteration callback dispatch andstatus.Current.Start()/Stop()tracking inside the watch loop, ensuring each individual watch cycle sends a clean callback with its own uniqueoperation_id.ReadMe.mdandManual.md, and added an entry toChangeLog.md.Key Constraints Respected
CallbackPayload.Errorintentionally retains noomitemptytag so API callback JSON payloads remain byte-identical ("error": ""is always present).commandanddurationuseomitempty.Testing
Followed workflow across all modified packages:
pkg/config: Tested parsing from YAML, ENV overrides, and default timeout handling.pkg/status: Tested payload serialization, HTTP timeout enforcement, and non-200 response handling.pkg/server: Tested fallback logic when?callback=is absent/empty vs explicitly set.cmd/clickhouse-backup: Tested CLI callback dispatch on command success/failure and confirmed non-zero callback failures do not mutate command exit codes.pkg/backup: Tested per-iteration callback firing and error recovery across multiple watch ticks.All tests pass cleanly:
go test -v ./pkg/... ./cmd/...