Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to enable caching of GetMap/GetTile requests #921

Open
omad opened this issue Jan 25, 2023 · 1 comment
Open

Unable to enable caching of GetMap/GetTile requests #921

omad opened this issue Jan 25, 2023 · 1 comment

Comments

@omad
Copy link
Member

omad commented Jan 25, 2023

Description

I'm trying to setup CloudFront (AWS's CDN/cache) to work in front of a datacube-ows deployment.

We have quite a complex configuration, but I believe I've setup the correct options. GetCapabilities requests are now being cached, but GetMap/GetTile requests are not, and I can't work out why.

I'm expecting cache-control: max-age 3600 headers to be added to my requests, but instead they're still getting cache-control: no-cache headers.

Steps to Reproduce

curl -I 'https://ows.dea.ga.gov.au/?transparent=true&format=image%2Fpng&exceptions=XML&styles=true_colour&version=1.3.0&time=2023-01-24&service=WMS&request=GetMap&layers=ga_ls_ard_3&bbox=15536896.1173580
62%2C-2113330.958028555%2C15576031.875840079%2C-2074195.199546542&width=256&height=256&crs=EPSG%3A3857'
HTTP/2 200 
content-type: image/png
content-length: 167321
date: Wed, 25 Jan 2023 04:34:42 GMT
server: gunicorn
access-control-allow-origin: *
cache-control: no-cache
x-request-id: 1-63d0b161-57cc35d054da33cb162ca65c
x-cache: Miss from cloudfront
via: 1.1 5e473a5e64c6a2f7bc916721cc188252.cloudfront.net (CloudFront)
x-amz-cf-pop: SYD62-P2
x-amz-cf-id: WV69MgOnjdDM1i5QkKVfd_HjZiSb_4zHw8qaoRVDu7UdKSnLP8JIjg==

I've checked as best I can that the expected configuration is being loaded:

<<K9s-Shell>> Pod: web/ows-datacube-ows-prod-b47db98-7fjdd | Container: ows 
ows@ows-datacube-ows-prod-b47db98-7fjdd:~$ python
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datacube_ows.startup_utils import parse_config_file
>>> cfg = parse_config_file()
>>> cfg.layers[0].child_layers[0].resource_limits.wms_cache_rules
<datacube_ows.resource_limits.CacheControlRules object at 0x7fab72b34f70>
>>> cfg.layers[0].child_layers[0].resource_limits.wms_cache_rules.rules
[{'min_datasets': 1, 'max_age': 3600}, {'min_datasets': 5, 'max_age': 86400}, {'min_datasets': 9, 'max_age': 1209600}]
>>> cfg.layers[0].child_layers[0].name
'ga_ls_ard_3'

But when I try using this CacheControlRules object, it's not behaving as I'd expect.

>>> cfg.layers[0].child_layers[0].resource_limits.wms_cache_rules.cache_headers(1)
{'cache-control': 'no-cache'}
>>> cfg.layers[0].child_layers[0].resource_limits.wms_cache_rules.cache_headers(2)
{'cache-control': 'no-cache'}
>>> cfg.layers[0].child_layers[0].resource_limits.wms_cache_rules.cache_headers(3)
{'cache-control': 'no-cache'}
>>> cfg.layers[0].child_layers[0].resource_limits.wms_cache_rules.cache_headers(4)
{'cache-control': 'no-cache'}

Argh, I've solved it, it seems that max_datasets hasn't been specified, and is defaulting to 0, which is disabling caching!

I can fix it by setting it, but, it also seems like not a good default.

>>> cfg.layers[0].child_layers[0].resource_limits.wms_cache_rules.max_datasets = 20
>>> cfg.layers[0].child_layers[0].resource_limits.wms_cache_rules.cache_headers(6)
{'cache-control': 'max-age=86400'}

Context (Environment)

datacube-ows version (datacube-ows --version):

ows@ows-datacube-ows-prod-b47db98-7fjdd:~$ datacube-ows --version
 * Serving Flask app 'datacube_ows'
 * Debug mode: off
[2023-01-25 04:43:58,592] [INFO] WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
[2023-01-25 04:43:58,592] [INFO] Press CTRL+C to quit

Whoops, looks like --version isn't implemented?

ows_config.py file (link, sample code)

https://github.com/GeoscienceAustralia/dea-config/blob/master/prod/services/wms/ows_refactored/ows_reslim_cfg.py#L4-L17

datacube product metadata (datacube product show product_name)

@SpacemanPaul
Copy link
Contributor

Agreed this is a bug - WMS caching should be possible without a WMS max_datasets being set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants