mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
feat(server): Support CLIENT SETINFO
(#3673)
Add support for `CLIENT SETINFO <LIB-NAME | LIB-VER>` and also return that as part of `CLIENT LIST`, like Valkey. Fixes #3137
This commit is contained in:
parent
b7b96424e4
commit
b10a4a5348
5 changed files with 94 additions and 4 deletions
|
@ -541,6 +541,31 @@ void ClientCaching(CmdArgList args, ConnectionContext* cntx) {
|
|||
cntx->SendOk();
|
||||
}
|
||||
|
||||
void ClientSetInfo(CmdArgList args, ConnectionContext* cntx) {
|
||||
if (args.size() != 2) {
|
||||
return cntx->SendError(kSyntaxErr);
|
||||
}
|
||||
|
||||
auto* conn = cntx->conn();
|
||||
if (conn == nullptr) {
|
||||
return cntx->SendError("No connection");
|
||||
}
|
||||
|
||||
ToUpper(&args[0]);
|
||||
string_view type = ArgS(args, 0);
|
||||
string_view val = ArgS(args, 1);
|
||||
|
||||
if (type == "LIB-NAME") {
|
||||
conn->SetLibName(string(val));
|
||||
} else if (type == "LIB-VER") {
|
||||
conn->SetLibVersion(string(val));
|
||||
} else {
|
||||
return cntx->SendError(kSyntaxErr);
|
||||
}
|
||||
|
||||
cntx->SendOk();
|
||||
}
|
||||
|
||||
void ClientId(CmdArgList args, ConnectionContext* cntx) {
|
||||
if (args.size() != 0) {
|
||||
return cntx->SendError(kSyntaxErr);
|
||||
|
@ -1207,6 +1232,13 @@ void PrintPrometheusMetrics(const Metrics& m, DflyCmd* dfly_cmd, StringResponse*
|
|||
AppendMetricWithoutLabels("pipeline_commands_duration_seconds", "",
|
||||
conn_stats.pipelined_cmd_latency * 1e-6, MetricType::COUNTER,
|
||||
&resp->body());
|
||||
string connections_libs;
|
||||
AppendMetricHeader("connections_libs", "Total number of connections by libname:ver",
|
||||
MetricType::GAUGE, &connections_libs);
|
||||
for (const auto& [lib, count] : m.connections_lib_name_ver_map) {
|
||||
AppendMetricValue("connections_libs", count, {"lib"}, {lib}, &connections_libs);
|
||||
}
|
||||
absl::StrAppend(&resp->body(), connections_libs);
|
||||
|
||||
// Memory metrics
|
||||
auto sdata_res = io::ReadStatusInfo();
|
||||
|
@ -1770,14 +1802,12 @@ void ServerFamily::Client(CmdArgList args, ConnectionContext* cntx) {
|
|||
return ClientKill(sub_args, absl::MakeSpan(listeners_), cntx);
|
||||
} else if (sub_cmd == "CACHING") {
|
||||
return ClientCaching(sub_args, cntx);
|
||||
} else if (sub_cmd == "SETINFO") {
|
||||
return ClientSetInfo(sub_args, cntx);
|
||||
} else if (sub_cmd == "ID") {
|
||||
return ClientId(sub_args, cntx);
|
||||
}
|
||||
|
||||
if (sub_cmd == "SETINFO") {
|
||||
return cntx->SendOk();
|
||||
}
|
||||
|
||||
LOG_FIRST_N(ERROR, 10) << "Subcommand " << sub_cmd << " not supported";
|
||||
return cntx->SendError(UnknownSubCmd(sub_cmd, "CLIENT"), kSyntaxErrType);
|
||||
}
|
||||
|
@ -2049,6 +2079,11 @@ Metrics ServerFamily::GetMetrics(Namespace* ns) const {
|
|||
|
||||
result.lua_stats += InterpreterManager::tl_stats();
|
||||
|
||||
auto connections_lib_name_ver_map = facade::Connection::GetLibStatsTL();
|
||||
for (auto& [k, v] : connections_lib_name_ver_map) {
|
||||
result.connections_lib_name_ver_map[k] += v;
|
||||
}
|
||||
|
||||
service_.mutable_registry()->MergeCallStats(index, cmd_stat_cb);
|
||||
}; // cb
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue