Skip to content

Commit a1bdcf1

Browse files
committed
[Celestica] Leh800bcls: Resolve multi-switch empty fb303 counters in IS_OSS Split Agent mode
1 parent 7965f21 commit a1bdcf1

6 files changed

Lines changed: 77 additions & 6 deletions

File tree

‎fboss/agent/hw/test/BUCK‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ cpp_library(
759759
],
760760
exported_deps = [
761761
":hw_test_thrift_handler_h",
762+
"//fb303:service_data",
763+
"//fb303:thread_cached_service_data",
762764
"//folly:synchronized",
763765
"//folly/logging:log_handler",
764766
"//folly/logging:logging",

‎fboss/agent/hw/test/HwTestLogCaptureThriftHandler.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "fboss/agent/hw/test/HwTestThriftHandler.h"
44

5+
#include <fb303/ServiceData.h>
6+
#include <fb303/ThreadCachedServiceData.h>
57
#include <folly/Synchronized.h>
68
#include <folly/logging/LogHandler.h>
79
#include <folly/logging/LogHandlerConfig.h>
@@ -87,6 +89,18 @@ void HwTestThriftHandler::getMatchingLogMessages(
8789
out = static_cast<CaptureLogHandler*>(handler.get())->matching(*substring);
8890
}
8991

92+
void HwTestThriftHandler::getFb303RegexCounters(
93+
std::map<std::string, int64_t>& counters,
94+
std::unique_ptr<std::string> regex) {
95+
facebook::fb303::ThreadCachedServiceData::get()->publishStats();
96+
counters = facebook::fb303::fbData->getRegexCounters(*regex);
97+
}
98+
99+
int64_t HwTestThriftHandler::getFb303Counter(std::unique_ptr<std::string> key) {
100+
facebook::fb303::ThreadCachedServiceData::get()->publishStats();
101+
return facebook::fb303::fbData->getCounterIfExists(*key).value_or(0);
102+
}
103+
90104
} // namespace utility
91105
} // namespace fboss
92106
} // namespace facebook

‎fboss/agent/hw/test/HwTestThriftHandler.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ class HwTestThriftHandler : public AgentHwTestCtrlSvIf {
258258
std::vector<std::string>& out,
259259
std::unique_ptr<std::string> substring) override;
260260

261+
void getFb303RegexCounters(
262+
std::map<std::string, int64_t>& counters,
263+
std::unique_ptr<std::string> regex) override;
264+
265+
int64_t getFb303Counter(std::unique_ptr<std::string> key) override;
266+
261267
private:
262268
HwSwitch* hwSwitch_;
263269
// Captures log messages in this process for tests to read over RPC.

‎fboss/agent/if/agent_hw_test_ctrl.thrift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,8 @@ service AgentHwTestCtrl {
240240
// installLogCapture() must be called before the log is emitted.
241241
void installLogCapture();
242242
list<string> getMatchingLogMessages(1: string substring);
243+
244+
// fb303 cross-process utils for multi-switch testing
245+
map<string, i64> getFb303RegexCounters(1: string regex);
246+
i64 getFb303Counter(1: string key);
243247
}

‎fboss/agent/test/AgentEnsemble.cpp‎

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,8 @@ std::map<std::string, int64_t> AgentEnsemble::getFb303CountersByRegex(
881881
client->getChannelShared()};
882882
monitoringClient.sync_getRegexCounters(counters, regex);
883883
#else
884-
// TODO: This needs to be updated to support multi-switch.
885-
counters = facebook::fb303::fbData->getRegexCounters(regex);
884+
auto switchID = scopeResolver().scope(portId).switchId();
885+
counters = queryHwAgentFb303RegexCounters(switchID, regex);
886886
#endif
887887
return counters;
888888
}
@@ -908,8 +908,7 @@ int64_t AgentEnsemble::getFb303Counter(
908908
client->getChannelShared()};
909909
counter = monitoringClient.sync_getCounter(key);
910910
#else
911-
// TODO: This needs to be updated to support multi-switch.
912-
counter = facebook::fb303::fbData->getCounter(key);
911+
counter = queryHwAgentFb303Counter(switchID, key);
913912
#endif
914913
return counter;
915914
}
@@ -959,12 +958,51 @@ std::map<std::string, int64_t> AgentEnsemble::getFb303RegexCounters(
959958
client->getChannelShared()};
960959
monitoringClient.sync_getRegexCounters(counters, regex);
961960
#else
962-
// TODO: This needs to be updated to support multi-switch.
963-
counters = facebook::fb303::fbData->getRegexCounters(regex);
961+
counters = queryHwAgentFb303RegexCounters(switchID, regex);
964962
#endif
965963
return counters;
966964
}
967965

966+
std::map<std::string, int64_t> AgentEnsemble::queryHwAgentFb303RegexCounters(
967+
const SwitchID& switchID,
968+
const std::string& regex) {
969+
std::map<std::string, int64_t> counters;
970+
if (!getSw()->isRunModeMultiSwitch()) {
971+
counters = facebook::fb303::fbData->getRegexCounters(regex);
972+
} else {
973+
try {
974+
auto hwTestClient = getHwAgentTestClient(switchID);
975+
hwTestClient->sync_getFb303RegexCounters(counters, regex);
976+
} catch (const std::exception& ex) {
977+
XLOG(ERR)
978+
<< "Failed to fetch remote fb303 counters via HwTestCtrl for switch "
979+
<< switchID << ": " << ex.what();
980+
throw;
981+
}
982+
}
983+
return counters;
984+
}
985+
986+
int64_t AgentEnsemble::queryHwAgentFb303Counter(
987+
const SwitchID& switchID,
988+
const std::string& key) {
989+
int64_t counter{0};
990+
if (!getSw()->isRunModeMultiSwitch()) {
991+
counter = facebook::fb303::fbData->getCounter(key);
992+
} else {
993+
try {
994+
auto hwTestClient = getHwAgentTestClient(switchID);
995+
counter = hwTestClient->sync_getFb303Counter(key);
996+
} catch (const std::exception& ex) {
997+
XLOG(ERR)
998+
<< "Failed to fetch remote fb303 counter via HwTestCtrl for switch "
999+
<< switchID << ": " << ex.what();
1000+
throw;
1001+
}
1002+
}
1003+
return counter;
1004+
}
1005+
9681006
std::string AgentEnsemble::getHwDebugDump() {
9691007
std::string out{};
9701008
ThriftHandler(getSw()).getHwDebugDump(out);

‎fboss/agent/test/AgentEnsemble.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,13 @@ class AgentEnsemble : public TestEnsembleIf {
405405
void overrideConfigFlag(const std::string& fileName);
406406
void dumpConfigForHwAgent(AgentConfig* agentConf);
407407

408+
std::map<std::string, int64_t> queryHwAgentFb303RegexCounters(
409+
const SwitchID& switchId,
410+
const std::string& regex);
411+
int64_t queryHwAgentFb303Counter(
412+
const SwitchID& switchId,
413+
const std::string& key);
414+
408415
void writeConfig(const cfg::SwitchConfig& config);
409416
void writeConfig(const cfg::AgentConfig& config);
410417
bool waitForRateOnPort(

0 commit comments

Comments
 (0)