Skip to content

Commit

Permalink
minor integration improvements (#6)
Browse files Browse the repository at this point in the history
* add 'inputs.ping' defaults
* fix lint warnings (ansible-galaxy)
* try test query 3 times
* add debug to tests
* increase cq interval
  • Loading branch information
DrPsychick authored Jan 21, 2019
1 parent fec18aa commit 7c955fd
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 245 deletions.
2 changes: 2 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
skip_list:
- '602'
26 changes: 21 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ before_install:
install:
# start influxdb (will take some time to be reachable!)
- rm -rf $PWD/integration/influxdb/*
- docker run --rm -d --name influxdb -p 8086:8086 -v $PWD/integration/influxdb:/var/lib/influxdb influxdb:alpine
- >
docker run --rm -d --name influxdb -p 8086:8086 -v $PWD/integration/influxdb:/var/lib/influxdb influxdb:alpine;
sleep 10;
docker logs influxdb
# start telegraf to continuously write data to influxdb
- >
if [ "$TEST" = "setup" -o "$TEST" = "compact" ]; then
docker run --rm -d --net host --privileged --name telegraf telegraf:alpine;
sleep 10;
docker run --rm -d --net host --privileged --name telegraf telegraf:alpine telegraf --debug;
sleep 12;
docker logs telegraf;
fi
Expand Down Expand Up @@ -75,12 +78,16 @@ script:
# TEST = setup (wait for CQ to run)
- >
if [ "$TEST" = "setup" ]; then
sleep 25;
sleep 15;
curl http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT ROUND(MEAN(usage_user)) AS usage_user FROM $db_name.$rp_name.cpu WHERE time >= now() -1m" | jq .;
for i in 1 2 3; do
result=$(curl http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT ROUND(MEAN(usage_user)) AS usage_user FROM $db_name.$rp_name.cpu WHERE time >= now() -1m"
| jq .results[0].series[0].values[0][1]);
[ "null" != "$result" ] && break;
sleep 5;
done;
[ "$result" -gt 0 ]
&& (echo -e "Setup test: ${GREEN}pass${NC}"; exit 0)
|| (echo -e -e "Setup test: ${RED}fail${NC} ($result)"; exit 1);
Expand Down Expand Up @@ -142,8 +149,18 @@ after_script:
- docker logs influxdb;
- >
if [ "$TEST" = "setup" ]; then
echo "$db_name.$rp_name:";
curl http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT usage_user FROM $db_name.$rp_name.cpu" | jq .;
now=$(date -u +%Y-%m-%dT%H:%M:%SZ);
now_5s=$(date -u -d-5seconds +%Y-%m-%dT%H:%M:%SZ);
curl http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT mean(usage_user) FROM telegraf.rp_7d.cpu
WHERE time >= '$now_5s' AND time < '$now' GROUP BY time(5s, 1s), *" | jq .;
curl http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT mean(usage_user) FROM telegraf.rp_7d.cpu
WHERE time >= '$now_5s' AND time < '$now' GROUP BY time(10s, 1s), *" | jq .;
echo "telegraf.rp_7d:";
curl http://localhost:8086/query?db=telegraf --data-urlencode
"q=SELECT usage_user FROM telegraf.rp_7d.cpu" | jq .;
fi
Expand All @@ -159,4 +176,3 @@ after_script:
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---

ansible_influx_url: "http://localhost:8086"
ansible_influx_timeout: 120
Expand Down Expand Up @@ -86,6 +87,10 @@ ansible_influx_queries:
, mean(TcpInSegs) AS TcpInSegs, mean(TcpMaxConn) AS TcpMaxConn, mean(TcpOutSegs) AS TcpOutSegs
, mean(TcpRtoAlgorithm) AS TcpRtoAlgorithm, mean(TcpRtoMax) AS TcpRtoMax, mean(TcpRtoMin) AS TcpRtoMin
, mean(UdpInDatagrams) AS UdpInDatagrams, mean(UdpOutDatagrams) AS UdpOutDatagrams
ping: >
SELECT max(maximum_response_ms) AS maximum_response_ms, mean(average_response_ms) AS average_response_ms, min(minimum_response_ms) AS minimum_response_ms
, mean(packets_received) AS packets_received, mean(packets_transmitted) AS packets_transmitted, mean(percent_packet_loss) AS percent_packet_loss
, median(result_code) AS result_code, mean(standard_deviation_ms) AS standard_deviation_ms
procstat: >
SELECT mean(cpu_time_guest) AS cpu_time_guest, mean(cpu_time_guest_nice) AS cpu_time_guest_nice, mean(cpu_time_idle) AS cpu_time_idle
, mean(cpu_time_iowait) AS cpu_time_iowait, mean(cpu_time_irq) AS cpu_time_irq, mean(cpu_time_nice) AS cpu_time_nice, mean(cpu_time_soft_irq) AS cpu_time_soft_irq
Expand Down
293 changes: 163 additions & 130 deletions tasks/influxdb_database.yml

Large diffs are not rendered by default.

192 changes: 98 additions & 94 deletions tasks/influxdb_measurement.yml

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,45 @@

- name: Set variables
set_fact:
ifx_start: "{{lookup('pipe', 'date +%s')}}"
ifx_start: "{{ lookup('pipe', 'date +%s') }}"

- name: Get databases
uri: url="{{ansible_influx_url}}/query" method=POST body="q=SHOW DATABASES" return_content=yes
uri: url="{{ ansible_influx_url }}/query" method=POST body="q=SHOW DATABASES" return_content=yes
register: ansible_influx_dbs
changed_when: false
failed_when: ansible_influx_dbs.status != 200 or (ansible_influx_dbs.rc|default(0) == 1)
or (ansible_influx_dbs.json is defined and ansible_influx_dbs.json.results[0].error is defined)

- name: Set facts
set_fact:
ifx_dbs: "{{ansible_influx_dbs.json.results
ifx_dbs: "{{ ansible_influx_dbs.json.results
|selectattr('series','defined')|map(attribute='series')|flatten
|map(attribute='values')|flatten}}"
ansible_influx_queries: "{{ansible_influx_queries|combine(my_ansible_influx_queries|default({}))}}"
recreate_cqs: "{{recreate_cqs|default(false)}}"
|map(attribute='values')|flatten }}"
ansible_influx_queries: "{{ ansible_influx_queries|combine(my_ansible_influx_queries|default({})) }}"
recreate_cqs: "{{ recreate_cqs|default(false) }}"

# needed to check if RP needs to be created
- name: Show continuous queries
uri: url="{{ansible_influx_url}}/query" method=POST body="q=SHOW CONTINUOUS QUERIES" return_content=yes
uri: url="{{ ansible_influx_url }}/query" method=POST body="q=SHOW CONTINUOUS QUERIES" return_content=yes
register: ansible_influx_cqs
changed_when: false
failed_when: (ansible_influx_cqs.rc|default(0) == 1)
or (ansible_influx_cqs.json is defined and ansible_influx_cqs.json.results[0].error is defined)

- set_fact:
ifx_cqs: "{{ansible_influx_cqs.json.results
- name: Set facts
set_fact:
ifx_cqs: "{{ ansible_influx_cqs.json.results
|selectattr('series', 'defined')|map(attribute='series')|flatten
|rejectattr('values', 'callable')|map(attribute='values')|flatten
|select('match', '^(?!CREATE).*') |list
if ansible_influx_cqs.json.results is defined else []}}"
if ansible_influx_cqs.json.results is defined else [] }}"

- name: Setup databases
include_tasks: influxdb_database.yml # no longer supported: database={{db_item}}
with_items: "{{ansible_influx_databases|sort}}"
include_tasks: influxdb_database.yml # no longer supported: database={{ db_item }}
with_items: "{{ ansible_influx_databases|sort }}"
vars:
database: "{{db_item}}"
database: "{{ db_item }}"
loop_control: { loop_var: db_item }

- name: Total duration
debug: msg="Total duration (all levels) = {{(lookup('pipe', 'date +%s')|int - ifx_start|int)/60}} minutes"
debug: msg="Total duration (all levels) = {{ (lookup('pipe', 'date +%s')|int - ifx_start|int)/60 }} minutes"
1 change: 0 additions & 1 deletion tests/vars/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ ansible_influx_databases:
amount: "4"
unit: "d"
default: true

2 changes: 1 addition & 1 deletion tests/vars/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ ansible_influx_databases:
name: "telegraf_30d"
retention_policy: { amount: "30", unit: "d", default: true }
source: { name: "telegraf" }
continuous_query: { interval: "5s", offset: "1s" }
continuous_query: { interval: "10s", offset: "1s" }
measurements: { cpu, mem }

0 comments on commit 7c955fd

Please sign in to comment.