Unverified Commit 2f411770 authored by Wen Hui's avatar Wen Hui Committed by GitHub
Browse files

Add CONFIG SET and GET loglevel feature in Sentinel (#11214)

Till now Sentinel allowed modifying the log level in the config file, but not at runtime.
this makes it possible to tune the log level at runtime
parent 203b12e4
......@@ -19,6 +19,14 @@ daemonize no
# location here.
pidfile /var/run/redis-sentinel.pid
# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel notice
# Specify the log file name. Also the empty string can be used to force
# Sentinel to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
......
......@@ -3182,7 +3182,17 @@ void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) {
/* =========================== SENTINEL command ============================= */
/* SENTINEL CONFIG SET <option> */
const char* getLogLevel() {
switch (server.verbosity) {
case LL_DEBUG: return "debug";
case LL_VERBOSE: return "verbose";
case LL_NOTICE: return "notice";
case LL_WARNING: return "warning";
}
return "unknown";
}
/* SENTINEL CONFIG SET <option> <value>*/
void sentinelConfigSetCommand(client *c) {
robj *o = c->argv[3];
robj *val = c->argv[4];
......@@ -3213,6 +3223,17 @@ void sentinelConfigSetCommand(client *c) {
sentinel.sentinel_auth_pass = sdslen(val->ptr) == 0 ?
NULL : sdsdup(val->ptr);
drop_conns = 1;
} else if (!strcasecmp(o->ptr, "loglevel")) {
if (!strcasecmp(val->ptr, "debug"))
server.verbosity = LL_DEBUG;
else if (!strcasecmp(val->ptr, "verbose"))
server.verbosity = LL_VERBOSE;
else if (!strcasecmp(val->ptr, "notice"))
server.verbosity = LL_NOTICE;
else if (!strcasecmp(val->ptr, "warning"))
server.verbosity = LL_WARNING;
else
goto badfmt;
} else {
addReplyErrorFormat(c, "Invalid argument '%s' to SENTINEL CONFIG SET",
(char *) o->ptr);
......@@ -3275,6 +3296,11 @@ void sentinelConfigGetCommand(client *c) {
matches++;
}
if (stringmatch(pattern, "loglevel", 1)) {
addReplyBulkCString(c, "loglevel");
addReplyBulkCString(c, getLogLevel());
matches++;
}
setDeferredMapLen(c, replylen, matches);
}
......
......@@ -37,3 +37,11 @@ test "After Sentinel 1 is restarted, its config gets updated" {
test "New master [join $addr {:}] role matches" {
assert {[RI $master_id role] eq {master}}
}
test "Update log level" {
set current_loglevel [S 0 SENTINEL CONFIG GET loglevel]
assert {[lindex $current_loglevel 1] == {notice}}
S 0 SENTINEL CONFIG SET loglevel warning
set updated_loglevel [S 0 SENTINEL CONFIG GET loglevel]
assert {[lindex $updated_loglevel 1] == {warning}}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment