Improve the test to address review comments

Signed-off-by: Frank Chen <frank.chen021@outlook.com>
This commit is contained in:
Frank Chen 2022-09-14 11:43:23 +08:00
parent f8dcf01aa6
commit 569167d9aa
2 changed files with 17 additions and 19 deletions

View File

@ -1,4 +1,4 @@
{"query":"show processlist format Null\n "} {"query":"show processlist format Null\n "}
{"query":"show databases format Null\n "} {"query":"show databases format Null\n "}
{"query":"insert into opentelemetry_test values","read_rows":"3","read_bytes":"24","written_rows":"3","written_bytes":"24"} {"query":"insert into opentelemetry_test values","read_rows":"3","written_rows":"3"}
{"query":"select * from opentelemetry_test format Null\n ","read_rows":"3","read_bytes":"24","written_rows":"","written_bytes":""} {"query":"select * from opentelemetry_test format Null\n ","read_rows":"3","written_rows":""}

View File

@ -5,16 +5,16 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../shell_config.sh . "$CURDIR"/../shell_config.sh
# This function takes 2 arguments: # This function takes 2 arguments:
# $1 - query # $1 - query id
# $2 - trace id # $2 - query
function executeQuery() function execute_query()
{ {
${CLICKHOUSE_CLIENT} --database=${CLICKHOUSE_DATABASE} --opentelemetry_start_trace_probability=1 --query_id $1 -nq " ${CLICKHOUSE_CLIENT} --opentelemetry_start_trace_probability=1 --query_id $1 -nq "
${2} ${2}
" "
} }
# For some quries, it's not able to know how many bytes/rows are read when tests are executed on CI, # For some queries, it's not possible to know how many bytes/rows are read when tests are executed on CI,
# so we only to check the db.statement only # so we only to check the db.statement only
function check_query_span_query_only() function check_query_span_query_only()
{ {
@ -35,9 +35,7 @@ ${CLICKHOUSE_CLIENT} -nq "
SYSTEM FLUSH LOGS; SYSTEM FLUSH LOGS;
SELECT attribute['db.statement'] as query, SELECT attribute['db.statement'] as query,
attribute['clickhouse.read_rows'] as read_rows, attribute['clickhouse.read_rows'] as read_rows,
attribute['clickhouse.read_bytes'] as read_bytes, attribute['clickhouse.written_rows'] as written_rows
attribute['clickhouse.written_rows'] as written_rows,
attribute['clickhouse.written_bytes'] as written_bytes
FROM system.opentelemetry_span_log FROM system.opentelemetry_span_log
WHERE finish_date >= yesterday() WHERE finish_date >= yesterday()
AND operation_name = 'query' AND operation_name = 'query'
@ -49,36 +47,36 @@ ${CLICKHOUSE_CLIENT} -nq "
# #
# Set up # Set up
# #
${CLICKHOUSE_CLIENT} --database=${CLICKHOUSE_DATABASE} -nq " ${CLICKHOUSE_CLIENT} -nq "
DROP TABLE IF EXISTS opentelemetry_test; DROP TABLE IF EXISTS ${CLICKHOUSE_DATABASE}.opentelemetry_test;
CREATE TABLE opentelemetry_test (id UInt64) Engine=MergeTree Order By id; CREATE TABLE ${CLICKHOUSE_DATABASE}.opentelemetry_test (id UInt64) Engine=MergeTree Order By id;
" "
# test 1, a query that has special path in the code # test 1, a query that has special path in the code
# Format Null is used to make sure no output is generated so that it won't pollute the reference file # Format Null is used to make sure no output is generated so that it won't pollute the reference file
query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()"); query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()");
executeQuery $query_id 'show processlist format Null' execute_query $query_id 'show processlist format Null'
check_query_span_query_only "$query_id" check_query_span_query_only "$query_id"
# test 2, a normal show command # test 2, a normal show command
query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()"); query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()");
executeQuery $query_id 'show databases format Null' execute_query $query_id 'show databases format Null'
check_query_span_query_only "$query_id" check_query_span_query_only "$query_id"
# test 3, a normal insert query on local table # test 3, a normal insert query on local table
query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()"); query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()");
executeQuery $query_id 'insert into opentelemetry_test values(1)(2)(3)' execute_query $query_id 'insert into opentelemetry_test values(1)(2)(3)'
check_query_span "$query_id" check_query_span "$query_id"
# test 4, a normal select query # test 4, a normal select query
query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()"); query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()");
executeQuery $query_id 'select * from opentelemetry_test format Null' execute_query $query_id 'select * from opentelemetry_test format Null'
check_query_span $query_id check_query_span $query_id
# #
# Tear down # Tear down
# #
${CLICKHOUSE_CLIENT} --database=${CLICKHOUSE_DATABASE} -q " ${CLICKHOUSE_CLIENT} -q "
DROP TABLE IF EXISTS opentelemetry_test; DROP TABLE IF EXISTS ${CLICKHOUSE_DATABASE}.opentelemetry_test;
" "