hbase-exporter/tests/test_hbase_exporter.sh

140 lines
4.5 KiB
Bash
Raw Normal View History

2021-03-03 18:00:03 +00:00
#!/usr/bin/env bash
2021-03-09 19:15:25 +00:00
SETUP_HBASE=false
SETUP_HADOOP=true
2021-03-04 20:00:10 +00:00
HBASE_TIME_STARTUP=15
HBASE_EXPORTER_TIME_STARTUP=60
2021-03-07 22:53:00 +00:00
HADOOP_CONFIG_DIR="hadoop/etc/hadoop"
2021-03-03 18:00:03 +00:00
2021-03-03 21:16:55 +00:00
setup_suite() {
2021-03-07 02:34:18 +00:00
if [ "FreeBSD" = "$(uname)" ]; then
2021-03-07 02:31:29 +00:00
export JAVA_HOME=${JAVA_HOME:-"/usr/local"}
else
export JAVA_HOME=${JAVA_HOME:-"/"}
fi
2021-03-06 21:37:01 +00:00
export HADOOP_PREFIX="$(pwd)/hadoop"
2021-03-04 20:00:10 +00:00
2021-03-09 19:15:25 +00:00
cd ansible-hadoop/ || exit 1
2021-03-08 00:41:14 +00:00
2021-03-09 19:15:25 +00:00
SCRIPT_PATH=$(dirname "$0")
source $SCRIPT_PATH/ansible-hadoop/setup.sh
2021-03-06 21:37:01 +00:00
2021-03-09 19:15:25 +00:00
# Setup Hadoop
if [ true = "$SETUP_HADOOP" ]; then
if ! ansible-playbook -i inventory.yml \
-e hadoop_path="/tmp" \
-e hdfs_cluster_id="test-cluster" \
hdfs-create.yml; then
2021-03-07 22:53:00 +00:00
2021-03-09 19:15:25 +00:00
printf "Failed to setup HDFS to run test suite\n"
exit 1
fi
2021-03-06 21:37:01 +00:00
fi
2021-03-09 19:15:25 +00:00
# Setup HBase
if [ true = "$SETUP_HBASE" ]; then
if ! ansible-playbook -i inventory.yml \
-e hbase_path="/tmp" \
hbase-create.yml; then
printf "Failed to setup HBase to run test suite\n"
exit 1
fi
2021-03-06 21:37:01 +00:00
fi
2021-03-03 21:16:55 +00:00
2021-03-09 19:15:25 +00:00
# Start hdfs
2021-03-06 21:37:01 +00:00
# Start HBase
2021-03-04 20:00:10 +00:00
2021-03-06 21:37:01 +00:00
# Start exporter
run_exporter
printf "Waiting %ss to gather exporter values\n" ${HBASE_EXPORTER_TIME_STARTUP}
sleep $HBASE_EXPORTER_TIME_STARTUP
}
run_exporter() {
2021-03-06 00:19:31 +00:00
cd ../../ || exit
2021-03-04 20:00:10 +00:00
printf "Starting hbase-exporter\n"
2021-03-06 00:19:31 +00:00
./hbase-exporter --zookeeper-server="${ZK_SERVER:-"127.0.0.1"}" \
2021-03-05 00:01:03 +00:00
--hbase-pseudo-distributed=True \
2021-03-06 01:55:42 +00:00
--hbase-table="foo" > /dev/null 2>&1 &
2021-03-04 20:00:10 +00:00
PID=$!
2021-03-06 21:37:01 +00:00
}
test_hdfs_up() {
assert "curl -s http://127.0.0.1:50070 > /dev/null" "HDFS: Namenode ui down"
assert "curl -s http://127.0.0.1:8021 > /dev/null" "HDFS: IPC down"
2021-03-03 18:00:03 +00:00
}
test_hbase_running() {
2021-03-06 21:37:01 +00:00
assert "nc -n -w1 \"${1:-\"127.0.0.1\"}\" \"${2:-\"16010\"}\"" "HBase: Not running"
2021-03-03 18:00:03 +00:00
}
test_hbase_zk_running() {
2021-03-06 00:19:31 +00:00
r=$(echo ruok | nc -n -w1 "${1:-"127.0.0.1"}" "${2:-"2181"}")
2021-03-06 01:55:42 +00:00
assert_equals "imok" "$r" "Zookeeper: Unhealthy"
2021-03-04 20:00:10 +00:00
}
test_hbase_exporter_up() {
2021-03-06 01:55:42 +00:00
assert "curl -s http://127.0.0.1:9010 > /dev/null" "exporter: Could not GET export via Curl"
2021-03-04 20:00:10 +00:00
}
test_hbase_exporter_export_zk_live() {
r=$(curl -s http://127.0.0.1:9010 | grep '^zookeeper_num_live' | cut -d " " -f2)
2021-03-06 01:55:42 +00:00
assert_not_equals "0.0" "$r" "exporter: Zookeeper not live"
assert_not_equals "" "$r" "exporter: Zookeeper not live"
2021-03-04 20:00:10 +00:00
}
2021-03-05 00:01:03 +00:00
test_hbase_exporter_export_hbase_up() {
r=$(curl -s http://127.0.0.1:9010 | grep '^hbase_up' | cut -d " " -f2)
2021-03-06 01:55:42 +00:00
assert_not_equals "0.0" "$r" "exporter: HBase down"
assert_not_equals "" "$r" "exporter: HBase down"
2021-03-05 00:01:03 +00:00
}
test_hbase_exporter_export_zk_connection_count() {
r=$(curl -s http://127.0.0.1:9010 | grep '^zookeeper_num_connections' | cut -d " " -f2)
2021-03-06 01:55:42 +00:00
assert_not_equals "0.0" "$r" "exporter: Zookeeper has no connections"
assert_not_equals "" "$r" "exporter: Zookeeper has no connections"
2021-03-05 00:01:03 +00:00
}
2021-03-05 23:59:54 +00:00
test_hbase_exporter_export_zk_has_leader() {
r=$(curl -s http://127.0.0.1:9010 | grep '^zookeeper_has_leader' | cut -d " " -f2)
2021-03-06 21:37:01 +00:00
assert_not_equals "0.0" "$r" "exporter: Zookeeper has no leader"
assert_not_equals "" "$r" "exporter: Zookeeper has no leader"
2021-03-05 23:59:54 +00:00
}
test_hbase_exporter_export_regionserver_live() {
r=$(curl -s http://127.0.0.1:9010 | grep '^hbase_regionservers_live' | cut -d " " -f2)
2021-03-06 01:55:42 +00:00
assert_not_equals "0.0" "$r" "exporter: HBase - No regionservers"
assert_not_equals "" "$r" "exporter: HBase - No regionservers"
2021-03-05 23:59:54 +00:00
}
test_hbase_exporter_export_regionserver_dead() {
r=$(curl -s http://127.0.0.1:9010 | grep '^hbase_regionservers_dead' | cut -d " " -f2)
2021-03-06 01:55:42 +00:00
assert_equals "0.0" "$r" "exporter: HBase - Dead regionservers"
assert_not_equals "" "$r" "exporter: HBase - Dead regionservers"
2021-03-05 23:59:54 +00:00
}
2021-03-06 21:37:01 +00:00
test_hbase_exporter_export_hdfs_datanodes_live() {
r=$(curl -s http://127.0.0.1:9010 | grep '^hdfs_datanodes_live' | cut -d " " -f2)
assert_not_equals "0.0" "$r" "exporter: HDFS - No data nodes"
assert_not_equals "" "$r" "exporter: HDFS - No data nodes"
}
test_hbase_exporter_export_hdfs_datanodes_dead() {
r=$(curl -s http://127.0.0.1:9010 | grep '^hdfs_datanodes_dead' | cut -d " " -f2)
assert_equals "0.0" "$r" "exporter: HDFS - Dead data nodes"
assert_not_equals "" "$r" "exporter: HDFS - Dead data nodes"
}
2021-03-04 20:00:10 +00:00
teardown_suite() {
2021-03-06 01:55:42 +00:00
printf "Stopping hbase-exporter (%s)\n" "$PID"
2021-03-06 21:37:01 +00:00
if ! kill $PID > /dev/null 2>&1; then
printf "Failed to send SIGTERM to %s\n" "$PID"
fi
printf "Stopping HBase\n"
2021-03-05 00:13:18 +00:00
./tests/hbase/bin/hbase-daemon.sh stop master
2021-03-03 18:00:03 +00:00
}