Skip to content

Commit

Permalink
Fix show fsdb subscribers to handle patch subs
Browse files Browse the repository at this point in the history
Summary:
For patch subscribers, in OperSubscriberInfo optional path and extendedPaths
would not present. Add check to ensure that "fboss2 show fsdb subscribers"
doesn't crash in this case.

Reviewed By: wilsonwinhi

Differential Revision: D60996692

fbshipit-source-id: b521e4a360e865918d9d8fa63b88d90c376f771e
  • Loading branch information
Priyank Warkhede authored and facebook-github-bot committed Aug 14, 2024
1 parent 6ba2532 commit d0e1330
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions fboss/cli/fboss2/utils/CmdUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ std::optional<std::string> getMyHostname(const std::string& hostname) {
}

std::string escapeDoubleQuotes(const std::string& cmd) {
return std::regex_replace(cmd, std::regex("\""), "\\\"");
std::string cmdCopy = cmd;
const re2::RE2 doubleQuotes("\"");
re2::RE2::Replace(&cmdCopy, doubleQuotes, "\\\"");
return cmdCopy;
}

std::string getCmdToRun(const std::string& hostname, const std::string& cmd) {
Expand Down Expand Up @@ -293,18 +296,26 @@ std::string getSubscriptionPathStr(const fsdb::OperSubscriberInfo& subscriber) {
return folly::join("/", subscriber.get_path()->get_raw());
}
std::vector<std::string> extPaths;
for (const auto& extPath : *subscriber.get_extendedPaths()) {
std::vector<std::string> pathElements;
for (const auto& pathElm : *extPath.path()) {
if (pathElm.any_ref().has_value()) {
pathElements.push_back("*");
} else if (pathElm.regex_ref().has_value()) {
pathElements.push_back(*pathElm.regex_ref());
} else {
pathElements.push_back(*pathElm.raw_ref());
if (auto subExtPaths = subscriber.get_extendedPaths()) {
for (const auto& extPath : *subExtPaths) {
std::vector<std::string> pathElements;
for (const auto& pathElm : *extPath.path()) {
if (pathElm.any_ref().has_value()) {
pathElements.push_back("*");
} else if (pathElm.regex_ref().has_value()) {
pathElements.push_back(*pathElm.regex_ref());
} else {
pathElements.push_back(*pathElm.raw_ref());
}
}
extPaths.push_back(folly::join("/", pathElements));
}
}
auto paths = subscriber.get_paths();
if (paths) {
for (const auto& path : *paths) {
extPaths.push_back(folly::join("/", path.second.get_path()));
}
extPaths.push_back(folly::join("/", pathElements));
}
return folly::join(";", extPaths);
}
Expand Down

0 comments on commit d0e1330

Please sign in to comment.