X-Git-Url: https://gerrit.mcp.mirantis.com/gitweb?p=salt-formulas%2Finfluxdb.git;a=blobdiff_plain;f=influxdb%2Fserver.sls;h=30899fc28775e67db1e1f71244891bd329eb08af;hp=12be6389f16d9fc408eb556d2e598667f68e7a45;hb=1dd422969a205d0730d071fa8bbf6953ebeaff38;hpb=abef9f6c74471fbcbbece617149e8fc994c20139 diff --git a/influxdb/server.sls b/influxdb/server.sls index 12be638..30899fc 100644 --- a/influxdb/server.sls +++ b/influxdb/server.sls @@ -1,4 +1,5 @@ {%- from "influxdb/map.jinja" import server with context %} + {%- if server.enabled %} influxdb_packages: @@ -28,6 +29,9 @@ influxdb_service: # This delay is needed before being able to send data to server to create # users and databases. - init_delay: 5 + {%- if grains.get('noservices') %} + - onlyif: /bin/false + {%- endif %} - watch: - file: influxdb_config - file: influxdb_default @@ -77,6 +81,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 %}