Skip to content

Commit

Permalink
Make /status and /dirty URLs controlable with apache conf (#359)
Browse files Browse the repository at this point in the history
* Allow the …/status URL to be turned on or off (default of on remains)

Add ModTileEnableStatusURL On/Off to allow the …/status to be turned on
(default) or off. Previous behaviour has …/status on, which is not
changed in this patch.

* Allow the …/dirty URL to be turned on or off (default of on remains)

Add ModTileEnableDirtyURL On/Off to allow the …/dirty to be turned on
(default) or off. Previous behaviour has …/dirty on, which is not
changed in this patch.

* Make …/dirty & …/status disabled by default.

This is a breaking change. To get the old default behaviour back, you
must now manually add `ModTileEnableStatusURL On` &
`ModTileEnableDirtyURL On` to your apache configuration.

* Change default for ModTileEnable Dirty/Status URL to On

* Add log output for when `/dirty`/`/status` is Off

* Add tests for "ModTileEnable{Dirty|Status}URL Off"

---------

Co-authored-by: Amanda McCann <[email protected]>
  • Loading branch information
hummeltech and amandasaurus authored Dec 12, 2023
1 parent 4580b2e commit 925183a
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 13 deletions.
10 changes: 10 additions & 0 deletions etc/apache2/renderd-example-map.conf
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,14 @@ Listen 8081
# Parameters (poolsize in tiles and topup rate in tiles per second) for throttling render requests.
ModTileThrottlingRenders 128 0.2

# Enable the .../Z/X/Y.ext/status URL, which shows details of that tile.
# Off = a 404 is returned for that url instead.
# Default: On
#ModTileEnableStatusURL Off

# Enable the .../Z/X/Y.ext/dirty URL, which marks that tile as dirty.
# Off = a 404 is returned for that url instead.
# Default: On
#ModTileEnableDirtyURL Off

</VirtualHost>
2 changes: 2 additions & 0 deletions includes/mod_tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ typedef struct {
int delaypoolRenderSize;
long delaypoolRenderRate;
int bulkMode;
int enableStatusUrl;
int enableDirtyUrl;
} tile_server_conf;

typedef struct tile_request_data {
Expand Down
49 changes: 49 additions & 0 deletions src/mod_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,12 @@ static int tile_handler_dirty(request_rec *r)
sconf = r->server->module_config;
scfg = ap_get_module_config(sconf, &tile_module);

// Is /dirty URL enabled?
if (!scfg->enableDirtyUrl) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "tile_handler_dirty: /dirty URL is not enabled");
return HTTP_NOT_FOUND;
}

if (scfg->bulkMode) {
return OK;
}
Expand Down Expand Up @@ -1134,6 +1140,8 @@ static int tile_storage_hook(request_rec *r)

static int tile_handler_status(request_rec *r)
{
ap_conf_vector_t *sconf;
tile_server_conf *scfg;
enum tileState state;
char mtime_str[APR_CTIME_LEN];
char atime_str[APR_CTIME_LEN];
Expand All @@ -1145,6 +1153,15 @@ static int tile_handler_status(request_rec *r)
return DECLINED;
}

sconf = r->server->module_config;
scfg = ap_get_module_config(sconf, &tile_module);

// Is /status URL enabled?
if (!scfg->enableStatusUrl) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "tile_handler_status: /status URL is not enabled");
return HTTP_NOT_FOUND;
}

rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module);
cmd = rdata->cmd;

Expand Down Expand Up @@ -2672,6 +2689,20 @@ static const char *mod_tile_bulk_mode(cmd_parms *cmd, void *mconfig, int bulkMod
return NULL;
}

static const char *mod_tile_enable_status_url(cmd_parms *cmd, void *mconfig, int enableStatusUrl)
{
tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
scfg->enableStatusUrl = enableStatusUrl;
return NULL;
}

static const char *mod_tile_enable_dirty_url(cmd_parms *cmd, void *mconfig, int enableDirtyUrl)
{
tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
scfg->enableDirtyUrl = enableDirtyUrl;
return NULL;
}

