Skip to content

Commit

Permalink
feat(auto_discover): Add option to quit on discovery errors
Browse files Browse the repository at this point in the history
This adds a new config option, `api.targets.auto_discover_required`. If set to true, the API will quit with a fatal error if there is any problem performing the type mapping discovery.

In practice what this means is a working Elasticsearch cluster with a valid Pelias index must exist and be properly configured in `pelias.json`, or the API won't start.

This can actually be quite helpful in production environments as it can protect against misconfiguration issues such as using the wrong URL to the Elasticsearch cluster.

Because the check is only performed once at startup, it won't cause the API to quit if there's an intermittent network issue or something similar later on.

Connects #1591
Connects pelias/pelias#925
  • Loading branch information
orangejulius committed May 9, 2022
1 parent 4a817fb commit 93e6fc9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The API recognizes the following properties under the top-level `api` key in you
|`services`|*no*||Service definitions for [point-in-polygon](https://github.com/pelias/pip-service), [libpostal](https://github.com/whosonfirst/go-whosonfirst-libpostal), [placeholder](https://github.com/pelias/placeholder), and [interpolation](https://github.com/pelias/interpolation) services. For a description of when different Pelias services are recommended or required, see our [services documentation](https://github.com/pelias/documentation/blob/master/services.md).|
|`defaultParameters.focus.point.lon` <br> `defaultParameters.focus.point.lat`|no | |default coordinates for focus point
|`targets.auto_discover`|no|true|Should `sources` and `layers` be automatically discovered by querying Elasticsearch at process startup. (See more info in the [Custom sources and layers](#custom-sources-and-layers) section below).
|`targets.auto_discover_required`|no|false|If set to `true`, type mapping discovery failures will result in a fatal error. This means a valid connection to a working Elasticsearch cluster with a Pelias index is _required_ on startup. Setting this to true can help prevent issues such as incorrect configuration in production environments
|`targets.layers_by_source` <br> `targets.source_aliases` <br> `targets.layer_aliases`|no | |custom values for which `sources` and `layers` the API accepts (See more info in the [Custom sources and layers](#custom-sources-and-layers) section below). We recommend using the `targets.auto_discover:true` configuration instead of setting these manually.
|`customBoosts` | no | `{}` | Allows configuring boosts for specific sources and layers, in order to influence result order. See [Configurable Boosts](#custom-boosts) below for details |
|`autocomplete.exclude_address_length` | no | 0 | As a performance optimization, this optional filter excludes results from the 'address' layer for any queries where the character length of the 'subject' portion of the parsed_text is equal to or less than this many characters in length. Addresses are usually the bulk of the records in Elasticsearch, and searching across all of them for very short text inputs can be slow, with little benefit. Consider setting this to 1 or 2 if you have several million addresses in Pelias. |
Expand Down
8 changes: 7 additions & 1 deletion helper/type_mapping_discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ module.exports = (tm, done) => {
}

// query error
if( err ){ logger.error( err ); }
if( err ){
logger.error( err );

if (peliasConfig.get('api.targets.auto_discover_required') === true) {
process.exit(1);
}
}

// invalid response
else if ( totalHits < 1 ){
Expand Down

0 comments on commit 93e6fc9

Please sign in to comment.