Repository navigation
Implement CREATE HANDLER / DROP HANDLER / ALTER HANDLER queries - #100203
Daedalus-Icarus wants to merge 13 commits into
Conversation
|
Hi @alexey-milovidov @Avogar |
|
Workflow [PR], commit [0f1dba2] Summary: ✅ AI ReviewSummaryThis PR introduces SQL-managed HTTP handlers via Findings
ClickHouse Rules
User-LensUsers running multi-node setups can miss Final Verdict
|
|
Ok. Let's test (and add automated tests whenever possible) every single statement from the spec. Just to make sure... |
| const auto updated_query = removeOnClusterClauseIfNeeded(query_ptr, getContext()); | ||
| const auto & query = updated_query->as<const ASTCreateHandlerQuery &>(); | ||
|
|
||
| current_context->checkAccess(AccessType::CREATE_HANDLER); |
There was a problem hiding this comment.
This introduces a new SQL surface (CREATE HANDLER/ALTER HANDLER/DROP HANDLER) but there is no experimental feature gate check in the interpreters.
Per ClickHouse rollout rules, new behavior should be guarded (for example with allow_experimental_*) until it is proven safe in production. Without a gate, existing deployments cannot disable the feature after upgrade.
Please add an experimental setting check before executing these statements (and document the default).
|
|
||
| std::string file_path = metadata_path + "/" + escapeForFileName(handler_name) + ".sql"; | ||
| if (fs::exists(file_path)) | ||
| fs::remove(file_path); |
There was a problem hiding this comment.
DROP HANDLER deletes persisted metadata files, but this deletion path does not emit a log entry.
ClickHouse requires logging deletion events (data/metadata/Keeper entries) for auditability and incident debugging. Please add at least an INFO/DEBUG log before or after fs::remove (including handler name and file path).
| @@ -259,6 +260,9 @@ static inline auto createHandlersFactoryFromConfig( | |||
| "{}.{}, must be 'rule' or 'defaults'", prefix, key); | |||
| } | |||
|
|
|||
| /// Add SQL-defined custom handlers after config-defined handlers | |||
| main_handler_factory->addHandler(createCustomHandlerRequestHandlerFactory(server)); | |||
There was a problem hiding this comment.
createHandlersFactoryFromConfig always adds createCustomHandlerRequestHandlerFactory here, but the defaults branch already calls addDefaultHandlersFactory, which now also adds the same custom factory.
When http_handlers.defaults is enabled, this registers SQL handlers twice. It is easy to miss in tests but adds duplicate matching work on every HTTP request and can alter expected precedence when combined with custom rules.
Please keep a single insertion point (either only in addDefaultHandlersFactory or only here, with a guard).
|
|
||
| if (def.url_type == "regexp") | ||
| { | ||
| re2::RE2 regex(def.url); |
There was a problem hiding this comment.
matchesURL recompiles RE2 patterns on every request (re2::RE2 regex(def.url)), and then createRequestHandler compiles the same pattern again for PredefinedQueryHandler.
Because this code runs on the HTTP request path, repeated regex compilation can become a visible CPU overhead under load (especially with multiple regexp handlers). It also duplicates work for every successful regexp match.
Please compile regexp patterns once when handlers are created/altered/loaded, store the compiled object in the handler definition, and reuse it here.
| query->format(buf, format_settings); | ||
|
|
||
| std::string file_path = metadata_path + "/" + escapeForFileName(handler_name) + ".sql"; | ||
| WriteBufferFromFile out(file_path); |
There was a problem hiding this comment.
saveToDisk writes directly to the final metadata file path. If the process is interrupted during write (exception, power loss, restart), the .sql file can be left partially written.
On startup, loadFromDisk catches parse failures and continues, so a partially written file can silently drop a handler definition after restart.
Please switch to an atomic write pattern (write to temp file in the same directory, finalize/sync, then rename to target).
| def.methods.push_back("GET"); | ||
|
|
||
| if (def.url_type == "regexp") | ||
| def.compiled_regex = std::make_shared<re2::RE2>(def.url); |
There was a problem hiding this comment.
CREATE HANDLER/ALTER HANDLER currently accept invalid URL REGEXP patterns.
At this line, a re2::RE2 object is constructed but its validity is never checked (ok()), so malformed regexps are persisted successfully and only fail later at request match time (silently never matching). The same pattern appears in alter and loadFromDisk.
Please validate regexp compilation at definition time and throw CANNOT_COMPILE_REGEXP (or equivalent) when !compiled_regex->ok(), including the RE2 error text. That makes invalid definitions fail fast and avoids persisting broken handlers.
|
|
||
| std::unique_ptr<HTTPRequestHandler> createRequestHandler(const HTTPServerRequest & request) override | ||
| { | ||
| auto handlers = CustomHandlersFactory::instance().getAll(); |
There was a problem hiding this comment.
getAll) and sorts them every time. With many handlers this adds avoidable allocations and O(N log N) work to the hot path.
Please consider maintaining an immutable pre-sorted snapshot (updated on create/alter/drop) and reading that snapshot here, so request handling only does a linear scan without per-request copying/sorting.
| @@ -398,6 +405,9 @@ void addDefaultHandlersFactory( | |||
| { | |||
| addCommonDefaultHandlersFactory(factory, server, config); | |||
|
|
|||
| /// Add SQL-defined custom handlers before the default dynamic query handler | |||
| factory.addHandler(createCustomHandlerRequestHandlerFactory(server)); | |||
There was a problem hiding this comment.
allow_experimental_sql_handlers currently gates only DDL interpreters, but SQL handlers are still loaded and activated unconditionally in the HTTP handler chain.
That means the experimental feature remains active for request execution even when the setting is 0 (default), which weakens the rollout gate semantics.
Could you gate registration/loading of SQL handlers with the same setting (or a dedicated server-level setting), so disabling the experimental feature fully disables both management and runtime matching/execution?
|
Hi @alexey-milovidov |
| if (def.url_type == "regexp") | ||
| def.compiled_regex = std::make_shared<re2::RE2>(def.url); | ||
|
|
||
| handlers[query.handler_name] = std::move(def); |
There was a problem hiding this comment.
create mutates in-memory state before persistence (saveToDisk). If disk write/rename fails, the query throws but the handler remains active in memory until restart.
That breaks atomicity: users get an exception yet behavior changed, and state after restart differs from runtime state.
Please persist first (or rollback the in-memory insertion on exception) so CREATE HANDLER is all-or-nothing.
| if (it == handlers.end()) | ||
| throw Exception(ErrorCodes::BAD_ARGUMENTS, "Handler `{}` does not exist", handler_name); | ||
|
|
||
| handlers.erase(it); |
There was a problem hiding this comment.
remove erases the handler from memory before deleting metadata on disk. If removeFromDisk throws (I/O/permissions), DROP HANDLER fails but the handler is already gone from memory; after restart it can reappear from the leftover metadata file.
Please make this atomic: delete metadata first and erase from memory only after successful persistence, or rollback memory state on failure.
| SETTINGS="--allow_experimental_sql_handlers=1" | ||
|
|
||
| # Basic CREATE HANDLER | ||
| $CLICKHOUSE_CLIENT $SETTINGS -q "CREATE HANDLER test_h1_${SUFFIX} URL '/api/test1_${SUFFIX}' AS 'SELECT 1'" |
There was a problem hiding this comment.
CREATE HANDLER/ALTER HANDLER/DROP HANDLER statements parse and execute, but never checks runtime behavior through HTTP requests. The feature’s core contract is request matching and query execution, so we should add end-to-end assertions (for exact/prefix/regexp URL matching and method filtering) by issuing HTTP calls and validating responses.
Without that, regressions in CustomHandlerRequestHandlerFactory can pass CI while DDL-only checks remain green.
There was a problem hiding this comment.
+1, it does not test the feature.
|
|
||
| ## Part 2: End-to-end HTTP handler tests (exact URL match) | ||
|
|
||
| $CLICKHOUSE_CLIENT $SETTINGS -q "CREATE HANDLER test_exact_${SUFFIX} URL '/e2e_exact_${SUFFIX}' METHODS (GET) AS 'SELECT 42 AS answer'" |
There was a problem hiding this comment.
handlers_metadata restore on startup).
Please add a restart round-trip check: create handler → restart server → verify endpoint works; drop handler → restart server → verify endpoint is absent. This is the main behavior guarded by saveToDisk/loadFromDisk.
| query->query = query_ast->as<ASTLiteral &>().value.safeGet<String>(); | ||
| } | ||
|
|
||
| node = query; |
There was a problem hiding this comment.
ALTER HANDLER currently accepts a statement with no modifications (for example, ALTER HANDLER h), because all clauses are optional and there is no post-parse validation that at least one of URL / METHODS / AS was provided.
This silently succeeds as a no-op, which can hide user mistakes and make automation think an intended change was applied.
Please reject empty alters with a clear BAD_ARGUMENTS exception when none of the optional fields is set.
| def.query = *query.query; | ||
|
|
||
| if (!metadata_path.empty()) | ||
| saveToDisk(query.handler_name); |
There was a problem hiding this comment.
ALTER HANDLER mutates in-memory state before persistence. If saveToDisk throws here (I/O, permissions, rename failure), the query returns an exception but the modified handler stays active in memory until restart.
That breaks atomicity and can cause restart-time behavior rollback (disk still has old definition). Please make alter all-or-nothing: either persist first and then swap state, or keep a copy and roll back in-memory fields if persistence fails.
| node2.restart_clickhouse() | ||
|
|
||
| # Verify persistence on node1 after restart | ||
| text, code = http_get(node1, "/keeper_test_1") |
There was a problem hiding this comment.
The keeper tests still validate only node_with_keeper after restart, so they can pass even if cross-node Keeper propagation is broken.
In test_keeper_create_and_restart, we create the handler on node_with_keeper, restart both nodes, then assert only on node_with_keeper (/keeper_test_1). Please also assert that node_with_keeper_2 serves the same handler (and similarly for alter/drop paths), otherwise the advertised Keeper-backed multi-node behavior is not actually covered.
|
@Desel72, please fix tests and conflicts. |
| @@ -2100,6 +2101,12 @@ try | |||
| #endif | |||
|
|
|||
| NamedCollectionFactory::instance().loadIfNot(); | |||
|
|
|||
| { | |||
| auto handlers_metadata_path = fs::path(global_context->getPath()) / "handlers_metadata/"; | |||
There was a problem hiding this comment.
handlers_metadata is hardcoded here, so the new <custom_handlers_storage><type>zookeeper</type>...</custom_handlers_storage> configuration from the integration setup is never read by production code.
That means CREATE/ALTER/DROP HANDLER still persist only to local disk, and the Keeper-backed multi-node behavior exercised in tests/integration/test_sql_handlers is not actually implemented by this PR.
Please wire CustomHandlersFactory initialization to custom_handlers_storage config (at least selecting local vs zookeeper backend) and keep local-disk mode as the default fallback.
| @@ -0,0 +1,107 @@ | |||
| #!/usr/bin/env bash | |||
There was a problem hiding this comment.
❌ The PR removes the existing regression test 04040_clear_column_with_projection_index (for #99388) without adding equivalent coverage.
Per ClickHouse review rules, existing tests should not be removed unless replacement coverage is provided. Dropping this test weakens protection for CLEAR COLUMN + projection rebuild behavior and can reintroduce regressions unrelated to this feature.
Please restore this test (or move it with identical assertions so it still runs).
Add SQL-based management of custom HTTP handlers, allowing users to
create, alter, and drop HTTP endpoints without editing config files.
Syntax:
CREATE [IF NOT EXISTS] HANDLER name URL [PREFIX|REGEXP] '/path'
[METHODS (GET, POST)] AS 'SELECT ...'
ALTER HANDLER [IF EXISTS] name [URL ...] [METHODS ...] [AS ...]
DROP [IF EXISTS] HANDLER name
Handlers are persisted to disk and loaded on server startup. SQL-defined
handlers are matched after config-defined handlers but before the default
dynamic query handler, using PredefinedQueryHandler for execution.
New access types: CREATE_HANDLER, ALTER_HANDLER, DROP_HANDLER.
Gated by allow_experimental_sql_handlers setting (default: false).
ALTER HANDLER is atomic: persistence happens before in-memory swap,
with rollback on I/O failure. Metadata files use atomic write-then-rename.
Includes stateless tests (DDL, end-to-end HTTP exact/prefix/regexp URL
matching, method filtering, ALTER semantics, DROP removal, experimental
setting gate) and integration tests (local-disk and keeper-based storage
with restart round-trips and cross-node propagation).
#100000
|
|
||
| try | ||
| { | ||
| persist(query.handler_name); |
There was a problem hiding this comment.
create/alter/remove keep mutex locked while persisting (saveToDisk does sync + rename; saveToZooKeeper does network I/O). In parallel, each HTTP request path (CustomHandlerRequestHandlerFactory::createRequestHandler) calls getAll, which takes the same mutex.
This can serialize request matching behind slow I/O from a single DDL statement. Please consider shrinking the critical section: update in-memory state under lock, release lock, then persist with a rollback/swap strategy on failure.
| @@ -335,6 +335,7 @@ if (ENABLE_CLICKHOUSE_DISTRIBUTED_CACHE) | |||
| endif() | |||
|
|
|||
| add_object_library(clickhouse_server Server) | |||
| add_object_library(clickhouse_server_custom_handlers Server/CustomHandlers) | |||
There was a problem hiding this comment.
This PR is focused on SQL handler DDL/runtime, but this added object library introduces unrelated build-scope changes in src/CMakeLists.txt.
Please keep this PR scoped to handler functionality and move unrelated build-system changes (and any sanitizer-coverage adjustments) into a separate PR with dedicated motivation/validation. Mixing concerns makes review and regression attribution much harder.
rschu1ze
left a comment
There was a problem hiding this comment.
Please add end user documentation.
| { | ||
| if (!metadata_path.empty()) | ||
| removeFromDisk(handler_name); | ||
| if (!zk_path.empty()) |
There was a problem hiding this comment.
unpersist references zk_path and removeFromZooKeeper, but neither is declared in CustomHandlersFactory.
This is a build blocker: the PR cannot compile as-is because these identifiers are undefined in this translation unit/class.
Please either remove the ZooKeeper branch for now (since fallback-to-local is used), or add the missing member/function declarations and implementation.
|
I took a look at the changes (with the help from claude), and unfortunately we cannot merge it in the current state. Blockers1. No-op
|
…or SQL handlers
- Reject no-op `ALTER HANDLER` with no URL/METHODS/AS clause
- Validate query syntax at DDL time using `ParserQuery` (parse, not analyze)
- Validate HTTP methods against allowed set {GET, POST, PUT, DELETE}
- Check for URL ambiguity at CREATE/ALTER time (exact and prefix overlaps)
- Replace per-request copy+sort with pre-sorted snapshot (`shared_mutex`)
- Gate runtime handler matching by `allow_experimental_sql_handlers` setting
- Strip `#` fragment identifier from URL in `getRequestPath`
- Replace magic url_type strings with `HandlerURLType` enum
- Remove dead code (`global_context` member, empty `shutdown`)
- Fix grant syntax in docs (underscores to spaces)
- Strengthen test assertions and add coverage for new validations
|
|
||
| if (def.url_type == HandlerURLType::Exact && existing.url_type == HandlerURLType::Exact) | ||
| urls_conflict = (def.url == existing.url); | ||
| else if (def.url_type == HandlerURLType::Prefix && existing.url_type == HandlerURLType::Prefix) |
There was a problem hiding this comment.
checkAmbiguity handles Exact/Prefix overlap, but for Prefix/Prefix it only treats equal strings as conflicting. With prefix matching semantics (startsWith), handlers like /api and /api/v1 with overlapping methods are still ambiguous, and one silently shadows the other by name order.
Please treat nested prefixes as conflicts too (e.g. def.url.starts_with(existing.url) || existing.url.starts_with(def.url)), consistent with the Exact/Prefix branch.
…ix ambiguity for nested prefixes
| const auto updated_query = removeOnClusterClauseIfNeeded(query_ptr, getContext()); | ||
| const auto & query = updated_query->as<const ASTCreateHandlerQuery &>(); | ||
|
|
||
| current_context->checkAccess(AccessType::CREATE_HANDLER); |
There was a problem hiding this comment.
CREATE_HANDLER/ALTER_HANDLER/DROP_HANDLER checks were added here, but this PR still lacks coverage that these grants are actually enforced (GRANT, REVOKE, and denied execution paths).
Please add a stateless test that creates a user without these grants, verifies each statement fails with access denied, then grants each privilege and verifies success.
|
|
||
| current_context->checkAccess(AccessType::CREATE_HANDLER); | ||
|
|
||
| if (!query.cluster.empty()) |
There was a problem hiding this comment.
ON CLUSTER, but I don’t see tests covering distributed execution semantics.
Please add integration coverage for CREATE HANDLER/ALTER HANDLER/DROP HANDLER with ON CLUSTER on a multi-node cluster, including success paths and IF EXISTS/IF NOT EXISTS behavior.
…equest path The setting is session-level and not available in the HTTP request handler context (which has no session). Gate DDL only, consistent with how other experimental features work: once created, handlers serve requests; use `DROP HANDLER` to deactivate.
| /// Validate that each method in the list is one of the allowed HTTP methods. | ||
| static void validateMethods(const std::vector<std::string> & methods) | ||
| { | ||
| static const std::unordered_set<std::string> allowed_methods = {"GET", "POST", "PUT", "DELETE"}; |
There was a problem hiding this comment.
METHODS values are validated case-sensitively here ("GET", "POST", ...), but request matching later is case-insensitive via Poco::icompare.
As a result, CREATE HANDLER ... METHODS (get) is rejected with BAD_ARGUMENTS even though the runtime path treats method names case-insensitively. This is a user-visible inconsistency.
Please normalize methods before validation (for example, convert to uppercase once in parser/factory), then keep runtime matching as-is. Also add coverage for lowercase/mixed-case methods in both CREATE HANDLER and ALTER HANDLER.
|
Hi @alexey-milovidov If you have some free time, could you please review this PR? |
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
| /// Fall back to local storage so the server starts normally. | ||
| LOG_WARNING(log, "ZooKeeper-based storage for SQL handlers is not yet implemented, falling back to local storage"); | ||
|
|
||
| metadata_path = fs::path(context->getPath()) / "handlers_metadata/"; |
There was a problem hiding this comment.
When custom_handlers_storage.type is zookeeper/keeper, the fallback-to-local branch hardcodes metadata_path to <path>/handlers_metadata/ and ignores custom_handlers_storage.path. That means a user-provided path is silently discarded, and handlers are persisted/restored from an unexpected directory.
Please reuse the same path resolution as the local branch (respect custom_handlers_storage.path when present) even in fallback mode.
|
The flaky test failures in this PR ( |
|
The flaky check failure is fixed in #102148, let's update the branch. |
| @@ -0,0 +1,122 @@ | |||
| --- | |||
There was a problem hiding this comment.
The new docs page frontmatter is missing sidebar_position. For new files under docs/, we require full frontmatter fields (description, sidebar_label, sidebar_position, slug, title, doc_type) so navigation ordering is explicit and stable.
Please add sidebar_position to this file.
| bool matchesMethod(const CustomHandlerDefinition & def, const std::string & method) | ||
| { | ||
| if (def.methods.empty()) | ||
| return method == Poco::Net::HTTPRequest::HTTP_GET; |
There was a problem hiding this comment.
METHODS handling currently treats GET as GET only, so HEAD requests do not match handlers created with default methods (or explicit METHODS (GET)).
In ClickHouse HTTP handlers, GET endpoints generally also accept HEAD (e.g. via allowGetAndHeadRequest). With the current logic, clients relying on HEAD for health checks or metadata probes will get unexpected misses for SQL handlers.
Please either:
- treat
HEADas equivalent toGETinmatchesMethod, or - support
HEADin parser/validation/docs and include it in defaults.
Split flaky check and targeted check into separate roles: Flaky check — runs only new/modified tests from the PR with thread fuzzer enabled. Tests run in parallel with themselves (shared queue) to ensure new tests are parallel-safe under randomized thread ordering. Targeted check — runs previously failed and coverage-relevant tests with per-worker partitioning (--no-self-parallel) so the same test never runs concurrently on multiple workers, avoiding conflicts on shared resources (hardcoded users, roles, settings profiles, etc.). Both use --test-runs 50. Changes: - Add --no-self-parallel flag to clickhouse-test: partitions tests by name hash so all copies go to the same worker - Flaky check: only changed tests, thread fuzzer, shared queue - Targeted check: relevant tests, no thread fuzzer, per-worker queues, 50 runs, single clickhouse-test invocation - Restore original thread fuzzer parameters (reverts reductions from 06c945a and 9790435) - Add amd_binary to flaky check, use AMD_LARGE for targeted debug - Targeted check uses --flaky-check --no-self-parallel PRs affected by tests running in parallel with themselves: #102015 #101093 #99653 #101503 #101108 #101884 #100746 #101447 #100941 #101099 #100203 #96130 #102038
Split flaky check and targeted check into separate roles: Flaky check — runs only new/modified tests from the PR with thread fuzzer enabled. Tests can run in parallel with themselves (shared queue) to ensure new tests are parallel-safe. Targeted check — runs previously failed and coverage-relevant tests with per-worker partitioning (--no-self-parallel) so the same test never runs concurrently on multiple workers, avoiding conflicts on shared resources (hardcoded users, roles, settings profiles, etc.). Both use --test-runs 50. Changes: - Add --no-self-parallel flag to clickhouse-test: partitions tests by name hash so all copies go to the same worker - Flaky check: only changed tests, thread fuzzer, shared queue - Targeted check: relevant tests, no thread fuzzer, per-worker partitioning, 50 runs, single clickhouse-test invocation - Restore original thread fuzzer parameters - Change targeted check to arm_asan_ubsan on ARM_LARGE PRs affected by tests running in parallel with themselves: #102015 #101093 #99653 #101503 #101108 #101884 #100746 #101447 #100941 #101099 #100203 #96130
| **Syntax** | ||
|
|
||
| ```sql | ||
| CREATE [IF NOT EXISTS] HANDLER name URL [PREFIX|REGEXP] '/path' [METHODS (GET, POST, ...)] AS 'query' |
There was a problem hiding this comment.
CREATE HANDLER/ALTER HANDLER/DROP HANDLER support ON CLUSTER in parser/interpreter code, but this syntax block omits it. Please document the ON CLUSTER variants (or a dedicated note) for all three statements so users can discover distributed usage from docs.
LLVM Coverage Report
Changed lines: 79.00% (508/643) | lost baseline coverage: 3 line(s) · Uncovered code |
Split flaky check and targeted check into separate roles: Flaky check — runs only new/modified tests from the PR with thread fuzzer enabled. Tests run in parallel with themselves (shared queue) to ensure new tests are parallel-safe under randomized thread ordering. Targeted check — runs previously failed and coverage-relevant tests with per-worker partitioning (--no-self-parallel) so the same test never runs concurrently on multiple workers, avoiding conflicts on shared resources (hardcoded users, roles, settings profiles, etc.). Both use --test-runs 50. Changes: - Add --no-self-parallel flag to clickhouse-test: partitions tests by name hash so all copies go to the same worker - Flaky check: only changed tests, thread fuzzer, shared queue - Targeted check: relevant tests, no thread fuzzer, per-worker queues, 50 runs, single clickhouse-test invocation - Restore original thread fuzzer parameters (reverts reductions from 06c945a and 9790435) - Add amd_binary to flaky check, use AMD_LARGE for targeted debug - Targeted check uses --flaky-check --no-self-parallel PRs affected by tests running in parallel with themselves: ClickHouse#102015 ClickHouse#101093 ClickHouse#99653 ClickHouse#101503 ClickHouse#101108 ClickHouse#101884 ClickHouse#100746 ClickHouse#101447 ClickHouse#100941 ClickHouse#101099 ClickHouse#100203 ClickHouse#96130 ClickHouse#102038
Implement
CREATE HANDLER/DROP HANDLER/ALTER HANDLERqueriesAdd SQL-based management of custom HTTP handlers, allowing users to create, alter, and drop HTTP endpoints dynamically without editing XML configuration files.
Closes #100000
Syntax:
SQL-defined handlers are persisted to disk (under
handlers_metadata/) and restored on server startup. They are matched after config-defined handlers but before the default dynamic query handler, usingPredefinedQueryHandlerfor execution. Handlers are matched lexicographically by name for deterministic ordering.New access types:
CREATE_HANDLER,ALTER_HANDLER,DROP_HANDLER.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add
CREATE HANDLER,ALTER HANDLER, andDROP HANDLERqueries for SQL-based management of custom HTTP handlers, removing the need to edit XML configuration for defining HTTP endpoints.Documentation entry for user-facing changes
Motivation: Currently, custom HTTP handlers in ClickHouse can only be defined via XML configuration (
<http_handlers>section), requiring a config reload or server restart. This feature allows managing HTTP handlers dynamically via SQL, similar to howCREATE NAMED COLLECTIONworks.Parameters:
name— Handler identifier (used for matching priority and management).URL [PREFIX|REGEXP] '/path'— URL matching rule. Default is exact match.PREFIXmatches path prefixes,REGEXPuses RE2 regular expressions.METHODS (GET, POST, ...)— Allowed HTTP methods. Defaults toGET.AS 'query'— The SQL query to execute when the handler is matched.Access control: Requires
CREATE_HANDLER,ALTER_HANDLER, orDROP_HANDLERgrants respectively.Example use: