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

Configurable Geocoder (fix #210) #315

Merged
merged 25 commits into from Apr 26, 2021
Merged

Configurable Geocoder (fix #210) #315

merged 25 commits into from Apr 26, 2021

Conversation

borrob
Copy link
Collaborator

@borrob borrob commented Jan 31, 2020

An implementation for issue #210: Configurable Geocoder

The plugin system is used to create a configurable geocoder. The geocoder plugin class and specific parameters are specified in the config_main.py or config_site.py. The base setup refers to the ip-api.com that is already used at the moment.

This PR provides three plugins: using a geocode service on the web via a GET request and via a POST request. The third geocoder returns a (configurable) fixed location which might be useful for intranet/on prem installations of GHC.

I did not check compatibility with the other two open PRs, but conflicts (if any) should be minor.

@justb4
Copy link
Member

justb4 commented Jan 31, 2020

Need some time to dive in. At least the build failure is not from this PR, but a test that Probes the Resource https://demo.pygeoapi.io/master. That Resource has been failing I now see since jan 28, 2020 10:55 GMT. See https://demo.geohealthcheck.org/resource/165
Latest commit of GHC master and thus demo.geohealthcheck.org instance is from dec 2019. Need to investigate. The error signaled is Validate OpenAPI Compliance:HTTP Error 404: Not Found.

Dived into this, was quite a route among various products/components. All described here: geopython/pygeoapi#356 ...also to note @tomkralidis

@justb4
Copy link
Member

justb4 commented Feb 3, 2020

opengeospatial/ogcapi-processes#63 was cause and fixed so build shoild pass now.

@borrob
Copy link
Collaborator Author

borrob commented Feb 4, 2020

Great find and I am happy it all works now. All tests pass.

@borrob borrob self-assigned this Feb 4, 2020
@borrob borrob added this to the Version 0.8.0 milestone Feb 4, 2020
@justb4 justb4 modified the milestones: Version 0.8.0, Version 0.8.1 Jul 7, 2020
@justb4 justb4 self-requested a review October 26, 2020 10:12
docs/install.rst Outdated
@@ -81,6 +81,7 @@ Install
# - GHC_REQUIRE_WEBAPP_AUTH # optional: to require authentication to access webapp
# - GHC_SMTP # if GHC_NOTIFICATIONS is enabled
# - GHC_MAP # or use default settings
# - GEOIP # or use the feault settings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "default"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9699493

docs/config.rst Outdated
@@ -42,6 +42,7 @@ The configuration options are:
- **centre_long**: Centre longitude for homepage map
- **maxzoom**: maximum zoom level
- **subdomains**: available subdomains to help with parallel requests
- **GEOIP**: configuration for the geolocater service plugin. Default is the ip-api.com api.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

geolocater should be geolocator, multiple files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel stupid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with: e8868a1

docs/plugins.rst Outdated
@@ -10,7 +10,8 @@ one may want to perform. Hence developers can extend or even replace
the GHC standard Plugins with custom implementations.

Two Plugin types exist that can be extended: the `Probe` and `Check` class.
In v0.7.0 also plugins for Resource Authentication, `ResourceAuth`, were added.
In v0.7.0 also plugins for Resource Authentication, `ResourceAuth`, were added
and in v0.8.0 the geocoder plugin was introduced.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will hopefully be 0.8.1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a reference to 0.9 with commit 4fa7da7

Copy link
Member

@justb4 justb4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see the Plugin system used!
Main comment/changes needed: any config change also requires changes to the config for Docker deployment. Not handy but Docker uses env-vars a lot. See the files:
config_site.py and default env vars in Dockerfile. Changes will be bit similar to SMTP config convention.

@borrob
Copy link
Collaborator Author

borrob commented Oct 27, 2020

Thanks for the review work! I'll try to fix things up, but I'm quite busy lately, so it might take some time.

@justb4
Copy link
Member

justb4 commented Oct 27, 2020

@borrob no sweat! just keep your PR current with master, more changes upcoming in other PRs, and take your time!

@justb4 justb4 removed this from the Version 0.8.1 milestone Nov 2, 2020
@justb4 justb4 added this to the Version 0.9.0 milestone Nov 2, 2020
@borrob
Copy link
Collaborator Author

borrob commented Apr 9, 2021

Good to see the Plugin system used!
Main comment/changes needed: any config change also requires changes to the config for Docker deployment. Not handy but Docker uses env-vars a lot. See the files:
config_site.py and default env vars in Dockerfile. Changes will be bit similar to SMTP config convention.

I fixed the easy ones. I'll start to check up on the config changes.

@borrob
Copy link
Collaborator Author

borrob commented Apr 9, 2021

Good to see the Plugin system used!
Main comment/changes needed: any config change also requires changes to the config for Docker deployment. Not handy but Docker uses env-vars a lot. See the files:
config_site.py and default env vars in Dockerfile. Changes will be bit similar to SMTP config convention.

I fixed the easy ones. I'll start to check up on the config changes.

@justb4 Can you be a bit more specific? I changed the config_main.py here, the config for the docker file config_site.py here, and it is described in the documentation. Or would you rather have it configured in the Docker env-var (Dockerfile and overruled in ghc.env for example)?

@justb4
Copy link
Member

justb4 commented Apr 10, 2021

@borrob the reason for the specific Docker var setup is to enable overruling the default GHC configuration in config_site.py via env vars. For example when deploying in Kubernetes or other environments where there is no docker-compose nor ghc.env local Docker volume-mount possible.

The convention would be the same as for SMTP. Given the current GEOIP config this would require 3 env vars, e.g.
GHC_GEOIP_URL, GHC_GEOIP_LATFIELD, GHC_GEOIP_LONFIELD.

Set defaults in the Dockerfile:

ENV LC_ALL="en_US.UTF-8" \
.
.
	GHC_GEOIP_URL='http://ip-api.com/json/{hostname}' \
	GHC_GEOIP_LATFIELD='lat' \
	GHC_GEOIP_LONFIELD='lon' \
.
.

And then in the config_site.py use values from environment (either the default from the Dockerfile or an overruled value):

GEOIP = {
    'plugin': 'GeoHealthCheck.plugins.geocode.webgeocoder.HttpGetGeocoder',
    'parameters': {
        'geocoder_url':  os.environ['GHC_GEOIP_URL'],
        'lat_field':  os.environ['GHC_GEOIP_LATFIELD'],
        'lon_field':  os.environ['GHC_GEOIP_LONFIELD']
}

Feels like duplicate work, but this has evolved historically and came from Kubernetes deployment. This convention is very common for many tools. Hence also the convention to start env varnames with GHC_

@justb4
Copy link
Member

justb4 commented Apr 12, 2021

Looks good now! I propose to first finalize #349 and I will merge #347 and then this one.

@tomkralidis tomkralidis self-requested a review April 12, 2021 10:33
Dockerfile Outdated
@@ -44,6 +44,9 @@ ENV LC_ALL="en_US.UTF-8" \
GHC_SMTP_SSL=False \
GHC_SMTP_USERNAME=None \
GHC_SMTP_PASSWORD=None \
GHC_GEOIP_URL='http://ip-api.com/json/{hostname}' \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we align/indent accordingly?

Copy link
Collaborator Author

@borrob borrob Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaarrgh. tab vs space discussion.
Fixed with 39183ac.

@@ -0,0 +1,31 @@
from plugin import Plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a license header?

Copy link
Collaborator Author

@borrob borrob Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 7bdf022.

@@ -0,0 +1,49 @@
from GeoHealthCheck.geocoder import Geocoder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License header here as well

Copy link
Collaborator Author

@borrob borrob Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 7bdf022.

@@ -0,0 +1,200 @@
import requests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License header

Copy link
Collaborator Author

@borrob borrob Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 7bdf022.

@borrob
Copy link
Collaborator Author

borrob commented Apr 12, 2021

Thanks for all the review work and the explanation on the docker variables.

:param hostname string: the hostname of the server for which we want
the coords.

TOOD: return result as tuple with locatin in lat-lon like: (52.4, 21.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos:
TOOD --> TODO
locatin --> location

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should pay more attention to my typing.
Fixed with 0c377b0

@justb4
Copy link
Member

justb4 commented Apr 15, 2021

Ok, PRs #349 #347 are now in. Maybe you want to merge those in to get the green light on tests first.
So AFAICT a default config is in place, so upgrades should be smooth. You have also tested the Docker image?

BTW Whenever we merge in master branch the Docker image latest is automatically built and deployed as https://demo.geohealthcheck.org .

Need some time for full review...

@borrob
Copy link
Collaborator Author

borrob commented Apr 15, 2021

Ok, PRs #349 #347 are now in. Maybe you want to merge those in to get the green light on tests first.
So AFAICT a default config is in place, so upgrades should be smooth. You have also tested the Docker image?

BTW Whenever we merge in master branch the Docker image latest is automatically built and deployed as https://demo.geohealthcheck.org .

Need some time for full review...

Great!
I merged to new master to this PR (e200a8a) and I should get flake8 into my workflow before I commit.
I ran all the tests and I did make a (local) docker build. The app runs and all seems fine...

@justb4 justb4 merged commit 56b7a5e into geopython:master Apr 26, 2021
@justb4
Copy link
Member

justb4 commented Apr 26, 2021

Thanks @borrob !

@borrob borrob deleted the geocoder branch April 26, 2021 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants