launchdarkly / python-server-sdk

LaunchDarkly Server-side SDK for Python
https://docs.launchdarkly.com/sdk/server-side/python
Other
38 stars 45 forks source link

Feature store cache ignored prior to initialization #188

Closed farioas closed 1 year ago

farioas commented 1 year ago

Is this a support request? no

Describe the bug We're using Redis as a feature store cache. The logs are full of warning saying Feature Flag evaluation attempted before client has initialized.

To reproduce Client initialization:

store = Redis.new_feature_store(
    url=settings.REDIS_LOCATION,
    prefix='feature-flags',
    caching=CacheConfig(expiration=30))
ldclient.set_config(Config(
    settings.FEATURE_FLAGS_API_KEY,
    feature_store=store,
    http=HTTPConfig(connect_timeout=5)
))
client = ldclient.get()

uwsgi short config:

enable-threads = True
lazy-apps = True

! Note: we're using lazy-apps mode, it will load an application one time per worker instead of preforking.

Expected behavior There should be no warnings, because the feature store cache should be consulted prior initialization.

Logs

{"asctime": "29/Nov/2022:12:41:28 +0000", "name": "ldclient.util", "funcName": "_evaluate_internal", "lineno": 296, "levelname": "WARNING", "user_id": null, "message": "Feature Flag evaluation attempted before client has initialized - using last known values from feature store for feature key: ff_some_flag_redacted"}

SDK version

launchdarkly-server-sdk==7.5.0

Language version, developer tools Python 3.8.10 uwsgi 2.0.21

OS/platform Ubuntu 20.04

Additional context The issue is very similar to https://github.com/launchdarkly/java-server-sdk/issues/107

eli-darkly commented 1 year ago

I may be misunderstanding your description of the issue, but this seems to me to be intended behavior rather than a bug. I'll explain what the intention was.

eli-darkly commented 1 year ago

That is standard behavior across all of our server-side SDKs that have any database integrations.

eli-darkly commented 1 year ago

In other words, unless I'm misunderstanding your report, it is not "ignoring" the Redis cache. If there is flag data in Redis, and you do a flag evaluation, then the SDK will log a warning, but it should also be reading the flag data from Redis and using it to do your evaluation.

~I have some uncertainty here because you didn't mention the full log line— there are actually two different possible log messages that include the text you mentioned. And you also didn't mention whether the flag evaluation is in fact returning a reasonable value based on what the flag data in Redis was. But what I would expect is that the flag evaluation would use that flag data, and that the full log line would be this:~

(Update: sorry, I just reread your message and saw where you quoted the full log line. And indeed it was the one that I expected, which is this one:)

Feature Flag evaluation attempted before client has initialized - using last known values from feature store for feature key: <your flag key>

If it did not see any data in Redis, then it would be:

Feature Flag evaluation attempted before client has initialized! Feature store unavailable - returning default: <the default value parameter that you passed to variation()>

It is explicitly telling you that it is "using last known values from feature store", i.e. the cached data in Redis.

farioas commented 1 year ago

Thanks for such a detailed explanation, this should be published somewhere in documentation, especially sequence from your 1st message as a sequence diagram.

eli-darkly commented 1 year ago

Yes - I've asked the documentation team to look into making this clearer in docs.