Skip to content

[1.7.0] Custom resolver option - #241

Merged
technige merged 4 commits into
neo4j:1.7from
technige:1.6-custom-resolver
Jun 19, 2018
Merged

[1.7.0] Custom resolver option#241
technige merged 4 commits into
neo4j:1.7from
technige:1.6-custom-resolver

Conversation

@technige

Copy link
Copy Markdown
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.

Comment thread docs/source/driver.rst Outdated
``resolver``
------------

A custom resolver function to use for DNS resolution.

Copy link
Copy Markdown
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
Copy Markdown
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

eastlondoner commented May 16, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

eastlondoner commented May 16, 2018

Copy link
Copy Markdown
Contributor

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