Skip to content

Commit e9d950d

Browse files
committed
feat: Add runtime configuration help system
Implement CONFIG HELP, CONFIG SHOW, and CONFIG VERIFY commands to provide runtime configuration guidance without external documentation. Changes: - Add ConfigSchemaExplorer to navigate JSON Schema and extract help info - Implement CONFIG HELP [path] - display help for config options - Implement CONFIG SHOW [path] - display current config (masks secrets) - Implement CONFIG VERIFY <filepath> - validate config files - Add sensitive field masking (password, secret, key, token) - Update QueryParser to support CONFIG subcommands - Extend AdminHandler with CONFIG command handlers - Add comprehensive tests (41 tests: 22 unit + 19 integration) - Update documentation (en/ja for protocol and configuration) Features: - Runtime config exploration via dot-separated paths (e.g., mysql.port) - Automatic masking of sensitive fields with *** - Schema-based help with types, defaults, ranges, descriptions - Config file verification without loading into running server Closes #4
1 parent dc11a67 commit e9d950d

18 files changed

+2062
-53
lines changed

docs/en/configuration.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,96 @@ MygramDB automatically validates all configuration files (YAML and JSON) using a
522522

523523
If validation fails, MygramDB will display a detailed error message pointing to the exact problem.
524524

525+
## Runtime Configuration Help
526+
527+
MygramDB provides runtime commands to explore configuration options, view current settings, and verify configuration files without restarting the server.
528+
529+
### Getting Configuration Help
530+
531+
You can query configuration help at runtime using the `CONFIG HELP` command:
532+
533+
```bash
534+
# Show all configuration sections
535+
echo "CONFIG HELP" | nc localhost 11016
536+
```
537+
538+
**Example output:**
539+
```
540+
+OK
541+
Available configuration sections:
542+
mysql - MySQL connection settings
543+
tables - Table configuration (supports multiple tables)
544+
build - Index build configuration
545+
replication - Replication configuration
546+
memory - Memory management
547+
...
548+
```
549+
550+
### Viewing Detailed Help
551+
552+
Get help for specific configuration options:
553+
554+
```bash
555+
# Help for MySQL section
556+
echo "CONFIG HELP mysql" | nc localhost 11016
557+
558+
# Help for a specific property
559+
echo "CONFIG HELP mysql.port" | nc localhost 11016
560+
```
561+
562+
This displays:
563+
- Property type (string, integer, boolean, etc.)
564+
- Default value
565+
- Valid range or allowed values
566+
- Description
567+
- Whether the field is required
568+
569+
### Viewing Current Configuration
570+
571+
View the running configuration with sensitive fields masked:
572+
573+
```bash
574+
# Show entire configuration
575+
echo "CONFIG SHOW" | nc localhost 11016
576+
577+
# Show specific section
578+
echo "CONFIG SHOW mysql" | nc localhost 11016
579+
580+
# Show specific property
581+
echo "CONFIG SHOW mysql.port" | nc localhost 11016
582+
```
583+
584+
**Note**: Sensitive fields (passwords, secrets, keys, tokens) are automatically masked as `***` in the output.
585+
586+
### Verifying Configuration Files
587+
588+
Verify a configuration file before deploying it:
589+
590+
```bash
591+
echo "CONFIG VERIFY /path/to/config.yaml" | nc localhost 11016
592+
```
593+
594+
This validates the configuration without loading it into the running server. If the configuration is valid, you'll see a summary:
595+
596+
```
597+
+OK
598+
Configuration is valid
599+
Tables: 2 (articles, products)
600+
MySQL: repl_user@127.0.0.1:3306
601+
```
602+
603+
If invalid, you'll see detailed error messages:
604+
605+
```
606+
-ERR Configuration validation failed:
607+
- mysql.port: value 99999 exceeds maximum 65535
608+
- tables[0].name: missing required field
609+
```
610+
611+
For complete CONFIG command syntax, see the [Protocol Reference](protocol.md#config-commands).
612+
613+
---
614+
525615
## Testing Configuration
526616

527617
Before starting the server, you can test your configuration file:

docs/en/protocol.md

Lines changed: 195 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,208 @@ replication_deletes_applied: 5000
185185

186186
---
187187

188-
## CONFIG Command
188+
## CONFIG Commands
189189

190-
Get current server configuration (all settings).
190+
The CONFIG command family provides runtime configuration help, inspection, and verification.
191191

192-
### Syntax
192+
### CONFIG HELP [path]
193+
194+
Display help for configuration options.
193195

196+
**Syntax:**
194197
```
195-
CONFIG
198+
CONFIG HELP [path]
196199
```
197200

198-
### Response
201+
**Parameters:**
202+
- `path` (optional): Dot-separated configuration path (e.g., `mysql.port`)
203+
204+
**Examples:**
205+
206+
Show all top-level configuration sections:
207+
```
208+
CONFIG HELP
209+
```
210+
211+
Response:
212+
```
213+
+OK
214+
Available configuration sections:
215+
mysql - MySQL connection settings
216+
tables - Table configuration (supports multiple tables)
217+
build - Index build configuration
218+
replication - Replication configuration
219+
memory - Memory management
220+
dump - Dump persistence (automatic backup)
221+
api - API server configuration
222+
network - Network security (optional)
223+
logging - Logging configuration
224+
cache - Query cache configuration
225+
226+
Use "CONFIG HELP <section>" for detailed information.
227+
```
228+
229+
Show help for a specific section:
230+
```
231+
CONFIG HELP mysql
232+
```
233+
234+
Response:
235+
```
236+
+OK
237+
mysql - MySQL connection settings
238+
239+
Properties:
240+
host (string, default: "127.0.0.1")
241+
MySQL server hostname or IP
242+
243+
port (integer, default: 3306, range: 1-65535)
244+
MySQL server port
245+
246+
user (string, REQUIRED)
247+
MySQL username for replication
248+
249+
password (string)
250+
MySQL user password
251+
252+
database (string, REQUIRED)
253+
Database name
254+
255+
use_gtid (boolean, default: true)
256+
Enable GTID-based replication
257+
258+
...
259+
```
260+
261+
Show help for a specific property:
262+
```
263+
CONFIG HELP mysql.port
264+
```
265+
266+
Response:
267+
```
268+
+OK
269+
mysql.port
270+
271+
Type: integer
272+
Default: 3306
273+
Range: 1 - 65535
274+
Description: MySQL server port
275+
```
276+
277+
---
278+
279+
### CONFIG SHOW [path]
280+
281+
Display current configuration values. Sensitive fields (passwords, secrets) are masked with `***`.
282+
283+
**Syntax:**
284+
```
285+
CONFIG SHOW [path]
286+
```
287+
288+
**Parameters:**
289+
- `path` (optional): Dot-separated configuration path to show only specific section
290+
291+
**Examples:**
199292

200-
Returns a YAML-style formatted configuration showing:
201-
- MySQL connection settings
202-
- Table configurations (name, primary_key, ngram_size, filters count)
203-
- API server settings (bind address and port)
204-
- Replication settings (enable, server_id, start_from)
205-
- Memory configuration (limits, thresholds)
206-
- Snapshot directory
207-
- Logging level
208-
- Runtime status (connections, uptime, read_only mode)
293+
Show entire current configuration:
294+
```
295+
CONFIG SHOW
296+
```
297+
298+
Response:
299+
```
300+
+OK
301+
mysql:
302+
host: "127.0.0.1"
303+
port: 3306
304+
user: "repl_user"
305+
password: "***"
306+
database: "mydb"
307+
use_gtid: true
308+
...
309+
310+
tables:
311+
- name: "articles"
312+
primary_key: "id"
313+
...
314+
315+
replication:
316+
enable: true
317+
server_id: 12345
318+
...
319+
```
320+
321+
Show specific section:
322+
```
323+
CONFIG SHOW mysql
324+
```
325+
326+
Response:
327+
```
328+
+OK
329+
mysql:
330+
host: "127.0.0.1"
331+
port: 3306
332+
user: "repl_user"
333+
password: "***"
334+
database: "mydb"
335+
use_gtid: true
336+
...
337+
```
338+
339+
Show specific property:
340+
```
341+
CONFIG SHOW mysql.port
342+
```
343+
344+
Response:
345+
```
346+
+OK
347+
3306
348+
```
349+
350+
---
351+
352+
### CONFIG VERIFY <filepath>
353+
354+
Verify a configuration file without loading it.
355+
356+
**Syntax:**
357+
```
358+
CONFIG VERIFY <filepath>
359+
```
360+
361+
**Parameters:**
362+
- `filepath` (required): Path to configuration file (YAML or JSON)
363+
364+
**Examples:**
365+
366+
Verify valid config:
367+
```
368+
CONFIG VERIFY /etc/mygramdb/config.yaml
369+
```
370+
371+
Response (success):
372+
```
373+
+OK
374+
Configuration is valid
375+
Tables: 2 (articles, products)
376+
MySQL: repl_user@127.0.0.1:3306
377+
```
378+
379+
Verify invalid config:
380+
```
381+
CONFIG VERIFY /tmp/invalid.yaml
382+
```
383+
384+
Response (error):
385+
```
386+
-ERR Configuration validation failed:
387+
- mysql.port: value 99999 exceeds maximum 65535
388+
- tables[0].name: missing required field
389+
```
209390

210391
---
211392

0 commit comments

Comments
 (0)