Skip to content

Commit

Permalink
add client remote ip in log when errenous command executed
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh-murugiah committed Oct 7, 2024
1 parent 39f94d5 commit 88a6392
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct SupportedCommands {
* @return client sub commands thats supported
*/
static const absl::flat_hash_set<std::string>& clientSubCommands() {
CONSTRUCT_ON_FIRST_USE(absl::flat_hash_set<std::string>, "getname", "list","setname");
CONSTRUCT_ON_FIRST_USE(absl::flat_hash_set<std::string>, "getname","setname");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1842,19 +1842,19 @@ SplitRequestPtr InstanceImpl::makeRequest(Common::Redis::RespValuePtr&& request,
const StreamInfo::StreamInfo& stream_info) {
// Validate request type and contents.
if ((request->type() != Common::Redis::RespType::Array) || request->asArray().empty()) {
ENVOY_LOG(error,"invalid request - not an array or empty");
ENVOY_LOG(error,"invalid request - not an array or empty,sent from remote client ip '{}'",stream_info.downstreamAddressProvider().remoteAddress()->asString());
onInvalidRequest(callbacks);
return nullptr;
}

for (const Common::Redis::RespValue& value : request->asArray()) {
if (value.type() != Common::Redis::RespType::BulkString) {
ENVOY_LOG(error,"invalid request - not an array of bulk strings");
ENVOY_LOG(error,"invalid request - not an array of bulk strings,sent from remote client ip '{}' ",stream_info.downstreamAddressProvider().remoteAddress()->asString());
onInvalidRequest(callbacks);
return nullptr;
}
}
ENVOY_LOG(info, "command to process '{}'", request->toString());
ENVOY_LOG(info, "command to process '{}'- sent from remote client ip '{}'", request->toString(),stream_info.downstreamAddressProvider().remoteAddress()->asString());
// Extract command name
std::string command_name = absl::AsciiStrToLower(request->asArray()[0].asString());

Expand All @@ -1867,7 +1867,7 @@ SplitRequestPtr InstanceImpl::makeRequest(Common::Redis::RespValuePtr&& request,
// Handle AUTH command
if (command_name == Common::Redis::SupportedCommands::auth()) {
if (request->asArray().size() < 2) {
ENVOY_LOG(error,"invalid request - not enough arguments for auth command");
ENVOY_LOG(error,"invalid request - not enough arguments for auth command - sent from remote client ip '{}'",stream_info.downstreamAddressProvider().remoteAddress()->asString());
onInvalidRequest(callbacks);
return nullptr;
}
Expand Down Expand Up @@ -1944,7 +1944,7 @@ SplitRequestPtr InstanceImpl::makeRequest(Common::Redis::RespValuePtr&& request,

} else {
// Commands other than PING, TIME and transaction commands all have at least two arguments.
ENVOY_LOG(error,"invalid request - not enough arguments for command: '{}'", command_name);
ENVOY_LOG(error,"invalid request - not enough arguments for command: '{}' - sent from remote client ip '{}'", command_name,stream_info.downstreamAddressProvider().remoteAddress()->asString());
onInvalidRequest(callbacks);
return nullptr;
}
Expand All @@ -1955,7 +1955,7 @@ SplitRequestPtr InstanceImpl::makeRequest(Common::Redis::RespValuePtr&& request,
std::string sub_command = absl::AsciiStrToLower(request->asArray()[1].asString());
if (Common::Redis::SupportedCommands::clientSubCommands().count(sub_command) == 0) {
stats_.unsupported_command_.inc();
ENVOY_LOG(error, "unsupported command '{}' '{}'",command_name, sub_command);
ENVOY_LOG(error, "unsupported command '{}' '{}'- sent from remote client ip '{}'",command_name, sub_command,stream_info.downstreamAddressProvider().remoteAddress()->asString());
callbacks.onResponse(Common::Redis::Utility::makeError(
fmt::format("unsupported command '{}' '{}'",command_name, sub_command)));
return nullptr;
Expand Down Expand Up @@ -1998,7 +1998,7 @@ SplitRequestPtr InstanceImpl::makeRequest(Common::Redis::RespValuePtr&& request,

}else{
stats_.unsupported_command_.inc();
ENVOY_LOG(error, "unsupported command '{}'", request->asArray()[0].asString());
ENVOY_LOG(error, "unsupported command '{}', sent from remote client ip '{}'", request->asArray()[0].asString(), stream_info.downstreamAddressProvider().remoteAddress()->asString());
callbacks.onResponse(Common::Redis::Utility::makeError(
fmt::format("unsupported command '{}'", request->asArray()[0].asString())));
return nullptr;
Expand Down

0 comments on commit 88a6392

Please sign in to comment.