Skip to main content

mz_adapter_types/
dyncfgs.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Dyncfgs used by the adapter layer.
11
12use std::time::Duration;
13
14use mz_dyncfg::{Config, ConfigSet};
15
16pub const ALLOW_USER_SESSIONS: Config<bool> = Config::new(
17    "allow_user_sessions",
18    true,
19    "Whether to allow user roles to create new sessions. When false, only system roles will be permitted to create new sessions.",
20);
21
22// Slightly awkward with the WITH prefix, but we can't start with a 0..
23pub const WITH_0DT_DEPLOYMENT_MAX_WAIT: Config<Duration> = Config::new(
24    "with_0dt_deployment_max_wait",
25    Duration::from_secs(60 * 60 * 72),
26    "How long to wait at most for clusters to be hydrated, when doing a zero-downtime deployment.",
27);
28
29pub const WITH_0DT_DEPLOYMENT_DDL_CHECK_INTERVAL: Config<Duration> = Config::new(
30    "with_0dt_deployment_ddl_check_interval",
31    Duration::from_secs(5 * 60),
32    "How often to check for DDL changes during zero-downtime deployment.",
33);
34
35pub const ENABLE_0DT_DEPLOYMENT_PANIC_AFTER_TIMEOUT: Config<bool> = Config::new(
36    "enable_0dt_deployment_panic_after_timeout",
37    false,
38    "Whether to panic if the maximum wait time is reached but preflight checks have not succeeded.",
39);
40
41pub const WITH_0DT_DEPLOYMENT_CAUGHT_UP_CHECK_INTERVAL: Config<Duration> = Config::new(
42    // The feature flag name is historical.
43    "0dt_deployment_hydration_check_interval",
44    Duration::from_secs(10),
45    "Interval at which to check whether clusters are caught up, when doing zero-downtime deployment.",
46);
47
48pub const WITH_0DT_CAUGHT_UP_CHECK_ALLOWED_LAG: Config<Duration> = Config::new(
49    "with_0dt_caught_up_check_allowed_lag",
50    Duration::from_secs(60),
51    "Maximum allowed lag when determining whether collections are caught up for 0dt deployments.",
52);
53
54pub const WITH_0DT_CAUGHT_UP_CHECK_CUTOFF: Config<Duration> = Config::new(
55    "with_0dt_caught_up_check_cutoff",
56    Duration::from_secs(2 * 60 * 60), // 2 hours
57    "Collections whose write frontier is behind 'now' by more than the cutoff are ignored when doing caught-up checks for 0dt deployments.",
58);
59
60pub const ENABLE_0DT_CAUGHT_UP_REPLICA_STATUS_CHECK: Config<bool> = Config::new(
61    "enable_0dt_caught_up_replica_status_check",
62    true,
63    "Enable checking for crash/OOM-looping replicas during 0dt caught-up checks. Emergency break-glass flag to disable this feature if needed.",
64);
65
66/// Enable logging of statement lifecycle events in mz_internal.mz_statement_lifecycle_history.
67pub const ENABLE_STATEMENT_LIFECYCLE_LOGGING: Config<bool> = Config::new(
68    "enable_statement_lifecycle_logging",
69    true,
70    "Enable logging of statement lifecycle events in mz_internal.mz_statement_lifecycle_history.",
71);
72
73/// Enable installation of introspection subscribes.
74pub const ENABLE_INTROSPECTION_SUBSCRIBES: Config<bool> = Config::new(
75    "enable_introspection_subscribes",
76    true,
77    "Enable installation of introspection subscribes.",
78);
79
80/// Enable sending subscribes down the new frontend-peek path.
81pub const ENABLE_FRONTEND_SUBSCRIBES: Config<bool> = Config::new(
82    "enable_frontend_subscribes",
83    true,
84    "Enable sending subscribes down the new frontend-peek path.",
85);
86
87/// The plan insights notice will not investigate fast path clusters if plan optimization took longer than this.
88pub const PLAN_INSIGHTS_NOTICE_FAST_PATH_CLUSTERS_OPTIMIZE_DURATION: Config<Duration> = Config::new(
89    "plan_insights_notice_fast_path_clusters_optimize_duration",
90    // Looking at production values of the mz_optimizer_e2e_optimization_time_seconds metric, most
91    // optimizations run faster than 10ms, so this should still work well for most queries. We want
92    // to avoid the case where an optimization took just under this value and there are lots of
93    // clusters, so the extra delay to produce the plan insights notice will take the optimization
94    // time * the number of clusters longer.
95    Duration::from_millis(10),
96    "Enable plan insights fast path clusters calculation if the optimize step took less than this duration.",
97);
98
99/// Whether to create system builtin continual tasks on boot.
100pub const ENABLE_CONTINUAL_TASK_BUILTINS: Config<bool> = Config::new(
101    "enable_continual_task_builtins",
102    false,
103    "Create system builtin continual tasks on boot.",
104);
105
106/// Whether to use an expression cache on boot.
107pub const ENABLE_EXPRESSION_CACHE: Config<bool> = Config::new(
108    "enable_expression_cache",
109    true,
110    "Use a cache to store optimized expressions to help speed up start times.",
111);
112
113/// Whether we allow sources in multi-replica clusters.
114pub const ENABLE_MULTI_REPLICA_SOURCES: Config<bool> = Config::new(
115    "enable_multi_replica_sources",
116    true,
117    "Enable multi-replica sources.",
118);
119
120/// Whether to enable password authentication.
121pub const ENABLE_PASSWORD_AUTH: Config<bool> = Config::new(
122    "enable_password_auth",
123    false,
124    "Enable password authentication.",
125);
126
127/// OIDC issuer URL.
128pub const OIDC_ISSUER: Config<Option<&'static str>> =
129    Config::new("oidc_issuer", None, "OIDC issuer URL.");
130
131/// OIDC audience (client IDs). When empty, audience validation is skipped.
132/// Validates that the JWT's `aud` claim contains at least one of these values.
133/// It is insecure to skip validation because it is the only
134/// mechanism preventing attackers from authenticating using a JWT
135/// issued by a dummy application, but from the same identity provider.
136pub const OIDC_AUDIENCE: Config<fn() -> serde_json::Value> = Config::new(
137    "oidc_audience",
138    || serde_json::json!([]),
139    "OIDC audience (client IDs). A JSON array of strings. When empty, audience validation is skipped.",
140);
141
142/// OIDC authentication claim to use as username
143pub const OIDC_AUTHENTICATION_CLAIM: Config<&'static str> = Config::new(
144    "oidc_authentication_claim",
145    "sub",
146    "OIDC authentication claim to use as username.",
147);
148
149pub const PERSIST_FAST_PATH_ORDER: Config<bool> = Config::new(
150    "persist_fast_path_order",
151    false,
152    "If set, send queries with a compatible literal constraint or ordering clause down the Persist fast path.",
153);
154
155/// Whether to enforce that S3 Tables connections are in the same region as the Materialize
156/// environment.
157pub const ENABLE_S3_TABLES_REGION_CHECK: Config<bool> = Config::new(
158    "enable_s3_tables_region_check",
159    false,
160    "Whether to enforce that S3 Tables connections are in the same region as the environment.",
161);
162
163/// Whether the MCP agents endpoint is enabled.
164pub const ENABLE_MCP_AGENTS: Config<bool> = Config::new(
165    "enable_mcp_agents",
166    false,
167    "Whether the MCP agents HTTP endpoint is enabled. When false, requests to /api/mcp/agents return 503 Service Unavailable.",
168);
169
170/// Whether the MCP agents query tool is enabled.
171/// When false, the `query` tool is hidden from tools/list and calls to it return an error.
172/// Agents can still use `get_data_products` and `get_data_product_details`.
173pub const ENABLE_MCP_AGENTS_QUERY_TOOL: Config<bool> = Config::new(
174    "enable_mcp_agents_query_tool",
175    false,
176    "Whether the MCP agents query tool is enabled. When false, the query tool is not advertised and calls to it are rejected. Agents can still discover and inspect data products.",
177);
178
179/// Whether the MCP observatory endpoint is enabled.
180pub const ENABLE_MCP_OBSERVATORY: Config<bool> = Config::new(
181    "enable_mcp_observatory",
182    false,
183    "Whether the MCP observatory HTTP endpoint is enabled. When false, requests to /api/mcp/observatory return 503 Service Unavailable.",
184);
185
186/// Maximum size (in bytes) of MCP tool response content after JSON serialization.
187/// Responses exceeding this limit are rejected with a clear error telling the
188/// agent to narrow its query. Keeps responses within LLM context window limits.
189pub const MCP_MAX_RESPONSE_SIZE: Config<usize> = Config::new(
190    "mcp_max_response_size",
191    1_000_000,
192    "Maximum size in bytes of MCP tool response content. Responses exceeding this limit are rejected with an error telling the agent to narrow its query.",
193);
194
195/// Number of user IDs to pre-allocate in a batch. Pre-allocating IDs avoids
196/// a persist write + oracle call per DDL statement.
197pub const USER_ID_POOL_BATCH_SIZE: Config<u32> = Config::new(
198    "user_id_pool_batch_size",
199    512,
200    "Number of user IDs to pre-allocate in a batch for DDL operations.",
201);
202
203/// OIDC client ID for the web console.
204pub const CONSOLE_OIDC_CLIENT_ID: Config<&'static str> = Config::new(
205    "console_oidc_client_id",
206    "",
207    "OIDC client ID for the web console.",
208);
209
210/// Space-separated OIDC scopes requested by the web console.
211pub const CONSOLE_OIDC_SCOPES: Config<&'static str> = Config::new(
212    "console_oidc_scopes",
213    "",
214    "Space-separated OIDC scopes requested by the web console.",
215);
216
217/// Adds the full set of all adapter `Config`s.
218pub fn all_dyncfgs(configs: ConfigSet) -> ConfigSet {
219    configs
220        .add(&ALLOW_USER_SESSIONS)
221        .add(&WITH_0DT_DEPLOYMENT_MAX_WAIT)
222        .add(&WITH_0DT_DEPLOYMENT_DDL_CHECK_INTERVAL)
223        .add(&ENABLE_0DT_DEPLOYMENT_PANIC_AFTER_TIMEOUT)
224        .add(&WITH_0DT_DEPLOYMENT_CAUGHT_UP_CHECK_INTERVAL)
225        .add(&WITH_0DT_CAUGHT_UP_CHECK_ALLOWED_LAG)
226        .add(&WITH_0DT_CAUGHT_UP_CHECK_CUTOFF)
227        .add(&ENABLE_0DT_CAUGHT_UP_REPLICA_STATUS_CHECK)
228        .add(&ENABLE_STATEMENT_LIFECYCLE_LOGGING)
229        .add(&ENABLE_INTROSPECTION_SUBSCRIBES)
230        .add(&ENABLE_FRONTEND_SUBSCRIBES)
231        .add(&PLAN_INSIGHTS_NOTICE_FAST_PATH_CLUSTERS_OPTIMIZE_DURATION)
232        .add(&ENABLE_CONTINUAL_TASK_BUILTINS)
233        .add(&ENABLE_EXPRESSION_CACHE)
234        .add(&ENABLE_MULTI_REPLICA_SOURCES)
235        .add(&ENABLE_PASSWORD_AUTH)
236        .add(&OIDC_ISSUER)
237        .add(&OIDC_AUDIENCE)
238        .add(&OIDC_AUTHENTICATION_CLAIM)
239        .add(&PERSIST_FAST_PATH_ORDER)
240        .add(&ENABLE_S3_TABLES_REGION_CHECK)
241        .add(&ENABLE_MCP_AGENTS)
242        .add(&ENABLE_MCP_AGENTS_QUERY_TOOL)
243        .add(&ENABLE_MCP_OBSERVATORY)
244        .add(&MCP_MAX_RESPONSE_SIZE)
245        .add(&USER_ID_POOL_BATCH_SIZE)
246        .add(&CONSOLE_OIDC_CLIENT_ID)
247        .add(&CONSOLE_OIDC_SCOPES)
248}