Skip to content
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

[feature] Allowed specifying additional options for InfluxDB backend (UDP) #458 #472

Merged
merged 12 commits into from
Feb 9, 2023

Conversation

pandafy
Copy link
Member

@pandafy pandafy commented Dec 23, 2022

  • 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

Checks:

  • I have manually tested the proposed changes
  • I have written new test cases to avoid regressions (if necessary)
  • I have updated the documentation (e.g. README.rst)

@coveralls
Copy link

coveralls commented Dec 23, 2022

Coverage Status

Coverage: 98.908% (+0.005%) from 98.903% when pulling fa195eb on issues/458-influxdb-udp into 7f92b01 on master.

@pandafy
Copy link
Member Author

pandafy commented Dec 29, 2022

I have found some caveats with using UDP for writing data to the InfluxDB:

  • UDP is used only for writing data to the InfluxDB. It requires adding additional configuration to the InfluxDB config.
  • It does not supports authentication.
  • It allows using only one "retention policy" that too has to be specified in the InfluxDB configuration.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings about this, I do not feel comfortable in merging such a change while ignoring the test failures. See below.

I think the results which are coming out of the tests are encouraging on the perfomance side, but on the functionality side there's more work to do to merge this safely.

README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
tests/influxdb.conf Outdated Show resolved Hide resolved
@@ -28,7 +28,15 @@
'NAME': 'openwisp2',
'HOST': os.getenv('INFLUXDB_HOST', 'localhost'),
'PORT': '8086',
'OPTIONS': {'use_udp': True, 'udp_port': 8088},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should switch to use UDP by default yet because this will add friction and impredictable consequences right now:

  • The fact that we cannot run tests against the UDP mode worries me, what if there's some critical part of the system which will not work as expected in this mode? How will we find out? It seems to me that this is the case, how are you sure that alert settings and thresholds are working fine in this mode?

  • The newcomers who do not use docker and will want to test out this module will have to enable UDP in their influxdb instance, most likely they will come to the support chats to complain about this.

I think we shoud run both the app and the tests in HTTP mode but we could run a subsets of the tests in UDP mode just to make sure we have some automated tests using the UDP functionality and confirming is working as expected.

I just tried the following configuration and I was able to run a subset of the tests with only a few failures after adding a sleep of 0.1 in the timeseries_write celery task:

[[udp]]
  enabled = true
  database = "openwisp2_test"
  batch-size = 1
  batch-pending = 1
  batch-timeout = "0.1s"

A possible subsets of the test to run is the following, please double check my suggestion to see if there's anything critical regarding the interaction with the timeseries DB to add:

./manage.py test openwisp_monitoring.device.tests.test_api openwisp_monitoring.device.tests.test_models openwisp_monitoring.monitoring.tests.test_monitoring_notifications openwisp_monitoring.monitoring.tests.test_db_creation openwisp_monitoring.monitoring.tests.test_models openwisp_monitoring.check.tests.test_ping openwisp_monitoring.check.tests.test_models

The main problem is that the logic which performs the check of thresholds and alert settings relies on the fact that the data is written immediately, so we have to look into ways to work around that.

@nemesifier nemesifier changed the title [feature] Allowed specifying additional options for InfluxDB backend #458 [feature] Allowed specifying additional options for InfluxDB backend (UDP) #458 Jan 19, 2023
@pandafy pandafy force-pushed the issues/458-influxdb-udp branch 2 times, most recently from 022244a to 977144f Compare January 24, 2023 14:36
openwisp_monitoring/monitoring/tests/__init__.py Outdated Show resolved Hide resolved
@@ -127,10 +128,12 @@ def test_general_check_threshold_crossed_for_long_time(self):
self.assertEqual(m.is_healthy_tolerant, True)
self.assertEqual(Notification.objects.count(), 0)

time.sleep(0.1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure this sleep is executed only when in UDP mode and use the function mentioned above

@@ -31,7 +31,10 @@
'OPTIONS': {'udp_writes': True, 'udp_port': 8089},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not default to UDP as that will cause issues with new developers trying this module out. Default on TCP and enable UDP in the tests.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the docs where it mentions the various timeseries retry options to make it explicit that it doesn't apply when using UDP mode.

I also see no mention of this new feature in the README and that's not good.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's test this more before merging.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok great one docs change requested below.

enabled = true
bind-address = "127.0.0.1:8090"
database = "openwisp2"
retention-policy = 'short'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention that when using ansible-openwisp2 this can be done easily by setting the new var addded in openwisp/ansible-ow-influxdb#17 to true and link the role variables section of the ansible-ow-influxdb repo for reference.
This should help users figure out how to use this feature autonomously.

…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
@nemesifier nemesifier merged commit 476e7a3 into master Feb 9, 2023
@nemesifier nemesifier deleted the issues/458-influxdb-udp branch February 9, 2023 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[change] Find faster way to write to influxdb (eg: UDP)
3 participants