launchdarkly / ld-relay

LaunchDarkly Relay Proxy
Other
112 stars 80 forks source link

Add support for additional endpoints #68

Closed egiberti closed 5 years ago

egiberti commented 5 years ago

Currently some endpoints return an HTTP 404 from the ld-relay host. This is problematic if running ld-relay in relay proxy mode. Switching to daemon mode can alleviate this in some cases, but adds a dependency on Redis to application code. The alternative is adding logic to the application to make some requests through the relay and others directly to the LaunchDarkly service.

Example request:

$config = [
    'feature_requester' => new LaunchDarkly\Impl\Integrations\GuzzleFeatureRequester(
        'http://ld-relay.example.com:8030', 
        $apiKey, 
       [] // config'd as needed
    )
];
$ldClient = new \LaunchDarkly\LDClient($apiKey, $config)

$ldUser = new \LaunchDarkly\LDUserBuilder($userId); // config'd as needed
$ldClient->allFlagsState($ldUser);

This adds a couple of entries to the logs and comes back with no flags.

[2019-08-01 09:05:48] LaunchDarkly.ERROR: Received error 404 for GuzzleFeatureRequester::getAll - giving up permanently [] []
[2019-08-01 09:05:48] LaunchDarkly.ERROR: Due to an unrecoverable HTTP error, no further HTTP requests will be made during lifetime of LDClient [] []

Looking in the PHP SDK code to see what URL is being requested shows /sdk/flags. Making that request via curl directly to the ld-relay host confirms what the logging stated before, a missing endpoint.

curl -X GET -H "Authorization: sdk-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" http://ld-relay.example.net:8030/sdk/flags
404 page not found

The same request on the LaunchDarkly app host app.launchdarkly.com returns a JSON blob of current flag data; as expected. Ideally, the request would be answered with the state already stored in ld-relay and transparently proxied through to LaunchDarkly in the event the flag state isn't currently in memory.

eli-darkly commented 5 years ago

Thanks for catching this. PHP uses different endpoints than all of the other SDKs, because of HTTP caching considerations, and we failed to notice that we hadn't implemented those endpoints in ld-relay because all of our current PHP-using customers (as far as we knew) were using Redis. This will be added in the next ld-relay release after 5.6.0.

egiberti commented 5 years ago

I just tried a build with version 5.6.1 and it still behaves the same way, returning a 404 when accessing /sdk/flags. Do you have any idea when a version that will support this will be released?

eli-darkly commented 5 years ago

Sorry, I should have said "the next ld-relay minor version release" since this would be new behavior (even though it should have been implemented before). The 5.6.1 release was an unrelated bugfix patch, as described in the release notes. I don't know of the exact time frame for implementing this, but will update this issue to keep you posted.

eli-darkly commented 5 years ago

This is implemented in the 5.7.0 release.