From 75302b4028e5d8ac18d42dc2e3363647c9f0f4b3 Mon Sep 17 00:00:00 2001 From: Marcus Young Date: Tue, 24 Nov 2020 09:19:17 -0600 Subject: [PATCH] Add support for influx cloud via new influxdb client --- README.md | 19 +++--- poetry.lock | 133 +++++++++++++++++-------------------- pyproject.toml | 2 +- requirements-dev.txt | 12 ++-- requirements.txt | 8 +-- setup.py | 2 +- tests/test_influxdb.py | 40 +++++------ tilty/emitters/influxdb.py | 38 ++++++----- 8 files changed, 120 insertions(+), 134 deletions(-) diff --git a/README.md b/README.md index 2623ac4..1b3c1a5 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ The Tilt supports writing to a google doc which you could use with something lik * Generic (Send to any endpoint with any type) * Brewstat.us (Example below) * BrewersFriend (Example below) -* InfluxDB +* InfluxDB (1.8+) * Datadog (dogstatsd) * SQLite * Google Sheets (experimental/advanced) @@ -87,15 +87,14 @@ payload_template = {"name": "Tilt {{ color }}", "gravity": {{ gravity }}, "gravi method = POST [influxdb] -url = influxdb.corp.com -port = 80 -database = tilty -password = foo # optional -ssl = True # default is False -verify_ssl = True # default is False -gravity_payload_template = {"measurement": "gravity", "tags": {"color": "{{ color }}", "mac": "{{ mac }}"}, "fields": {"value": {{ gravity }}}} -temperature_payload_template = {"measurement": "temperature", "tags": {"color": "{{ color }}", "mac": "{{ mac }}"}, "fields": {"value": {{ temp }}}} -# `% curl -s -G 'http://influxdb.service.consul:8086/query?pretty=true' --data-urlencode "db=tilty" --data-urlencode 'q=SELECT "value", "mac", "color" FROM "autogen"."gravity"' | jq '.results[].series[].values[0]'` +url = http://localhost:8086 +verify_ssl = True # defaults to False, only used if url is https:// +bucket = tilty +org = Mine +token = mytoken # if using influx cloud +token = myuser:password # if using self hosted +gravity_payload_template = gravity,color={{ color }},mac={{ mac }} sg={{ gravity }} +temperature_payload_template = temperature,color={{ color }},mac={{ mac }} temp={{ temp }} [datadog] # Note: make sure that the dd agent has DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true diff --git a/poetry.lock b/poetry.lock index b392dad..273063b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -333,14 +333,14 @@ marker = "python_version < \"3.8\"" name = "importlib-metadata" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" -version = "2.0.0" +version = "2.1.0" [package.dependencies] zipp = ">=0.5" [package.extras] docs = ["sphinx", "rst.linker"] -testing = ["packaging", "pep517", "importlib-resources (>=1.3)"] +testing = ["packaging", "pep517", "unittest2", "importlib-resources (>=1.3)"] [[package]] category = "dev" @@ -361,21 +361,24 @@ docs = ["sphinx", "rst.linker", "jaraco.packaging"] [[package]] category = "main" -description = "InfluxDB client" -name = "influxdb" +description = "InfluxDB 2.0 Python client library" +name = "influxdb-client" optional = false -python-versions = "*" -version = "5.3.0" +python-versions = ">=3.6" +version = "1.12.0" [package.dependencies] -msgpack = "0.6.1" -python-dateutil = ">=2.6.0" -pytz = "*" -requests = ">=2.17.0" -six = ">=1.10.0" +certifi = ">=14.05.14" +python-dateutil = ">=2.5.3" +pytz = ">=2019.1" +rx = ">=3.0.1" +setuptools = ">=21.0.0" +six = ">=1.10" +urllib3 = ">=1.15.1" [package.extras] -test = ["nose", "nose-cov", "mock", "requests-mock"] +ciso = ["ciso8601 (>=2.1.1)"] +extra = ["pandas (>=0.25.3)", "numpy"] [[package]] category = "dev" @@ -437,14 +440,6 @@ optional = false python-versions = ">=3.5" version = "8.6.0" -[[package]] -category = "main" -description = "MessagePack (de)serializer." -name = "msgpack" -optional = false -python-versions = "*" -version = "0.6.1" - [[package]] category = "dev" description = "Optional static typing for Python" @@ -550,10 +545,9 @@ description = "Protocol Buffers" name = "protobuf" optional = false python-versions = "*" -version = "3.13.0" +version = "3.14.0" [package.dependencies] -setuptools = "*" six = ">=1.9" [[package]] @@ -707,13 +701,13 @@ description = "Python HTTP for Humans." name = "requests" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" -version = "2.24.0" +version = "2.25.0" [package.dependencies] certifi = ">=2017.4.17" chardet = ">=3.0.2,<4" idna = ">=2.5,<3" -urllib3 = ">=1.21.1,<1.25.0 || >1.25.0,<1.25.1 || >1.25.1,<1.26" +urllib3 = ">=1.21.1,<1.27" [package.extras] security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"] @@ -745,6 +739,14 @@ version = "4.6" [package.dependencies] pyasn1 = ">=0.1.3" +[[package]] +category = "main" +description = "Reactive Extensions (Rx) for Python" +name = "rx" +optional = false +python-versions = ">=3.6.0" +version = "3.1.1" + [[package]] category = "main" description = "Python 2 and 3 compatibility utilities" @@ -853,7 +855,7 @@ description = "Virtual Python Environment builder" name = "virtualenv" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" -version = "20.1.0" +version = "20.2.1" [package.dependencies] appdirs = ">=1.4.3,<2" @@ -863,7 +865,7 @@ six = ">=1.9.0,<2" [package.dependencies.importlib-metadata] python = "<3.8" -version = ">=0.12,<3" +version = ">=0.12" [package.dependencies.importlib-resources] python = "<3.7" @@ -903,7 +905,7 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] testing = ["pytest (>=3.5,<3.7.3 || >3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"] [metadata] -content-hash = "903cf8275497d3f8234fbd102a1b63177fc3e28cdcf3e1c87d24b4dc1a1d9aa8" +content-hash = "12a0cd6418cffd81fce98ee49cc85ee2766ebec6639d5e3c8ccf2ba1e42abe85" lock-version = "1.0" python-versions = ">=3.6,<4" @@ -1050,16 +1052,16 @@ idna = [ {file = "idna-2.10.tar.gz", hash = "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"}, ] importlib-metadata = [ - {file = "importlib_metadata-2.0.0-py2.py3-none-any.whl", hash = "sha256:cefa1a2f919b866c5beb7c9f7b0ebb4061f30a8a9bf16d609b000e2dfaceb9c3"}, - {file = "importlib_metadata-2.0.0.tar.gz", hash = "sha256:77a540690e24b0305878c37ffd421785a6f7e53c8b5720d211b211de8d0e95da"}, + {file = "importlib_metadata-2.1.0-py2.py3-none-any.whl", hash = "sha256:030f3b1bdb823ecbe4a9659e14cc861ce5af403fe99863bae173ec5fe00ab132"}, + {file = "importlib_metadata-2.1.0.tar.gz", hash = "sha256:caeee3603f5dcf567864d1be9b839b0bcfdf1383e3e7be33ce2dead8144ff19c"}, ] importlib-resources = [ {file = "importlib_resources-3.3.0-py2.py3-none-any.whl", hash = "sha256:a3d34a8464ce1d5d7c92b0ea4e921e696d86f2aa212e684451cb1482c8d84ed5"}, {file = "importlib_resources-3.3.0.tar.gz", hash = "sha256:7b51f0106c8ec564b1bef3d9c588bc694ce2b92125bbb6278f4f2f5b54ec3592"}, ] -influxdb = [ - {file = "influxdb-5.3.0-py2.py3-none-any.whl", hash = "sha256:b4c034ee9c9ee888d43de547cf40c616bba35f0aa8f11e5a6f056bf5855970ac"}, - {file = "influxdb-5.3.0.tar.gz", hash = "sha256:9bcaafd57ac152b9824ab12ed19f204206ef5df8af68404770554c5b55b475f6"}, +influxdb-client = [ + {file = "influxdb_client-1.12.0-py3-none-any.whl", hash = "sha256:f233da171a2508274d4cebba3ec66d2cc4729229e66419aabeb20220e3b36c82"}, + {file = "influxdb_client-1.12.0.tar.gz", hash = "sha256:213cece87fbb71411c6d387d65e0cbc3d529bc37c734635e6ee4449443757331"}, ] isort = [ {file = "isort-4.3.21-py2.py3-none-any.whl", hash = "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"}, @@ -1135,25 +1137,6 @@ more-itertools = [ {file = "more-itertools-8.6.0.tar.gz", hash = "sha256:b3a9005928e5bed54076e6e549c792b306fddfe72b2d1d22dd63d42d5d3899cf"}, {file = "more_itertools-8.6.0-py3-none-any.whl", hash = "sha256:8e1a2a43b2f2727425f2b5839587ae37093f19153dc26c0927d1048ff6557330"}, ] -msgpack = [ - {file = "msgpack-0.6.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:3129c355342853007de4a2a86e75eab966119733eb15748819b6554363d4e85c"}, - {file = "msgpack-0.6.1-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:31f6d645ee5a97d59d3263fab9e6be76f69fa131cddc0d94091a3c8aca30d67a"}, - {file = "msgpack-0.6.1-cp27-cp27m-win32.whl", hash = "sha256:fd509d4aa95404ce8d86b4e32ce66d5d706fd6646c205e1c2a715d87078683a2"}, - {file = "msgpack-0.6.1-cp27-cp27m-win_amd64.whl", hash = "sha256:70cebfe08fb32f83051971264466eadf183101e335d8107b80002e632f425511"}, - {file = "msgpack-0.6.1-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:8e68c76c6aff4849089962d25346d6784d38e02baa23ffa513cf46be72e3a540"}, - {file = "msgpack-0.6.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:86b963a5de11336ec26bc4f839327673c9796b398b9f1fe6bb6150c2a5d00f0f"}, - {file = "msgpack-0.6.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:72cb7cf85e9df5251abd7b61a1af1fb77add15f40fa7328e924a9c0b6bc7a533"}, - {file = "msgpack-0.6.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:8c73c9bcdfb526247c5e4f4f6cf581b9bb86b388df82cfcaffde0a6e7bf3b43a"}, - {file = "msgpack-0.6.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:26cb40116111c232bc235ce131cc3b4e76549088cb154e66a2eb8ff6fcc907ec"}, - {file = "msgpack-0.6.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:62bd8e43d204580308d477a157b78d3fee2fb4c15d32578108dc5d89866036c8"}, - {file = "msgpack-0.6.1-cp36-cp36m-win32.whl", hash = "sha256:a28e69fe5468c9f5251c7e4e7232286d71b7dfadc74f312006ebe984433e9746"}, - {file = "msgpack-0.6.1-cp36-cp36m-win_amd64.whl", hash = "sha256:97ac6b867a8f63debc64f44efdc695109d541ecc361ee2dce2c8884ab37360a1"}, - {file = "msgpack-0.6.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:3ce7ef7ee2546c3903ca8c934d09250531b80c6127e6478781ae31ed835aac4c"}, - {file = "msgpack-0.6.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:7c55649965c35eb32c499d17dadfb8f53358b961582846e1bc06f66b9bccc556"}, - {file = "msgpack-0.6.1-cp37-cp37m-win32.whl", hash = "sha256:9d4f546af72aa001241d74a79caec278bcc007b4bcde4099994732e98012c858"}, - {file = "msgpack-0.6.1-cp37-cp37m-win_amd64.whl", hash = "sha256:300fd3f2c664a3bf473d6a952f843b4a71454f4c592ed7e74a36b205c1782d28"}, - {file = "msgpack-0.6.1.tar.gz", hash = "sha256:4008c72f5ef2b7936447dcb83db41d97e9791c83221be13d5e19db0796df1972"}, -] mypy = [ {file = "mypy-0.782-cp35-cp35m-macosx_10_6_x86_64.whl", hash = "sha256:2c6cde8aa3426c1682d35190b59b71f661237d74b053822ea3d748e2c9578a7c"}, {file = "mypy-0.782-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:9c7a9a7ceb2871ba4bac1cf7217a7dd9ccd44c27c2950edbc6dc08530f32ad4e"}, @@ -1199,24 +1182,24 @@ prometheus-client = [ {file = "prometheus_client-0.8.0.tar.gz", hash = "sha256:c6e6b706833a6bd1fd51711299edee907857be10ece535126a158f911ee80915"}, ] protobuf = [ - {file = "protobuf-3.13.0-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:9c2e63c1743cba12737169c447374fab3dfeb18111a460a8c1a000e35836b18c"}, - {file = "protobuf-3.13.0-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:1e834076dfef9e585815757a2c7e4560c7ccc5962b9d09f831214c693a91b463"}, - {file = "protobuf-3.13.0-cp35-cp35m-macosx_10_9_intel.whl", hash = "sha256:df3932e1834a64b46ebc262e951cd82c3cf0fa936a154f0a42231140d8237060"}, - {file = "protobuf-3.13.0-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:8c35bcbed1c0d29b127c886790e9d37e845ffc2725cc1db4bd06d70f4e8359f4"}, - {file = "protobuf-3.13.0-cp35-cp35m-win32.whl", hash = "sha256:339c3a003e3c797bc84499fa32e0aac83c768e67b3de4a5d7a5a9aa3b0da634c"}, - {file = "protobuf-3.13.0-cp35-cp35m-win_amd64.whl", hash = "sha256:361acd76f0ad38c6e38f14d08775514fbd241316cce08deb2ce914c7dfa1184a"}, - {file = "protobuf-3.13.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:9edfdc679a3669988ec55a989ff62449f670dfa7018df6ad7f04e8dbacb10630"}, - {file = "protobuf-3.13.0-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:5db9d3e12b6ede5e601b8d8684a7f9d90581882925c96acf8495957b4f1b204b"}, - {file = "protobuf-3.13.0-cp36-cp36m-win32.whl", hash = "sha256:c8abd7605185836f6f11f97b21200f8a864f9cb078a193fe3c9e235711d3ff1e"}, - {file = "protobuf-3.13.0-cp36-cp36m-win_amd64.whl", hash = "sha256:4d1174c9ed303070ad59553f435846a2f877598f59f9afc1b89757bdf846f2a7"}, - {file = "protobuf-3.13.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0bba42f439bf45c0f600c3c5993666fcb88e8441d011fad80a11df6f324eef33"}, - {file = "protobuf-3.13.0-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:c0c5ab9c4b1eac0a9b838f1e46038c3175a95b0f2d944385884af72876bd6bc7"}, - {file = "protobuf-3.13.0-cp37-cp37m-win32.whl", hash = "sha256:f68eb9d03c7d84bd01c790948320b768de8559761897763731294e3bc316decb"}, - {file = "protobuf-3.13.0-cp37-cp37m-win_amd64.whl", hash = "sha256:91c2d897da84c62816e2f473ece60ebfeab024a16c1751aaf31100127ccd93ec"}, - {file = "protobuf-3.13.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:3dee442884a18c16d023e52e32dd34a8930a889e511af493f6dc7d4d9bf12e4f"}, - {file = "protobuf-3.13.0-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:e7662437ca1e0c51b93cadb988f9b353fa6b8013c0385d63a70c8a77d84da5f9"}, - {file = "protobuf-3.13.0-py2.py3-none-any.whl", hash = "sha256:d69697acac76d9f250ab745b46c725edf3e98ac24763990b24d58c16c642947a"}, - {file = "protobuf-3.13.0.tar.gz", hash = "sha256:6a82e0c8bb2bf58f606040cc5814e07715b2094caeba281e2e7d0b0e2e397db5"}, + {file = "protobuf-3.14.0-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:629b03fd3caae7f815b0c66b41273f6b1900a579e2ccb41ef4493a4f5fb84f3a"}, + {file = "protobuf-3.14.0-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:5b7a637212cc9b2bcf85dd828b1178d19efdf74dbfe1ddf8cd1b8e01fdaaa7f5"}, + {file = "protobuf-3.14.0-cp35-cp35m-macosx_10_9_intel.whl", hash = "sha256:43b554b9e73a07ba84ed6cf25db0ff88b1e06be610b37656e292e3cbb5437472"}, + {file = "protobuf-3.14.0-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:5e9806a43232a1fa0c9cf5da8dc06f6910d53e4390be1fa06f06454d888a9142"}, + {file = "protobuf-3.14.0-cp35-cp35m-win32.whl", hash = "sha256:1c51fda1bbc9634246e7be6016d860be01747354ed7015ebe38acf4452f470d2"}, + {file = "protobuf-3.14.0-cp35-cp35m-win_amd64.whl", hash = "sha256:4b74301b30513b1a7494d3055d95c714b560fbb630d8fb9956b6f27992c9f980"}, + {file = "protobuf-3.14.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:86a75477addde4918e9a1904e5c6af8d7b691f2a3f65587d73b16100fbe4c3b2"}, + {file = "protobuf-3.14.0-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:ecc33531a213eee22ad60e0e2aaea6c8ba0021f0cce35dbf0ab03dee6e2a23a1"}, + {file = "protobuf-3.14.0-cp36-cp36m-win32.whl", hash = "sha256:72230ed56f026dd664c21d73c5db73ebba50d924d7ba6b7c0d81a121e390406e"}, + {file = "protobuf-3.14.0-cp36-cp36m-win_amd64.whl", hash = "sha256:0fc96785262042e4863b3f3b5c429d4636f10d90061e1840fce1baaf59b1a836"}, + {file = "protobuf-3.14.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:4e75105c9dfe13719b7293f75bd53033108f4ba03d44e71db0ec2a0e8401eafd"}, + {file = "protobuf-3.14.0-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:2a7e2fe101a7ace75e9327b9c946d247749e564a267b0515cf41dfe450b69bac"}, + {file = "protobuf-3.14.0-cp37-cp37m-win32.whl", hash = "sha256:b0d5d35faeb07e22a1ddf8dce620860c8fe145426c02d1a0ae2688c6e8ede36d"}, + {file = "protobuf-3.14.0-cp37-cp37m-win_amd64.whl", hash = "sha256:8971c421dbd7aad930c9bd2694122f332350b6ccb5202a8b7b06f3f1a5c41ed5"}, + {file = "protobuf-3.14.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:9616f0b65a30851e62f1713336c931fcd32c057202b7ff2cfbfca0fc7d5e3043"}, + {file = "protobuf-3.14.0-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:22bcd2e284b3b1d969c12e84dc9b9a71701ec82d8ce975fdda19712e1cfd4e00"}, + {file = "protobuf-3.14.0-py2.py3-none-any.whl", hash = "sha256:0e247612fadda953047f53301a7b0407cb0c3cb4ae25a6fde661597a04039b3c"}, + {file = "protobuf-3.14.0.tar.gz", hash = "sha256:1d63eb389347293d8915fb47bee0951c7b5dab522a4a60118b9a18f33e21f8ce"}, ] py = [ {file = "py-1.9.0-py2.py3-none-any.whl", hash = "sha256:366389d1db726cd2fcfc79732e75410e5fe4d31db13692115529d34069a043c2"}, @@ -1306,8 +1289,8 @@ pyyaml = [ {file = "PyYAML-5.3.1.tar.gz", hash = "sha256:b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d"}, ] requests = [ - {file = "requests-2.24.0-py2.py3-none-any.whl", hash = "sha256:fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898"}, - {file = "requests-2.24.0.tar.gz", hash = "sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b"}, + {file = "requests-2.25.0-py2.py3-none-any.whl", hash = "sha256:e786fa28d8c9154e6a4de5d46a1d921b8749f8b74e28bde23768e5e16eece998"}, + {file = "requests-2.25.0.tar.gz", hash = "sha256:7f1a0b932f4a60a1a65caa4263921bb7d9ee911957e0ae4a23a6dd08185ad5f8"}, ] requests-oauthlib = [ {file = "requests-oauthlib-1.3.0.tar.gz", hash = "sha256:b4261601a71fd721a8bd6d7aa1cc1d6a8a93b4a9f5e96626f8e4d91e8beeaa6a"}, @@ -1318,6 +1301,10 @@ rsa = [ {file = "rsa-4.6-py3-none-any.whl", hash = "sha256:6166864e23d6b5195a5cfed6cd9fed0fe774e226d8f854fcb23b7bbef0350233"}, {file = "rsa-4.6.tar.gz", hash = "sha256:109ea5a66744dd859bf16fe904b8d8b627adafb9408753161e766a92e7d681fa"}, ] +rx = [ + {file = "Rx-3.1.1-py3-none-any.whl", hash = "sha256:0e0f2715a3452e95dcb5d6ea28ffe5742e832592bbcc67a48f394ef8ba871e6f"}, + {file = "Rx-3.1.1.tar.gz", hash = "sha256:562851cfdb27fd5a218443cdbd682029684144dbafeb5dce34f6a709511282de"}, +] six = [ {file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"}, {file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"}, @@ -1375,8 +1362,8 @@ urllib3 = [ {file = "urllib3-1.25.11.tar.gz", hash = "sha256:8d7eaa5a82a1cac232164990f04874c594c9453ec55eef02eab885aa02fc17a2"}, ] virtualenv = [ - {file = "virtualenv-20.1.0-py2.py3-none-any.whl", hash = "sha256:b0011228208944ce71052987437d3843e05690b2f23d1c7da4263fde104c97a2"}, - {file = "virtualenv-20.1.0.tar.gz", hash = "sha256:b8d6110f493af256a40d65e29846c69340a947669eec8ce784fcf3dd3af28380"}, + {file = "virtualenv-20.2.1-py2.py3-none-any.whl", hash = "sha256:07cff122e9d343140366055f31be4dcd61fd598c69d11cd33a9d9c8df4546dd7"}, + {file = "virtualenv-20.2.1.tar.gz", hash = "sha256:e0aac7525e880a429764cefd3aaaff54afb5d9f25c82627563603f5d7de5a6e5"}, ] wcwidth = [ {file = "wcwidth-0.2.5-py2.py3-none-any.whl", hash = "sha256:beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784"}, diff --git a/pyproject.toml b/pyproject.toml index 0b743a3..e22e740 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ click = "^7.0" pybluez = "^0.22.0" requests = "^2.22" jinja2 = "^2.11.1" -influxdb = "^5.2.3" +influxdb-client = "^1.12.0" datadog = "^0.34.1" google-api-core = "1.20.1" google-api-python-client = "^1.10.0" diff --git a/requirements-dev.txt b/requirements-dev.txt index 311d830..98d14d1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -26,16 +26,15 @@ google-auth-oauthlib==0.4.2 googleapis-common-protos==1.52.0 httplib2==0.18.1 idna==2.10 -importlib-metadata==2.0.0; python_version < "3.8" +importlib-metadata==2.1.0; python_version < "3.8" importlib-resources==3.3.0; python_version < "3.7" -influxdb==5.3.0 +influxdb-client==1.12.0 isort==4.3.21 jinja2==2.11.2 lazy-object-proxy==1.4.3 markupsafe==1.1.1 mccabe==0.6.1 more-itertools==8.6.0 -msgpack==0.6.1 mypy==0.782 mypy-extensions==0.4.3 oauth2client==4.1.3 @@ -44,7 +43,7 @@ packaging==20.4 pbr==5.5.1 pluggy==0.13.1 prometheus-client==0.8.0 -protobuf==3.13.0 +protobuf==3.14.0 py==1.9.0 pyasn1==0.4.8 pyasn1-modules==0.2.8 @@ -58,9 +57,10 @@ pytest-cov==2.10.1 python-dateutil==2.8.1 pytz==2020.4 pyyaml==5.3.1 -requests==2.24.0 +requests==2.25.0 requests-oauthlib==1.3.0 rsa==4.6 +rx==3.1.1 six==1.15.0 smmap==3.0.4 stevedore==3.2.2 @@ -70,7 +70,7 @@ typed-ast==1.4.1 typing-extensions==3.7.4.3 uritemplate==3.0.1 urllib3==1.25.11 -virtualenv==20.1.0 +virtualenv==20.2.1 wcwidth==0.2.5 wrapt==1.12.1 zipp==3.4.0; python_version < "3.8" diff --git a/requirements.txt b/requirements.txt index 65b3506..d85ca65 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,22 +12,22 @@ google-auth-oauthlib==0.4.2 googleapis-common-protos==1.52.0 httplib2==0.18.1 idna==2.10 -influxdb==5.3.0 +influxdb-client==1.12.0 jinja2==2.11.2 markupsafe==1.1.1 -msgpack==0.6.1 oauth2client==4.1.3 oauthlib==3.1.0 prometheus-client==0.8.0 -protobuf==3.13.0 +protobuf==3.14.0 pyasn1==0.4.8 pyasn1-modules==0.2.8 pybluez==0.22 python-dateutil==2.8.1 pytz==2020.4 -requests==2.24.0 +requests==2.25.0 requests-oauthlib==1.3.0 rsa==4.6 +rx==3.1.1 six==1.15.0 uritemplate==3.0.1 urllib3==1.25.11 diff --git a/setup.py b/setup.py index 531d3b8..87489d7 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ install_requires=[ 'Click', 'datadog', - 'influxdb', + 'influxdb-client==1.12.0', 'Jinja2', 'prometheus_client==0.8.0', 'pybluez', diff --git a/tests/test_influxdb.py b/tests/test_influxdb.py index 1910037..be41171 100644 --- a/tests/test_influxdb.py +++ b/tests/test_influxdb.py @@ -15,7 +15,9 @@ def test_influxdb( ): config = { 'url': 'http://www.google.com', - 'database': 'foo', + 'org': 'foo', + 'bucket': 'wat', + 'token': 'somelongtoken', 'gravity_payload_template': '{"measurement": "gravity", "tags": {"color": "{{ color }}"}, "fields": {"value": {{ gravity }}}}', # noqa 'temperature_payload_template': '{"measurement": "temperature", "tags": {"color": "{{ color }}"}, "fields": {"value": {{ temp }}}}', # noqa } @@ -28,26 +30,20 @@ def test_influxdb( }) assert mock_influx_client.mock_calls == [ mock.call( - database='foo', - host='http://www.google.com', - password=None, - port=80, - ssl=False, - username=None, - verify_ssl=False, + org='foo', + token='somelongtoken', + url='http://www.google.com', + verify_ssl=False + ), + mock.call().write_api(write_options=mock.ANY), + mock.call().write_api().write( + bucket='wat', + org='foo', + record='{"measurement": "temperature", "tags": {"color": "black"}, "fields": {"value": 80}}' # noqa + ), + mock.call().write_api().write( + bucket='wat', + org='foo', + record='{"measurement": "gravity", "tags": {"color": "black"}, "fields": {"value": 1.054}}' # noqa ), - mock.call().write_points([ - { - 'measurement': 'temperature', - 'tags': {'color': 'black'}, - 'fields': {'value': 80} - } - ]), - mock.call().write_points([ - { - 'measurement': 'gravity', - 'tags': {'color': 'black'}, - 'fields': {'value': 1.054} - } - ]) ] diff --git a/tilty/emitters/influxdb.py b/tilty/emitters/influxdb.py index 735314f..6d47158 100644 --- a/tilty/emitters/influxdb.py +++ b/tilty/emitters/influxdb.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- """ InfluxDB emitter """ -import json import logging from distutils import util as distutil -from influxdb import InfluxDBClient +from influxdb_client import InfluxDBClient +from influxdb_client.client.write_api import SYNCHRONOUS from jinja2 import Template from tilty.common import safe_get_key @@ -32,21 +32,19 @@ def __init__(self, config: dict) -> None: # temperature_payload_template = {"measurement": "temperature", "tags": {"color": "{{ color }}"}, "fields": {"value": {{ temp }}}} # noqa # pylint: disable=line-too-long self.gravity_template = Template(config['gravity_payload_template']) # noqa self.temperature_template = Template(config['temperature_payload_template']) # noqa - ssl = bool(distutil.strtobool( - safe_get_key(config, 'ssl', 'False') - )) + self.bucket = safe_get_key(config, 'bucket') + verify_ssl = bool(distutil.strtobool( safe_get_key(config, 'verify_ssl', 'False') )) - self.client = InfluxDBClient( - host=config['url'], - port=safe_get_key(config, 'port', 80), - username=safe_get_key(config, 'user'), - password=safe_get_key(config, 'password'), - ssl=ssl, - verify_ssl=verify_ssl, - database=config['database'] + self.org = safe_get_key(config, 'org') + client = InfluxDBClient( + url=config['url'], + org=self.org, + token=safe_get_key(config, 'token'), + verify_ssl=verify_ssl ) + self.write_api = client.write_api(write_options=SYNCHRONOUS) def emit(self, tilt_data: dict) -> None: """ Initializer @@ -59,16 +57,22 @@ def emit(self, tilt_data: dict) -> None: gravity=tilt_data['gravity'], mac=tilt_data['mac'], temp=tilt_data['temp'], - timestamp=tilt_data['timestamp'], ) gravity_payload = self.gravity_template.render( color=tilt_data['color'], gravity=tilt_data['gravity'], mac=tilt_data['mac'], temp=tilt_data['temp'], - timestamp=tilt_data['timestamp'], ) LOGGER.info('[influxdb] posting temperature data') - self.client.write_points([json.loads(temperature_payload)]) + self.write_api.write( + bucket=self.bucket, + org=self.org, + record=temperature_payload + ) LOGGER.info('[influxdb] posting gravity data') - self.client.write_points([json.loads(gravity_payload)]) + self.write_api.write( + bucket=self.bucket, + org=self.org, + record=gravity_payload + )