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/// The plan insights notice will not investigate fast path clusters if plan optimization took longer than this.
81pub const PLAN_INSIGHTS_NOTICE_FAST_PATH_CLUSTERS_OPTIMIZE_DURATION: Config<Duration> = Config::new(
82    "plan_insights_notice_fast_path_clusters_optimize_duration",
83    // Looking at production values of the mz_optimizer_e2e_optimization_time_seconds metric, most
84    // optimizations run faster than 10ms, so this should still work well for most queries. We want
85    // to avoid the case where an optimization took just under this value and there are lots of
86    // clusters, so the extra delay to produce the plan insights notice will take the optimization
87    // time * the number of clusters longer.
88    Duration::from_millis(10),
89    "Enable plan insights fast path clusters calculation if the optimize step took less than this duration.",
90);
91
92/// Whether to create system builtin continual tasks on boot.
93pub const ENABLE_CONTINUAL_TASK_BUILTINS: Config<bool> = Config::new(
94    "enable_continual_task_builtins",
95    false,
96    "Create system builtin continual tasks on boot.",
97);
98
99/// Whether to use an expression cache on boot.
100pub const ENABLE_EXPRESSION_CACHE: Config<bool> = Config::new(
101    "enable_expression_cache",
102    true,
103    "Use a cache to store optimized expressions to help speed up start times.",
104);
105
106/// Whether we allow sources in multi-replica clusters.
107pub const ENABLE_MULTI_REPLICA_SOURCES: Config<bool> = Config::new(
108    "enable_multi_replica_sources",
109    true,
110    "Enable multi-replica sources.",
111);
112
113/// Whether to enable password authentication.
114pub const ENABLE_PASSWORD_AUTH: Config<bool> = Config::new(
115    "enable_password_auth",
116    false,
117    "Enable password authentication.",
118);
119
120/// OIDC issuer URL.
121pub const OIDC_ISSUER: Config<Option<&'static str>> =
122    Config::new("oidc_issuer", None, "OIDC issuer URL.");
123
124/// OIDC audience (client IDs). When empty, audience validation is skipped.
125/// Validates that the JWT's `aud` claim contains at least one of these values.
126/// It is insecure to skip validation because it is the only
127/// mechanism preventing attackers from authenticating using a JWT
128/// issued by a dummy application, but from the same identity provider.
129pub const OIDC_AUDIENCE: Config<fn() -> serde_json::Value> = Config::new(
130    "oidc_audience",
131    || serde_json::json!([]),
132    "OIDC audience (client IDs). A JSON array of strings. When empty, audience validation is skipped.",
133);
134
135/// OIDC authentication claim to use as username
136pub const OIDC_AUTHENTICATION_CLAIM: Config<&'static str> = Config::new(
137    "oidc_authentication_claim",
138    "sub",
139    "OIDC authentication claim to use as username.",
140);
141
142pub const PERSIST_FAST_PATH_ORDER: Config<bool> = Config::new(
143    "persist_fast_path_order",
144    false,
145    "If set, send queries with a compatible literal constraint or ordering clause down the Persist fast path.",
146);
147
148/// Whether to enforce that S3 Tables connections are in the same region as the Materialize
149/// environment.
150pub const ENABLE_S3_TABLES_REGION_CHECK: Config<bool> = Config::new(
151    "enable_s3_tables_region_check",
152    false,
153    "Whether to enforce that S3 Tables connections are in the same region as the environment.",
154);
155
156/// Whether the MCP agents endpoint is enabled.
157pub const ENABLE_MCP_AGENTS: Config<bool> = Config::new(
158    "enable_mcp_agents",
159    true,
160    "Whether the MCP agents HTTP endpoint is enabled. When false, requests to /api/mcp/agents return 503 Service Unavailable.",
161);
162
163/// Whether the MCP observatory endpoint is enabled.
164pub const ENABLE_MCP_OBSERVATORY: Config<bool> = Config::new(
165    "enable_mcp_observatory",
166    true,
167    "Whether the MCP observatory HTTP endpoint is enabled. When false, requests to /api/mcp/observatory return 503 Service Unavailable.",
168);
169
170/// Number of user IDs to pre-allocate in a batch. Pre-allocating IDs avoids
171/// a persist write + oracle call per DDL statement.
172pub const USER_ID_POOL_BATCH_SIZE: Config<u32> = Config::new(
173    "user_id_pool_batch_size",
174    512,
175    "Number of user IDs to pre-allocate in a batch for DDL operations.",
176);
177
178/// Adds the full set of all adapter `Config`s.
179pub fn all_dyncfgs(configs: ConfigSet) -> ConfigSet {
180    configs
181        .add(&ALLOW_USER_SESSIONS)
182        .add(&WITH_0DT_DEPLOYMENT_MAX_WAIT)
183        .add(&WITH_0DT_DEPLOYMENT_DDL_CHECK_INTERVAL)
184        .add(&ENABLE_0DT_DEPLOYMENT_PANIC_AFTER_TIMEOUT)
185        .add(&WITH_0DT_DEPLOYMENT_CAUGHT_UP_CHECK_INTERVAL)
186        .add(&WITH_0DT_CAUGHT_UP_CHECK_ALLOWED_LAG)
187        .add(&WITH_0DT_CAUGHT_UP_CHECK_CUTOFF)
188        .add(&ENABLE_0DT_CAUGHT_UP_REPLICA_STATUS_CHECK)
189        .add(&ENABLE_STATEMENT_LIFECYCLE_LOGGING)
190        .add(&ENABLE_INTROSPECTION_SUBSCRIBES)
191        .add(&PLAN_INSIGHTS_NOTICE_FAST_PATH_CLUSTERS_OPTIMIZE_DURATION)
192        .add(&ENABLE_CONTINUAL_TASK_BUILTINS)
193        .add(&ENABLE_EXPRESSION_CACHE)
194        .add(&ENABLE_MULTI_REPLICA_SOURCES)
195        .add(&ENABLE_PASSWORD_AUTH)
196        .add(&OIDC_ISSUER)
197        .add(&OIDC_AUDIENCE)
198        .add(&OIDC_AUTHENTICATION_CLAIM)
199        .add(&PERSIST_FAST_PATH_ORDER)
200        .add(&ENABLE_S3_TABLES_REGION_CHECK)
201        .add(&ENABLE_MCP_AGENTS)
202        .add(&ENABLE_MCP_OBSERVATORY)
203        .add(&USER_ID_POOL_BATCH_SIZE)
204}