diff --git a/mcrouter/lib/carbon/MessageCommon.h b/mcrouter/lib/carbon/MessageCommon.h index 71193791..3d2fcd44 100644 --- a/mcrouter/lib/carbon/MessageCommon.h +++ b/mcrouter/lib/carbon/MessageCommon.h @@ -37,6 +37,9 @@ class MessageCommon { static constexpr std::string_view kCryptoAuthTokenHeader = "crypto_auth_tokens"; + static constexpr std::string_view kClientIdentifierHeader = + "client_identifier"; + protected: std::string traceContext_; }; diff --git a/mcrouter/lib/carbon/RequestCommon.h b/mcrouter/lib/carbon/RequestCommon.h index bcd1c196..b0761248 100644 --- a/mcrouter/lib/carbon/RequestCommon.h +++ b/mcrouter/lib/carbon/RequestCommon.h @@ -24,11 +24,13 @@ class RequestCommon : public MessageCommon { RequestCommon(const RequestCommon& other) { traceContext_ = other.traceContext_; cryptoAuthToken_ = other.cryptoAuthToken_; + clientIdentifier_ = other.clientIdentifier_; } RequestCommon& operator=(const RequestCommon& other) { if (this != &other) { traceContext_ = other.traceContext_; cryptoAuthToken_ = other.cryptoAuthToken_; + clientIdentifier_ = other.clientIdentifier_; } return *this; } @@ -83,7 +85,7 @@ class RequestCommon : public MessageCommon { return cryptoAuthToken_; } - const std::string& getClientIdentifier() const noexcept { + const std::optional& getClientIdentifier() const noexcept { return clientIdentifier_; } @@ -101,7 +103,7 @@ class RequestCommon : public MessageCommon { // cat token(s) in string serialzed format std::optional cryptoAuthToken_; // Hash string of primary (non-host) tls client identities - std::string clientIdentifier_; + std::optional clientIdentifier_; }; } // namespace carbon diff --git a/mcrouter/lib/carbon/example/gen/HelloGoodbyeThriftTransport.h b/mcrouter/lib/carbon/example/gen/HelloGoodbyeThriftTransport.h index 901bbffc..f1852024 100644 --- a/mcrouter/lib/carbon/example/gen/HelloGoodbyeThriftTransport.h +++ b/mcrouter/lib/carbon/example/gen/HelloGoodbyeThriftTransport.h @@ -50,6 +50,10 @@ folly::Try> send rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -86,6 +90,10 @@ folly::Try> sendSy rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -125,6 +133,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE diff --git a/mcrouter/lib/carbon/example/main.cpp b/mcrouter/lib/carbon/example/main.cpp index 49e337cc..449ae94a 100644 --- a/mcrouter/lib/carbon/example/main.cpp +++ b/mcrouter/lib/carbon/example/main.cpp @@ -82,6 +82,11 @@ class ThriftHandler : virtual public hellogoodbye::thrift::HelloGoodbyeSvIf { LOG(INFO) << "Got optional header props " << it->second << " from thrift header."; } + it = headers.find("client_identifier"); + if (it != headers.end()) { + LOG(INFO) << "Got client_identifier " << it->second + << " from thrift header."; + } } else { LOG(ERROR) << "Cannot get context."; } diff --git a/mcrouter/lib/carbon/test/gen/AThriftTransport.h b/mcrouter/lib/carbon/test/gen/AThriftTransport.h index 16ff272f..95cb868f 100644 --- a/mcrouter/lib/carbon/test/gen/AThriftTransport.h +++ b/mcrouter/lib/carbon/test/gen/AThriftTransport.h @@ -50,6 +50,10 @@ folly::Try> sen rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -86,6 +90,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE diff --git a/mcrouter/lib/carbon/test/gen/BThriftTransport.h b/mcrouter/lib/carbon/test/gen/BThriftTransport.h index 24662d10..16402451 100644 --- a/mcrouter/lib/carbon/test/gen/BThriftTransport.h +++ b/mcrouter/lib/carbon/test/gen/BThriftTransport.h @@ -50,6 +50,10 @@ folly::Try> sen rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -86,6 +90,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE diff --git a/mcrouter/lib/carbon/test/gen/CarbonTestThriftTransport.h b/mcrouter/lib/carbon/test/gen/CarbonTestThriftTransport.h index 3f5836ac..40ae29a8 100644 --- a/mcrouter/lib/carbon/test/gen/CarbonTestThriftTransport.h +++ b/mcrouter/lib/carbon/test/gen/CarbonTestThriftTransport.h @@ -50,6 +50,10 @@ folly::Try> sendSyn rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -86,6 +90,10 @@ folly::Try rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -122,6 +130,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE diff --git a/mcrouter/lib/carbon/test/gen/CarbonThriftTestThriftTransport.h b/mcrouter/lib/carbon/test/gen/CarbonThriftTestThriftTransport.h index 3f634110..c563d75e 100644 --- a/mcrouter/lib/carbon/test/gen/CarbonThriftTestThriftTransport.h +++ b/mcrouter/lib/carbon/test/gen/CarbonThriftTestThriftTransport.h @@ -50,6 +50,10 @@ folly::Try> sendS rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -86,6 +90,10 @@ folly::Try> rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -122,6 +130,10 @@ folly::Try> s rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -158,6 +170,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE diff --git a/mcrouter/lib/network/gen/MemcacheThriftTransport.h b/mcrouter/lib/network/gen/MemcacheThriftTransport.h index b94c3b63..fcc82d34 100644 --- a/mcrouter/lib/network/gen/MemcacheThriftTransport.h +++ b/mcrouter/lib/network/gen/MemcacheThriftTransport.h @@ -50,6 +50,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -86,6 +90,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -122,6 +130,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -158,6 +170,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -194,6 +210,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -230,6 +250,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -266,6 +290,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -302,6 +330,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -338,6 +370,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -374,6 +410,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -410,6 +450,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -446,6 +490,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -482,6 +530,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -518,6 +570,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -554,6 +610,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -590,6 +650,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -626,6 +690,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -662,6 +730,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -698,6 +770,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE @@ -734,6 +810,10 @@ folly::Try> sendSyncHelper( rpcOptions.setWriteHeader( std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value()); } + if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) { + rpcOptions.setWriteHeader( + std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value()); + } rpcOptions.setContextPropMask(0); #ifndef LIBMC_FBTRACE_DISABLE