From a20e49917c64e9935d212fcb7d81d7a1688c63ce Mon Sep 17 00:00:00 2001 From: Petr Michalec Date: Wed, 6 Dec 2017 13:32:13 +0100 Subject: [PATCH] FEATURE, add continuous query support Change-Id: I6f449e55220263149074e310047d13f05a521ea8 --- README.rst | 14 ++++++++++++++ influxdb/client.sls | 14 ++++++++++++++ tests/pillar/client.sls | 5 +++++ tests/pillar/repo_influxdata.sls | 4 ++-- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index a27364f..f9d05c3 100644 --- a/README.rst +++ b/README.rst @@ -264,6 +264,20 @@ InfluxDB client for configuring databases, users and retention policies: database: mydb1 privilege: all + +Create an continuous queries: + +.. code-block:: yaml + + influxdb: + client: + database: + mydb1: + continuos_query: + cq_avg_bus_passengers: >- + SELECT mean("passengers") INTO "transportation"."three_weeks"."average_passengers" FROM "bus_data" GROUP BY time(1h) + + InfluxDB relay with HTTP outputs: .. code-block:: yaml diff --git a/influxdb/client.sls b/influxdb/client.sls index f312531..f698a64 100644 --- a/influxdb/client.sls +++ b/influxdb/client.sls @@ -80,4 +80,18 @@ influxdb_grant_{{ grant_name }}: {%- endif %} {%- endfor %} + +{# CONTINUOUS QUERIES #} +{%- for db_name, db in client.get('database', {}).iteritems() %} + {%- set db_name = db.get('name', db_name) %} + {%- for cq_name, cq in db.get('continuous_query', {}).iteritems() %} + {%- set query_continuous_query = 'CONTINUOUS QUERY {} ON {} BEGIN {} END'.format(cq_name, db_name, cq ) %} +influxdb_continuous_query_{{db_name}}_{{ cq_name }}: + cmd.run: + - name: {{ curl_command }} -s -S -POST "{{ auth_url }}" --data-urlencode "q=CREATE {{ query_continuous_query }}"|grep -v "already exists" || {{ curl_command }} -s -S -POST "{{ auth_url }}" --data-urlencode "q=ALTER {{ query_continuous_query }}" + - onlyif: {{ curl_command }} -s -S -POST "{{ auth_url }}" --data-urlencode "q=SHOW DATABASES" | grep {{ db_name }} + + {%- endfor %} +{%- endfor %} + {%- endif %} diff --git a/tests/pillar/client.sls b/tests/pillar/client.sls index 5d1f0d2..6a38619 100644 --- a/tests/pillar/client.sls +++ b/tests/pillar/client.sls @@ -25,6 +25,11 @@ influxdb: - name: rp_db2 duration: 365d replication: 1 + continuous_query: + cq_avg_passenger: >- + SELECT mean("passengers") INTO "transportation"."rp_db1"."average_passengers" FROM "_data" GROUP BY time(1h) + cq_basic_br: -> + SELECT mean(*) INTO "downsampled_transportation"."autogen".:MEASUREMENT FROM /.*/ GROUP BY time(30m),* mydb2: enabled: true name: mydb2 diff --git a/tests/pillar/repo_influxdata.sls b/tests/pillar/repo_influxdata.sls index 9599f02..012a7ae 100644 --- a/tests/pillar/repo_influxdata.sls +++ b/tests/pillar/repo_influxdata.sls @@ -3,6 +3,6 @@ linux: enabled: true repo: linux_influxdata: - source: "deb https://repos.influxdata.com/ubuntu {{ grains.get('oscodename') }} stable" + source: "deb http://repos-backend.influxdata.com/ubuntu {{ grains.get('oscodename') }} stable" architectures: amd64 - key_url: "https://repos.influxdata.com/influxdb.key" + key_url: "http://repos-backend.influxdata.com/influxdb.key" -- 2.32.7