Skip to content

Commit dc31279

Browse files
committed
feat(php): Enable FFE tests and add /ffe endpoints
- Add /ffe/start and /ffe/evaluate to PHP parametric server - Add /ffe.php for end-to-end tests - Remove missing_feature for PHP FFE tests in manifest
1 parent 284ef78 commit dc31279

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

manifests/php.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,6 @@ manifest:
474474
tests/docker_ssi/test_docker_ssi.py::TestDockerSSIFeatures::test_instrumentation_source_ssi:
475475
- declaration: missing_feature (Not implemented yet)
476476
component_version: <1.12.0
477-
tests/ffe/test_dynamic_evaluation.py: missing_feature
478-
tests/ffe/test_exposures.py: missing_feature
479477
tests/integrations/crossed_integrations/test_kafka.py::Test_Kafka: missing_feature
480478
tests/integrations/crossed_integrations/test_kinesis.py::Test_Kinesis_PROPAGATION_VIA_MESSAGE_ATTRIBUTES: missing_feature
481479
tests/integrations/crossed_integrations/test_rabbitmq.py::Test_RabbitMQ_Trace_Context_Propagation: missing_feature
@@ -532,7 +530,6 @@ manifest:
532530
tests/parametric/test_dynamic_configuration.py::TestDynamicConfigV1_EmptyServiceTargets: v1.4.0
533531
tests/parametric/test_dynamic_configuration.py::TestDynamicConfigV1_ServiceTargets: missing_feature
534532
tests/parametric/test_dynamic_configuration.py::TestDynamicConfigV2: missing_feature
535-
tests/parametric/test_ffe/test_dynamic_evaluation.py::Test_Feature_Flag_Dynamic_Evaluation: missing_feature
536533
tests/parametric/test_headers_b3.py::Test_Headers_B3::test_headers_b3_migrated_extract_invalid: missing_feature (Need to remove b3=b3multi alias)
537534
tests/parametric/test_headers_b3.py::Test_Headers_B3::test_headers_b3_migrated_extract_valid: missing_feature (Need to remove b3=b3multi alias)
538535
tests/parametric/test_headers_b3.py::Test_Headers_B3::test_headers_b3_migrated_inject_valid: missing_feature (Need to remove b3=b3multi alias)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
header('Content-Type: application/json');
4+
5+
$input = json_decode(file_get_contents('php://input'), true);
6+
7+
if (!is_array($input)) {
8+
http_response_code(400);
9+
echo json_encode(['error' => 'Invalid JSON body']);
10+
exit;
11+
}
12+
13+
$flag = isset($input['flag']) ? $input['flag'] : null;
14+
$variationType = isset($input['variationType']) ? $input['variationType'] : null;
15+
$defaultValue = isset($input['defaultValue']) ? $input['defaultValue'] : null;
16+
$targetingKey = array_key_exists('targetingKey', $input) ? $input['targetingKey'] : '';
17+
$attributes = isset($input['attributes']) ? $input['attributes'] : [];
18+
19+
try {
20+
$provider = \DDTrace\FeatureFlags\Provider::getInstance();
21+
$provider->start();
22+
23+
$result = $provider->evaluate($flag, $variationType, $defaultValue, $targetingKey, $attributes);
24+
25+
// Flush exposure events immediately for system test observability
26+
$provider->flush();
27+
28+
echo json_encode($result);
29+
} catch (\Throwable $e) {
30+
echo json_encode(['value' => $defaultValue, 'reason' => 'ERROR', 'error' => $e->getMessage()]);
31+
}

utils/build/docker/php/parametric/server.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,41 @@ function remappedSpanKind($spanKind) {
546546
return jsonResponse([]);
547547
}));
548548

549+
// FFE (Feature Flags & Experimentation) endpoints
550+
$ffeProvider = null;
551+
552+
$router->addRoute('POST', '/ffe/start', new ClosureRequestHandler(function (Request $req) use (&$ffeProvider) {
553+
try {
554+
if ($ffeProvider === null) {
555+
$ffeProvider = \DDTrace\FeatureFlags\Provider::getInstance();
556+
}
557+
$ffeProvider->start();
558+
return jsonResponse([]);
559+
} catch (\Throwable $e) {
560+
return new Response(status: 500, body: json_encode(['error' => $e->getMessage()]));
561+
}
562+
}));
563+
564+
$router->addRoute('POST', '/ffe/evaluate', new ClosureRequestHandler(function (Request $req) use (&$ffeProvider) {
565+
try {
566+
if ($ffeProvider === null) {
567+
$ffeProvider = \DDTrace\FeatureFlags\Provider::getInstance();
568+
$ffeProvider->start();
569+
}
570+
571+
$flag = arg($req, 'flag');
572+
$variationType = arg($req, 'variationType');
573+
$defaultValue = arg($req, 'defaultValue');
574+
$targetingKey = arg($req, 'targetingKey');
575+
$attributes = arg($req, 'attributes') ?? [];
576+
577+
$result = $ffeProvider->evaluate($flag, $variationType, $defaultValue, $targetingKey, $attributes);
578+
return jsonResponse($result);
579+
} catch (\Throwable $e) {
580+
return new Response(status: 500, body: json_encode(['error' => $e->getMessage()]));
581+
}
582+
}));
583+
549584
$middleware = new class implements Middleware {
550585
public function handleRequest(Request $request, RequestHandler $next): Response {
551586
$response = $next->handleRequest($request);

0 commit comments

Comments
 (0)