Simplify test

Signed-off-by: Frank Chen <frank.chen021@outlook.com>
This commit is contained in:
Frank Chen 2022-09-09 12:18:27 +08:00
parent 237abffdba
commit 92a92baa33

View File

@ -1,16 +1,44 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Tags: no-fasttest, distributed # Tags: no-fasttest, distributed
set -ue
unset CLICKHOUSE_LOG_COMMENT
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh # shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh . "$CURDIR"/../shell_config.sh
${CLICKHOUSE_CLIENT} --distributed_ddl_output_mode=none -nq " function insert()
{
echo "INSERT INTO ${CLICKHOUSE_DATABASE}.dist_opentelemetry SETTINGS insert_distributed_sync=$2 VALUES(1),(2)" |
${CLICKHOUSE_CURL} \
-X POST \
-H "traceparent: 00-$1-5150000000000515-01" \
-H "tracestate: some custom state" \
"${CLICKHOUSE_URL}" \
--data @-
}
function check_span()
{
${CLICKHOUSE_CLIENT} -nq "
SYSTEM FLUSH LOGS;
SELECT count() FROM system.opentelemetry_span_log
WHERE lower(hex(trace_id)) = '${1}'
AND operation_name like '${2}'
AND attribute['clickhouse.shard_num'] = '${3}'
AND attribute['clickhouse.cluster'] = 'test_cluster_two_shards'
AND attribute['clickhouse.distributed'] = '${CLICKHOUSE_DATABASE}.dist_opentelemetry'
AND attribute['clickhouse.remote'] = '${CLICKHOUSE_DATABASE}.local_opentelemetry'
AND attribute['clickhouse.rows'] = '1'
AND attribute['clickhouse.bytes'] = '8'
;"
}
#
# Prepare tables for tests
#
${CLICKHOUSE_CLIENT} -nq "
DROP TABLE IF EXISTS ${CLICKHOUSE_DATABASE}.dist_opentelemetry; DROP TABLE IF EXISTS ${CLICKHOUSE_DATABASE}.dist_opentelemetry;
DROP TABLE IF EXISTS ${CLICKHOUSE_DATABASE}.local_opentelemetry; DROP TABLE IF EXISTS ${CLICKHOUSE_DATABASE}.local_opentelemetry;
@ -19,96 +47,26 @@ CREATE TABLE ${CLICKHOUSE_DATABASE}.local_opentelemetry (key UInt64) Engine=Merg
" "
# #
# INSERT ASYNC test # ASYNC INSERT test with opentelemetry enabled
# Do test with opentelemetry enabled
# #
trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(generateUUIDv4()))"); trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(generateUUIDv4()))");
echo "INSERT INTO ${CLICKHOUSE_DATABASE}.dist_opentelemetry SETTINGS insert_distributed_sync=0 VALUES(1),(2)" | insert $trace_id 0
${CLICKHOUSE_CURL} \ check_span $trace_id '%writeToLocal%' '1'
-X POST \ check_span $trace_id '%writeToLocal%' '2'
-H "traceparent: 00-$trace_id-5250000000000525-01" \
-H "tracestate: some custom state" \
"${CLICKHOUSE_URL}" \
--data @-
# Check log
${CLICKHOUSE_CLIENT} --distributed_ddl_output_mode=none -nq "
-- Make sure INSERT on distributed finishes
SYSTEM FLUSH DISTRIBUTED ${CLICKHOUSE_DATABASE}.dist_opentelemetry;
-- Make sure opentelemetry span log flushed
SYSTEM FLUSH LOGS;
-- Above INSERT will insert data to two shards respectively, so there will be two spans generated
SELECT count() FROM system.opentelemetry_span_log
WHERE lower(hex(trace_id)) = '${trace_id}'
AND operation_name like '%writeToLocal%'
AND attribute['clickhouse.shard_num'] = '1'
AND attribute['clickhouse.cluster'] = 'test_cluster_two_shards'
AND attribute['clickhouse.distributed'] = '${CLICKHOUSE_DATABASE}.dist_opentelemetry'
AND attribute['clickhouse.remote'] = '${CLICKHOUSE_DATABASE}.local_opentelemetry'
AND attribute['clickhouse.rows'] = '1'
AND attribute['clickhouse.bytes'] = '8'
;
SELECT count() FROM system.opentelemetry_span_log
WHERE lower(hex(trace_id)) = '${trace_id}'
AND operation_name like '%writeToLocal%'
AND attribute['clickhouse.shard_num'] = '2'
AND attribute['clickhouse.cluster'] = 'test_cluster_two_shards'
AND attribute['clickhouse.distributed'] = '${CLICKHOUSE_DATABASE}.dist_opentelemetry'
AND attribute['clickhouse.remote'] = '${CLICKHOUSE_DATABASE}.local_opentelemetry'
AND attribute['clickhouse.rows'] = '1'
AND attribute['clickhouse.bytes'] = '8'
;
"
# #
# INSERT SYNC test # SYNC INSERT SYNC test with opentelemetry enabled
# Do test with opentelemetry enabled and in SYNC mode
# #
trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(generateUUIDv4()))"); trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(generateUUIDv4()))");
echo "INSERT INTO ${CLICKHOUSE_DATABASE}.dist_opentelemetry SETTINGS insert_distributed_sync=1 VALUES(1),(2)" | insert $trace_id 1
${CLICKHOUSE_CURL} \ check_span $trace_id '%runWritingJob%' '1'
-X POST \ check_span $trace_id '%runWritingJob%' '2'
-H "traceparent: 00-$trace_id-5250000000000525-01" \
-H "tracestate: some custom state" \
"${CLICKHOUSE_URL}" \
--data @-
# Check log
${CLICKHOUSE_CLIENT} --distributed_ddl_output_mode=none -nq "
SYSTEM FLUSH LOGS;
-- Above INSERT will insert data to two shards in the same flow, so there should be two spans generated with the same operation name
SELECT count() FROM system.opentelemetry_span_log
WHERE lower(hex(trace_id)) = '${trace_id}'
AND operation_name like '%runWritingJob%'
AND attribute['clickhouse.shard_num'] = '1'
AND attribute['clickhouse.cluster'] = 'test_cluster_two_shards'
AND attribute['clickhouse.distributed'] = '${CLICKHOUSE_DATABASE}.dist_opentelemetry'
AND attribute['clickhouse.remote'] = '${CLICKHOUSE_DATABASE}.local_opentelemetry'
AND attribute['clickhouse.rows'] = '1'
AND attribute['clickhouse.bytes'] = '8'
;
SELECT count() FROM system.opentelemetry_span_log
WHERE lower(hex(trace_id)) = '${trace_id}'
AND operation_name like '%runWritingJob%'
AND attribute['clickhouse.shard_num'] = '2'
AND attribute['clickhouse.cluster'] = 'test_cluster_two_shards'
AND attribute['clickhouse.distributed'] = '${CLICKHOUSE_DATABASE}.dist_opentelemetry'
AND attribute['clickhouse.remote'] = '${CLICKHOUSE_DATABASE}.local_opentelemetry'
AND attribute['clickhouse.rows'] = '1'
AND attribute['clickhouse.bytes'] = '8'
;
"
# #
# Cleanup # Cleanup
# #
${CLICKHOUSE_CLIENT} --distributed_ddl_output_mode=none -nq " ${CLICKHOUSE_CLIENT} -nq "
DROP TABLE ${CLICKHOUSE_DATABASE}.dist_opentelemetry; DROP TABLE ${CLICKHOUSE_DATABASE}.dist_opentelemetry;
DROP TABLE ${CLICKHOUSE_DATABASE}.local_opentelemetry; DROP TABLE ${CLICKHOUSE_DATABASE}.local_opentelemetry;
" "