Skip to content
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

Merged
merged 1 commit into from
Jan 4, 2017
Merged

Conversation

trescube
Copy link
Contributor

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:

{
      "env": "development",
      "protocol": "http",
      "host": "localhost",
      "port": 9200
},
{
      "env": "production",
      "protocol": "http",
      "host": "internal-pelias-production-es2-162482742.us-east-1.elb.amazonaws.com",
      "port": 9200
}

No warning would be given even though it would drop the production index.

@trescube trescube force-pushed the add-checks-for-localhost-drop branch from 892db19 to 92e5ecf Compare December 29, 2016 19:42
Copy link
Member

@orangejulius orangejulius left a 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...

@trescube
Copy link
Contributor Author

trescube commented Jan 3, 2017

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"));
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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

@trescube trescube merged commit 4f0012f into master Jan 4, 2017
@trescube trescube deleted the add-checks-for-localhost-drop branch January 4, 2017 17:01
@trescube trescube removed the in review label Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants