Skip to content

[1.7.0] Custom resolver option #241

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

Merged
merged 4 commits into from
Jun 19, 2018
Merged

[1.7.0] Custom resolver option #241

merged 4 commits into from
Jun 19, 2018

Conversation

technige
Copy link
Contributor

This PR adds an option to pass a custom resolver function into the driver configuration. This allows an override of the regular getaddrinfo call used for DNS resolution, introducing the possibility for multiple addresses to be provided for bootstrapping the routing process.

``resolver``
------------

A custom resolver function to use for DNS resolution.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can say that it is a hostname or IP address resolver and default implementation performs DNS resolution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Yes, that's better wording.

@eastlondoner
Copy link
Contributor

eastlondoner commented May 16, 2018

I'm not sure this should replace getaddrinfo.

I'd rather that it just comes before getaddrinfo as a straight transform - so I can return new hostnames or ip addresses

e.g. in AWS I might want to transform an external hostname to an internal hostname using some regex - but I still want you to do the DNS resolution.

@technige
Copy link
Contributor Author

That's an interesting idea. Maybe we should also fall back to getaddrinfo not just when no resolver is supplied but also if it returns nothing.

@eastlondoner
Copy link
Contributor

eastlondoner commented May 16, 2018

What I'd like is something that works with

def my_resolver(socket_address):
         target_host, target_port = socket_address
         my_config = json.loads("/my-config-mount/latest.json")
         results = my_config[target_host]
         for x in results:
             yield x.host, x.port

given

### latest.json
{
  "dev": [
    {
      "host": "127.0.0.1"
      "port": 7687
    }
  ],
  "production": [
    {
      "host": "andy.neo4j.io"
      "port": 7000
    }
  ]
}

usage example
neo4j.driver(f"bolt+routing://dev")

@technige technige changed the base branch from 1.6 to 1.7 June 19, 2018 13:57
@technige technige changed the title [1.6.1] Custom resolver option [1.7.0] Custom resolver option Jun 19, 2018
@technige technige merged commit dfa99a3 into neo4j:1.7 Jun 19, 2018
@technige technige deleted the 1.6-custom-resolver branch June 20, 2018 15:41
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