Skip to content

Commit

Permalink
fix: switch to python3 (#11)
Browse files Browse the repository at this point in the history
closes #7 
fix: skip idempodence test on compact
  • Loading branch information
DrPsychick authored Sep 6, 2020
1 parent c62883f commit 640b259
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
25 changes: 13 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
---
services:
- docker
os: linux
dist: bionic
language: python
python: "2.7"
cache: pip

sudo: required
dist: xenial
services:
- docker

env:
global:
- GREEN='\033[0;32m'
- RED='\033[0;31m'
- NC='\033[0m' # No Color
matrix:
jobs:
- TEST=basic db_name=telegraf rp_name=rp_4d
- TEST=setup db_name=telegraf_30d rp_name=rp_30d
- TEST=migrate db_name=test_4d rp_name=rp_4d db_name_source=test
Expand All @@ -40,7 +38,7 @@ install:
fi
# Install ansible and jq.
- "pip install ansible jq"
- pip3 install -U ansible jq

# Add ansible.cfg to pick up roles path.
- printf "[defaults]\nroles_path = ../" > ansible.cfg
Expand All @@ -59,11 +57,14 @@ script:
- yes | ansible-playbook -i tests/inventory tests/test.yml --connection=local

# Run the role/playbook again, checking to make sure it's idempotent.
# Skip on "compact" as it will result in 3 changes (create and drop source RP)
- >
yes | ansible-playbook -i tests/inventory tests/test.yml --connection=local
| grep -q 'changed=0.*failed=0'
&& (echo -e "Idempotence test: ${GREEN}pass${NC}" && exit 0)
|| (echo -e "Idempotence test: ${RED}fail${NC}" && exit 1);
if [ "$TEST" != "compact" ]; then
result=$(yes | ansible-playbook -i tests/inventory tests/test.yml --connection=local);
echo "$result" | grep -q 'changed=0.*failed=0'
&& (echo -e "Idempotence test: ${GREEN}pass${NC}"; exit 0)
|| (echo -e "Idempotence test: ${RED}fail${NC}"; echo -e "$result"; exit 1);
fi
# TEST = basic
- >
Expand Down
26 changes: 23 additions & 3 deletions tasks/influxdb_database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,30 @@
when: ifx_mm_defined and (ifx_source_exists or not ifx_source_rp_name)
and (ifx_cq_recreate or ansible_influx_db_create is changed or mm_item not in ifx_mms or ifx_bf_force)

# count new metrics -> if 0, then skip backfill
- name: '{{ db_prefix }} Count new metrics in default RP'
uri:
url: "{{ ansible_influx_url }}/query?db={{ ifx_db.name }}"
method: POST
body: >
q=SELECT COUNT(*)
FROM "{{ ifx_db.source.name }}"."{{ ifx_source_rp_name }}"./^({{ ifx_db.measurements|join('|') }})$/
WHERE time >= {{ ifx_backfill_start }}000ms
return_content: yes
register: ansible_influx_newmetrics
when: ifx_source_drop and ifx_source_exists
- name: '{{ db_prefix }} Set count_newmetrics'
set_fact:
count_newmetrics: "{{ 0 if ansible_influx_newmetrics.json.results[0].series is not defined else
ansible_influx_newmetrics.json.results
|selectattr('series','defined')|map(attribute='series')|flatten
|map(attribute='values')|flatten|select('number')|map('int')|max }}"
when: ifx_source_drop and ifx_source_exists

- name: '{{ db_prefix }} Ask to continue and switch default RP (may result in data loss!)'
pause:
prompt: "I will now backfill gap and switch default RP and DROP the source! Continue?"
when: ifx_source_drop and ifx_source_exists
when: ifx_source_drop and ifx_source_exists and count_newmetrics|int > 0

# run twice -> sum up results
- name: '{{ db_prefix }} Set backfill_start2'
Expand All @@ -280,7 +300,7 @@
GROUP BY *
return_content: yes
register: ansible_influx_bf_closegap
when: ifx_source_drop and ifx_source_exists
when: ifx_source_drop and ifx_source_exists and count_newmetrics|int > 0

- name: '{{ db_prefix }} Backfill again (2) since start (close gap)'
uri:
Expand All @@ -293,7 +313,7 @@
GROUP BY *
return_content: yes
register: ansible_influx_bf_closegap2
when: ifx_source_drop and ifx_source_exists
when: ifx_source_drop and ifx_source_exists and count_newmetrics|int > 0

- name: '{{ db_prefix }} Get backfill points written'
set_fact:
Expand Down
3 changes: 3 additions & 0 deletions tests/vars/compact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# backfill 4 days, then make new RP default and drop old RP
ansible_influx_databases:
level_0:
name: "telegraf"
retention_policy: { name: "autogen" }
level_1:
name: "telegraf"
retention_policy:
amount: "4"
Expand Down

0 comments on commit 640b259

Please sign in to comment.