more tests + clickhouse-client options

This commit is contained in:
Alexander Kuzmenkov 2020-08-29 02:25:30 +03:00
parent c02f9e1dd1
commit fa8eebed78
4 changed files with 76 additions and 31 deletions

View File

@ -2180,6 +2180,8 @@ public:
("log-level", po::value<std::string>(), "client log level")
("server_logs_file", po::value<std::string>(), "put server logs into specified file")
("query-fuzzer-runs", po::value<int>()->default_value(0), "query fuzzer runs")
("opentelemetry-traceparent", po::value<std::string>(), "OpenTelemetry traceparent header as described by W3C Trace Context recommendation")
("opentelemetry-tracestate", po::value<std::string>(), "OpenTelemetry tracestate header as described by W3C Trace Context recommendation")
;
Settings cmd_settings;
@ -2348,6 +2350,25 @@ public:
ignore_error = true;
}
if (options.count("opentelemetry-traceparent"))
{
std::string traceparent = options["opentelemetry-traceparent"].as<std::string>();
std::string error;
if (!context.getClientInfo().setOpenTelemetryTraceparent(
traceparent, error))
{
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"Cannot parse OpenTelemetry traceparent '{}': {}",
traceparent, error);
}
}
if (options.count("opentelemetry-tracestate"))
{
context.getClientInfo().opentelemetry_tracestate =
options["opentelemetry-tracestate"].as<std::string>();
}
argsToConfig(common_arguments, config(), 100);
clearPasswordFromCommandLine(argc, argv);

View File

@ -1,31 +0,0 @@
#!/usr/bin/env bash
set -ue
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../shell_config.sh
# Generate some random trace id so that the prevous runs of the test do not interfere.
trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(reverse(reinterpretAsString(generateUUIDv4()))))")
${CLICKHOUSE_CURL} --header "traceparent: 00-$trace_id-0000000000000010-01" --header "tracestate: some custom state" "http://localhost:8123/" --get --data-urlencode "query=select 1 from remote('127.0.0.2', system, one)"
${CLICKHOUSE_CLIENT} -q "system flush logs"
# Check that the HTTP traceparent was read, and then passed to `remote` instance.
# We expect 4 queries, because there are two DESC TABLE queries for the shard.
# This is bug-ish, see https://github.com/ClickHouse/ClickHouse/issues/14228
${CLICKHOUSE_CLIENT} -q "select count(*) from system.opentelemetry_log where trace_id = reinterpretAsUUID(reverse(unhex('$trace_id')))"
# Check that the tracestate header was read and passed. Must have
# exactly the same value for all "query" spans in this trace.
${CLICKHOUSE_CLIENT} -q "
select count(distinct attribute.values)
from system.opentelemetry_log
array join attribute.names, attribute.values
where
trace_id = reinterpretAsUUID(reverse(unhex('$trace_id')))
and operation_name = 'query'
and attribute.names = 'tracestate'
"

View File

@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -ue
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../shell_config.sh
function check_log
{
${CLICKHOUSE_CLIENT} -nq "
system flush logs;
-- Check the number of spans with given trace id, to verify it was propagated.
select count(*)
from system.opentelemetry_log
where trace_id = reinterpretAsUUID(reverse(unhex('$trace_id')))
and operation_name = 'query'
;
-- Check that the tracestate header was propagated. It must have exactly the
-- same non-empty value for all 'query' spans in this trace.
select count(distinct value)
from system.opentelemetry_log
array join attribute.names as name, attribute.values as value
where
trace_id = reinterpretAsUUID(reverse(unhex('$trace_id')))
and operation_name = 'query'
and name = 'tracestate'
and length(value) > 0
;
"
}
# Generate some random trace id so that the prevous runs of the test do not interfere.
trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(reverse(reinterpretAsString(generateUUIDv4()))))")
# Check that the HTTP traceparent is read, and then passed through `remote` table function.
# We expect 4 queries, because there are two DESC TABLE queries for the shard.
# This is bug-ish, see https://github.com/ClickHouse/ClickHouse/issues/14228
${CLICKHOUSE_CURL} --header "traceparent: 00-$trace_id-0000000000000010-01" --header "tracestate: some custom state" "http://localhost:8123/" --get --data-urlencode "query=select 1 from remote('127.0.0.2', system, one)"
check_log
# With another trace id, check that clickhouse-client accepts traceparent, and
# that it is passed through URL table function. We expect two query spans, one
# for the initial query, and one for the HTTP query.
trace_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(reverse(reinterpretAsString(generateUUIDv4()))))")
${CLICKHOUSE_CLIENT} --opentelemetry-traceparent "00-$trace_id-0000000000000020-02" --opentelemetry-tracestate "another custom state" --query "
select * from url('http://127.0.0.2:8123/?query=select%201', CSV, 'a int')
"
check_log