Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add short client info log to CLUSTER MEET / FORGET / RESET commands #1249

Open
wants to merge 4 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6519,6 +6519,10 @@ int clusterCommandSpecial(client *c) {
addReplyErrorFormat(c, "Invalid node address specified: %s:%s", (char *)c->argv[2]->ptr,
(char *)c->argv[3]->ptr);
} else {
sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);
serverLog(LL_NOTICE, "Cluster meet %s:%lld (user request from '%s').", (char *)c->argv[2]->ptr, port,
client);
sdsfree(client);
addReply(c, shared.ok);
}
} else if (!strcasecmp(c->argv[1]->ptr, "flushslots") && c->argc == 2) {
Expand Down Expand Up @@ -6633,6 +6637,9 @@ int clusterCommandSpecial(client *c) {
addReplyError(c, "Can't forget my master!");
return 1;
}
sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);
serverLog(LL_NOTICE, "Cluster forget %s (user request from '%s').", (char *)c->argv[2]->ptr, client);
sdsfree(client);
clusterBlacklistAddNode(n);
clusterDelNode(n);
clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_SAVE_CONFIG);
Expand Down Expand Up @@ -6722,7 +6729,7 @@ int clusterCommandSpecial(client *c) {
}
resetManualFailover();
server.cluster->mf_end = mstime() + CLUSTER_MF_TIMEOUT;
sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log);
sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);

if (takeover) {
/* A takeover does not perform any initial check. It just
Expand Down Expand Up @@ -6801,6 +6808,9 @@ int clusterCommandSpecial(client *c) {
"master nodes containing keys");
return 1;
}
sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);
serverLog(LL_NOTICE, "Cluster reset (user request from '%s').", client);
sdsfree(client);
clusterReset(hard);
addReply(c, shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr, "links") && c->argc == 2) {
Expand Down
23 changes: 23 additions & 0 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -3372,6 +3372,29 @@ sds catClientInfoString(sds s, client *client, int hide_user_data) {
return ret;
}

/* Concatenate a string representing the state of a client in a human
* readable format, into the sds string 's'.
*
* This is a simplified and shortened version of catClientInfoString,
* it only added some basic fields for tracking clients. */
sds catClientInfoShortString(sds s, client *client, int hide_user_data) {
if (!server.crashed) waitForClientIO(client);
char conninfo[CONN_INFO_LEN];

sds ret = sdscatfmt(
s,
FMTARGS(
"id=%U", (unsigned long long)client->id,
" addr=%s", getClientPeerId(client),
" laddr=%s", getClientSockname(client),
" %s", connGetInfo(client->conn, conninfo, sizeof(conninfo)),
" name=%s", hide_user_data ? "*redacted*" : (client->name ? (char *)client->name->ptr : ""),
" user=%s", hide_user_data ? "*redacted*" : (client->user ? client->user->name : "(superuser)"),
" lib-name=%s", client->lib_name ? (char *)client->lib_name->ptr : "",
" lib-ver=%s", client->lib_ver ? (char *)client->lib_ver->ptr : ""));
return ret;
}

sds getAllClientsInfoString(int type, int hide_user_data) {
listNode *ln;
listIter li;
Expand Down
6 changes: 3 additions & 3 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ void syncCommand(client *c) {
} else {
replicationUnsetPrimary();
}
sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log);
sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);
serverLog(LL_NOTICE, "PRIMARY MODE enabled (failover request from '%s')", client);
sdsfree(client);
} else {
Expand Down Expand Up @@ -3978,7 +3978,7 @@ void replicaofCommand(client *c) {
if (!strcasecmp(c->argv[1]->ptr, "no") && !strcasecmp(c->argv[2]->ptr, "one")) {
if (server.primary_host) {
replicationUnsetPrimary();
sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log);
sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);
serverLog(LL_NOTICE, "PRIMARY MODE enabled (user request from '%s')", client);
sdsfree(client);
}
Expand Down Expand Up @@ -4007,7 +4007,7 @@ void replicaofCommand(client *c) {
/* There was no previous primary or the user specified a different one,
* we can continue. */
replicationSetPrimary(c->argv[1]->ptr, port, 0);
sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log);
sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);
serverLog(LL_NOTICE, "REPLICAOF %s:%d enabled (user request from '%s')", server.primary_host,
server.primary_port, client);
sdsfree(client);
Expand Down
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -4317,7 +4317,7 @@ int prepareForShutdown(client *c, int flags) {
server.shutdown_flags = flags;

if (c != NULL) {
sds client = catClientInfoString(sdsempty(), c, server.hide_user_data_from_log);
sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);
serverLog(LL_NOTICE, "User requested shutdown... (user request from '%s')", client);
sdsfree(client);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,7 @@ char *getClientPeerId(client *client);
char *getClientSockName(client *client);
int isClientConnIpV6(client *c);
sds catClientInfoString(sds s, client *client, int hide_user_data);
sds catClientInfoShortString(sds s, client *client, int hide_user_data);
sds getAllClientsInfoString(int type, int hide_user_data);
int clientSetName(client *c, robj *name, const char **err);
void rewriteClientCommandVector(client *c, int argc, ...);
Expand Down
Loading