-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathtest_opentsdb.sh
executable file
·131 lines (116 loc) · 3.79 KB
/
test_opentsdb.sh
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
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2016-10-10 11:54:19 +0100 (Mon, 10 Oct 2016)
#
# https://github.com/HariSekhon/DevOps-Python-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn
# and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$srcdir/.."
# shellcheck disable=SC1090
. "$srcdir/utils.sh"
echo "
# ============================================================================ #
# O p e n T S D B
# ============================================================================ #
"
OPENTSDB_HOST="${DOCKER_HOST:-${OPENTSDB_HOST:-${HOST:-localhost}}}"
OPENTSDB_HOST="${OPENTSDB_HOST##*/}"
OPENTSDB_HOST="${OPENTSDB_HOST%%:*}"
export OPENTSDB_HOST
export HBASE_STARGATE_PORT=8080
export HBASE_THRIFT_PORT=9090
export ZOOKEEPER_PORT=2181
export OPENTSDB_PORTS="$ZOOKEEPER_PORT $HBASE_STARGATE_PORT 8085 $HBASE_THRIFT_PORT 9095 3000 16000 16010 16201 16301"
export OPENTSDB_TEST_PORTS="$ZOOKEEPER_PORT $HBASE_THRIFT_PORT 3000"
export OPENTSDB_VERSIONS="${*:-latest}"
#export DOCKER_IMAGE="opower/opentsdb"
#export DOCKER_IMAGE="petergrace/opentsdb-docker"
export DOCKER_CONTAINER="opentsdb-test"
export DATA_FILE='tests/data/opentsdb_data.txt'
#if ! is_docker_available; then
# echo "WARNING: Docker not available, skipping OpenTSDB checks"
# exit 0
#fi
startupwait 50
generate_test_data(){
if [ -f "$DATA_FILE" ]; then
echo "data file '$DATA_FILE' already exists, not regenerating"
return
fi
echo "generating opentsdb test data => $DATA_FILE"
local chars
local ts
local metric
#chars="$(echo {A..Z} {a..z} {0..9})"
chars=$(echo {A..Z} | tr -d ' ')
ts="$(date '+%s')"
# shellcheck disable=SC2034
for x in {1..100}; do
# shellcheck disable=SC2034
for y in {1..1000}; do
metric="metric${chars:$((RANDOM % ${#chars})):1}"
for z in {1..5}; do
echo "ship${RANDOM:0:3} $((ts + RANDOM)) $RANDOM id=$metric crew=$z"
done
done
done > "$DATA_FILE"
}
generate_test_data
test_opentsdb(){
local version="$1"
#hr
#echo "Setting up OpenTSDB $version test container"
#hr
#local DOCKER_OPTS="-v $srcdir/..:$MNTDIR"
#launch_container "$DOCKER_IMAGE:$version" "$DOCKER_CONTAINER" 2181 8080 8085 9090 9095 16000 16010 16201 16301
#when_ports_available $startupwait $OPENTSDB_HOST $OPENTSDB_TEST_PORTS
if [ -n "${NOTESTS:-}" ]; then
return
fi
hr
echo "testing from data file:"
./opentsdb_import_metric_distribution.py -K 1 -vv "$DATA_FILE"
hr
echo "testing from STDIN:"
./opentsdb_import_metric_distribution.py -K 2 -vv - < "$DATA_FILE"
hr
echo "testing including timestamps:"
./opentsdb_import_metric_distribution.py -K 22 -vv --include-timestamps "$DATA_FILE"
hr
echo "testing reverse sort on count:"
./opentsdb_import_metric_distribution.py -K 3 -d "$DATA_FILE"
hr
echo "testing skipping error lines:"
./opentsdb_import_metric_distribution.py -K 4 --skip-errors - <<EOF
shipCustom $(date +%s) 10 id=metric1
made up error line
EOF
hr
echo "testing from data file and STDIN at the same time:"
# shellcheck disable=SC2094
./opentsdb_import_metric_distribution.py --key-prefix-length 7 "$DATA_FILE" - < "$DATA_FILE"
hr
#delete_container
echo
}
for version in $OPENTSDB_VERSIONS; do
test_opentsdb "$version"
done
if [ -z "${NODELETE:-}" ]; then
echo -n "removing test data: "
rm -vf "$DATA_FILE"
echo; echo
fi
echo "All OpenTSDB tests succeeded"
echo