From 5fc2058b928d7c3e62d997a79740ec1e21d58eb9 Mon Sep 17 00:00:00 2001 From: Petr Michalec Date: Mon, 11 Dec 2017 15:00:38 +0100 Subject: [PATCH] FEATURE: add custom ad-hoc queries for schedulled run, etc Change-Id: Idabbb59c74a6ca004629c8f33e92c96d2d35c113 --- README.rst | 32 +++++++++++++++++++++++++++++++- influxdb/query.sls | 34 ++++++++++++++++++++++++++++++++++ tests/pillar/client.sls | 7 +++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 influxdb/query.sls diff --git a/README.rst b/README.rst index 75ffe55..854da83 100644 --- a/README.rst +++ b/README.rst @@ -273,10 +273,40 @@ Create an continuous queries: client: database: mydb1: - continuos_query: + continuous_query: cq_avg_bus_passengers: >- SELECT mean("passengers") INTO "transportation"."three_weeks"."average_passengers" FROM "bus_data" GROUP BY time(1h) +Prunning data and data management: + +Intended to use in scheduled jobs, executed to maintain data life cycle above retention policy. These states are executed by +``query.sls`` and you are expected to trigger ``sls_id`` individually. + +.. code-block:: yaml + + influxdb: + client: + database: + mydb1: + query: + drop_measurement_h2o: >- + DROP MEASUREMENT h2o_quality + drop_shard_h2o: >- + DROP SHARD h2o_quality + drop_series_h2o_feet: >- + DROP SERIES FROM "h2o_feet" + drop_series_h2o_feet_loc_smonica: >- + DROP SERIES FROM "h2o_feet" WHERE "location" = 'santa_monica' + delete_h2o_quality_rt3: >- + DELETE FROM "h2o_quality" WHERE "randtag" = '3' + delete_h2o_quality: >- + DELETE FROM "h2o_quality" + + +.. code-block:: shell + + salt \* state.sls_id influxdb_query_delete_h2o_quality influxdb.query + InfluxDB relay with HTTP outputs: diff --git a/influxdb/query.sls b/influxdb/query.sls new file mode 100644 index 0000000..a24e2fa --- /dev/null +++ b/influxdb/query.sls @@ -0,0 +1,34 @@ +{%- from "influxdb/map.jinja" import client with context %} + +{%- if client.get('enabled') %} +{# CUSTOM QUERIES, intended to be called by salt_id #} + +{%- set mconf = pillar.salt.minion.get('config', {}).get('influxdb') %} + +{%- for db_name,db in client.get('database', {}).iteritems() %} +{%- set db_name = db.get('name', db_name) %} +{%- for qr_name,qr in db.get('query', {}).iteritems() %} + +{%- if qr is string %} +{%- set query = { 'query': qr } %} +{%- endif %} + +influxdb_query_{{ db_name }}_{{ qr_name }}: + module.run: + influxdb.query: + - database: {{ db_name }} + - query: {{ query }} + {%- if grains.saltversion >= "2017.7" %} + - client_args: + host: {{ mconf.host }} + port: {{ mconf.port }} + {%- if qr.user is defined OR mconf.password is defined %} + user: {{ qr.get('user', mconf.user) }} + {%- endif %} + {%- if qr.password is defined OR mconf.password is defined %} + password: {{ qr.get('password', mconf.password) }} + {%- endif %} + {%- endif %} +{%- endfor %} +{%- endfor %} + diff --git a/tests/pillar/client.sls b/tests/pillar/client.sls index 6a38619..d352076 100644 --- a/tests/pillar/client.sls +++ b/tests/pillar/client.sls @@ -30,6 +30,13 @@ influxdb: 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),* + query: + insert_h2o_dummy: >- + INSERT cpu,host=dummyA value=10 + delete_h2o_dummy: + query: DELETE FROM "h2o_quality" + user: admin + password: foobar mydb2: enabled: true name: mydb2 -- 2.32.7