barrycarey / Speedmon

Run ISP speed tests and save results
10 stars 6 forks source link

InfluxDBv1 Write error - "partial write: field type conflict" #4

Closed jack828 closed 2 years ago

jack828 commented 2 years ago

Hey, thanks for the previous package and this shiny new one.

I'm trying to replace my current setup with this and just going thru seeing how well it works with my setup before I delete stuff. I've noticed a few bugs so I've submitted PRs for them (#1, #2, #3)

I'm getting this error:

➜ SPEEDTEST_CONFIG=config.ini python3 speedmon.py
2021-10-04 20:05:37,884 - config_manager:__init__:19 - INFO: Loading config from config.ini
2021-10-04 20:05:37,884 - config_manager:__init__:27 - INFO: Configuration Successfully Loaded
2021-10-04 20:05:37,888 - storage_handler_base:__init__:18 - INFO: Built storage handler influx
2021-10-04 20:05:37,889 - storage_builder:init_storage_handler_from_ini:65 - INFO: No config section defined for INFLUXV2 in INI
2021-10-04 20:05:37,889 - storage_builder:init_storage_handler_from_ini:65 - INFO: No config section defined for GRAPHITE in INI
2021-10-04 20:05:37,889 - influxv1_storage_handler:validate_connection:37 - DEBUG: Testing connection to InfluxDb using provided credentials
2021-10-04 20:05:37,898 - influxv1_storage_handler:validate_connection:39 - DEBUG: Successful connection to InfluxDb
2021-10-04 20:05:37,899 - utils:run_speed_test:65 - DEBUG: Running with args: speedtest -f json
27368096 1949397 2.421 36.593 None
2021-10-04 20:06:03,296 - influxv1_storage_handler:save_results:71 - ERROR: Failed To Write To InfluxDB
Traceback (most recent call last):
  File "/home/jack/Personal/speedmon/speedmon/storage/influxv1/influxv1_storage_handler.py", line 61, in save_results
    self.client.write_points(self.format_results(data))
  File "/home/jack/.local/lib/python3.6/site-packages/influxdb/client.py", line 608, in write_points
    consistency=consistency)
  File "/home/jack/.local/lib/python3.6/site-packages/influxdb/client.py", line 685, in _write_points
    protocol=protocol
  File "/home/jack/.local/lib/python3.6/site-packages/influxdb/client.py", line 419, in write
    headers=headers
  File "/home/jack/.local/lib/python3.6/site-packages/influxdb/client.py", line 378, in request
    raise InfluxDBClientError(err_msg, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: {"error":"partial write: field type conflict: input field \"download\" on measurement \"speed_test_results\" is type integer, already exists as type float dropped=1"}

I fixed the error by changing format_influxdb_results like so:

    return [
        {
            'measurement': 'speed_test_results',
            'fields': {
-               'download': data.download,
+               'download': float(data.download),
-               'upload': data.upload,
+               'upload': float(data.upload),
-               'ping': data.latency,
+               'ping': float(data.latency),
-               'jitter': data.jitter,
+               'jitter': float(data.jitter),
-               'packetloss': data.packetloss,
+               'packetloss': 0 if data.packetloss == None else data.packetloss,
            },
            'tags': {

But I am not a python programmer so I am not sure why that fixes it to be honest...

config file:

[GENERAL]
Delay = 1
# Leave blank to auto pick server
Servers =

[INFLUXV1]
Name = influx
URL = 192.168.1.7
Port = 8086
Database_name = speedtests2
Username =
Password =
SSL = False
Verify_SSL = False

Using InfluxDB v1.8.0 & python 3.6.9. Clean database freshly created with create database speedtest2.

Let me know if you need more info.

jack828 commented 2 years ago

.....and I think I've just answered my own issue - I got this because the database name wasn't being loaded correctly (see #3), therefore it was trying to push data into the database for the old script, which for whatever reason is storing as floats.

Do you think it is worth converting all necessary datatypes to floats for backwards compatability or is there a way I can "un-float" my existing data so I don't lose it?

barrycarey commented 2 years ago

@jack828 I just converted it to use floats to remain consistent. This will break and new data written by the tool but I think it ultimately needed to be done before this repo picks up steam and gets more usage.