2424#include " iocore/hostdb/HostDBProcessor.h"
2525#include " ../src/iocore/hostdb/P_HostDBProcessor.h"
2626#include " swoc/MemSpan.h"
27+ #include " swoc/TextView.h"
2728#include " tsutil/TsSharedMutex.h"
2829#include " yaml-cpp/node/node.h"
2930#include < shared_mutex>
3031#include < string>
32+ #include < string_view>
3133
3234namespace
3335{
3436DbgCtl dbg_ctl_rpc_server{" rpc.server" };
3537DbgCtl dbg_ctl_rpc_handler_server{" rpc.handler.hostdb" };
3638
39+ struct HostDBGetStatusCmdInfo {
40+ std::string hostname;
41+ };
42+
3743constexpr std::string_view
3844str (HostDBType type)
3945{
@@ -74,7 +80,7 @@ namespace YAML
7480{
7581template <> struct convert <HostDBCache> {
7682 static Node
77- encode (const HostDBCache *const hostDB)
83+ encode (const HostDBCache *const hostDB, std::string_view hostname )
7884 {
7985 Node partitions;
8086 for (size_t i = 0 ; i < hostDB->refcountcache ->partition_count (); i++) {
@@ -96,6 +102,9 @@ template <> struct convert<HostDBCache> {
96102
97103 for (RefCountCacheHashEntry *entry : partition_entries) {
98104 HostDBRecord *record = static_cast <HostDBRecord *>(entry->item .get ());
105+ if (!hostname.empty () && record->name_view ().find (hostname) == std::string_view::npos) {
106+ continue ;
107+ }
99108 partition_node[" records" ].push_back (*record);
100109 }
101110
@@ -157,18 +166,34 @@ template <> struct convert<HostDBRecord> {
157166 return node;
158167 }
159168};
169+
170+ template <> struct convert <HostDBGetStatusCmdInfo> {
171+ static bool
172+ decode (const Node &node, HostDBGetStatusCmdInfo &rhs)
173+ {
174+ if (auto n = node[" hostname" ]) {
175+ rhs.hostname = n.as <std::string>();
176+ } else {
177+ return false ;
178+ }
179+
180+ return true ;
181+ }
182+ };
160183} // namespace YAML
161184
162185namespace rpc ::handlers::hostdb
163186{
164187namespace err = rpc::handlers::errors;
165188
166189swoc::Rv<YAML::Node>
167- get_hostdb_status (std::string_view const & /* params ATS_UNUSED */ , YAML::Node const & /* params ATS_UNUSED */ )
190+ get_hostdb_status (std::string_view const & /* id ATS_UNUSED */ , YAML::Node const ¶ms)
168191{
169192 swoc::Rv<YAML::Node> resp;
170193 try {
171- YAML::Node data = YAML::convert<HostDBCache>::encode (hostDBProcessor.cache ());
194+ HostDBGetStatusCmdInfo cmd = params.as <HostDBGetStatusCmdInfo>();
195+
196+ YAML::Node data = YAML::convert<HostDBCache>::encode (hostDBProcessor.cache (), cmd.hostname );
172197
173198 resp.result ()[" data" ] = data;
174199 } catch (std::exception const &ex) {
0 commit comments