Skip to content

Commit dba20c8

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

3 files changed

Lines changed: 58 additions & 6 deletions

File tree

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

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

1111
#pragma once
1212

13+
#include <fb303/ServiceData.h>
14+
#include <fb303/ThreadCachedServiceData.h>
1315
#include "fboss/agent/if/gen-cpp2/AgentHwTestCtrl.h"
1416

1517
#include "fboss/agent/FbossError.h"
@@ -258,6 +260,18 @@ class HwTestThriftHandler : public AgentHwTestCtrlSvIf {
258260
std::vector<std::string>& out,
259261
std::unique_ptr<std::string> substring) override;
260262

263+
void getFb303RegexCounters(
264+
std::map<std::string, int64_t>& counters,
265+
std::unique_ptr<std::string> regex) override {
266+
facebook::fb303::ThreadCachedServiceData::get()->publishStats();
267+
counters = facebook::fb303::fbData->getRegexCounters(*regex);
268+
}
269+
270+
int64_t getFb303Counter(std::unique_ptr<std::string> key) override {
271+
facebook::fb303::ThreadCachedServiceData::get()->publishStats();
272+
return facebook::fb303::fbData->getCounterIfExists(*key).value_or(0);
273+
}
274+
261275
private:
262276
HwSwitch* hwSwitch_;
263277
// 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: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,20 @@ 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+
if (!getSw()->isRunModeMultiSwitch()) {
885+
counters = facebook::fb303::fbData->getRegexCounters(regex);
886+
} else {
887+
try {
888+
auto switchID = scopeResolver().scope(portId).switchId();
889+
auto hwTestClient = getHwAgentTestClient(switchID);
890+
hwTestClient->sync_getFb303RegexCounters(counters, regex);
891+
} catch (const std::exception& ex) {
892+
XLOG(WARNING)
893+
<< "Failed to fetch remote fb303 counters via HwTestCtrl for port "
894+
<< portId << ": " << ex.what();
895+
counters = facebook::fb303::fbData->getRegexCounters(regex);
896+
}
897+
}
886898
#endif
887899
return counters;
888900
}
@@ -908,8 +920,19 @@ int64_t AgentEnsemble::getFb303Counter(
908920
client->getChannelShared()};
909921
counter = monitoringClient.sync_getCounter(key);
910922
#else
911-
// TODO: This needs to be updated to support multi-switch.
912-
counter = facebook::fb303::fbData->getCounter(key);
923+
if (!getSw()->isRunModeMultiSwitch()) {
924+
counter = facebook::fb303::fbData->getCounterIfExists(key).value_or(0);
925+
} else {
926+
try {
927+
auto hwTestClient = getHwAgentTestClient(switchID);
928+
counter = hwTestClient->sync_getFb303Counter(key);
929+
} catch (const std::exception& ex) {
930+
XLOG(WARNING)
931+
<< "Failed to fetch remote fb303 counter via HwTestCtrl for switch "
932+
<< switchID << ": " << ex.what();
933+
counter = facebook::fb303::fbData->getCounterIfExists(key).value_or(0);
934+
}
935+
}
913936
#endif
914937
return counter;
915938
}
@@ -959,8 +982,19 @@ std::map<std::string, int64_t> AgentEnsemble::getFb303RegexCounters(
959982
client->getChannelShared()};
960983
monitoringClient.sync_getRegexCounters(counters, regex);
961984
#else
962-
// TODO: This needs to be updated to support multi-switch.
963-
counters = facebook::fb303::fbData->getRegexCounters(regex);
985+
if (!getSw()->isRunModeMultiSwitch()) {
986+
counters = facebook::fb303::fbData->getRegexCounters(regex);
987+
} else {
988+
try {
989+
auto hwTestClient = getHwAgentTestClient(switchID);
990+
hwTestClient->sync_getFb303RegexCounters(counters, regex);
991+
} catch (const std::exception& ex) {
992+
XLOG(WARNING)
993+
<< "Failed to fetch remote fb303 counters via HwTestCtrl for switch "
994+
<< switchID << ": " << ex.what();
995+
counters = facebook::fb303::fbData->getRegexCounters(regex);
996+
}
997+
}
964998
#endif
965999
return counters;
9661000
}

0 commit comments

Comments
 (0)