Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Using client behind AWS NAT #860

@dgnorton

Description

@dgnorton
  • InfluxDB version: 1.8.2
  • InfluxDB-python version: 5.3.0
  • Python version: unknown
  • Operating system version: unsure - running on AWS and assume Linux

Using the Python InfluxDB client behind an AWS NAT gateway

The AWS NAT gateway will time out an idle connection after 350 seconds. The InfluxDB Python library uses the Python requests module under the hood to create a session and make all of the InfluxDB API calls using that session. While requests supports keep-alive (https://requests.readthedocs.io/en/latest/user/advanced/#keep-alive) it does not set the TCP socket to use keep alive and send ping probes to keep the connection from appearing to be idle. To work around this issue, the following code enables TCP keep-alives, which starts sending keep-alive probes after the connection has been idle for 60 seconds, sends a probe every 60 seconds and sends a maximum of 15 keep alive probes.

HTTPConnection.default_socket_options = HTTPConnection.default_socket_options + \
                [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
                (socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 60),
                (socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 60),
                (socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 15)]

LOGGER.info('Sending query to InfluxDB: query(%s)' % (query,))
client = InfluxDBClient(host, port, username, password, dbname, ssl, True)
response = client.query(query=query, database=dbname)
LOGGER.info(response)

Can this keep alive functionality be added to the InfluxDB Python client library so it doesn't have to be done by users of the library?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions