Skip to content
This repository has been archived by the owner on Aug 5, 2023. It is now read-only.

path support in constructor #24

Closed
carlos-jenkins opened this issue Jun 6, 2019 · 4 comments
Closed

path support in constructor #24

carlos-jenkins opened this issue Jun 6, 2019 · 4 comments

Comments

@carlos-jenkins
Copy link
Contributor

Hi, thanks again for this great package, been very helpful.

Sync InfluxDB client has in its constructor a path parameter:

https://influxdb-python.readthedocs.io/en/latest/api-documentation.html#influxdb.InfluxDBClient

path (str) – path of InfluxDB on the server to connect, defaults to ‘’

And the URL is built as follows:

https://github.com/influxdata/influxdb-python/blob/d5d12499f3755199d5eedd8b363450f1cf4073bd/influxdb/client.py#L123

        self.__baseurl = "{0}://{1}:{2}{3}".format(
            self._scheme,
            self._host,
            self._port,
            self._path)

Although in aioinflux there is no path parameter, and the URL is built as follows:

https://github.com/gusutabopb/aioinflux/blob/master/aioinflux/client.py#L163

        return f'{"https" if self.ssl else "http"}://{self.host}:{self.port}/{{endpoint}}'

So, it seems that I cannot connect with aioinflux to our Influx deployment, as for reasons unknown to me, it is under a path.

Currently, I created a quick monkey patch as follows:

class MonkeyPatchedInfluxDBClient(InfluxDBClient):
    def __init__(self, *args, path='/', **kwargs):
        super().__init__(*args, **kwargs)
        self._path = path

    @property
    def path(self):
        return self._path

    @property
    def url(self):
        return '{protocol}://{host}:{port}{path}{{endpoint}}'.format(
            protocol='https' if self.ssl else 'http',
            host=self.host,
            port=self.port,
            path=self.path,
        )

Thanks for placing the url in a property, that was useful.

@gusutabopb
Copy link
Owner

Thanks for the issue and sorry for the late reply.

The implementation seems trivial but I am not sure how to test such code.

What exactly is the environment you use InfluxDB so that you need such path? Do you use some sort of proxy in front of InfluxDB? If so, could you share any ideas (maybe some Nginx config?) of how to launch InfluxDB at localhost:8086/some/random/path so I could test the code.

@carlos-jenkins
Copy link
Contributor Author

carlos-jenkins commented Jun 21, 2019

Yes, indeed, that's exactly the case.

We are using Kubernetes to deploy our services, and depending of the configuration of the ingress, many services can share one single domain, and what Kubernetes does is putting an Nginx as reverse proxy of those services, using a path to identify them.

I'll try to fiddle with a docker stack configuration that should do the same.

@carlos-jenkins
Copy link
Contributor Author

aioinfluxdeploy.zip

Ok this deployment works to test the scenario.

Deploy stack with:

docker stack deploy --compose-file=stack.yml aioinflux

Access InfluxDB with:

curl -L -i http://127.0.0.1:8000/my/custom/path/ping?verbose=true

Connect using Sync Python client with:

from influxdb import InfluxDBClient
client = InfluxDBClient(host='127.0.0.1', port=8000, path='/my/custom/path/')
client.ping()

@carlos-jenkins
Copy link
Contributor Author

Thanks a lot!

If anyone comes here, this was fix-released in 0.9.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants