mz_storage_client/
healthcheck.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
10use mz_repr::{RelationDesc, SqlScalarType};
11use std::sync::LazyLock;
12
13pub static MZ_PREPARED_STATEMENT_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
14    RelationDesc::builder()
15        .with_column("id", SqlScalarType::Uuid.nullable(false))
16        .with_column("session_id", SqlScalarType::Uuid.nullable(false))
17        .with_column("name", SqlScalarType::String.nullable(false))
18        .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
19        .with_column(
20            "prepared_at",
21            SqlScalarType::TimestampTz { precision: None }.nullable(false),
22        )
23        .with_column("statement_type", SqlScalarType::String.nullable(true))
24        .with_column("throttled_count", SqlScalarType::UInt64.nullable(false))
25        .finish()
26});
27
28pub static MZ_SQL_TEXT_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
29    RelationDesc::builder()
30        .with_column(
31            "prepared_day",
32            SqlScalarType::TimestampTz { precision: None }.nullable(false),
33        )
34        .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
35        .with_column("sql", SqlScalarType::String.nullable(false))
36        .with_column("redacted_sql", SqlScalarType::String.nullable(false))
37        .finish()
38});
39
40pub static MZ_SESSION_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
41    RelationDesc::builder()
42        .with_column("session_id", SqlScalarType::Uuid.nullable(false))
43        .with_column(
44            "connected_at",
45            SqlScalarType::TimestampTz { precision: None }.nullable(false),
46        )
47        .with_column(
48            "initial_application_name",
49            SqlScalarType::String.nullable(false),
50        )
51        .with_column("authenticated_user", SqlScalarType::String.nullable(false))
52        .finish()
53});
54
55// NOTE: Update the views `mz_statement_execution_history_redacted`
56// and `mz_activity_log`, and `mz_activity_log_redacted` whenever this
57// is updated, to include the new columns where appropriate.
58//
59// The `redacted` views should contain only those columns that should
60// be queryable by support.
61pub static MZ_STATEMENT_EXECUTION_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
62    RelationDesc::builder()
63        .with_column("id", SqlScalarType::Uuid.nullable(false))
64        .with_column("prepared_statement_id", SqlScalarType::Uuid.nullable(false))
65        .with_column("sample_rate", SqlScalarType::Float64.nullable(false))
66        .with_column("cluster_id", SqlScalarType::String.nullable(true))
67        .with_column("application_name", SqlScalarType::String.nullable(false))
68        .with_column("cluster_name", SqlScalarType::String.nullable(true))
69        .with_column("database_name", SqlScalarType::String.nullable(false))
70        .with_column(
71            "search_path",
72            SqlScalarType::List {
73                element_type: Box::new(SqlScalarType::String),
74                custom_id: None,
75            }
76            .nullable(false),
77        )
78        .with_column(
79            "transaction_isolation",
80            SqlScalarType::String.nullable(false),
81        )
82        // Note that this can't be a timestamp, as it might be u64::max,
83        // which is out of range.
84        .with_column("execution_timestamp", SqlScalarType::UInt64.nullable(true))
85        .with_column("transaction_id", SqlScalarType::UInt64.nullable(false))
86        .with_column("transient_index_id", SqlScalarType::String.nullable(true))
87        .with_column(
88            "params",
89            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
90        )
91        .with_column("mz_version", SqlScalarType::String.nullable(false))
92        .with_column(
93            "began_at",
94            SqlScalarType::TimestampTz { precision: None }.nullable(false),
95        )
96        .with_column(
97            "finished_at",
98            SqlScalarType::TimestampTz { precision: None }.nullable(true),
99        )
100        .with_column("finished_status", SqlScalarType::String.nullable(true))
101        .with_column("error_message", SqlScalarType::String.nullable(true))
102        .with_column("result_size", SqlScalarType::Int64.nullable(true))
103        .with_column("rows_returned", SqlScalarType::Int64.nullable(true))
104        .with_column("execution_strategy", SqlScalarType::String.nullable(true))
105        .finish()
106});
107
108pub static MZ_SOURCE_STATUS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
109    RelationDesc::builder()
110        .with_column(
111            "occurred_at",
112            SqlScalarType::TimestampTz { precision: None }.nullable(false),
113        )
114        .with_column("source_id", SqlScalarType::String.nullable(false))
115        .with_column("status", SqlScalarType::String.nullable(false))
116        .with_column("error", SqlScalarType::String.nullable(true))
117        .with_column("details", SqlScalarType::Jsonb.nullable(true))
118        .with_column("replica_id", SqlScalarType::String.nullable(true))
119        .finish()
120});
121
122pub static MZ_SINK_STATUS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
123    RelationDesc::builder()
124        .with_column(
125            "occurred_at",
126            SqlScalarType::TimestampTz { precision: None }.nullable(false),
127        )
128        .with_column("sink_id", SqlScalarType::String.nullable(false))
129        .with_column("status", SqlScalarType::String.nullable(false))
130        .with_column("error", SqlScalarType::String.nullable(true))
131        .with_column("details", SqlScalarType::Jsonb.nullable(true))
132        .with_column("replica_id", SqlScalarType::String.nullable(true))
133        .finish()
134});
135
136pub static MZ_AWS_PRIVATELINK_CONNECTION_STATUS_HISTORY_DESC: LazyLock<RelationDesc> =
137    LazyLock::new(|| {
138        RelationDesc::builder()
139            .with_column(
140                "occurred_at",
141                SqlScalarType::TimestampTz { precision: None }.nullable(false),
142            )
143            .with_column("connection_id", SqlScalarType::String.nullable(false))
144            .with_column("status", SqlScalarType::String.nullable(false))
145            .finish()
146    });
147
148pub static REPLICA_STATUS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
149    RelationDesc::builder()
150        .with_column("replica_id", SqlScalarType::String.nullable(false))
151        .with_column("process_id", SqlScalarType::UInt64.nullable(false))
152        .with_column("status", SqlScalarType::String.nullable(false))
153        .with_column("reason", SqlScalarType::String.nullable(true))
154        .with_column(
155            "occurred_at",
156            SqlScalarType::TimestampTz { precision: None }.nullable(false),
157        )
158        .finish()
159});
160
161pub static REPLICA_METRICS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
162    RelationDesc::builder()
163        .with_column("replica_id", SqlScalarType::String.nullable(false))
164        .with_column("process_id", SqlScalarType::UInt64.nullable(false))
165        .with_column("cpu_nano_cores", SqlScalarType::UInt64.nullable(true))
166        .with_column("memory_bytes", SqlScalarType::UInt64.nullable(true))
167        .with_column("disk_bytes", SqlScalarType::UInt64.nullable(true))
168        .with_column(
169            "occurred_at",
170            SqlScalarType::TimestampTz { precision: None }.nullable(false),
171        )
172        .finish()
173});
174
175pub static WALLCLOCK_LAG_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
176    RelationDesc::builder()
177        .with_column("object_id", SqlScalarType::String.nullable(false))
178        .with_column("replica_id", SqlScalarType::String.nullable(true))
179        .with_column("lag", SqlScalarType::Interval.nullable(true))
180        .with_column(
181            "occurred_at",
182            SqlScalarType::TimestampTz { precision: None }.nullable(false),
183        )
184        .finish()
185});
186
187pub static WALLCLOCK_GLOBAL_LAG_HISTOGRAM_RAW_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
188    RelationDesc::builder()
189        .with_column(
190            "period_start",
191            SqlScalarType::TimestampTz { precision: None }.nullable(false),
192        )
193        .with_column(
194            "period_end",
195            SqlScalarType::TimestampTz { precision: None }.nullable(false),
196        )
197        .with_column("object_id", SqlScalarType::String.nullable(false))
198        .with_column("lag_seconds", SqlScalarType::UInt64.nullable(true))
199        .with_column("labels", SqlScalarType::Jsonb.nullable(false))
200        .finish()
201});