Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benraskin92 committed Dec 2, 2019
1 parent 7a50808 commit 5f7bc6b
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@ services:
image: "m3coordinator_integration:${REVISION}"
volumes:
- "./:/etc/m3coordinator/"
prometheus01:
expose:
- "9090"
ports:
- "0.0.0.0:9090:9090"
networks:
- backend
image: prom/prometheus:latest
volumes:
- "./prometheus.yml:/etc/prometheus/prometheus.yml"
networks:
backend:
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,29 @@ clusters:

downsample:
rules:
# mappingRules:
# - filter: "foo:bar"
# aggregation:
# - 2
# storagePolicies:
# - retention: 12h
# resolution: 10s
# drop: false
rollupRules:
mappingRules:
- filter: "foo:bar"
transforms:
- rollup:
metricName: "new_metric"
aggregate:
type: Sum
aggregations:
- Sum
storagePolicies:
- retention: 10h
resolution: 5s
name: "testRollup"
drop: false
# rollupRules:
# - filter: "foo:bar"
# transforms:
# - rollup:
# metricName: "new_metric"
# aggregations:
# - Sum
# groupBy:
# - foo
# # aggregate:
# # type: Sum
# storagePolicies:
# - retention: 10h
# resolution: 5s
# name: "testRollup"


tagOptions:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# my global config
global:
external_labels:
role: "remote"
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

static_configs:
- targets: ['localhost:9090']

- job_name: 'coordinator'
static_configs:
- targets: ['coordinator01:7203']

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

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

remote_write:
- url: http://coordinator01:7201/api/v1/prom/remote/write
78 changes: 59 additions & 19 deletions scripts/docker-integration-tests/coordinator_config_rules/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,35 @@
set -xe

source $GOPATH/src/github.com/m3db/m3/scripts/docker-integration-tests/common.sh
source $GOPATH/src/github.com/m3db/m3/scripts/docker-integration-tests/prometheus/test-correctness.sh
REVISION=$(git rev-parse HEAD)
SCRIPT_PATH=$GOPATH/src/github.com/m3db/m3/scripts/docker-integration-tests/coordinator_config_rules
COMPOSE_FILE=$SCRIPT_PATH/docker-compose.yml
EXPECTED_PATH=$SCRIPT_PATH/expected
METRIC_NAME_TEST_OLD=foo
COMPOSE_FILE=$GOPATH/src/github.com/m3db/m3/scripts/docker-integration-tests/coordinator_config_rules/docker-compose.yml
# quay.io/m3db/prometheus_remote_client_golang @ v0.4.3
PROMREMOTECLI_IMAGE=quay.io/m3db/prometheus_remote_client_golang@sha256:fc56df819bff9a5a087484804acf3a584dd4a78c68900c31a28896ed66ca7e7b
JQ_IMAGE=realguess/jq:1.4@sha256:300c5d9fb1d74154248d155ce182e207cf6630acccbaadd0168e18b15bfaa786
METRIC_NAME_TEST_TOO_OLD=foo
METRIC_NAME_OLD=old_metric
METRIC_NAME_NEW=new_metric
export REVISION

echo "Pull containers required for test"
docker pull $PROMREMOTECLI_IMAGE
docker pull $JQ_IMAGE

echo "Run m3dbnode and m3coordinator containers"
docker-compose -f ${COMPOSE_FILE} up -d dbnode01
docker-compose -f ${COMPOSE_FILE} up -d coordinator01

# Think of this as a defer func() in golang
function defer {
docker-compose -f ${COMPOSE_FILE} down || echo "unable to shutdown containers" # CI fails to stop all containers sometimes
}
trap defer EXIT

setup_single_m3db_node

echo "Start Prometheus containers"
docker-compose -f ${COMPOSE_FILE} up -d prometheus01

