appsembler / configuration

a simple, but flexible, way for anyone to stand up an instance of the edX platform that is fully configured and ready-to-go
GNU Affero General Public License v3.0
14 stars 13 forks source link

use consistent unique value for staticfiles cache prefix #368

Closed thraxil closed 3 years ago

thraxil commented 3 years ago

With the hostname+random number approach, every edxapp server gets a different KEY_PREFIX. Eg, juniper prod currently has:

/edx/etc/lms.yml on edxapp0 and edxapp1:

KEY_PREFIX: prod-tahoe-us-juniper-edxapp-0_2666298_general

KEY_PREFIX: prod-tahoe-us-juniper-edxapp-1_5857041_general

/edx/etc/studio.yml on edxapp0 and edxapp1:

KEY_PREFIX: prod-tahoe-us-juniper-edxapp-0_4594680_general

KEY_PREFIX: prod-tahoe-us-juniper-edxapp-1_14407_general

etc. That means that they are not sharing the cache. So each server has to do the URL generation/lookup for itself the first time it gets the first request for a given static file.

Instead, we should be using the same KEY_PREFIX on all the servers, except we want to be very careful that it changes on each deploy so the cache is forced to update when staticfiles may have changed.

To do that, https://github.com/appsembler/tahoe_deploy/pull/42 passes in the Cloud Build BUILD_ID variable as EDXAPP_APPSEMBLER_BUILD_ID. That should fit our requirement of being unique per deploy but consistent across servers.

thraxil commented 3 years ago

@OmarIthawi yeah, I wasn't positive how that should work. I think if we need a different key for lms/cms, we should do that in lms/envs/production.py and cms/envs/production.py in the edx-platform code. Eg, we currently have: https://github.com/appsembler/edx-platform/blob/main/cms/envs/production.py#L212-L216

# if 'staticfiles' in CACHES:
#     CACHES['staticfiles']['KEY_PREFIX'] = EDX_PLATFORM_REVISION

I think what we want is to put that back in but with a change like:

if 'staticfiles' in CACHES:
    CACHES['staticfiles']['KEY_PREFIX'] = CACHES['staticfiles']['KEY_PREFIX'] + "_cms"

And maybe leave the lms one as it is. That way, cms and lms have independent caches, but are otherwise consistent and sharing across servers.

OmarIthawi commented 3 years ago

@OmarIthawi yeah, I wasn't positive how that should work. I think if we need a different key for lms/cms, we should do that in lms/envs/production.py and cms/envs/production.py in the edx-platform code. Eg, we currently have: https://github.com/appsembler/edx-platform/blob/main/cms/envs/production.py#L212-L216

# if 'staticfiles' in CACHES:
#     CACHES['staticfiles']['KEY_PREFIX'] = EDX_PLATFORM_REVISION

I think what we want is to put that back in but with a change like:

if 'staticfiles' in CACHES:
    CACHES['staticfiles']['KEY_PREFIX'] = CACHES['staticfiles']['KEY_PREFIX'] + "_cms"

And maybe leave the lms one as it is. That way, cms and lms have independent caches, but are otherwise consistent and sharing across servers.

That definitely works! Thanks Anders!

thraxil commented 3 years ago

https://github.com/appsembler/edx-platform/pull/920 will be required before merging this.