Skip to content

Commit

Permalink
[feature] Allowed specifying additional options for InfluxDB backend #…
Browse files Browse the repository at this point in the history
…458

- Additional options can be specified to the TIMESERIES_DATABASE setting
  which are passed to the underlying backend library. This allows using
  UDP for writing to InfluxDB.
- "openwisp_monitoring.db.backends.influxdb.client.DatabaseClient.write"
  will use "InfluxDBClient.write_points" instead of "InfluxDBClient.write"
  because the former allows writing data using the UDP protocol.

Closes #458
  • Loading branch information
pandafy committed Feb 7, 2023
1 parent 79f3e62 commit 24a40b1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ Follow the setup instructions of `openwisp-controller
'NAME': 'openwisp2',
'HOST': 'localhost',
'PORT': '8086',
'OPTIONS': {
# Specify additional options to be used while initializing
# database connection.
# Note: These options may differ based on the backend used.
'use_udp': True,
'udp_port': 8088,
}
}
``urls.py``:
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ services:
image: influxdb:1.8-alpine
volumes:
- influxdb-data:/var/lib/influxdb
- ./tests/influxdb.conf:/etc/influxdb/influxdb.conf
ports:
- "8086:8086"
- "8088:8088/udp"
environment:
INFLUXDB_DB: openwisp2
INFLUXDB_USER: openwisp
Expand Down
1 change: 1 addition & 0 deletions openwisp_monitoring/db/backends/influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def db(self):
TIMESERIES_DB['USER'],
TIMESERIES_DB['PASSWORD'],
self.db_name,
**TIMESERIES_DB.get('OPTIONS', {}),
)

@retry
Expand Down
15 changes: 15 additions & 0 deletions tests/influxdb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[meta]
dir = "/var/lib/influxdb/meta"

[data]
dir = "/var/lib/influxdb/data"
engine = "tsm1"
wal-dir = "/var/lib/influxdb/wal"

[[udp]]
enabled = true
bind-address = ":8088"
database = "openwisp2"
batch-size = 0c
batch-pending = 0
batch-timeout = "0s"
8 changes: 8 additions & 0 deletions tests/openwisp2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@
'NAME': 'openwisp2',
'HOST': os.getenv('INFLUXDB_HOST', 'localhost'),
'PORT': '8086',
'OPTIONS': {'use_udp': True, 'udp_port': 8088},
}
if TESTING:
# Some automated tests queries InfluxDB just after
# writing the data. Occasionally, the read operation
# is performed before InfluxDB has processed the UDP
# packet which leads to failing test cases. Therefore,
# we always run test suite without UDP support.
TIMESERIES_DATABASE['OPTIONS']['use_udp'] = False

SECRET_KEY = 'fn)t*+$)ugeyip6-#txyy$5wf2ervc0d2n#h)qb)y5@ly$t*@w'

Expand Down

0 comments on commit 24a40b1

Please sign in to comment.