Skip to content

Commit 40d8928

Browse files
authored
Merge pull request #439 from ClickHouse/client-name
Change client name
2 parents 5a34843 + 00f820f commit 40d8928

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

.github/workflows/macos.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ jobs:
7373
env:
7474
# It is impossible to start CH server in docker on macOS due to github actions limitations,
7575
# so we use remote server to execute tests, some do not allow some features for anonymoust/free users:
76-
# - system.query_log used by 'Client/ClientCase.Query_ID'
77-
GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*"
76+
# - system.query_log used by 'Client/ClientCase.Query_ID' and 'Client/ClientCase.ClientName'
77+
# - system.opentelemetry_span_log is used by 'Client/ClientCase.TracingContext'
78+
GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*:Client/ClientCase.ClientName/*"
7879
run: ./clickhouse-cpp-ut ${GTEST_FILTER}

.github/workflows/windows_mingw.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ jobs:
9393
env:
9494
# It is impossible to start CH server in docker on Windows due to github actions limitations,
9595
# so we use remote server to execute tests, some do not allow some features for anonymoust/free users:
96-
# - system.query_log used by 'Client/ClientCase.Query_ID'
97-
GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*"
96+
# - system.query_log used by 'Client/ClientCase.Query_ID' and 'Client/ClientCase.ClientName'
97+
# - system.opentelemetry_span_log is used by 'Client/ClientCase.TracingContext'
98+
GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*:Client/ClientCase.ClientName/*"
9899
run: ./build/ut/clickhouse-cpp-ut.exe ${GTEST_FILTER}
99100

100101
- name: Test (simple)

.github/workflows/windows_msvc.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ jobs:
6868
env:
6969
# It is impossible to start CH server in docker on Windows due to github actions limitations,
7070
# so we use remote server to execute tests, some do not allow some features for anonymoust/free users:
71-
# - system.query_log used by 'Client/ClientCase.Query_ID'
72-
GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*"
71+
# - system.query_log used by 'Client/ClientCase.Query_ID' and 'Client/ClientCase.ClientName'
72+
# - system.opentelemetry_span_log is used by 'Client/ClientCase.TracingContext'
73+
GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*:Client/ClientCase.ClientName/*"
7374
working-directory: ${{github.workspace}}/build/ut
7475
run: Release\clickhouse-cpp-ut.exe "${{env.GTEST_FILTER}}"

clickhouse/client.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "base/sslsocket.h"
1818
#endif
1919

20-
#define DBMS_NAME "ClickHouse"
20+
#define CLIENT_NAME "clickhouse-cpp"
2121

2222
#define DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES 50264
2323
#define DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS 51554
@@ -813,7 +813,7 @@ void Client::Impl::SendQuery(const Query& query, bool finalize) {
813813
ClientInfo info;
814814

815815
info.query_kind = 1;
816-
info.client_name = "ClickHouse client";
816+
info.client_name = CLIENT_NAME;
817817
info.client_version_major = CLICKHOUSE_CPP_VERSION_MAJOR;
818818
info.client_version_minor = CLICKHOUSE_CPP_VERSION_MINOR;
819819
info.client_version_patch = CLICKHOUSE_CPP_VERSION_PATCH;
@@ -978,7 +978,7 @@ void Client::Impl::InitializeStreams(std::unique_ptr<SocketBase>&& socket) {
978978

979979
bool Client::Impl::SendHello() {
980980
WireFormat::WriteUInt64(*output_, ClientCodes::Hello);
981-
WireFormat::WriteString(*output_, std::string(DBMS_NAME) + " client");
981+
WireFormat::WriteString(*output_, std::string(CLIENT_NAME));
982982
WireFormat::WriteUInt64(*output_, CLICKHOUSE_CPP_VERSION_MAJOR);
983983
WireFormat::WriteUInt64(*output_, CLICKHOUSE_CPP_VERSION_MINOR);
984984
WireFormat::WriteUInt64(*output_, DMBS_PROTOCOL_REVISION);

ut/client_ut.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,3 +1553,30 @@ TEST_P(ClientCase, QueryParameters) {
15531553

15541554
client_->Execute("DROP TEMPORARY TABLE " + table_name);
15551555
}
1556+
1557+
TEST_P(ClientCase, ClientName) {
1558+
const auto server_info = client_->GetServerInfo();
1559+
1560+
std::srand(std::time(nullptr) + reinterpret_cast<int64_t>(&server_info));
1561+
const auto * test_info = ::testing::UnitTest::GetInstance()->current_test_info();
1562+
const std::string query_id = std::to_string(std::rand()) + "-" + test_info->test_suite_name() + "/" + test_info->name();
1563+
1564+
SCOPED_TRACE(query_id);
1565+
1566+
client_->Select("SELECT 1", query_id, [](const Block&) { /* make sure the data is delivered in full */ });
1567+
1568+
FlushLogs();
1569+
1570+
std::string query_log_query
1571+
= "SELECT CAST(client_name, 'String') FROM system.query_log WHERE query_id = '" + query_id + "'";
1572+
1573+
size_t total_rows = 0;
1574+
client_->Select(query_log_query, [&total_rows](const Block& block) {
1575+
const auto row_count = block.GetRowCount();
1576+
total_rows += row_count;
1577+
for (size_t i = 0; i < row_count; ++i) {
1578+
ASSERT_EQ(block[0]->AsStrict<ColumnString>()->At(i), "clickhouse-cpp");
1579+
}
1580+
});
1581+
ASSERT_GT(total_rows, 0UL) << "Query with query_id " << query_id << " is not found";
1582+
}

0 commit comments

Comments
 (0)