-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.travis.yml
177 lines (161 loc) · 7.59 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
os: linux
dist: bionic
language: python
cache: pip
services:
- docker
env:
global:
- GREEN='\033[0;32m'
- RED='\033[0;31m'
- NC='\033[0m' # No Color
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
- TEST=compact db_name=telegraf rp_name=rp_4d
before_install:
# Make sure everything's up to date.
#- sudo apt-get update -qq
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:1.8-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 telegraf --debug;
sleep 5;
docker logs telegraf;
fi
# Install ansible and jq.
- pip3 install -U ansible jq
# Add ansible.cfg to pick up roles path.
- printf "[defaults]\nroles_path = ../" > ansible.cfg
# Seed influxdb (after pip, so influxdb will be reachable)
- >
if [ "$TEST" = "migrate" ]; then
./tests/seed.sh 1m 10s "$(date -d -1hour +"%Y-%m-%d %H:%M:00")" seq+step10;
fi
script:
# Check the role/playbook's syntax.
- ansible-playbook -i tests/inventory tests/test.yml --syntax-check
# Run the role/playbook with ansible-playbook.
- 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)
- >
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
- >
if [ "$TEST" = "basic" ]; then
result=$(curl http://localhost:8086/query?db=$db_name --data-urlencode
"q=SHOW RETENTION POLICIES" | jq .results[0].series[0].values[1][0] |tr -d '"');
[ "$result" = "$rp_name" ]
&& (echo -e "Retention policy test: ${GREEN}pass${NC}"; exit 0)
|| (echo -e -e "Retention policy test: ${RED}fail${NC} ('$result' != '$rp_name')"; exit 1);
fi
# TEST = setup (wait for CQ to run)
- >
if [ "$TEST" = "setup" ]; then
for i in 1 2 3 4 5 6; 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]);
echo "$i: $result";
[ "null" != "$result" ] && break;
sleep 5;
done;
echo "Loops (5s) needed: $i";
[ "$result" -gt 0 ]
&& (echo -e "Setup test: ${GREEN}pass${NC}"; exit 0)
|| (echo -e -e "Setup test: ${RED}fail${NC} ($result)"; exit 1);
fi
# TEST = migrate
- >
if [ "$TEST" = "migrate" ]; then
curl -s http://localhost:8086/query?db=$db_name --data-urlencode "q=SELECT * FROM $db_name.$rp_name.test";
result=$(curl -s http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT * FROM $db_name.$rp_name.test" | jq .results[0].series[0].values[0][1]);
[ "$result" = "35" ]
&& (echo -e "Aggregation test: ${GREEN}pass${NC}"; exit 0)
|| (echo -e "Aggregation test: ${RED}fail${NC}ed: ('$result' != 35)"; exit 1);
curl -s http://localhost:8086/query?db=$db_name --data-urlencode
"q=SHOW CONTINUOUS QUERIES" | jq . | grep 'cq_cpu_';
sed -i -e 's#^\( *interval: "\)1m\(".*\)$#\130s\2#' -e 's#^\(.*every: "\)1m\(".*\)$#\130s\2#' ./tests/vars/migrate.yml;
ansible-playbook -i tests/inventory tests/test.yml --connection=local --extra-vars=recreate_cqs=yes 2>&1
| grep -A1 -e 'Drop continuous';
result=$(curl -s http://localhost:8086/query?db=$db_name --data-urlencode
"q=SHOW CONTINUOUS QUERIES" | jq .);
result1="$(echo "$result" | grep "_30s")";
result2="$(echo "$result" | grep "_1m")";
[ -n "$result1" ]
&& (echo -e "CQ update test: ${GREEN}pass${NC} (new CQ exists)"; exit 0)
|| (echo -e "CQ update test: ${RED}fail${NC} (new CQ does not exist)"; exit 1);
[ -z "$result2" ]
&& (echo -e "CQ update test: ${GREEN}pass${NC} (old CQ is gone)"; exit 0)
|| (echo -e "CQ update test: ${RED}fail${NC} (old CQ still exists = $result2)"; exit 1);
fi
# TEST = compact
- >
if [ "$TEST" = "compact" ]; then
result1=$(curl -s http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT MEAN(usage_user) AS usage_user FROM $db_name.$rp_name.cpu" | jq .results[0].series[0].values[0][1]);
curl -s http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT MEAN(usage_user) AS usage_user FROM $db_name..cpu";
result2=$(curl -s http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT MEAN(usage_user) AS usage_user FROM $db_name..cpu" | jq .results[0].series[0].values[0][1]);
[ "$result1" = "$result2" ]
&& (echo -e "Compact test: ${GREEN}pass${NC} (new RP is default)"; exit 0)
|| (echo -e -e "Compact test: ${RED}fail${NC} (new RP is not default):\n$result1 != $result2"; exit 1);
curl -s http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT MEAN(usage_user) AS usage_user FROM $db_name.autogen.cpu";
result3=$(curl -s http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT MEAN(usage_user) AS usage_user FROM $db_name.autogen.cpu" | jq .results[0].error);
[ -n "$result3" ]
&& (echo -e "Compact test: ${GREEN}pass${NC} (source is gone)"; exit 0)
|| (echo -e "Compact test: ${RED}fail${NC} (source still exists)"; exit 1);
fi
after_script:
- curl http://localhost:8086/query?db=$db_name --data-urlencode "q=SHOW DATABASES";
- curl http://localhost:8086/query?db=$db_name --data-urlencode "q=SHOW RETENTION POLICIES";
- curl http://localhost:8086/query?db=$db_name --data-urlencode "q=SHOW CONTINUOUS QUERIES";
- curl http://localhost:8086/query?db=$db_name --data-urlencode "q=SHOW MEASUREMENTS";
- docker logs telegraf;
- 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 .;
echo "telegraf.rp_7d: (CQ)";
curl http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT mean(usage_user) FROM telegraf.rp_7d.cpu
WHERE time >= now() - 20s AND time < now() - 10s 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() - 20s AND time < now() - 10s 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
- >
if [ "$TEST" = "migrate" ]; then
curl http://localhost:8086/query?db=$db_name_source --data-urlencode
"q=SELECT * FROM $db_name_source.autogen.test" | jq .results[0].series[0];
curl http://localhost:8086/query?db=$db_name_source --data-urlencode
"q=SELECT MEAN(value) FROM $db_name_source.autogen.test" | jq .results[0].series[0];
curl http://localhost:8086/query?db=$db_name --data-urlencode
"q=SELECT MEAN(value) FROM $db_name.$rp_name.test" | jq .results[0].series[0];
fi
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/