-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add checks for localhost drop #200
Conversation
892db19
to
92e5ecf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! I hope there isn't an interesting story I missed about how this was discovered...
Nope, no interesting story, just something I saw when add configuration validation. |
function warnIfNotLocal() { | ||
if(config.esclient.hosts[0].host !== "localhost") { | ||
if (config.esclient.hosts.some((env) => { return env.host !== 'localhost'; } )) { | ||
console.log(colors.red("WARNING: DROPPING SCHEMA NOT ON LOCALHOST")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes people store various hosts in their config and move them to the top of the list when needed because we always grab the first one (I think). This warning would always yell at those people even though we would only use the first item in the list which they have set to localhost. Is that true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But wouldn't having multiple hosts listed cause the index to be dropped in all those hosts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The elasticsearch-js module is where those config options eventually end up, and it does support multiple hosts. The docs are a little unclear but it feels like it does connect to all of them.
So yes, storing multiple hosts in the config section is probably a bad idea.
I had a similar problem with the whosonfirst
datapath where extra values are no longer supported, but I was storing several different paths to different copies of WOF data for different purposes. I just moved them out of the entire whosonfirst
section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that the elasticsearch client operates on all hosts in pelias.json:
[stephenhess@slumlord schema (add-checks-for-localhost-drop $)]$ node scripts/create_index.js
Elasticsearch INFO: 2017-01-04T16:44:15Z
Adding connection to http://localhost:9200/
Elasticsearch INFO: 2017-01-04T16:44:15Z
Adding connection to http://localhost:10200/
--------------
create index
--------------
[stephenhess@slumlord ~]$ curl --head 'localhost:9200/asdf1234'
HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Content-Length: 0
[stephenhess@slumlord ~]$ curl --head 'localhost:10200/asdf1234'
HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Content-Length: 0
[stephenhess@slumlord schema (add-checks-for-localhost-drop $)]$ node scripts/drop_index.js
Elasticsearch INFO: 2017-01-04T16:44:45Z
Adding connection to http://localhost:9200/
Elasticsearch INFO: 2017-01-04T16:44:45Z
Adding connection to http://localhost:10200/
Are you sure you want to drop the asdf1234 index and delete ALL records? y
[delete mapping] asdf1234 { acknowledged: true }
[stephenhess@slumlord ~]$ curl --head 'localhost:10200/asdf1234'
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=UTF-8
Content-Length: 0
[stephenhess@slumlord ~]$ curl --head 'localhost:9200/asdf1234'
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=UTF-8
Content-Length: 0
Previously, only the first host in
esclient.hosts
was checked for localhost value so if the array contained multiple hosts and the first was not localhost, no warning would be given about dropping a non-localhost index. For example:No warning would be given even though it would drop the production index.