Skip to content

[0.11.0] Fix user agent #3232

Closed
Closed

Description

@chernser

Description

Propagate PR from main to v0.11.0:
#3213

Use patch or cherry pick - no rewrites. Changes should be indentical.

Activity

  1. added this to the 0.11.0 milestone on Oct 20, 2026
  2. chernser commented on Oct 20, 2026

    @chernser
    ContributorAuthor

    @polyglotAI-bot fix this please

  3. polyglotAI-bot commented on Oct 20, 2026

    @polyglotAI-bot
    Collaborator

    We cannot open this backport PR. Maintainers own backports and release branches, so we do not open PRs into v0.11.0. I tested the cherry-pick against origin/v0.11.0 (eeebd1ece). It applies with one conflict, in a test file. With the resolution below, the change is the same as #3213.

    #3213 was merged as a merge commit, so -m 1 is necessary:

    git fetch origin
    git switch -c backport/0.11.0-3213 origin/v0.11.0
    git cherry-pick -m 1 7f2cb5787   # #3213, 1 conflict: jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java

    The conflict. It is in executeQueryAndVerifyUserAgent in jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java. On main, #3187 (cluster tests) changed this helper to a retry loop before #3213 merged. #3187 is not on v0.11.0. #3213 makes only two changes to the helper: the return type changes from void to String, and the helper returns userAgent. To resolve:

    1. Keep the v0.11.0 body of the helper (the HEAD side).
    2. In the theirs side, delete the lines from Assert.assertTrue(found, … to return userAgent; and the } after it. These lines are the [repo] Cluster Tests #3187 version of the helper.
    3. Add return userAgent; as the last statement in the try block of the helper.
    4. Keep the rest of the theirs side: the new test testClientMetadataInUserAgent and its data provider.
    git add jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java
    git cherry-pick --continue
    Resulting diff of ConnectionTest.java against v0.11.0
    --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java
    +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java
    @@ -8,6 +8,7 @@ import com.clickhouse.client.api.ClientConfigProperties;
     import com.clickhouse.client.api.DataTypeUtils;
     import com.clickhouse.client.api.ServerException;
     import com.clickhouse.client.api.internal.ServerSettings;
    +import com.clickhouse.client.api.internal.Versions;
     import com.clickhouse.client.api.query.QueryResponse;
     import com.clickhouse.data.ClickHouseFormat;
     import com.fasterxml.jackson.databind.JsonNode;
    @@ -345,7 +346,7 @@ public class ConnectionTest extends JdbcIntegrationTest {
             }
         }
     
    -    private void executeQueryAndVerifyUserAgent(Statement stmt, String clientName) throws Exception {
    +    private String executeQueryAndVerifyUserAgent(Statement stmt, String clientName) throws Exception {
             final String testQuery = "SELECT '" + UUID.randomUUID() + "'";
             stmt.execute(testQuery);
             String queryId = ((StatementImpl)stmt).getLastQueryId();
    @@ -362,9 +363,49 @@ public class ConnectionTest extends JdbcIntegrationTest {
                 }
                 Assert.assertTrue(userAgent.contains(Client.CLIENT_USER_AGENT), "Expected to contain '" + Client.CLIENT_USER_AGENT + "' but value was '" + userAgent + "'");
                 Assert.assertTrue(userAgent.contains(Driver.DRIVER_CLIENT_NAME), "Expected to contain '" + Driver.DRIVER_CLIENT_NAME + "' but value was '" + userAgent + "'");
    +            return userAgent;
             }
         }
     
    +    @Test(groups = { "integration" }, dataProvider = "clientMetadataInUserAgentDP")
    +    public void testClientMetadataInUserAgent(boolean setInUrl) throws Exception {
    +        if (isCloud()) {
    +            throw new SkipException("Cloud does not support flushing query_log");
    +        }
    +
    +        final String metadata = "fv=flink/2.0.0,api=table";
    +        Properties info = new Properties();
    +        info.setProperty("user", "default");
    +        info.setProperty("password", ClickHouseServerForTest.getPassword());
    +        info.setProperty(ClientConfigProperties.DATABASE.getKey(), ClickHouseServerForTest.getDatabase());
    +        String url = getEndpointString();
    +        if (setInUrl) {
    +            url += "?" + ClientConfigProperties.CLIENT_ID_METADATA.getKey() + "=" + metadata;
    +        } else {
    +            info.setProperty(ClientConfigProperties.CLIENT_ID_METADATA.getKey(), metadata);
    +        }
    +
    +        String expectedSuffix = "clickhouse-java-v2/" + Client.clientVersion + " (fv:flink/2.0.0; api:table; lv:java/"
    +                + System.getProperty("java.version") + "; os:" + System.getProperty("os.name") + "; hc:ahc_"
    +                + Versions.APACHE_HTTP_CLIENT + ")";
    +        try (Connection localConnection = new ConnectionImpl(url, info);
    +             Statement stmt = localConnection.createStatement()) {
    +            String userAgent = executeQueryAndVerifyUserAgent(stmt, null);
    +            Assert.assertTrue(userAgent.endsWith(expectedSuffix),
    +                    "Expected to end with '" + expectedSuffix + "' but value was '" + userAgent + "'");
    +
    +            localConnection.setClientInfo(ClientInfoProperties.APPLICATION_NAME.getKey(), "my-app/1.0");
    +            userAgent = executeQueryAndVerifyUserAgent(stmt, "my-app/1.0");
    +            Assert.assertTrue(userAgent.endsWith(expectedSuffix),
    +                    "Expected to end with '" + expectedSuffix + "' but value was '" + userAgent + "'");
    +        }
    +    }
    +
    +    @DataProvider(name = "clientMetadataInUserAgentDP")
    +    public static Object[][] clientMetadataInUserAgentDP() {
    +        return new Object[][] {{false}, {true}};
    +    }
    +
         @Test(groups = { "integration" })
         public void influenceUserAgentClientNameTest() throws SQLException {
             String clientName = UUID.randomUUID().toString().replace("-", "");

    Result: 26 files, +982/−97. These are the same counts as #3213 on main. In 25 files, the added and removed lines are identical to #3213. In ConnectionTest.java, the added lines are also the same, but return userAgent; is one indent level deeper because it is in the try block of the v0.11.0 helper.

    Verification in a devbox, with only #3213 applied (JDK 17 + JDK 8 toolchain, ClickHouse 26.9.1.1629):

    • mvn -B -DskipTests -Dmaven.javadoc.skip=true install: BUILD SUCCESS. The test sources also compile.
    • The client-v2 unit tests that [client-v2] Send the User-Agent in the standard client format and add client metadata #3213 adds or changes (UserAgentUnitTest, VersionsTest, WorkloadIdentitySupportTest, ClientUtilsTest, ClientConfigPropertiesTest, HttpAPIClientHelperTest, InsertExceptionClassificationTest): 140 of 140 pass.
    • HttpTransportTests#testUserAgentHasCompleteProductName+testClientName+testClientNameThruRawOptions: 11 of 11 pass.
    • ConnectionTest#setAndGetClientInfoTest+testClientMetadataInUserAgent+influenceUserAgentClientNameTest: 6 of 6 pass.

    I did not run the full test suites.

    How this combines with the other v0.11.0 backports:

  4. chernser commented on Oct 20, 2026

    @chernser
    ContributorAuthor

    @polyglotAI-bot I'm a maintainer and asking you do the PR to v0.11.0 for me I'll review myself

  5. polyglotAI-bot commented on Oct 20, 2026

    @polyglotAI-bot
    Collaborator

    I cannot open this PR yet. Our current rules do not let me open PRs into release branches, so I need approval from the operator of this bot. The request for approval covers this issue, #3230 and #3231. When I have the decision, I reply here.

    The recipe in my previous comment is still valid: v0.11.0 is still at eeebd1ece, and git cherry-pick -m 1 7f2cb5787 applies with the one conflict in jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java that the comment describes.

    Update 2026-10-20: The operator approved. I will open the PR into v0.11.0 when the rule change is live. The PR will link this issue.

  6. polyglotAI-bot commented on Oct 20, 2026

    @polyglotAI-bot
    Collaborator

    I opened the PR into v0.11.0: #3235

    It contains only #3213 (git cherry-pick -x -m 1 7f2cb5787), with the one ConnectionTest.java conflict resolved as in my earlier comment. The diff is 26 files, +982/−97, the same as #3213 on main.

    CI on the PR fails until v0.11.0 has the Maven 3.10 fix for packages/clickhouse-jdbc-all/pom.xml. See #3233 (comment).

    A PR into v0.11.0 does not close this issue automatically. Please close it after the merge.

  7. chernser commented on Oct 21, 2026

    @chernser
    ContributorAuthor

    all merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions