tuwunel_admin/debug/mod.rs
1mod backoff_metrics;
2mod change_log_level;
3mod create_jwt;
4mod database_files;
5mod database_stats;
6mod delete_forward_extremities;
7mod dump_pdus;
8mod echo;
9mod first_pdu_in_room;
10mod force_device_list_updates;
11mod force_set_room_state_from_server;
12mod get_auth_chain;
13mod get_pdu;
14mod get_remote_pdu;
15mod get_remote_pdu_list;
16mod get_retained_pdu;
17mod get_room_state;
18mod get_short_pdu;
19mod get_signing_keys;
20mod get_verify_keys;
21mod latest_pdu_in_room;
22mod list_dependencies;
23mod memory_stats;
24mod parse_pdu;
25mod ping;
26mod prev_walk_metrics;
27mod prev_walk_rooms;
28mod rebuild_relation_index;
29mod rebuild_thread_index;
30mod resolve_true_destination;
31mod resync_database;
32mod runtime_interval;
33mod runtime_metrics;
34mod sign_json;
35mod state_at_incoming;
36mod state_local_metrics;
37mod task_interval;
38mod task_metrics;
39pub(crate) mod tester;
40mod time;
41mod trim_memory;
42mod verify_json;
43mod verify_pdu;
44
45use clap::Subcommand;
46use ruma::{OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName};
47use tuwunel_core::Result;
48use tuwunel_service::rooms::short::ShortRoomId;
49
50use self::tester::TesterCommand;
51use crate::{
52 admin_command_dispatch,
53 event_fetcher::{self, EventFetcherCommand},
54};
55
56#[admin_command_dispatch]
57#[derive(Debug, Subcommand)]
58pub(super) enum DebugCommand {
59 /// - Echo input of admin command
60 Echo {
61 message: Vec<String>,
62 },
63
64 /// - Get the auth_chain of a PDU
65 GetAuthChain {
66 /// An event ID (the $ character followed by the base64 reference hash)
67 event_id: OwnedEventId,
68 },
69
70 /// - Parse and print a PDU from a JSON
71 ///
72 /// The PDU event is only checked for validity and is not added to the
73 /// database.
74 ///
75 /// This command needs a JSON blob provided in a Markdown code block below
76 /// the command.
77 ParsePdu,
78
79 /// - Retrieve and print a PDU by EventID from the tuwunel database
80 GetPdu {
81 /// An event ID (a $ followed by the base64 reference hash)
82 event_id: OwnedEventId,
83 },
84
85 /// - Retrieve and print a PDU by PduId from the tuwunel database
86 GetShortPdu {
87 /// Shortroomid integer
88 shortroomid: ShortRoomId,
89
90 /// PduCount integer
91 count: i64,
92 },
93
94 /// - Attempts to retrieve a PDU from a remote server. Inserts it into our
95 /// database/timeline if found and we do not have this PDU already
96 /// (following normal event auth rules, handles it as an incoming PDU).
97 GetRemotePdu {
98 /// An event ID (a $ followed by the base64 reference hash)
99 event_id: OwnedEventId,
100
101 /// Argument for us to attempt to fetch the event from the
102 /// specified remote server.
103 server: OwnedServerName,
104 },
105
106 /// - Same as `get-remote-pdu` but accepts a codeblock newline delimited
107 /// list of PDUs and a single server to fetch from
108 GetRemotePduList {
109 /// Argument for us to attempt to fetch all the events from the
110 /// specified remote server.
111 server: OwnedServerName,
112
113 /// If set, ignores errors, else stops at the first error/failure.
114 #[arg(short, long)]
115 force: bool,
116 },
117
118 /// - Gets all the room state events for the specified room.
119 GetRoomState {
120 /// Room ID
121 room_id: OwnedRoomOrAliasId,
122
123 /// Event Type
124 kind: Option<String>,
125
126 /// State Key
127 state_key: Option<String>,
128 },
129
130 /// - Get and display signing keys from local cache or remote server.
131 GetSigningKeys {
132 server_name: Option<OwnedServerName>,
133
134 #[arg(long)]
135 notary: Option<OwnedServerName>,
136
137 #[arg(short, long)]
138 query: bool,
139 },
140
141 /// - Get and display signing keys from local cache or remote server.
142 GetVerifyKeys {
143 server_name: Option<OwnedServerName>,
144 },
145
146 /// - Sends a federation request to the remote server's
147 /// `/_matrix/federation/v1/version` endpoint and measures the latency it
148 /// took for the server to respond
149 Ping {
150 server: OwnedServerName,
151 },
152
153 /// - Forces device lists for all local and remote users to be updated (as
154 /// having new keys available)
155 ForceDeviceListUpdates,
156
157 /// - Change tracing log level/filter on the fly
158 ///
159 /// This accepts the same format as the `log` config option.
160 ChangeLogLevel {
161 /// Log level/filter
162 filter: Option<String>,
163
164 /// Resets the log level/filter to the one in your config
165 #[arg(short, long)]
166 reset: bool,
167 },
168
169 /// - Sign JSON blob
170 ///
171 /// This command needs a JSON blob provided in a Markdown code block below
172 /// the command.
173 SignJson,
174
175 /// - Verify JSON signatures
176 ///
177 /// This command needs a JSON blob provided in a Markdown code block below
178 /// the command.
179 VerifyJson,
180
181 /// - Verify PDU
182 ///
183 /// This re-verifies a PDU existing in the database found by ID.
184 VerifyPdu {
185 event_id: OwnedEventId,
186 },
187
188 /// - Prints the very first PDU in the specified room (typically
189 /// m.room.create)
190 FirstPduInRoom {
191 /// The room ID
192 room_id: OwnedRoomId,
193 },
194
195 /// - Prints the latest ("last") PDU in the specified room (typically a
196 /// message)
197 LatestPduInRoom {
198 /// The room ID
199 room_id: OwnedRoomId,
200 },
201
202 /// - Forcefully replaces the room state of our local copy of the specified
203 /// room, with the copy (auth chain and room state events) the specified
204 /// remote server says.
205 ///
206 /// A common desire for room deletion is to simply "reset" our copy of the
207 /// room. While this admin command is not a replacement for that, if you
208 /// know you have split/broken room state and you know another server in the
209 /// room that has the best/working room state, this command can let you use
210 /// their room state. Such example is your server saying users are in a
211 /// room, but other servers are saying they're not in the room in question.
212 ///
213 /// This command will get the latest PDU in the room we know about, and
214 /// request the room state at that point in time via
215 /// `/_matrix/federation/v1/state/{roomId}`.
216 ForceSetRoomStateFromServer {
217 /// The impacted room ID
218 room_id: OwnedRoomId,
219 /// The server we will use to query the room state for
220 server_name: OwnedServerName,
221 },
222
223 /// - Prunes the room's forward extremities down to a single one, keeping
224 /// the extremity furthest along in stream order.
225 ///
226 /// A room accumulates extra forward extremities when it takes on events
227 /// across a gap or fork it cannot fully resolve; collapsing them repairs a
228 /// room wedged with a large or growing extremity set. This is the
229 /// admin-command counterpart to the Synapse
230 /// `DELETE /_synapse/admin/v1/rooms/{roomId}/forward_extremities` endpoint.
231 DeleteForwardExtremities {
232 /// The room ID or alias
233 room_id: OwnedRoomOrAliasId,
234 },
235
236 /// - Runs a server name through tuwunel's true destination resolution
237 /// process
238 ///
239 /// Useful for debugging well-known issues
240 ResolveTrueDestination {
241 server_name: OwnedServerName,
242
243 #[arg(short, long)]
244 no_cache: bool,
245 },
246
247 /// - Print extended memory usage
248 ///
249 /// Optional argument is a character mask (a sequence of characters in any
250 /// order) which enable additional extended statistics. Known characters are
251 /// "abdeglmx". For convenience, a '*' will enable everything.
252 MemoryStats {
253 opts: Option<String>,
254 },
255
256 /// - Print general tokio runtime metric totals.
257 RuntimeMetrics,
258
259 /// - Print detailed tokio runtime metrics accumulated since last command
260 /// invocation.
261 RuntimeInterval,
262
263 /// - Print detailed tokio task metrics accumulated in total.
264 TaskMetrics,
265
266 /// - Print process-lifetime state-local build metrics.
267 ///
268 /// Difference two snapshots to observe an interval.
269 StateLocalMetrics,
270
271 /// - Print process-lifetime incoming prev-walk metrics.
272 ///
273 /// Difference two snapshots to observe an interval.
274 PrevWalkMetrics,
275
276 /// - Print process-lifetime backoff verdict metrics.
277 ///
278 /// Difference two snapshots to observe an interval.
279 BackoffMetrics,
280
281 /// - Print the prev walk passes recorded per room, kept for up to three days.
282 ///
283 /// Without a room, lists the rooms with the most recorded passes and their
284 /// totals. With a room, lists its latest passes. A pass is recorded when it
285 /// ends, unless a backoff hold withheld it or its fetch left nothing to walk.
286 PrevWalkRooms {
287 /// The room to list the latest passes of
288 room_id: Option<OwnedRoomId>,
289
290 /// How many rooms or passes to list
291 #[arg(short, long, default_value_t = 20)]
292 limit: usize,
293 },
294
295 /// - Print detailed tokio task metrics accumulated since last command
296 /// invocation.
297 TaskInterval,
298
299 /// - Print the current time
300 Time,
301
302 /// - List dependencies
303 ListDependencies {
304 #[arg(short, long)]
305 names: bool,
306 },
307
308 /// - Get database statistics
309 DatabaseStats {
310 property: Option<String>,
311
312 #[arg(short, long, alias("column"))]
313 map: Option<String>,
314 },
315
316 /// - Trim memory usage
317 TrimMemory,
318
319 /// - List database files
320 DatabaseFiles {
321 map: Option<String>,
322
323 #[arg(long)]
324 level: Option<i32>,
325 },
326
327 /// - Create a JWT token for login
328 CreateJwt {
329 /// Localpart of the user's MXID
330 user: String,
331
332 /// Set expiration time in seconds from now.
333 #[arg(long)]
334 exp_from_now: Option<u64>,
335
336 /// Set not-before time in seconds from now.
337 #[arg(long)]
338 nbf_from_now: Option<u64>,
339
340 /// Claim an issuer.
341 #[arg(long)]
342 issuer: Option<String>,
343
344 /// Claim an audience.
345 #[arg(long)]
346 audience: Option<String>,
347 },
348
349 /// - Synchronize database with primary (secondary only)
350 ResyncDatabase,
351
352 /// - Rebuild the typed relation index (relatesto_typed) from all PDUs
353 RebuildRelationIndex,
354
355 /// - Rebuild the thread activity index (threadactivityid_rootid) from all
356 /// thread roots
357 RebuildThreadIndex,
358
359 /// - Retrieves the saved original PDU before it has been redacted
360 GetRetainedPdu {
361 event_id: OwnedEventId,
362 },
363
364 /// - Dump all stored PDUs
365 DumpPdus {
366 dir: String,
367 },
368
369 /// - Run a diagnostic local state derivation for one stored event and report
370 /// the outcome without writing room state, resolved-state memos, or
371 /// production counters
372 StateAtIncoming {
373 /// An event ID (a $ followed by the base64 reference hash)
374 event_id: OwnedEventId,
375 },
376
377 /// - Drive the federation event-fetcher service directly (diagnostic)
378 #[command(subcommand)]
379 #[clap(hide = true)]
380 EventFetcher(EventFetcherCommand),
381
382 /// - Developer test stubs
383 #[command(subcommand)]
384 #[clap(hide(true))]
385 Tester(TesterCommand),
386}