-
Notifications
You must be signed in to change notification settings - Fork 185
Simple way to test connection and auth info #131
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
Comments
Hi @mdegat01, the from influxdb_client import InfluxDBClient
client = InfluxDBClient(url="http://localhost:9999",
token="my-token",
org="my-org",)
health = client.health()
if health.status == "pass":
print("Connection success.")
else:
print(f"Connection failure: {health.message}!")
client.__del__() I will take a look to solution for check permission to the Regards |
Hi @bednar, your solution works to test basic connectivity to the DB in question. However, it does not address testing whether the supplied token has appropriate rights to. e.g. write data. Best regards, |
Hi @malwinweiler, currently the InfluxDB doesn't have API to test the token to have appropriate rights. You can use something similar as is in this pending PR: https://github.com/influxdata/influxdb-client-python/pull/269/files#diff-294bf3f7a19058974064e47c8e95dce7383a1716d1e59822a81fefca09ce7d48 Regards |
Proposal:
When using this library if the config information (url, org, bucket and token) is collected from users then there needs to be a way to test that configuration to see if:
I think the library should include a simple way to do this test which succeeds without exception on success and fails with an exception otherwise.
Current behavior:
I believe the best way available to do this test today is the following:
b""
. On success it will fail with an Invalid InputsApiException
with the message 'writing requires points'. On failure it will return aurllib3.exceptions.MaxRetryError
on connection failure and an UnauthorizedApiException
if the other config is invalid or a permissions failure.buckets()
. This returns the buckets that can be seen with the provided config on success. On failure it will return aurllib3.exceptions.MaxRetryError
on connnection failure and an UnauthorizedApiException
if the config is invalidDesired behavior:
First, assuming I am correct about those being the ideal ways to do a test read and write it would be good if they were added to the doc as cookbook examples.
Also ideally the test write should only throw an exception in case of failure. Perhaps instead of using the normal
write
method for this test thenwrite_api
could have atest
method that does awrite(b"")
behind the scenes and only returns an exception in case of connection or authorization failure?Alternatives considered:
I noticed that the
InfluxDBClient
class also has a method calledhealth
andready
which seem like they should be usable for doing a connection check. I wasn't sure how to make them work though or if they were implemented yet.Use case:
I feel like users of this library will often be collecting config information that they then need to test. Even if no enhancements are prioritized at this time around this it would be good if the documentation included an example of the best practice way to do this.
The text was updated successfully, but these errors were encountered: