From: Swann Croiset Date: Fri, 2 Dec 2016 13:42:48 +0000 (+0100) Subject: Support rentention policies X-Git-Tag: 2016.12^2 X-Git-Url: https://gerrit.mcp.mirantis.com/gitweb?p=salt-formulas%2Finfluxdb.git;a=commitdiff_plain;h=1eaf36173f581028b0e1336aaab4a7fe1c7a16b6;ds=sidebyside Support rentention policies The default (named autogen) policy has an infinite retention period --- diff --git a/README.rst b/README.rst index 23b12f0..3027252 100644 --- a/README.rst +++ b/README.rst @@ -108,6 +108,30 @@ Single-node influxdb with new databases: enabled: true name: mydb2 +Manage the retention policies for a database: + +.. code-block:: yaml + + influxdb: + server: + database: + mydb1: + enabled: true + name: mydb1 + retention_policy: + - name: rp_db1 + duration: 30d + replication: 1 + is_default: true + +Where default values are: + +* name = autogen +* duration = INF +* replication = 1 +* is_default: false + + Here is how to manage grants on database: .. code-block:: yaml diff --git a/influxdb/server.sls b/influxdb/server.sls index 12be638..c77ec82 100644 --- a/influxdb/server.sls +++ b/influxdb/server.sls @@ -77,6 +77,31 @@ influxdb_create_db_{{db.name}}: - cmd: influxdb_create_admin {%- endif %} # TODO: manage database deletion + + {% for rp in db.get('retention_policy', []) %} + {% set rp_name = rp.get('name', 'autogen') %} + {% if rp.get('is_default') %} + {% set is_default = 'DEFAULT' %} + {% else %} + {% set is_default = '' %} + {% endif %} + {% set duration = rp.get('duration', 'INF') %} + {% set replication = rp.get('replication', '1') %} + {% if rp.get('shard_duration') %} + {% set shard_duration = 'SHARD DURATION {}'.format(rp.shard_duration) %} + {% else %} + {% set shard_duration = '' %} + {% endif %} + {% set query_retention_policy = 'RETENTION POLICY {} ON {} DURATION {} REPLICATION {} {} {}'.format( + rp_name, db.name, duration, replication, shard_duration, is_default) + %} +influxdb_retention_policy_{{db.name}}_{{ rp_name }}: + cmd.run: + + - name: curl -s -S -POST "{{ url_for_query }}" --data-urlencode "q=CREATE {{ query_retention_policy }}"|grep -v "policy already exists" || curl -s -S -POST "{{ url_for_query }}" --data-urlencode "q=ALTER {{ query_retention_policy }}" + - require: + - cmd: influxdb_create_db_{{db.name}} + {%- endfor %} {%- endif %} {%- endfor %}