thomaspoignant / go-feature-flag

GO Feature Flag is a simple, complete and lightweight self-hosted feature flag solution 100% Open Source. 🎛️
https://gofeatureflag.org/
MIT License
1.45k stars 140 forks source link

(change) Improve error handling in case flag is not found by relay proxy #581

Closed Yaroslav-Kovalchyk-Imprivata closed 1 year ago

Yaroslav-Kovalchyk-Imprivata commented 1 year ago

Motivation

I'm trying to get flag value from relay proxy using OpenFeature SDK and dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProvider and getting unclear error message in log:

2023-03-20 13:38:26.397 ERROR 2146891 --- [nio-8081-exec-3] dev.openfeature.sdk.OpenFeatureClient : Unable to correctly evaluate flag with key 'demo.feature-b'

dev.openfeature.sdk.exceptions.GeneralError: unknown error while retrieving flag demo.feature-b at dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProvider.resolveEvaluationGoFeatureFlagProxy(GoFeatureFlagProvider.java:224) ~[go-feature-flag-0.2.3.jar:na] at dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProvider.getBooleanEvaluation(GoFeatureFlagProvider.java:124) ~[go-feature-flag-0.2.3.jar:na] at dev.openfeature.sdk.OpenFeatureClient.createProviderEvaluation(OpenFeatureClient.java:168) ~[sdk-1.3.0.jar:na] at dev.openfeature.sdk.OpenFeatureClient.evaluateFlag(OpenFeatureClient.java:134) ~[sdk-1.3.0.jar:na] at dev.openfeature.sdk.OpenFeatureClient.getBooleanDetails(OpenFeatureClient.java:211) ~[sdk-1.3.0.jar:na] at dev.openfeature.sdk.OpenFeatureClient.getBooleanDetails(OpenFeatureClient.java:205) ~[sdk-1.3.0.jar:na] at dev.openfeature.sdk.OpenFeatureClient.getBooleanValue(OpenFeatureClient.java:189) ~[sdk-1.3.0.jar:na] at com.demo.openfeature.service.HelloService.sayHello(HelloService.java:21) ~[main/:na] at com.demo.openfeature.controller.HelloController.sayHello(HelloController.java:24) ~[main/:na]

After debugging the GoFeatureFlagProvider I found, that it sends GET request http://127.0.0.1:1031/v1/feature/demo.feature-a/eval It is strange, but error response comes with 200 OK status. Response body contains following error:

{"trackEvents":true,"variationType":"SdkDefault","failed":true,"version":"","reason":"ERROR","errorCode":"FLAG_NOT_FOUND","value":false,"cacheable":false}

Provider attempts to parse this response in that way: GoFeatureFlagResponse goffResp = responseMapper.readValue(body, GoFeatureFlagResponse.class);

And gets parsing exception, that result in that unclear log message.

Requirements

Would be great to have error response with error status code and with meaningful and easy to understand message in logs.

thomaspoignant commented 1 year ago

@Yaroslav-Kovalchyk-Imprivata thanks for raising this issue.

1st, we are sending an HTTP 200 because the relay proxy is working as expected but the flag evaluation itself has returned an error.

I would check what happened in the java SDK and provide a fix. I will let you know as soon as I have more information.

thomaspoignant commented 1 year ago

@Yaroslav-Kovalchyk-Imprivata I've opened a PR to make it more explicit. You can check it https://github.com/thomaspoignant/go-feature-flag/issues/581

thomaspoignant commented 1 year ago

A new version of the provider as been released and will be soon available in maven repository.

Yaroslav-Kovalchyk-Imprivata commented 1 year ago

Thank you, @thomaspoignant!