From e6a428e48fcac083fcad7d82f1ab4f47531bf8a4 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Thu, 24 Oct 2024 15:22:08 +0300 Subject: [PATCH] Improve whitespace handling in oracle jdbc url parser --- .../jdbc/internal/JdbcConnectionUrlParser.java | 6 ++++-- .../jdbc/internal/JdbcConnectionUrlParserTest.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParser.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParser.java index 81da42ff811c..ef0c5e08a719 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParser.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParser.java @@ -530,10 +530,12 @@ DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) { }, ORACLE_AT() { + private final Pattern descriptionPattern = Pattern.compile("@\\s*\\(\\s*description"); + @Override @CanIgnoreReturnValue DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) { - if (jdbcUrl.contains("@(description")) { + if (descriptionPattern.matcher(jdbcUrl).find()) { return ORACLE_AT_DESCRIPTION.doParse(jdbcUrl, builder); } String user; @@ -565,7 +567,7 @@ DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) { /** * This parser can locate incorrect data if multiple addresses are defined but not everything is - * defined in the first block. (It would locate data from subsequent address blocks. + * defined in the first block. It would locate data from subsequent address blocks. */ ORACLE_AT_DESCRIPTION() { private final Pattern hostPattern = Pattern.compile("\\(\\s*host\\s*=\\s*([^ )]+)\\s*\\)"); diff --git a/instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParserTest.java b/instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParserTest.java index 68b4a84ba653..bc90cbc72908 100644 --- a/instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParserTest.java +++ b/instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParserTest.java @@ -559,7 +559,7 @@ public Stream provideArguments(ExtensionContext context) { .setPort(666) .setName("orclsn") .build(), - arg("jdbc:oracle:thin:@(description = (connect_timeout=90)(retry_count=20)(retry_delay=3) (transport_connect_timeout=3000) (address_list = (load_balance = on) (failover = on) (address = (protocol = tcp)(host = orcl.host1)(port = 1521)) (address = (protocol = tcp)(host = orcl.host2)(port = 1521)) (address = (protocol = tcp)(host = orcl.host3)(port = 1521)) (address = (protocol = tcp)(host = orcl.host4)(port = 1521)) ) (connect_data = (server = dedicated) (service_name = orclsn)))") + arg("jdbc:oracle:thin:@ ( description = (connect_timeout=90)(retry_count=20)(retry_delay=3) (transport_connect_timeout=3000) (address_list = (load_balance = on) (failover = on) (address = (protocol = tcp)(host = orcl.host1 )(port = 1521 )) (address = (protocol = tcp)(host = orcl.host2)(port = 1521)) (address = (protocol = tcp)(host = orcl.host3)(port = 1521)) (address = (protocol = tcp)(host = orcl.host4)(port = 1521)) ) (connect_data = (server = dedicated) (service_name = orclsn)))") .setShortUrl("oracle:thin://orcl.host1:1521") .setSystem("oracle") .setSubtype("thin")