static const char *mod_tile_delaypool_tiles_config(cmd_parms *cmd, void *mconfig, const char *bucketsize_string, const char *topuprate_string)
{
int bucketsize;
Expand Down Expand Up @@ -2751,6 +2782,8 @@ static void *create_tile_config(apr_pool_t *p, server_rec *s)
scfg->delaypoolRenderSize = AVAILABLE_RENDER_BUCKET_SIZE;
scfg->delaypoolRenderRate = RENDER_TOPUP_RATE;
scfg->bulkMode = 0;
scfg->enableStatusUrl = 1;
scfg->enableDirtyUrl = 1;


return scfg;
Expand Down Expand Up @@ -2793,6 +2826,8 @@ static void *merge_tile_config(apr_pool_t *p, void *basev, void *overridesv)
scfg->delaypoolRenderSize = scfg_over->delaypoolRenderSize;
scfg->delaypoolRenderRate = scfg_over->delaypoolRenderRate;
scfg->bulkMode = scfg_over->bulkMode;
scfg->enableStatusUrl = scfg_over->enableStatusUrl;
scfg->enableDirtyUrl = scfg_over->enableDirtyUrl;

//Construct a table of minimum cache times per zoom level
for (i = 0; i <= MAX_ZOOM_SERVER; i++) {
Expand Down Expand Up @@ -2984,6 +3019,20 @@ static const command_rec tile_cmds[] = {
OR_OPTIONS, /* where available */
"On Off - make all requests to renderd with bulk render priority, never mark tiles dirty" /* directive description */
),
AP_INIT_FLAG(
"ModTileEnableStatusURL", /* directive name */
mod_tile_enable_status_url, /* config action routine */
NULL, /* argument to include in call */
OR_OPTIONS, /* where available */
"On Off - whether to handle .../status urls " /* directive description */
),
AP_INIT_FLAG(
"ModTileEnableDirtyURL", /* directive name */
mod_tile_enable_dirty_url, /* config action routine */
NULL, /* argument to include in call */
OR_OPTIONS, /* where available */
"On Off - whether to handle .../dirty urls " /* directive description */
),
{NULL}
};

Expand Down
42 changes: 29 additions & 13 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ set(TILE_PNG256_URL "http://localhost:${HTTPD0_PORT}/tiles/renderd-example-png25
set(TILE_PNG32_URL "http://localhost:${HTTPD0_PORT}/tiles/renderd-example-png32/9/297/191.png")
set(TILE_WEBP_URL "http://localhost:${HTTPD0_PORT}/tiles/renderd-example-webp/9/297/191.webp")

set(TILE_DEFAULT_CMD "${CURL_EXECUTABLE} --fail --silent ${TILE_DEFAULT_URL}")
set(TILE_DIRTY_OFF_URL "http://localhost:${HTTPD1_PORT}/tiles/renderd-example/9/297/191.png/dirty")
set(TILE_DIRTY_ON_URL "http://localhost:${HTTPD0_PORT}/tiles/renderd-example/9/297/191.png/dirty")
set(TILE_STATUS_OFF_URL "http://localhost:${HTTPD1_PORT}/tiles/renderd-example/9/297/191.png/status")
set(TILE_STATUS_ON_URL "http://localhost:${HTTPD0_PORT}/tiles/renderd-example/9/297/191.png/status")

set(CURL_CMD "${CURL_EXECUTABLE} --fail --silent")
set(TILE_DEFAULT_CMD "${CURL_CMD} ${TILE_DEFAULT_URL}")
set(TILE_DEFAULT_SHA256SUM "dbf26531286e844a3a9735cdd193598dca78d22f77cafe5824bcaf17f88cbb08")
set(TILE_JPG_CMD "${CURL_EXECUTABLE} --fail --silent ${TILE_JPG_URL}")
set(TILE_JPG_CMD "${CURL_CMD} ${TILE_JPG_URL}")
set(TILE_JPG_SHA256SUM "e09c3406c02f03583dadf0c8404c2d3efdc06a40d399e381ed2f47f49fde42d7")
set(TILE_PNG256_CMD "${CURL_EXECUTABLE} --fail --silent ${TILE_PNG256_URL}")
set(TILE_PNG256_CMD "${CURL_CMD} ${TILE_PNG256_URL}")
set(TILE_PNG256_SHA256SUM "${TILE_DEFAULT_SHA256SUM}")
set(TILE_PNG32_CMD "${CURL_EXECUTABLE} --fail --silent ${TILE_PNG32_URL}")
set(TILE_PNG32_CMD "${CURL_CMD} ${TILE_PNG32_URL}")
set(TILE_PNG32_SHA256SUM "1006d92152f1e18896e0016fb43201b14bbcf7655955b74495ad3610541d325b")
set(TILE_WEBP_CMD "${CURL_EXECUTABLE} --fail --silent ${TILE_WEBP_URL}")
set(TILE_WEBP_CMD "${CURL_CMD} ${TILE_WEBP_URL}")
set(TILE_WEBP_SHA256SUM_4 "ef3862a57831b21ec69c15be196e1e2b4fea66246c361142631b9fa22b85decc") # libwebp.so.4
set(TILE_WEBP_SHA256SUM_6 "96fc0455b2269a7bcd4a5b3c9844529c3c77e3bb15f56e72f78a5af3bc15b6b5") # libwebp.so.6
set(TILE_WEBP_SHA256SUM_7 "a82ef9ba5dc333de88af7b645084c30ab2b01c664e17162cbf6659c287cc4df4") # libwebp.so.7
Expand Down Expand Up @@ -202,24 +208,34 @@ add_test(
add_test(
NAME dirty_tile
COMMAND ${BASH} -c "
TILE_STATUS_CMD=\"${TILE_DEFAULT_CMD}/status\"
TILE_LAST_RENDERED_AT_OLD=$(\${TILE_STATUS_CMD} | ${GREP_EXECUTABLE} -o 'Last rendered at [^\\.]*.')
TILE_DIRTY_ON_CMD=\"${CURL_CMD} ${TILE_DIRTY_ON_URL}\"
TILE_STATUS_ON_CMD=\"${CURL_CMD} ${TILE_STATUS_ON_URL}\"
TILE_LAST_RENDERED_AT_OLD=$(\${TILE_STATUS_ON_CMD} | ${GREP_EXECUTABLE} -o 'Last rendered at [^\\.]*.')
echo \"Tile Last Rendered At (Old): \${TILE_LAST_RENDERED_AT_OLD}\"
sleep 5;
TILE_DIRTY_CMD=\"${TILE_DEFAULT_CMD}/dirty\"
TILE_DIRTY_OUTPUT=$(\${TILE_DIRTY_CMD})
echo \"Dirty: \${TILE_DIRTY_OUTPUT}\"
if [ \"\${TILE_DIRTY_OUTPUT}\" != \"Tile submitted for rendering\" ]; then
TILE_DIRTY_ON_OUTPUT=$(\${TILE_DIRTY_ON_CMD})
echo \"Dirty: \${TILE_DIRTY_ON_OUTPUT}\"
if [ \"\${TILE_DIRTY_ON_OUTPUT}\" != \"Tile submitted for rendering\" ]; then
exit 1;
fi
TILE_LAST_RENDERED_AT_NEW=$(\${TILE_STATUS_CMD} | ${GREP_EXECUTABLE} -o 'Last rendered at [^\\.]*.')
TILE_LAST_RENDERED_AT_NEW=$(\${TILE_STATUS_ON_CMD} | ${GREP_EXECUTABLE} -o 'Last rendered at [^\\.]*.')
echo \"Tile Last Rendered At (New): \${TILE_LAST_RENDERED_AT_NEW}\"
until [ \"\${TILE_LAST_RENDERED_AT_OLD}\" != \"\${TILE_LAST_RENDERED_AT_NEW}\" ]; do
echo 'Sleeping 1s';
sleep 1;
TILE_LAST_RENDERED_AT_NEW=$(\${TILE_STATUS_CMD} | ${GREP_EXECUTABLE} -o 'Last rendered at [^\\.]*.');
TILE_LAST_RENDERED_AT_NEW=$(\${TILE_STATUS_ON_CMD} | ${GREP_EXECUTABLE} -o 'Last rendered at [^\\.]*.');
echo \"Tile Last Rendered At (New): \${TILE_LAST_RENDERED_AT_NEW}\";
done
TILE_DIRTY_OFF_CODE=$(${CURL_CMD} --write-out '%{http_code}' ${TILE_DIRTY_OFF_URL})
echo \"Dirty Off code: '\${TILE_DIRTY_OFF_CODE}'\"
if [ \"\${TILE_DIRTY_OFF_CODE}\" != \"404\" ]; then
exit 1;
fi
TILE_STATUS_OFF_CODE=$(${CURL_CMD} --write-out '%{http_code}' ${TILE_STATUS_OFF_URL})
echo \"Status Off code: '\${TILE_STATUS_OFF_CODE}'\"
if [ \"\${TILE_STATUS_OFF_CODE}\" != \"404\" ]; then
exit 1;
fi
"
WORKING_DIRECTORY tests
)
Expand Down
4 changes: 4 additions & 0 deletions tests/httpd.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Redirect /renderd-example-map/leaflet/leaflet.min.js https://unpkg.com/leaflet/d
ModTileCacheDurationMediumZoom 13 86400
ModTileCacheDurationMinimum 10800
ModTileCacheLastModifiedFactor 0.20
ModTileEnableDirtyURL On
ModTileEnableStats On
ModTileEnableStatusURL On
ModTileEnableTileThrottling Off
ModTileEnableTileThrottlingXForward 0
ModTileMaxLoadMissing 5
Expand All @@ -45,7 +47,9 @@ Redirect /renderd-example-map/leaflet/leaflet.min.js https://unpkg.com/leaflet/d
ModTileCacheDurationMediumZoom 13 86400
ModTileCacheDurationMinimum 10800
ModTileCacheLastModifiedFactor 0.20
ModTileEnableDirtyURL Off
ModTileEnableStats On
ModTileEnableStatusURL Off
ModTileEnableTileThrottling Off
ModTileEnableTileThrottlingXForward 0
ModTileMaxLoadMissing 5
Expand Down

0 comments on commit 925183a

Please sign in to comment.