From c18055dfd24b3941136b1292850cc925b2358c78 Mon Sep 17 00:00:00 2001 From: Vignesh Ananth Date: Thu, 25 Jul 2024 11:22:16 -0700 Subject: [PATCH] Make RIM compile within memcache Summary: In this approach, we create a weakly defined symbol in TargetHooks.cpp that is defined in the mcrouter-core target and conditionally checked and invoked in the gen utils visitor. This approach minimizes the amount of changes we want to make as opposed to previous approaches (most of which required making changes to hundreds of target files). Here we do a few things to make this work: 1. In rim's stats.cpp TARGET, we have to change the odsl library to use the "via_mcrouter" flavor of those targets. autodeps wants to change it back, but that will immediately trigger circular dependencies. For good measure I added, autodeps-skip nocodemods to that target. 2. stuclar taught me about nm and how I can dump the symbols that are compiled in the different modes (dev/opt). I dumped the symbols when building mcrouter_core in both dev and opt mode and I see that gRIMReport is NOT a weak symbol, which IIUC is what we desire. P1430729979, P1430693327 have the full pastes. opt mode: > 0000000000000000 W _ZN8facebook8memcache8mcrouter10gRIMReportERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS8_EERKSt13unordered_mapIS8_mSt4hashIS8_ESt8equal_toIS8_ESaISt4pairIKS8_mEEE > 0000000000000000 b _ZZN8facebook8memcache8mcrouter10gRIMReportERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS8_EERKSt13unordered_mapIS8_mSt4hashIS8_ESt8equal_toIS8_ESaISt4pairIKS8_mEEEE14LOGGING_helper dev mode: > 00000000002055f0 W _ZN8facebook8memcache8mcrouter10gRIMReportERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS8_EERKSt13unordered_mapIS8_mSt4hashIS8_ESt8equal_toIS8_ESaISt4pairIKS8_mEEE > _ZZN8facebook8memcache8mcrouter10gRIMReportERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS8_EERKSt13unordered_mapIS8_mSt4hashIS8_ESt8equal_toIS8_ESaISt4pairIKS8_mEEEE14LOGGING_helper Edit on Version 6: 1. I've extracted productId and plumbed it to RIM. 2. Swayze Test: https://www.internalfb.com/intern/hhvm/automator/workflows/134338/ Another Swayze Test (with CD_MEMCACHE_ATTRIBUTION used): https://www.internalfb.com/intern/hhvm/automator/workflows/140328/ Reviewed By: stuclar Differential Revision: D57884193 fbshipit-source-id: 77f67f14b2db93018b668411a9cdc40c043ae4cf --- mcrouter/TargetHooks.h | 7 +++++++ mcrouter/stat_list.h | 4 ++++ mcrouter/stats.h | 1 + 3 files changed, 12 insertions(+) diff --git a/mcrouter/TargetHooks.h b/mcrouter/TargetHooks.h index 310d573f3..cab1e209a 100644 --- a/mcrouter/TargetHooks.h +++ b/mcrouter/TargetHooks.h @@ -15,6 +15,13 @@ namespace facebook { namespace memcache { namespace mcrouter { +/** + * If linked, initializes and reports utilization to RIM. + */ +FOLLY_ATTR_WEAK bool gRIMReport( + const std::vector& tenancyHierarchyPath, + const std::unordered_map& resourceUsageMap); + /** * SR factory init hook */ diff --git a/mcrouter/stat_list.h b/mcrouter/stat_list.h index 7282ac886..64fc23c96 100644 --- a/mcrouter/stat_list.h +++ b/mcrouter/stat_list.h @@ -414,3 +414,7 @@ EXTERNAL_STAT(prefix_acl_concurrent_refresh_fail) EXTERNAL_STAT(prefix_acl_refresh_success) EXTERNAL_STAT(prefix_acl_refresh_timeout) EXTERNAL_STAT(prefix_acl_refresh_error) + +#define GROUP visitor_stats +STUI(rim_report_failed, 0, 1) +#undef GROUP diff --git a/mcrouter/stats.h b/mcrouter/stats.h index 867cfe90b..6c14ef39a 100644 --- a/mcrouter/stats.h +++ b/mcrouter/stats.h @@ -77,6 +77,7 @@ enum stat_group_t { suspect_server_stats = 0x40000, external_stats = 0x80000, unknown_stats = 0x10000000, + visitor_stats = 0x20000000, }; /** defines a statistic: name, type, and data */