From 92a92baa33842f6a1aeee232f22a17b4fd71e923 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 9 Sep 2022 12:18:27 +0800 Subject: [PATCH] Simplify test Signed-off-by: Frank Chen --- ...entelemetry_insert_on_distributed_table.sh | 126 ++++++------------ 1 file changed, 42 insertions(+), 84 deletions(-) diff --git a/tests/queries/0_stateless/02417_opentelemetry_insert_on_distributed_table.sh b/tests/queries/0_stateless/02417_opentelemetry_insert_on_distributed_table.sh index 7ec0650aaac..1b4e1da97f9 100755 --- a/tests/queries/0_stateless/02417_opentelemetry_insert_on_distributed_table.sh +++ b/tests/queries/0_stateless/02417_opentelemetry_insert_on_distributed_table.sh @@ -1,16 +1,44 @@ #!/usr/bin/env bash # Tags: no-fasttest, distributed -set -ue - -unset CLICKHOUSE_LOG_COMMENT - CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # shellcheck source=../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}.local_opentelemetry; @@ -19,96 +47,26 @@ CREATE TABLE ${CLICKHOUSE_DATABASE}.local_opentelemetry (key UInt64) Engine=Merg " # -# INSERT ASYNC test -# Do test with opentelemetry enabled +# ASYNC INSERT test with opentelemetry enabled # trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(generateUUIDv4()))"); -echo "INSERT INTO ${CLICKHOUSE_DATABASE}.dist_opentelemetry SETTINGS insert_distributed_sync=0 VALUES(1),(2)" | -${CLICKHOUSE_CURL} \ - -X POST \ - -H "traceparent: 00-$trace_id-5250000000000525-01" \ - -H "tracestate: some custom state" \ - "${CLICKHOUSE_URL}" \ - --data @- +insert $trace_id 0 +check_span $trace_id '%writeToLocal%' '1' +check_span $trace_id '%writeToLocal%' '2' -# 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 -# Do test with opentelemetry enabled and in SYNC mode +# SYNC INSERT SYNC test with opentelemetry enabled # trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(generateUUIDv4()))"); -echo "INSERT INTO ${CLICKHOUSE_DATABASE}.dist_opentelemetry SETTINGS insert_distributed_sync=1 VALUES(1),(2)" | -${CLICKHOUSE_CURL} \ - -X POST \ - -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' -; -" +insert $trace_id 1 +check_span $trace_id '%runWritingJob%' '1' +check_span $trace_id '%runWritingJob%' '2' # # Cleanup # -${CLICKHOUSE_CLIENT} --distributed_ddl_output_mode=none -nq " +${CLICKHOUSE_CLIENT} -nq " DROP TABLE ${CLICKHOUSE_DATABASE}.dist_opentelemetry; DROP TABLE ${CLICKHOUSE_DATABASE}.local_opentelemetry; "