Skip to content

Commit ec6ff0f

Browse files
committed
renamed client name prefix
1 parent cfae514 commit ec6ff0f

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.clickhouse.client.api.internal.ClickHouseLZ4OutputStream;
2727
import com.clickhouse.client.api.internal.ClientStatisticsHolder;
2828
import com.clickhouse.client.api.internal.ClientV1AdaptorHelper;
29+
import com.clickhouse.client.api.internal.EnvUtils;
2930
import com.clickhouse.client.api.internal.HttpAPIClientHelper;
3031
import com.clickhouse.client.api.internal.MapUtils;
3132
import com.clickhouse.client.api.internal.SettingsConverter;
@@ -901,7 +902,7 @@ public Builder useHTTPBasicAuth(boolean useBasicAuth) {
901902
* @return same instance of the builder
902903
*/
903904
public Builder setClientName(String clientName) {
904-
this.configuration.put(ClientSettings.CLIENT_NAME, clientName);
905+
this.configuration.put(ClientConfigProperties.CLIENT_NAME.getKey(), clientName);
905906
return this;
906907
}
907908

@@ -1044,8 +1045,8 @@ private void setDefaults() {
10441045
useHTTPBasicAuth(true);
10451046
}
10461047

1047-
String userAgent = configuration.getOrDefault(ClientSettings.HTTP_HEADER_PREFIX + HttpHeaders.USER_AGENT.toUpperCase(Locale.US), "");
1048-
String clientName = configuration.getOrDefault(ClientSettings.CLIENT_NAME, "");
1048+
String userAgent = configuration.getOrDefault(ClientConfigProperties.HTTP_HEADER_PREFIX + HttpHeaders.USER_AGENT.toUpperCase(Locale.US), "");
1049+
String clientName = configuration.getOrDefault(ClientConfigProperties.CLIENT_NAME.getKey(), "");
10491050
httpHeader(HttpHeaders.USER_AGENT, buildUserAgent(userAgent.isEmpty() ? clientName : userAgent));
10501051
}
10511052

@@ -1077,7 +1078,7 @@ private static String buildUserAgent(String customUserAgent) {
10771078
}
10781079

10791080
public static final String LATEST_ARTIFACT_VERSION = "0.7.1-patch1";
1080-
public static final String CLIENT_USER_AGENT = "ch-j-v2/";
1081+
public static final String CLIENT_USER_AGENT = "clickhouse-java-v2/";
10811082
}
10821083

10831084
private ClickHouseNode getServerNode() {

client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ public enum ClientConfigProperties {
112112

113113
CONNECTION_REQUEST_TIMEOUT("connection_request_timeout"),
114114

115-
CLIENT_RETRY_ON_FAILURE("client_retry_on_failures");
115+
CLIENT_RETRY_ON_FAILURE("client_retry_on_failures"),
116+
117+
CLIENT_NAME("client_name");
116118

117119
private String key;
118120

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.clickhouse.client.api.internal;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.net.NetworkInterface;
7+
8+
/**
9+
* Environment utility class.
10+
*/
11+
public class EnvUtils {
12+
13+
private static final Logger LOG = LoggerFactory.getLogger(EnvUtils.class);
14+
15+
/**
16+
* Returns the local host name or address.
17+
* @param returnAddress if true, return address; otherwise, return name
18+
* @return string representing the local host name or address
19+
*/
20+
public static String getLocalhostNameOrAddress(final boolean returnAddress) {
21+
try {
22+
23+
return NetworkInterface.networkInterfaces()
24+
.flatMap(NetworkInterface::inetAddresses)
25+
.filter(ia -> !ia.isLoopbackAddress())
26+
.findFirst()
27+
.map(ia -> returnAddress ? ia.getHostAddress() : ia.getCanonicalHostName())
28+
.orElse("");
29+
} catch (Exception e) {
30+
LOG.error("Failed to get local host name or address", e);
31+
}
32+
return "";
33+
}
34+
}

client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,8 @@ public void testUserAgentHasCompleteProductName(String clientName, Pattern userA
790790
@DataProvider(name = "testUserAgentHasCompleteProductName_dataProvider")
791791
public static Object[][] testUserAgentHasCompleteProductName_dataProvider() {
792792
return new Object[][] {
793-
{ "", Pattern.compile("ch-j-v2\\/.+ \\(.+\\) Apache HttpClient\\/[\\d\\.]+$") },
794-
{ "test-client/1.0", Pattern.compile("test-client/1.0 ch-j-v2\\/.+ \\(.+\\) Apache HttpClient\\/[\\d\\.]+$")},
795-
{ "test-client/", Pattern.compile("test-client/ ch-j-v2\\/.+ \\(.+\\) Apache HttpClient\\/[\\d\\.]+$")}};
793+
{ "", Pattern.compile("clickhouse-java-v2\\/.+ \\(.+\\) Apache HttpClient\\/[\\d\\.]+$") },
794+
{ "test-client/1.0", Pattern.compile("test-client/1.0 clickhouse-java-v2\\/.+ \\(.+\\) Apache HttpClient\\/[\\d\\.]+$")},
795+
{ "test-client/", Pattern.compile("test-client/ clickhouse-java-v2\\/.+ \\(.+\\) Apache HttpClient\\/[\\d\\.]+$")}};
796796
}
797797
}

0 commit comments

Comments
 (0)