function prometheus_remote_write {
local metric_name=$1
local datapoint_timestamp=$2
Expand All @@ -34,37 +44,49 @@ function prometheus_remote_write {
local metrics_storage_policy=$9

network=$(docker network ls --format '{{.ID}}' | tail -n 1)
out=$((docker run -it --rm --network $network \
out=$((docker run -it --rm --network coordinator_config_rules_backend \
$PROMREMOTECLI_IMAGE \
-u http://coordinator01:7201/api/v1/prom/remote/write \
-t __name__:${metric_name} \
-t foo:bar
-t foo:bar \
-h "M3-Metrics-Type: ${metrics_type}" \
-h "M3-Storage-Policy: ${metrics_storage_policy}" \
-d ${datapoint_timestamp},${datapoint_value} | grep -v promremotecli_log) || true)
success=$(echo $out | grep -v promremotecli_log | docker run --rm -i $JQ_IMAGE jq .success)
status=$(echo $out | grep -v promremotecli_log | docker run --rm -i $JQ_IMAGE jq .statusCode)
if [[ "$success" != "$expect_success" ]]; then
echo $expect_success_err
sleep 10000000
return 1
fi
if [[ "$status" != "$expect_status" ]]; then
echo "${expect_status_err}: actual=${status}"
sleep 10000000
return 1
fi
echo "Returned success=${success}, status=${status} as expected"
return 0
}
function prometheus_write_metric {
echo "Test write with aggregated metrics type works as expected"
function test_prometheus_remote_write_restrict_metrics_type {
# Test we can specify metrics type
echo "Test write with unaggregated metrics type works as expected"
prometheus_remote_write \
old_metric now 84.84 \
$METRIC_NAME_NEW now 42.42 \
true "Expected request to succeed" \
200 "Expected request to return status code 200" \
aggregated 15s:10h
unaggregated
# echo "Test write with aggregated metrics type works as expected"
# prometheus_remote_write \
# $METRIC_NAME_OLD now 84.84 \
# true "Expected request to succeed" \
# 200 "Expected request to return status code 200" \
# aggregated 5s:10h
}
function prometheus_query_native {
local endpoint=${endpoint:-}
local query=${query:-}
Expand All @@ -87,22 +109,40 @@ function prometheus_query_native {
return $?
}
function test_query_rollup_rule {
function test_query_new_name {
now=$(date +"%s")
hour_ago=$(expr $now - 3600)
step="30s"
params_instant=""
params_range="start=${hour_ago}"'&'"end=${now}"'&'"step=30s"
jq_path_instant=".data.result[0].value[1]"
jq_path_range=".data.result[0].metric[\"__name__\"]"
jq_path_range=".data.result[0].values[][1]"
# # Test metric name is changed
# echo "Test query restrict to unaggregated metrics type (instant)"
# ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 \
# endpoint=query query="$METRIC_NAME_NEW" params="$params_instant" \
# metrics_type="unaggregated" jq_path="$jq_path_instant" expected_value="42.42" \
# retry_with_backoff prometheus_query_native
# echo "Test query restrict to unaggregated metrics type (range)"
# ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 \
# endpoint=query_range query="$METRIC_NAME_NEW" params="$params_range" \
# metrics_type="unaggregated" jq_path="$jq_path_range" expected_value="42.42" \
# retry_with_backoff prometheus_query_native
echo "Test query rollup rule"
# Test restricting to aggregated metrics
# echo "Test query restrict to aggregated metrics type (instant)"
# ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 \
# endpoint=query query="$METRIC_NAME_NEW" params="$params_instant" \
# metrics_type="aggregated" metrics_storage_policy="5s:10h" jq_path="$jq_path_instant" expected_value="84.84" \
# retry_with_backoff prometheus_query_native
echo "Test query restrict to aggregated metrics type (range)"
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 \
endpoint=query_range query=new_metric params="$params_range" \
metrics_type="aggregated" metrics_storage_policy="15s:10h" jq_path="$jq_path_range" expected_value="new_metric" \
endpoint=query_range query="$METRIC_NAME_NEW" params="$params_range" \
metrics_type="aggregated" metrics_storage_policy="5s:10h" jq_path="$jq_path_range" expected_value="84.84" \
retry_with_backoff prometheus_query_native
}
echo "Running prometehus tests"
test_query_rollup_rule
echo "Running rule config tests..."
test_prometheus_remote_write_restrict_metrics_type
test_query_new_name
3 changes: 3 additions & 0 deletions src/metrics/rules/store/kv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (s *store) WriteAll(nss *rules.Namespaces, rs rules.MutableRuleSet) error {
if err != nil {
return err
}

r, _ := rs.RollupRules()
fmt.Println("ruleset rollup rules: ", r)
conditions = append(conditions, ruleSetCond)
ops = append(ops, ruleSetOp)

Expand Down

0 comments on commit 5f7bc6b

Please sign in to comment.