Repository navigation
TIKA-5025: Set the server block's fields from the command line and environment (TIKA_SERVER_SETTING_<FIELD>) - #3519
Conversation
…vironment tika-server takes --serverSetting <field>=<value> (repeatable) and TIKA_SERVER_<FIELD> (TIKA_SERVER_MAX_REQUEST_SIZE_BYTES), bound through the same Jackson path as the config file, so the setter checks the value and an unknown field fails startup. Option over variable over file. The 413 names the limit and where to raise it.
Kubernetes gives every pod TIKA_SERVER_PORT=tcp://..., TIKA_SERVER_SERVICE_HOST and more for a Service named tika-server; with TIKA_SERVER_ as the prefix those would set the port to a URL or name an unknown field, and the server would stop starting on upgrade with no config change. The prefix is TIKA_SERVER_SETTING_ now, the test puts those variables into the environment, and the javadoc and the docs say why the prefix is this long.
|
Good catch, thanks. The prefix is |
ab1f350 to
28dd01a
Compare
|
Only nits from by 🤖 . Let me know what you think |
|
Thanks, all four fixed in f48b1a6: a setting and |
The fields of the config's
serverblock (maxRequestSizeBytes,maxRequestReadMillis,maxInFlightRequestBytes,idleTimeoutMillis,allowHttp2,cors, ...) can only be set in the config file. In the Docker image that means mounting a file and passing-cfor a single number, for example to raise the 1 GiB request body limit for large audio or video files.tika-server now also takes
--serverSetting <field>=<value>(repeatable) and the environment variableTIKA_SERVER_SETTING_<FIELD>, the field's name in upper snake case:Every field of the block is covered the same way, so nothing has to be added per field.
The prefix is
TIKA_SERVER_SETTING_rather thanTIKA_SERVER_because Kubernetes gives every podTIKA_SERVER_PORT=tcp://...,TIKA_SERVER_SERVICE_HOSTand more for a Service namedtika-server; with the shorter prefix those would set the port to a URL or name an unknown field, and an existing deployment would stop starting on upgrade. The test puts those variables into the environment and expects them ignored.Implementation:
TikaServerConfig.loadcollects the option values and the matching environment variables, logs each with its source (and the file value it replaces, if any), and applies them to theTikaServerConfigwith Jackson'sreaderForUpdatingafter the file'sserverblock has been deserialized. Because that is the same binding the file goes through, the field's own setter checks the value (e.g.requestLogLevel must be one of 'debug' or 'info'), a value of the wrong type is reported with the variable's name and value, and an unknown field fails startup with the list of fields that exist. Precedence: option over variable over file;-p,-h,-iand--metricsPortstill override everything as before.configPathis refused with a pointer to-c.tlsConfigandendpointstake an object and a list and remain file-only. Only the front end reads theserverblock, so the forked workers' config is untouched.The 413 response body now names the limit and how to raise it:
Request body exceeds maxRequestSizeBytes (1073741824 bytes); raise it in the config's server block or with TIKA_SERVER_SETTING_MAX_REQUEST_SIZE_BYTES, for a declared Content-Length and a chunked body alike.Tests:
TikaServerConfigTestcovers parsing of option and variable, precedence, overriding a file value, the error messages and the name mapping.ServerSettingsIntegrationTeststarts the real server withTIKA_SERVER_SETTING_MAX_REQUEST_SIZE_BYTES=10and with--serverSetting, checks the 413 and its hint, and that an unknown field fails startup.Docs: server page (options table, configuration section), Docker page, CHANGES.
Open question: the option is a generic
--serverSetting <field>=<value>because commons-cli needs options registered up front. A generated--<field>option per setter would be possible if that is preferred. Values are plain numbers, no4gstyle suffixes.https://issues.apache.org/jira/browse/TIKA-5025