From 3ed49dd705ec63af16967b37249c050261c97856 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 3 Nov 2024 09:15:24 -0500 Subject: [PATCH 1/8] chore(deps): update dependency datadog/dd-trace to ^0.99.0 (#56) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Thomas Poignant --- hooks/DDTrace/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/DDTrace/composer.json b/hooks/DDTrace/composer.json index a385e0e2..dd6eae71 100644 --- a/hooks/DDTrace/composer.json +++ b/hooks/DDTrace/composer.json @@ -27,7 +27,7 @@ "open-feature/sdk": "^2.0" }, "require-dev": { - "datadog/dd-trace": "^0.82.0", + "datadog/dd-trace": "^0.99.0", "ergebnis/composer-normalize": "^2.25", "friendsofphp/php-cs-fixer": "^3.13", "hamcrest/hamcrest-php": "^2.0", From 0dab8ad39ada03fb178d706fa957cf104934fa97 Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Fri, 24 Jan 2025 18:39:49 +0100 Subject: [PATCH 2/8] feat(go-feature-flag): Support exporter metadata Signed-off-by: Thomas Poignant --- providers/GoFeatureFlag/src/config/Config.php | 29 +++++++++++- .../GoFeatureFlag/src/controller/OfrepApi.php | 3 ++ .../tests/unit/GoFeatureFlagProviderTest.php | 46 +++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/providers/GoFeatureFlag/src/config/Config.php b/providers/GoFeatureFlag/src/config/Config.php index 510bc9e1..41ccb330 100644 --- a/providers/GoFeatureFlag/src/config/Config.php +++ b/providers/GoFeatureFlag/src/config/Config.php @@ -19,17 +19,37 @@ class Config */ private ?ClientInterface $httpclient; + /** + * @var array exporterMetadata - is the metadata we send to the GO Feature Flag relay proxy when we report + * the evaluation data usage. + * + * ‼️Important: If you are using a GO Feature Flag relay proxy before version v1.41.0, the information of this + * field will not be added to your feature events. + */ + private array $exporterMetadata = []; + /** * @param string $endpoint - The endpoint to your GO Feature Flag Instance * @param string|null $apiKey - API Key to use to connect to GO Feature Flag * @param array|null $customHeaders - Custom headers you want to send * @param ClientInterface|null $httpclient - The HTTP Client to use (if you want to use a custom one) */ - public function __construct(string $endpoint, ?string $apiKey = '', ?array $customHeaders = [], ?ClientInterface $httpclient = null) - { + public function __construct( + string $endpoint, + ?string $apiKey = '', + ?array $customHeaders = [], + ?array $exporterMetadata = [], + ?ClientInterface $httpclient = null, + ) { $this->httpclient = $httpclient; $this->endpoint = $endpoint; $this->customHeaders = $customHeaders ?? []; + + // set default exporter metadata fields + $this->exporterMetadata = $exporterMetadata ?? []; + $this->exporterMetadata['openfeature'] = true; + $this->exporterMetadata['provider'] = 'php'; + if ($apiKey !== null && $apiKey !== '') { $this->customHeaders['Authorization'] = 'Bearer ' . $apiKey; } @@ -57,4 +77,9 @@ public function getHttpClient(): ?ClientInterface { return $this->httpclient; } + + public function getExporterMetadata(): array + { + return $this->exporterMetadata; + } } diff --git a/providers/GoFeatureFlag/src/controller/OfrepApi.php b/providers/GoFeatureFlag/src/controller/OfrepApi.php index d5d17edb..1b0f1700 100644 --- a/providers/GoFeatureFlag/src/controller/OfrepApi.php +++ b/providers/GoFeatureFlag/src/controller/OfrepApi.php @@ -75,6 +75,9 @@ public function evaluate(string $flagKey, EvaluationContext $evaluationContext): ['targetingKey' => $evaluationContext->getTargetingKey()], ); + // Add exporter metadata to the context + $fields['gofeatureflag'] = ['exporterMetadata' => $this->options->getExporterMetadata()]; + $requestBody = json_encode(['context' => $fields]); if ($requestBody === false) { throw new ParseException('failed to encode request body'); diff --git a/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php b/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php index e990ec90..811c7e5a 100644 --- a/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php +++ b/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php @@ -474,6 +474,52 @@ public function testReturnAnErrorAPIResponseIf500(): void assertEquals('boolean_flag', $got->getFlagKey()); } + public function testShouldSendExporterMetadataInContext(): void + { + $mockClient = $this->createMock(ClientInterface::class); + $mockResponse = new Response(200, [], json_encode([ + 'key' => 'integer_key', + 'value' => 42, + 'reason' => 'TARGETING_MATCH', + 'variant' => 'default', + ])); + + $requestBody = ''; + $mockClient + ->expects($this->once()) + ->method('sendRequest') + ->willReturnCallback(function ($request) use ($mockResponse, &$requestBody) { + $requestBody = $request->getBody()->getContents(); + + return $mockResponse; + }); + + $config = new Config( + 'http://gofeatureflag.org', + null, + [], + ['key1' => 'value', 'key2' => 123, 'key3' => 123.45], + ); + + $provider = new GoFeatureFlagProvider($config); + $this->mockHttpClient($provider, $mockClient); + + $api = OpenFeatureAPI::getInstance(); + $api->setProvider($provider); + $client = $api->getClient(); + $client->getBooleanDetails('boolean_flag', false, $this->defaultEvaluationContext); + + // get the request body of the request received by the mock client + $want = ['key1' => 'value', + 'key2' => 123, + 'key3' => 123.45, + 'openfeature' => true, + 'provider' => 'php', + ]; + $got = json_decode($requestBody, true)['context']['gofeatureflag']['exporterMetadata']; + assertEquals($want, $got); + } + protected function setUp(): void { parent::setUp(); From d6304caf991d7fd63fa511bb38d588b94721f4fd Mon Sep 17 00:00:00 2001 From: CristianCurteanu Date: Wed, 22 Jan 2025 17:33:09 +0200 Subject: [PATCH 3/8] upgrade rollout/rox to 6.0.1 (#119) Signed-off-by: CristianCurteanu Signed-off-by: Thomas Poignant --- providers/CloudBees/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/CloudBees/composer.json b/providers/CloudBees/composer.json index 67640d8a..c4946acc 100644 --- a/providers/CloudBees/composer.json +++ b/providers/CloudBees/composer.json @@ -25,7 +25,7 @@ "require": { "php": "^8", "open-feature/sdk": "^2.0", - "rollout/rox": "^5.0" + "rollout/rox": "^6.0" }, "require-dev": { "ergebnis/composer-normalize": "^2.25", From e66a3bca85c2eec000ffa85910befd61bbee74e1 Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Fri, 24 Jan 2025 19:02:09 +0100 Subject: [PATCH 4/8] fix php doc Signed-off-by: Thomas Poignant --- providers/GoFeatureFlag/src/config/Config.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/providers/GoFeatureFlag/src/config/Config.php b/providers/GoFeatureFlag/src/config/Config.php index 41ccb330..db50572a 100644 --- a/providers/GoFeatureFlag/src/config/Config.php +++ b/providers/GoFeatureFlag/src/config/Config.php @@ -20,7 +20,7 @@ class Config private ?ClientInterface $httpclient; /** - * @var array exporterMetadata - is the metadata we send to the GO Feature Flag relay proxy when we report + * @var array exporterMetadata - is the metadata we send to the GO Feature Flag relay proxy when we report * the evaluation data usage. * * ‼️Important: If you are using a GO Feature Flag relay proxy before version v1.41.0, the information of this @@ -78,6 +78,9 @@ public function getHttpClient(): ?ClientInterface return $this->httpclient; } + /** + * @return array + */ public function getExporterMetadata(): array { return $this->exporterMetadata; From 3e34f75172caacc4a58381e2c07005328258cabb Mon Sep 17 00:00:00 2001 From: Michael Beemer Date: Fri, 24 Jan 2025 13:02:53 -0500 Subject: [PATCH 5/8] chore: remove hardcoded version (#122) Signed-off-by: Michael Beemer Signed-off-by: Thomas Poignant --- release-please-config.json | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/release-please-config.json b/release-please-config.json index e84fa621..c25cd034 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -7,32 +7,25 @@ "include-v-in-tag": false, "packages": { "hooks/DDTrace": { - "package-name": "open-feature/dd-trace-hook", - "release-as": "1.0.0" + "package-name": "open-feature/dd-trace-hook" }, "hooks/OpenTelemetry": { - "package-name": "open-feature/otel-hook", - "release-as": "1.0.0" + "package-name": "open-feature/otel-hook" }, "hooks/Validators": { - "package-name": "open-feature/validators-hook", - "release-as": "1.0.0" + "package-name": "open-feature/validators-hook" }, "providers/CloudBees": { - "package-name": "open-feature/cloudbees-provider", - "release-as": "1.0.0" + "package-name": "open-feature/cloudbees-provider" }, "providers/Flagd": { - "package-name": "open-feature/flagd-provider", - "release-as": "1.0.0" + "package-name": "open-feature/flagd-provider" }, "providers/Split": { - "package-name": "open-feature/split-provider", - "release-as": "1.0.0" + "package-name": "open-feature/split-provider" }, "providers/GoFeatureFlag": { - "package-name": "open-feature/go-feature-flag-provider", - "release-as": "1.0.0" + "package-name": "open-feature/go-feature-flag-provider" } } } From 39f6d3f45bb1352796a7d9df06446c634486e472 Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Sat, 25 Jan 2025 10:02:45 +0100 Subject: [PATCH 6/8] fix: add explicit usage of json_decode Signed-off-by: Thomas Poignant --- providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php b/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php index 811c7e5a..e55369e9 100644 --- a/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php +++ b/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php @@ -22,6 +22,7 @@ use function PHPUnit\Framework\assertEquals; use function json_encode; +use function json_decode; class GoFeatureFlagProviderTest extends TestCase { From 9a3c4670bfc40c2e4064d46ab483ca42e3d02b92 Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Sat, 25 Jan 2025 10:05:50 +0100 Subject: [PATCH 7/8] fix: use in alphabetical order Signed-off-by: Thomas Poignant --- .../GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php b/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php index e55369e9..2f1b0a68 100644 --- a/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php +++ b/providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php @@ -21,8 +21,8 @@ use ReflectionException; use function PHPUnit\Framework\assertEquals; -use function json_encode; use function json_decode; +use function json_encode; class GoFeatureFlagProviderTest extends TestCase { From 55a9edfbe6723ad0d2ef5d4235a105cba415941e Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Mon, 27 Jan 2025 11:24:56 +0100 Subject: [PATCH 8/8] fix lint type in doc Signed-off-by: Thomas Poignant --- providers/GoFeatureFlag/src/config/Config.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/providers/GoFeatureFlag/src/config/Config.php b/providers/GoFeatureFlag/src/config/Config.php index db50572a..8ba5851f 100644 --- a/providers/GoFeatureFlag/src/config/Config.php +++ b/providers/GoFeatureFlag/src/config/Config.php @@ -20,7 +20,7 @@ class Config private ?ClientInterface $httpclient; /** - * @var array exporterMetadata - is the metadata we send to the GO Feature Flag relay proxy when we report + * @var array exporterMetadata - is the metadata we send to the GO Feature Flag relay proxy when we report * the evaluation data usage. * * ‼️Important: If you are using a GO Feature Flag relay proxy before version v1.41.0, the information of this @@ -32,6 +32,7 @@ class Config * @param string $endpoint - The endpoint to your GO Feature Flag Instance * @param string|null $apiKey - API Key to use to connect to GO Feature Flag * @param array|null $customHeaders - Custom headers you want to send + * @param array|null $exporterMetadata - Metadata to send to the relay proxy during evaluation data collection * @param ClientInterface|null $httpclient - The HTTP Client to use (if you want to use a custom one) */ public function __construct( @@ -79,7 +80,7 @@ public function getHttpClient(): ?ClientInterface } /** - * @return array + * @return array */ public function getExporterMetadata(): array {