Skip to content

Commit fd9949d

Browse files
john9xotelbot[bot]
andauthored
ClickHouse JDBC URL support (#13884)
Co-authored-by: otelbot <[email protected]>
1 parent f3690c1 commit fd9949d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParser.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,24 @@ DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
892892

893893
return builder;
894894
}
895+
},
896+
/**
897+
* <a
898+
* href="https://clickhouse.com/docs/integrations/language-clients/java/jdbc#configuration">Driver
899+
* configuration doc</a> mentions that besides <code>clickhouse</code> <code>ch</code> could also
900+
* be used but ClickHouse Connection implementation always returns full prefix <code>
901+
* jdbc:clickhouse:</code>
902+
*/
903+
CLICKHOUSE("clickhouse") {
904+
@Override
905+
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
906+
String clickhouseUrl = jdbcUrl.substring("clickhouse:".length());
907+
int typeEndIndex = clickhouseUrl.indexOf("://");
908+
if (typeEndIndex > 0) {
909+
builder.subtype(clickhouseUrl.substring(0, typeEndIndex));
910+
}
911+
return GENERIC_URL_LIKE.doParse(clickhouseUrl, builder);
912+
}
895913
};
896914

897915
private static final Logger logger = Logger.getLogger(JdbcConnectionUrlParser.class.getName());
@@ -1079,6 +1097,8 @@ private static String toDbSystem(String type) {
10791097
return DbSystemValues.MSSQL;
10801098
case "sap": // SAP Hana
10811099
return DbSystemValues.HANADB;
1100+
case "clickhouse": // ClickHouse
1101+
return DbSystemValues.CLICKHOUSE;
10821102
default:
10831103
return DbSystemValues.OTHER_SQL; // Unknown DBMS
10841104
}
@@ -1098,6 +1118,7 @@ private static final class DbSystemValues {
10981118
static final String DERBY = "derby";
10991119
static final String MARIADB = "mariadb";
11001120
static final String H2 = "h2";
1121+
static final String CLICKHOUSE = "clickhouse";
11011122

11021123
private DbSystemValues() {}
11031124
}

instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParserTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,35 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
207207
}
208208
}
209209

210+
@ParameterizedTest(name = "{index}: {0}")
211+
@ArgumentsSource(ClickHouseProvider.class)
212+
void testClickHouseParsing(ParseTestArgument argument) {
213+
testVerifySystemSubtypeParsingOfUrl(argument);
214+
}
215+
216+
static final class ClickHouseProvider implements ArgumentsProvider {
217+
@Override
218+
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
219+
return args(
220+
// https://clickhouse.com/docs/integrations/language-clients/java/jdbc#configuration
221+
arg("jdbc:clickhouse:http://localhost:8123/mydb")
222+
.setShortUrl("clickhouse:http://localhost:8123")
223+
.setSystem("clickhouse")
224+
.setSubtype("http")
225+
.setHost("localhost")
226+
.setPort(8123)
227+
.setDb("mydb")
228+
.build(),
229+
arg("jdbc:clickhouse:https://localhost:8443?ssl=true")
230+
.setShortUrl("clickhouse:https://localhost:8443")
231+
.setSystem("clickhouse")
232+
.setSubtype("https")
233+
.setHost("localhost")
234+
.setPort(8443)
235+
.build());
236+
}
237+
}
238+
210239
@ParameterizedTest(name = "{index}: {0}")
211240
@ArgumentsSource(PostgresProvider.class)
212241
void testPostgresParsing(ParseTestArgument argument) {

0 commit comments

Comments
 (0)