mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-15 20:24:07 +00:00
Add test case
Signed-off-by: Frank Chen <frank.chen021@outlook.com>
This commit is contained in:
parent
f576d8191c
commit
2ae43bb4e8
@ -232,11 +232,11 @@ void TracingContext::deserialize(ReadBuffer & buf)
|
||||
{
|
||||
buf >> "tracing: "
|
||||
>> this->trace_id
|
||||
>> " "
|
||||
>> "\n"
|
||||
>> this->span_id
|
||||
>> " "
|
||||
>> "\n"
|
||||
>> this->tracestate
|
||||
>> " "
|
||||
>> "\n"
|
||||
>> this->trace_flags
|
||||
>> "\n";
|
||||
}
|
||||
@ -246,11 +246,11 @@ void TracingContext::serialize(WriteBuffer & buf) const
|
||||
{
|
||||
buf << "tracing: "
|
||||
<< this->trace_id
|
||||
<< " "
|
||||
<< "\n"
|
||||
<< this->span_id
|
||||
<< " "
|
||||
<< "\n"
|
||||
<< this->tracestate
|
||||
<< " "
|
||||
<< "\n"
|
||||
<< this->trace_flags
|
||||
<< "\n";
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
1
|
||||
1
|
||||
2
|
||||
===case 2====
|
||||
1
|
||||
1
|
||||
exception_code=60
|
||||
exception_code=60
|
92
tests/queries/0_stateless/02423_ddl_for_opentelemetry.sh
Executable file
92
tests/queries/0_stateless/02423_ddl_for_opentelemetry.sh
Executable file
@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tags: distributed
|
||||
|
||||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CURDIR"/../shell_config.sh
|
||||
|
||||
# This function takes following arguments:
|
||||
# $1 - OpenTelemetry Trace Id
|
||||
# $2 - Query
|
||||
# $3 - Query Settings
|
||||
# $4 - Output device, default is stdout
|
||||
function execute_query()
|
||||
{
|
||||
if [ -n "${4}" ]; then
|
||||
output=$4
|
||||
else
|
||||
output="/dev/stdout"
|
||||
fi
|
||||
|
||||
echo $2 | ${CLICKHOUSE_CURL} \
|
||||
-X POST \
|
||||
-H "traceparent: 00-$1-5150000000000515-01" \
|
||||
-H "tracestate: a\nb cd" \
|
||||
"${CLICKHOUSE_URL}?${3}" \
|
||||
--data @- \
|
||||
> $output
|
||||
}
|
||||
|
||||
# This function takes 3 argument:
|
||||
# $1 - OpenTelemetry Trace Id
|
||||
# $2 - Fields
|
||||
# $3 - operation_name pattern
|
||||
function check_span()
|
||||
{
|
||||
${CLICKHOUSE_CLIENT} -nq "
|
||||
SYSTEM FLUSH LOGS;
|
||||
|
||||
SELECT ${2}
|
||||
FROM system.opentelemetry_span_log
|
||||
WHERE finish_date >= yesterday()
|
||||
AND lower(hex(trace_id)) = '${1}'
|
||||
AND operation_name like '${3}'
|
||||
;"
|
||||
}
|
||||
|
||||
#
|
||||
# Set up
|
||||
#
|
||||
${CLICKHOUSE_CLIENT} -q "
|
||||
DROP TABLE IF EXISTS ddl_test_for_opentelemetry;
|
||||
"
|
||||
|
||||
#
|
||||
# Case 1, a normal case
|
||||
#
|
||||
trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(generateUUIDv4()))");
|
||||
execute_query $trace_id "CREATE TABLE ddl_test_for_opentelemetry ON CLUSTER test_shard_localhost (id UInt64) Engine=MergeTree ORDER BY id" "distributed_ddl_output_mode=none"
|
||||
|
||||
check_span $trace_id "count()" "HTTPHandler"
|
||||
check_span $trace_id "count()" "%DDLWorker::processTask%"
|
||||
|
||||
# There should be two 'query' spans,
|
||||
# one is for the HTTPHandler, the other is for the DDL executing in DDLWorker
|
||||
check_span $trace_id "count()" "query"
|
||||
|
||||
# Echo a separator so that the reference file is more clear for reading
|
||||
echo "===case 2===="
|
||||
|
||||
#
|
||||
# Case 2, an exceptional case, DROP a non-exist table
|
||||
#
|
||||
trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(generateUUIDv4()))");
|
||||
|
||||
# Since this query is supposed to fail, we redirect the error message to /dev/null to discard the error message so that it won't pollute the reference file.
|
||||
# The exception will be checked in the span log
|
||||
execute_query $trace_id "DROP TABLE ddl_test_for_opentelemetry_non_exist ON CLUSTER test_shard_localhost" "distributed_ddl_output_mode=none" "/dev/null"
|
||||
|
||||
check_span $trace_id "count()" "HTTPHandler"
|
||||
check_span $trace_id "count()" "%DDLWorker::processTask%"
|
||||
|
||||
# There should be two 'query' spans,
|
||||
# one is for the HTTPHandler, the other is for the DDL executing in DDLWorker.
|
||||
# Both of these two spans contain exception
|
||||
check_span $trace_id "concat('exception_code=', attribute['clickhouse.exception_code'])" "query"
|
||||
|
||||
#
|
||||
# Tear down
|
||||
#
|
||||
${CLICKHOUSE_CLIENT} -q "
|
||||
DROP TABLE IF EXISTS ddl_test_for_opentelemetry;
|
||||
"
|
Loading…
Reference in New Issue
Block a user