Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for informix connection string parsing in jdbc instrumentation #11542

Merged
merged 10 commits into from
Jun 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,81 @@ DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {

return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder);
}
},
INFORMIX_SQLI("informix-sqli") {
@Override
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
builder = MODIFIED_URL_LIKE.doParse(jdbcUrl, builder);
builder = INFORMIX.doParse(jdbcUrl, builder);

int hostIndex = jdbcUrl.indexOf("://");
if (hostIndex == -1) {
return builder;
}

int dbNameStartIndex = jdbcUrl.indexOf('/', hostIndex + 3);
if (dbNameStartIndex == -1) {
return builder;
}
int dbNameEndIndex = jdbcUrl.indexOf(':', dbNameStartIndex);
if (dbNameEndIndex == -1) {
dbNameEndIndex = jdbcUrl.length();
}
String name = jdbcUrl.substring(dbNameStartIndex + 1, dbNameEndIndex);
if (name.isEmpty()) {
builder.name(null);
} else {
builder.name(name);
}

return builder;
}
},

INFORMIX_DIRECT("informix-direct") {
private static final String DEFAULT_HOST = "infxhost";

@Override
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
builder = MODIFIED_URL_LIKE.doParse(jdbcUrl, builder);
builder = INFORMIX.doParse(jdbcUrl, builder);
builder.host(DEFAULT_HOST);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me this is strange. Looking at https://www.ibm.com/docs/en/informix-servers/12.10?topic=method-format-database-urls before informix-direct it says

For connections on the database server, use the following format:

Does this mean that informix-direct is used when the server is connecting to somewhere? If that is the case should we bother with it at all? Considering that it is difficult to find info about informix-direct it might be the best option. There doesn't seem to be a host and port for informix-direct, if we are going to parse this then imo we should not fill these at all (could skip MODIFIED_URL_LIKE.doParse and INFORMIX.doParse calls).


int hostIndex = jdbcUrl.indexOf("://");
if (hostIndex == -1) {
return builder;
}

int informixUrlStartIdx =
jdbcUrl.indexOf("informix-direct://") + "informix-direct://".length();
jaydeluca marked this conversation as resolved.
Show resolved Hide resolved
int colonLoc = jdbcUrl.indexOf(":", informixUrlStartIdx);
jaydeluca marked this conversation as resolved.
Show resolved Hide resolved

String name;
if (colonLoc > -1) {
name = jdbcUrl.substring(informixUrlStartIdx, colonLoc);
} else {
name = jdbcUrl.substring(informixUrlStartIdx);
}
if (!name.isEmpty()) {
builder.name(name);
}

return builder;
}
},

INFORMIX {
private static final int DEFAULT_PORT = 9088;

@Override
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
DbInfo dbInfo = builder.build();
if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT);
}

return builder;
}
};

private static final Logger logger = Logger.getLogger(JdbcConnectionUrlParser.class.getName());
Expand Down Expand Up @@ -1000,6 +1075,10 @@ private static String toDbSystem(String type) {
return DbSystemValues.H2;
case "hsqldb": // Hyper SQL Database
return "hsqldb";
case "informix-sqli": // IBM Informix
return DbSystemValues.INFORMIX_SQLI;
case "informix-direct":
return DbSystemValues.INFORMIX_DIRECT;
case "mariadb": // MariaDB
return DbSystemValues.MARIADB;
case "mysql": // MySQL
Expand All @@ -1026,6 +1105,8 @@ private static final class DbSystemValues {
static final String MYSQL = "mysql";
static final String ORACLE = "oracle";
static final String DB2 = "db2";
static final String INFORMIX_SQLI = "informix-sqli";
static final String INFORMIX_DIRECT = "informix-direct";
static final String POSTGRESQL = "postgresql";
static final String HANADB = "hanadb";
static final String DERBY = "derby";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,61 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
.setDb("sapdb")
.build(),

// https://www.ibm.com/support/pages/how-configure-informix-jdbc-connection-string-connect-group
arg("jdbc:informix-sqli://infxhost:99/infxdb:INFORMIXSERVER=infxsn;user=infxuser;password=PW")
.setSystem("informix-sqli")
.setUser("infxuser")
.setShortUrl("informix-sqli://infxhost:99")
.setHost("infxhost")
.setPort(99)
.setName("infxdb")
.build(),
arg("jdbc:informix-sqli://localhost:9088/stores_demo:INFORMIXSERVER=informix")
.setSystem("informix-sqli")
.setShortUrl("informix-sqli://localhost:9088")
.setHost("localhost")
.setPort(9088)
.setName("stores_demo")
.build(),
arg("jdbc:informix-sqli://infxhost:99")
.setSystem("informix-sqli")
.setShortUrl("informix-sqli://infxhost:99")
.setHost("infxhost")
.setPort(99)
.build(),
arg("jdbc:informix-sqli://infxhost/")
.setSystem("informix-sqli")
.setShortUrl("informix-sqli://infxhost:9088")
.setHost("infxhost")
.setPort(9088)
.build(),
arg("jdbc:informix-sqli:")
.setSystem("informix-sqli")
.setShortUrl("informix-sqli:")
.setPort(9088)
.build(),
arg("jdbc:informix-direct://infxdb:999;user=infxuser;password=PW")
.setSystem("informix-direct")
.setUser("infxuser")
.setShortUrl("informix-direct://infxhost:999")
.setHost("infxhost")
.setPort(999)
.setName("infxdb")
.build(),
arg("jdbc:informix-direct://infxdb")
.setSystem("informix-direct")
.setShortUrl("informix-direct://infxhost:9088")
.setHost("infxhost")
.setName("infxdb")
.setPort(9088)
.build(),
arg("jdbc:informix-direct:")
.setSystem("informix-direct")
.setShortUrl("informix-direct://infxhost:9088")
.setHost("infxhost")
.setPort(9088)
.build(),

// http://www.h2database.com/html/features.html#database_url
arg("jdbc:h2:mem:").setShortUrl("h2:mem:").setSystem("h2").setSubtype("mem").build(),
arg("jdbc:h2:mem:")
Expand Down
Loading