WikiWatershed / model-my-watershed

The web application front end for Model My Watershed.
https://modelmywatershed.org
Apache License 2.0
57 stars 31 forks source link

Add hybrid tiler to Windshaft service #3655

Closed KlaasH closed 1 month ago

KlaasH commented 1 month ago

Overview

Adds an endpoint to the Tiler service that passes requests along to a TiTiler-MosaicJSON endpoint, then returns the resulting tiles to the user but also caches them to S3 so they won't have to be generated again for subsequent requests.

The endpoint is minimally integrated with Windshaft—it seemed like it should be possible to create an http tile source and use most of the Windshaft machinery to do something like this, but after multiple failed attempts I gave up and implemented it more like the health-check endpoint, i.e. as an endpoint that's run by the same service as Windshaft but pretty much does its own thing, just using the Express.js functionality of the Windshaft server. To take advantage of the S3 caching behavior, however, the function that handles that had to be pulled out from the Windshaft class and made into a stand-alone utility function. So it (and sendError) live in src/tiler/http/utils.js now. The changes required to break them out were fairly minimal.

The TiTiler service identifies layers by a UUID that gets assigned when they're first created, so we need this endpoint to provide the right UUID to the upstream TiTiler service, one way or another. Rather than feed those UUIDs to the front end and end up with long, inscrutable URLs for the tiler service endpoint, I set it up so that the service translates nice human-readable params (layer name and year) into the right UUID. That means the layer name and year -> UUID mapping needs to be provided to the service, and the answer is different between staging and production. So I added a variable for it, titiler_layer_map, which gets fed into an environment variable, MMW_TITILER_LAYER_MAP, in the tiler VM. To avoid having to try to pass a slightly complex JSON structure into an Ansible variable, I used a strategy that has been used elsewhere on the project, encoding each layer's values into a single string with __ between the terms, and passing in a comma-separated list of those terms.

To confirm that the CloudFormation changes work and that the hybrid tiler works as expected in a deployed environment, I got Jenkins to build and deploy this branch. So the current site on staging (as of right now, on Oct 10) is showing the changes here, and caching any tiles it generates to the staging tile cache.

Connects https://github.com/WikiWatershed/mmw-tiler/issues/11

Demo

image

image

image

image

Notes

Testing Instructions