Skip to content

Commit

Permalink
Paramaterize Prometheus integration test to use for local testing (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
robskillington authored Sep 21, 2018
1 parent bf62df3 commit b2d4ba4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 47 deletions.
8 changes: 8 additions & 0 deletions scripts/integration-tests/prometheus/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,13 @@ services:
image: prom/prometheus:latest
volumes:
- "./:/etc/prometheus/"
grafana:
expose:
- "3000"
ports:
- "0.0.0.0:3000:3000"
networks:
- backend
image: grafana/grafana:latest
networks:
backend:
106 changes: 59 additions & 47 deletions scripts/integration-tests/prometheus/prometheus-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ set -xe
rm -rf /tmp/m3dbdata/
mkdir -p /tmp/m3dbdata/

echo "Build docker images"
PARAM_TEST_BUILD="${TEST_BUILD:-true}"
PARAM_TEST_VERIFY="${TEST_VERIFY:-true}"
PARAM_TEST_TEARDOWN="${TEST_TEARDOWN:-true}"

docker-compose -f docker-compose.yml build
if [ $PARAM_TEST_BUILD != "true" ]; then
echo "SKIP build docker images"
else
echo "Build docker images"
docker-compose -f docker-compose.yml build
fi

echo "Run m3dbnode and m3coordinator containers"

Expand Down Expand Up @@ -78,56 +85,61 @@ echo "Start Prometheus container"

docker-compose -f docker-compose.yml up -d prometheus01

sleep 10

echo "Write data"

curl -vvvsSf -X POST localhost:9003/writetagged -d '{
"namespace": "prometheus_metrics",
"id": "foo",
"tags": [
{
"name": "city",
"value": "new_york"
},
{
"name": "endpoint",
"value": "/request"
if [ $PARAM_TEST_VERIFY != "true" ]; then
echo "SKIP verify"
else
echo "Write direct test data"

curl -vvvsSf -X POST localhost:9003/writetagged -d '{
"namespace": "prometheus_metrics",
"id": "foo",
"tags": [
{
"name": "city",
"value": "new_york"
},
{
"name": "endpoint",
"value": "/request"
}
],
"datapoint": {
"timestamp":'"$(date +"%s")"',
"value": 42.123456789
}
],
"datapoint": {
"timestamp":'"$(date +"%s")"',
"value": 42.123456789
}
}'
}'

echo "Read data"
echo "Read direct test data"

queryResult=$(curl -sSf -X POST localhost:9003/query -d '{
"namespace": "prometheus_metrics",
"query": {
"regexp": {
"field": "city",
"regexp": ".*"
}
},
"rangeStart": 0,
"rangeEnd":'"$(date +"%s")"'
}' | jq '.results | length')

if [ "$queryResult" -lt 1 ]; then
echo "Result not found"
exit 1
else
echo "Result found"
fi
queryResult=$(curl -sSf -X POST localhost:9003/query -d '{
"namespace": "prometheus_metrics",
"query": {
"regexp": {
"field": "city",
"regexp": ".*"
}
},
"rangeStart": 0,
"rangeEnd":'"$(date +"%s")"'
}' | jq '.results | length')

echo "Sleep for 30 seconds to let the remote write endpoint generate some data"
if [ "$queryResult" -lt 1 ]; then
echo "Result not found"
exit 1
else
echo "Result found"
fi

sleep 30
echo "Sleep for 30 seconds to let the remote write endpoint generate some data"

# Ensure Prometheus can proxy a Prometheus query
[ "$(curl -sSf localhost:9090/api/v1/query?query=prometheus_remote_storage_succeeded_samples_total | jq .data.result[].value[1])" != '"0"' ]
sleep 30

# Ensure Prometheus can proxy a Prometheus query
[ "$(curl -sSf localhost:9090/api/v1/query?query=prometheus_remote_storage_succeeded_samples_total | jq .data.result[].value[1])" != '"0"' ]
fi

docker-compose -f docker-compose.yml down || echo "unable to shutdown containers" # CI fails to stop all containers sometimes
if [ $PARAM_TEST_TEARDOWN != "true" ]; then
echo "SKIP teardown"
else
docker-compose -f docker-compose.yml down || echo "unable to shutdown containers" # CI fails to stop all containers sometimes
fi
4 changes: 4 additions & 0 deletions scripts/integration-tests/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ scrape_configs:
static_configs:
- targets: ['coordinator01:7203']

- job_name: 'dbnode'
static_configs:
- targets: ['dbnode01:9004']

remote_read:
- url: http://coordinator01:7201/api/v1/prom/remote/read

Expand Down

0 comments on commit b2d4ba4

Please sign in to comment.