Skip to content

Commit

Permalink
refactor ServerHealthCheckerCallback::ExtraInfo
Browse files Browse the repository at this point in the history
Summary:
ExtraInfo was a vector of pairs, refactor it to inherit from a vector of pairs (to not break existing use cases), and add new use cases as struct members.

The struct members can be empty just fine, and we can then factor out parsing each struct member. Right now the code depends on some hardcoded strings never changing.

Also did some minor code cleanup

Reviewed By: jerryliu55

Differential Revision: D69268041

fbshipit-source-id: 4c24907e63d6bd424b4b9a650b4cef4a3f4bd6fa
  • Loading branch information
David Lu authored and facebook-github-bot committed Feb 7, 2025
1 parent a289876 commit 232aa9c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions proxygen/lib/healthcheck/ServerHealthCheckerCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,14 @@ const std::string serverDownInfoStr(ServerDownInfo info) {
}
}

// Convert extraInfo to a map, overrides duplicate headers
folly::F14FastMap<std::string, std::string>
ServerHealthCheckerCallback::ExtraInfo::toMap() const {
folly::F14FastMap<std::string, std::string> mapOut;
for (const auto& it : *this) {
mapOut.insert(it);
}
return mapOut;
}

} // namespace proxygen
24 changes: 23 additions & 1 deletion proxygen/lib/healthcheck/ServerHealthCheckerCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>

#include <folly/SocketAddress.h>
#include <folly/container/F14Map.h>

#include <proxygen/lib/utils/Time.h>

Expand Down Expand Up @@ -59,7 +60,28 @@ const std::string serverDownInfoStr(ServerDownInfo info);
class ServerHealthCheckerCallback {
public:
// Additional info received from a successful healthcheck (e.g. HTTP headers)
using ExtraInfo = std::vector<std::pair<std::string, std::string>>;
// This is a vector of pairs for legacy reasons.
// All new usecases should be defined as struct members.
struct ExtraInfo : public std::vector<std::pair<std::string, std::string>> {
ExtraInfo() = default;
ExtraInfo(const ExtraInfo&) = default;
ExtraInfo(ExtraInfo&&) = default;
explicit ExtraInfo(std::vector<std::pair<std::string, std::string>> v)
: std::vector<std::pair<std::string, std::string>>(std::move(v)) {
}
ExtraInfo& operator=(
const std::vector<std::pair<std::string, std::string>>& v) {
std::vector<std::pair<std::string, std::string>>::operator=(v);
return *this;
}
ExtraInfo& operator=(const ExtraInfo& other) = default;

// Converts all fields within the vector of pairs to a map.
[[nodiscard]] folly::F14FastMap<std::string, std::string> toMap() const;

// Custom fields for WWW healthchecks
folly::F14FastMap<std::string, std::string> thriftWWWCustomFields;
};

virtual void processHealthCheckFailure(
const TimePoint& startTime,
Expand Down

0 comments on commit 232aa9c

Please sign in to comment.