Skip to content

Commit 24a43da

Browse files
Re-sync with internal repository (facebook#9577)
The internal and external repositories are out of sync. This Pull Request attempts to brings them back in sync by patching the GitHub repository. Please carefully review this patch. You must disable ShipIt for your project in order to merge this pull request. DO NOT IMPORT this pull request. Instead, merge it directly on GitHub using the MERGE BUTTON. Re-enable ShipIt after merging.
1 parent 75c1143 commit 24a43da

40 files changed

+360
-149
lines changed

third-party/thrift/src/thrift/lib/hack/src/TClientAsyncHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TClientAsyncHandler {
3434
string $service_name,
3535
string $func_name,
3636
?IThriftStruct $args = null,
37-
)[zoned_local]: Awaitable<void> {
37+
): Awaitable<void> {
3838
// Do nothing
3939
}
4040

third-party/thrift/src/thrift/lib/hack/src/TClientMultiAsyncHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getHandlers()[]: readonly dict<string, TClientAsyncHandler> {
5252
string $service_name,
5353
string $func_name,
5454
?IThriftStruct $args = null,
55-
)[zoned_shallow]: Awaitable<void> {
55+
): Awaitable<void> {
5656
await Vec\map_async(
5757
$this->handlers,
5858
async $handler ==>

third-party/thrift/src/thrift/lib/hack/src/TContextPropV2ServerHandler.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ public function preWrite(
4141
string $fn_name,
4242
mixed $result,
4343
): void {
44+
// keeping this logic in tact from v1 and not moving it to handlers
45+
// because we write to ARTILLERY_TRACING_HEADERS and not TFMR
46+
if (
47+
JustKnobs::eval('artillery/sdk_www:response_header_propagation_rollout')
48+
) {
49+
$context_manager = ContextManager::get();
50+
if ($context_manager->getCoreContext() !== null) {
51+
$ctx_prop_headers = $context_manager->processOutgoingResponse(shape());
52+
53+
if (
54+
C\contains_key(
55+
$ctx_prop_headers,
56+
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
57+
)
58+
) {
59+
$this->thriftServer->addHTTPHeader(
60+
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
61+
$ctx_prop_headers[HTTPResponseHeader::ARTILLERY_TRACING_HEADERS],
62+
);
63+
}
64+
}
65+
}
66+
4467
$full_params = $this->params;
4568
$full_params['fn_name'] = $fn_name;
4669
$full_params['fn_result'] = $result;
@@ -68,29 +91,6 @@ public function preWrite(
6891
HTTPResponseHeader::THRIFT_FRAMEWORK_METADATA_RESPONSE,
6992
$encoded_response_tfm,
7093
);
71-
72-
// keeping this logic in tact from v1 and not moving it to handlers
73-
// because we write to ARTILLERY_TRACING_HEADERS and not TFMR
74-
if (
75-
JustKnobs::eval('artillery/sdk_www:response_header_propagation_rollout')
76-
) {
77-
$context_manager = ContextManager::get();
78-
if ($context_manager->getCoreContext() !== null) {
79-
$ctx_prop_headers = $context_manager->processOutgoingResponse(shape());
80-
81-
if (
82-
C\contains_key(
83-
$ctx_prop_headers,
84-
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
85-
)
86-
) {
87-
$this->thriftServer->addHTTPHeader(
88-
HTTPResponseHeader::ARTILLERY_TRACING_HEADERS,
89-
$ctx_prop_headers[HTTPResponseHeader::ARTILLERY_TRACING_HEADERS],
90-
);
91-
}
92-
}
93-
}
9494
}
9595

9696
}

third-party/thrift/src/thrift/lib/hack/src/ThriftContextPropState.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,53 @@ public function getModelTypeId()[]: ?int {
233233
return $this->getModelInfo()?->get_model_type_id();
234234
}
235235

236+
// user id getters
237+
public function getUserIds()[]: ?ContextProp\UserIds {
238+
return $this->getBaggage()?->user_ids;
239+
}
240+
241+
public function getFBUserId()[]: ?int {
242+
return $this->getUserIds()?->fb_user_id;
243+
}
244+
245+
public function getIGUserId()[]: ?int {
246+
return $this->getUserIds()?->ig_user_id;
247+
}
248+
249+
// user id setters
250+
public function setUserIds(
251+
?ContextProp\UserIds $user_ids,
252+
)[write_props]: void {
253+
$this->storage->baggage =
254+
$this->storage->baggage ?? ContextProp\Baggage::withDefaultValues();
255+
256+
$baggage = $this->storage->baggage as nonnull;
257+
$baggage->user_ids = $user_ids;
258+
$this->dirty();
259+
}
260+
261+
public function setFBUserId(int $fb_user_id)[write_props]: void {
262+
$this->storage->baggage =
263+
$this->storage->baggage ?? ContextProp\Baggage::withDefaultValues();
264+
$baggage = $this->storage->baggage as nonnull;
265+
266+
$baggage->user_ids =
267+
$baggage->user_ids ?? ContextProp\UserIds::withDefaultValues();
268+
$baggage->user_ids->fb_user_id = $fb_user_id;
269+
$this->dirty();
270+
}
271+
272+
public function setIGUserId(int $ig_user_id)[write_props]: void {
273+
$this->storage->baggage =
274+
$this->storage->baggage ?? ContextProp\Baggage::withDefaultValues();
275+
$baggage = $this->storage->baggage as nonnull;
276+
277+
$baggage->user_ids =
278+
$baggage->user_ids ?? ContextProp\UserIds::withDefaultValues();
279+
$baggage->user_ids->ig_user_id = $ig_user_id;
280+
$this->dirty();
281+
}
282+
236283
public function getTraceContext()[]: ?ContextProp\TraceContext {
237284
if ($this->storage->baggage is nonnull) {
238285
$trace_context = $this->storage->baggage?->trace_context;

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftBacktraceEventHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ final class BacktraceClientEventHandlerTest extends WWWTest {
6969

7070
<<Oncalls('xdc_artillery')>>
7171
final class ThriftBacktraceServerEventHandlerTest extends WWWTest {
72+
use ClassLevelTest;
7273
public async function testSetsHeaderWhenBacktraceActive(): Awaitable<void> {
7374
$thrift_server = mock(ThriftServer::class);
7475
$handler = new ThriftBacktraceServerEventHandler($thrift_server);

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftContextPropHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<<Oncalls('thrift')>>
55
final class ThriftContextPropHandlerTest extends WWWTest {
6+
use ClassLevelTest;
67
private static function readTFMForTest(string $v): ThriftFrameworkMetadata {
78
$transport = Base64::decode($v);
89
$buf = new TMemoryBuffer($transport);

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftContextPropServerEventHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<<Oncalls('xdc_artillery')>>
55
final class ThriftContextPropServerEventHandlerTest extends WWWTest {
6+
use ClassLevelTest;
67
public async function testThriftContextPropResponsePath(): Awaitable<void> {
78
ThriftContextPropState::get()->addExperimentId(1);
89

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftContextPropStateScopeGuardTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<<Oncalls('xdc_artillery')>>
55
final class ThriftContextPropStateScopeGuardTest extends WWWTest {
66

7+
use ClassLevelTest;
8+
79
private function getSerializedTFMHeaders(
810
string $overriden_request_id,
911
int $overriden_origin_id,

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftContextPropStateTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<<Oncalls('thrift')>>
55
final class ThriftContextPropStateTest extends WWWTest {
6+
use ClassLevelTest;
67
public function testAccess(): void {
78
$tcps = ThriftContextPropState::get();
89
expect($tcps->getRequestId())->toEqual("");
@@ -37,6 +38,39 @@ public function testRegionalizationEntityNullable(): void {
3738
expect($tcps->getRegionalizationEntity())->toBeNull();
3839
}
3940

41+
public function testUserIdsNullable(): void {
42+
$tcps = ThriftContextPropState::get();
43+
expect($tcps->getUserIds())->toBeNull();
44+
45+
// 0 is different from null
46+
$tcps->setUserIds(ContextProp\UserIds::withDefaultValues());
47+
expect($tcps->getUserIds())->toNotBeNull();
48+
expect($tcps->getUserIds()?->fb_user_id)->toEqual(0);
49+
expect($tcps->getUserIds()?->ig_user_id)->toEqual(0);
50+
51+
// override existing value
52+
$tcps->setUserIds(new ContextProp\UserIds(1, 2));
53+
expect($tcps->getUserIds()?->fb_user_id)->toEqual(1);
54+
expect($tcps->getUserIds()?->ig_user_id)->toEqual(2);
55+
56+
// back to null
57+
$tcps->setUserIds(null);
58+
expect($tcps->getUserIds())->toBeNull();
59+
60+
// set FB Id only
61+
$tcps->setFBUserId(3);
62+
expect($tcps->getUserIds()?->fb_user_id)->toEqual(3);
63+
expect($tcps->getFBUserId())->toEqual(3);
64+
expect($tcps->getUserIds()?->ig_user_id)->toEqual(0);
65+
66+
// set IG Id only
67+
$tcps->setIGUserId(4);
68+
expect($tcps->getUserIds()?->fb_user_id)->toEqual(3);
69+
expect($tcps->getUserIds()?->ig_user_id)->toEqual(4);
70+
expect($tcps->getIGUserId())->toEqual(4);
71+
72+
}
73+
4074
public function testBaggage(): void {
4175
$tcps = ThriftContextPropState::get();
4276
$tcps->clear();

third-party/thrift/src/thrift/lib/hack/src/__tests__/ThriftImmutableWrapperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<<Oncalls('signals_infra')>>
55
final class ThriftImmutableWrapperTest extends WWWTest {
66

7+
use ClassLevelTest;
8+
79
public async function testGetSerializedThrift(): Awaitable<void> {
810
$underlying = AdsConsentPlatformParams::fromShape(shape(
911
'traceID' => '123',

0 commit comments

Comments
 (0)