influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
721 stars 187 forks source link

Replication Create/Update Request is Missing the 'maxAgeSeconds' Parameter #587

Closed chrmel closed 1 year ago

chrmel commented 1 year ago

Specifications

Code sample to reproduce problem

Run 2 InflxuDB Instances

docker run -dit --rm --name influxdb1 -p 8086:8086 -e DOCKER_INFLUXDB_INIT_MODE=setup -e DOCKER_INFLUXDB_INIT_USERNAME=my-user -e DOCKER_INFLUXDB_INIT_PASSWORD=my-password -e DOCKER_INFLUXDB_INIT_ORG=my-org -e DOCKER_INFLUXDB_INIT_BUCKET=my-bucket -e DOCKER_INFLUXDB_INIT_RETENTION=1h -e DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=my-super-secret-auth-token influxdb:2.6
docker run -dit --rm --name influxdb2 -p 8096:8086 -e DOCKER_INFLUXDB_INIT_MODE=setup -e DOCKER_INFLUXDB_INIT_USERNAME=my-user -e DOCKER_INFLUXDB_INIT_PASSWORD=my-password -e DOCKER_INFLUXDB_INIT_ORG=my-org -e DOCKER_INFLUXDB_INIT_BUCKET=my-bucket -e DOCKER_INFLUXDB_INIT_RETENTION=1h -e DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=my-super-secret-auth-token influxdb:2.6

Create Replication

import influxdb_client
from influxdb_client.service import remote_connections_service, replications_service
from influxdb_client.domain.remote_connection_creation_request import RemoteConnectionCreationRequest
from influxdb_client.domain.replication_creation_request import ReplicationCreationRequest

# connect to influxdb
client = influxdb_client.InfluxDBClient(
    url='http://localhost:8086/', token='my-super-secret-auth-token', org='my-org',
    verify_ssl=False, timeout=180_000, debug=False,
)
client.ping()
print(client)

# get remote connections and replications services
rcs = remote_connections_service.RemoteConnectionsService(client.api_client)
rps = replications_service.ReplicationsService(client.api_client)
print(rcs, rps)

# create remote connection
remote = rcs.post_remote_connection(
    RemoteConnectionCreationRequest(
        org_id=client.organizations_api().find_organizations(org='my-org').pop().id,
        name='my-remote',
        remote_url='http://localhost:8096',
        remote_api_token='my-super-secret-auth-token',
        remote_org_id='6e3fd6b1a1113a50',
        allow_insecure_tls=True,
    )
)
print(remote)

# create replication
replication = rps.post_replication(
    ReplicationCreationRequest(
        org_id=client.organizations_api().find_organizations(org='my-org').pop().id,
        name='my-replication',
        local_bucket_id=client.buckets_api().find_buckets(name='my-bucket').buckets.pop().id,
        remote_id=remote.id,
        remote_bucket_id='1f61610ba134d6a1',
        max_age_seconds=0,
    )
)
print(replication)

Expected behavior

Create replication with maxAgeSeconds set to provided parameter.

Actual behavior

Fails becaus API parameter maxAgeSeconds (see API docs) is not reflected in python-client:

TypeError: ReplicationCreationRequest.__init__() got an unexpected keyword argument `max_age_seconds`

This means the replication parameter maxAgeSeconds cannot be set via the python client, thus defaults to 604800 seconds which might not be wanted.

Additional info

If there is a Python client it would be nice if it would also reflect the API. In my opinion the maxAgeSeconds parameter is kind of essential for a replication.

powersj commented 1 year ago

@bednar is resolving this a matter of updating the API with the apigen?

bednar commented 1 year ago

@powersj Yes, I've prepared the following PR #588

bednar commented 1 year ago

Hi @chrmel,

I've prepared PR #588. If you would like to use the development version of the client, you can install it via:

pip install git+https://github.com/influxdata/influxdb-client-python.git@master

The stable version of the client will be available in our regular release cycle.

Regards

chrmel commented 1 year ago

Hi @bednar,

thank you for the quick response and fix, it is much appreciated!

Regards