Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions tests/integration/test_rename_column/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,37 @@ def rename_column_on_cluster(
break


def _num2_converged(nodes, table_name):
return all(
node.query(
"SELECT count() FROM system.columns "
"WHERE database = 'default' AND table IN ('{t}', '{t}_replicated') "
"AND name = 'num2'".format(t=table_name)
).strip()
== "2"
for node in nodes
)


def wait_for_rename_to_num2(nodes, table_name, attempts=12, poll_seconds=5):
# Best-effort cleanup renames + async ON CLUSTER replication can leave the
# column as foo2/foo3 on some replicas. Re-drive the idempotent rename-back
# until num2 is present on every node's Distributed and _replicated tables,
# so the strict queries below do not race schema convergence (UNKNOWN_IDENTIFIER).
tables = [table_name, "%s_replicated" % table_name]
for _ in range(attempts):
if _num2_converged(nodes, table_name):
return
for old_name in ("foo2", "foo3"):
for table in tables:
rename_column_on_cluster(nodes[0], table, old_name, "num2", 1, True)
time.sleep(poll_seconds)
if not _num2_converged(nodes, table_name):
raise Exception(
"columns did not converge to num2 for {} on all nodes".format(table_name)
)


def alter_move(node, table_name, iterations=1, ignore_exception=False):
i = 0
while True:
Expand Down Expand Up @@ -809,14 +840,7 @@ def test_rename_distributed_parallel_insert_and_select(started_cluster):
for task in tasks:
task.get(timeout=240)

rename_column_on_cluster(node1, table_name, "foo2", "num2", 1, True)
rename_column_on_cluster(
node1, "%s_replicated" % table_name, "foo2", "num2", 1, True
)
rename_column_on_cluster(node1, table_name, "foo3", "num2", 1, True)
rename_column_on_cluster(
node1, "%s_replicated" % table_name, "foo3", "num2", 1, True
)
wait_for_rename_to_num2(nodes, table_name)

insert(node1, table_name, 1000, col_names=["num", "num2"])
select(node1, table_name, "num2")
Expand Down
4 changes: 2 additions & 2 deletions tests/queries/0_stateless/01017_uniqCombined_memory_usage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ SELECT 'K=16';
SELECT 'UInt32';
SET max_memory_usage = 2000000;
SELECT sum(u) FROM (SELECT intDiv(number, 4096) AS k, uniqCombined(16)(number % 4096) u FROM numbers(4096 * 100) GROUP BY k); -- { serverError MEMORY_LIMIT_EXCEEDED }
SET max_memory_usage = 5230000;
SET max_memory_usage = 6300000;
SELECT sum(u) FROM (SELECT intDiv(number, 4096) AS k, uniqCombined(16)(number % 4096) u FROM numbers(4096 * 100) GROUP BY k);

-- HashTable for UInt64 (used until (1<<11) elements), hence 2048 elements
SELECT 'UInt64';
SET max_memory_usage = 2000000;
SELECT sum(u) FROM (SELECT intDiv(number, 2048) AS k, uniqCombined(16)(reinterpretAsString(number % 2048)) u FROM numbers(2048 * 100) GROUP BY k); -- { serverError MEMORY_LIMIT_EXCEEDED }
SET max_memory_usage = 5900000;
SET max_memory_usage = 7100000;
SELECT sum(u) FROM (SELECT intDiv(number, 2048) AS k, uniqCombined(16)(reinterpretAsString(number % 2048)) u FROM numbers(2048 * 100) GROUP BY k);

SELECT 'K=18';
Expand Down
35 changes: 22 additions & 13 deletions tests/queries/0_stateless/02421_simple_queries_for_opentelemetry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ function check_tcp_attributes()

function execute_query_HTTP()
{
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&database=${CLICKHOUSE_DATABASE}&query_id=$1" -d "$2"
# A traceparent header (with the sampled flag) forces the request to be traced, and the
# Referer / User-Agent headers populate the http.* attributes on the HTTPHandler span.
local trace_id
trace_id=$(${CLICKHOUSE_CLIENT} -q "SELECT lower(hex(generateUUIDv4()))")
${CLICKHOUSE_CURL} -sS \
-H "traceparent: 00-${trace_id}-0000000000000010-01" \
-H "referer: some-referer" \
-H "user-agent: some-user-agent" \
"${CLICKHOUSE_URL}&database=${CLICKHOUSE_DATABASE}&query_id=$1" -d "$2"
}

function check_http_attributes()
Expand All @@ -119,32 +127,34 @@ function check_http_attributes()
local agent="not found"
local method="not found"

# The http.* attributes live on the HTTPHandler (SERVER) span, not on the child query span.
# Match it by the query_id embedded in the request URI (clickhouse.uri).
result=$(${CLICKHOUSE_CLIENT} -q "
SYSTEM FLUSH LOGS opentelemetry_span_log;
SELECT attribute['http.referer'],
attribute['http.user.agent'],
attribute['http.method']
SELECT attribute['http.referer'] AS referer,
attribute['http.user.agent'] AS user_agent,
attribute['http.method'] AS method
FROM system.opentelemetry_span_log
WHERE finish_date >= yesterday()
AND operation_name = 'query'
AND attribute['clickhouse.query_id'] = '${query_id}'
AND operation_name = 'HTTPHandler'
AND attribute['clickhouse.uri'] LIKE '%${query_id}%'
FORMAT JSONEachRow;
")

if [[ -z "$result" ]]; then
echo "Error: No result returned from ClickHouse server"
return 1
fi
if [[ $result == *"http.referer"* ]]; then

if [[ $result == *'"referer":"some-referer"'* ]]; then
referer="present"
fi
if [[ $result == *"http.user.agent"* ]]; then

if [[ $result == *'"user_agent":"some-user-agent"'* ]]; then
agent="present"
fi

if [[ $result == *"http.method"* ]]; then
if [[ $result == *'"method":"POST"'* ]]; then
method="present"
fi

Expand Down Expand Up @@ -191,9 +201,8 @@ query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()")
execute_query $query_id 'select * from opentelemetry_test format Null'
check_tcp_attributes $query_id

# Test 7: Executes a TCP SELECT query and checks for http attributes in OpenTelemetry spans.
# Test 7: Executes an HTTP SELECT query and checks for http attributes in OpenTelemetry spans.
query_id=$(${CLICKHOUSE_CLIENT} -q "select generateUUIDv4()")
execute_query "$query_id" 'set opentelemetry_start_trace_probability=1'
execute_query_HTTP "$query_id" 'select * from opentelemetry_test FORMAT Null'
check_http_attributes "$query_id"
#
Expand Down
Loading