Fix db.system for SAP Hana and remove unnecessary code (#6401)

* Remove unnecessary code

* Remove unnecessary code

* Fix tests
This commit is contained in:
Trask Stalnaker 2022-08-02 11:16:38 -07:00 committed by GitHub
parent faa367395f
commit 11a057594e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 17 deletions

View File

@ -636,7 +636,7 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
kind CLIENT kind CLIENT
childOf span(0) childOf span(0)
attributes { attributes {
"$SemanticAttributes.DB_SYSTEM" "testdb" "$SemanticAttributes.DB_SYSTEM" "other_sql"
"$SemanticAttributes.DB_STATEMENT" "testing ?" "$SemanticAttributes.DB_STATEMENT" "testing ?"
"$SemanticAttributes.DB_CONNECTION_STRING" "testdb://localhost" "$SemanticAttributes.DB_CONNECTION_STRING" "testdb://localhost"
"$SemanticAttributes.NET_PEER_NAME" "localhost" "$SemanticAttributes.NET_PEER_NAME" "localhost"
@ -677,7 +677,7 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
kind CLIENT kind CLIENT
childOf span(0) childOf span(0)
attributes { attributes {
"$SemanticAttributes.DB_SYSTEM" "testdb" "$SemanticAttributes.DB_SYSTEM" "other_sql"
"$SemanticAttributes.DB_NAME" databaseName "$SemanticAttributes.DB_NAME" databaseName
"$SemanticAttributes.DB_CONNECTION_STRING" "testdb://localhost" "$SemanticAttributes.DB_CONNECTION_STRING" "testdb://localhost"
"$SemanticAttributes.DB_STATEMENT" sanitizedQuery "$SemanticAttributes.DB_STATEMENT" sanitizedQuery
@ -783,7 +783,7 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
kind CLIENT kind CLIENT
childOf span(0) childOf span(0)
attributes { attributes {
"$SemanticAttributes.DB_SYSTEM" "testdb" "$SemanticAttributes.DB_SYSTEM" "other_sql"
"$SemanticAttributes.DB_CONNECTION_STRING" "testdb://localhost" "$SemanticAttributes.DB_CONNECTION_STRING" "testdb://localhost"
"$SemanticAttributes.DB_STATEMENT" "SELECT * FROM table" "$SemanticAttributes.DB_STATEMENT" "SELECT * FROM table"
"$SemanticAttributes.DB_OPERATION" "SELECT" "$SemanticAttributes.DB_OPERATION" "SELECT"

View File

@ -55,19 +55,16 @@ public enum JdbcConnectionUrlParser {
if (!path.isEmpty()) { if (!path.isEmpty()) {
builder.db(path); builder.db(path);
} }
if (uri.getHost() != null) { if (uri.getHost() != null) {
builder.host(uri.getHost()); builder.host(uri.getHost());
} }
if (uri.getPort() > 0) { if (uri.getPort() > 0) {
builder.port(uri.getPort()); builder.port(uri.getPort());
} }
return builder.system(uri.getScheme());
} catch (Exception e) { } catch (Exception e) {
return builder; logger.log(FINE, e.getMessage(), e);
} }
return builder;
} }
}, },
@ -629,13 +626,13 @@ public enum JdbcConnectionUrlParser {
if (dbInfo.getPort() == null) { if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT); builder.port(DEFAULT_PORT);
} }
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystemValues.H2).subtype("tcp"); return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).subtype("tcp");
} else if (h2Url.startsWith("ssl:")) { } else if (h2Url.startsWith("ssl:")) {
DbInfo dbInfo = builder.build(); DbInfo dbInfo = builder.build();
if (dbInfo.getPort() == null) { if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT); builder.port(DEFAULT_PORT);
} }
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system(DbSystemValues.H2).subtype("ssl"); return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).subtype("ssl");
} else { } else {
builder.subtype("file").host(null).port(null); builder.subtype("file").host(null).port(null);
int propLoc = h2Url.indexOf(";"); int propLoc = h2Url.indexOf(";");
@ -688,22 +685,22 @@ public enum JdbcConnectionUrlParser {
if (dbInfo.getPort() == null) { if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT); builder.port(DEFAULT_PORT);
} }
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system("hsqldb").subtype("hsql"); return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).subtype("hsql");
} else if (hsqlUrl.startsWith("hsqls:")) { } else if (hsqlUrl.startsWith("hsqls:")) {
if (dbInfo.getPort() == null) { if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT); builder.port(DEFAULT_PORT);
} }
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system("hsqldb").subtype("hsqls"); return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).subtype("hsqls");
} else if (hsqlUrl.startsWith("http:")) { } else if (hsqlUrl.startsWith("http:")) {
if (dbInfo.getPort() == null) { if (dbInfo.getPort() == null) {
builder.port(80); builder.port(80);
} }
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system("hsqldb").subtype("http"); return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).subtype("http");
} else if (hsqlUrl.startsWith("https:")) { } else if (hsqlUrl.startsWith("https:")) {
if (dbInfo.getPort() == null) { if (dbInfo.getPort() == null) {
builder.port(443); builder.port(443);
} }
return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).system("hsqldb").subtype("https"); return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder).subtype("https");
} else { } else {
builder.subtype("mem").host(null).port(null); builder.subtype("mem").host(null).port(null);
instance = hsqlUrl; instance = hsqlUrl;
@ -969,6 +966,8 @@ public enum JdbcConnectionUrlParser {
case "microsoft": case "microsoft":
case "sqlserver": // Microsoft SQL Server case "sqlserver": // Microsoft SQL Server
return DbSystemValues.MSSQL; return DbSystemValues.MSSQL;
case "sap": // SAP Hana
return DbSystemValues.HANADB;
default: default:
return DbSystemValues.OTHER_SQL; // Unknown DBMS return DbSystemValues.OTHER_SQL; // Unknown DBMS
} }

View File

@ -147,9 +147,9 @@ class JdbcConnectionUrlParserTest extends Specification {
"jdbc:as400://ashost:66/asdb:user=asuser;password=PW;" | null | "as400://ashost:66" | "db2" | null | "asuser" | "ashost" | 66 | "asdb" | null "jdbc:as400://ashost:66/asdb:user=asuser;password=PW;" | null | "as400://ashost:66" | "db2" | null | "asuser" | "ashost" | 66 | "asdb" | null
// https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/2.0.03/en-US/ff15928cf5594d78b841fbbe649f04b4.html // https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/2.0.03/en-US/ff15928cf5594d78b841fbbe649f04b4.html
"jdbc:sap://sap.host" | null | "sap://sap.host" | "sap" | null | null | "sap.host" | null | null | null "jdbc:sap://sap.host" | null | "sap://sap.host" | "hanadb" | null | null | "sap.host" | null | null | null
"jdbc:sap://sap.host" | stdProps | "sap://sap.host:9999" | "sap" | null | "stdUserName" | "sap.host" | 9999 | null | "stdDatabaseName" "jdbc:sap://sap.host" | stdProps | "sap://sap.host:9999" | "hanadb" | null | "stdUserName" | "sap.host" | 9999 | null | "stdDatabaseName"
"jdbc:sap://sap.host:88/?databaseName=sapdb&user=sapuser&password=PW" | null | "sap://sap.host:88" | "sap" | null | "sapuser" | "sap.host" | 88 | null | "sapdb" "jdbc:sap://sap.host:88/?databaseName=sapdb&user=sapuser&password=PW" | null | "sap://sap.host:88" | "hanadb" | null | "sapuser" | "sap.host" | 88 | null | "sapdb"
// TODO: // TODO:
// "jdbc:informix-sqli://infxhost:99/infxdb:INFORMIXSERVER=infxsn;user=infxuser;password=PW" | null | "informix-sqli" | null | "infxuser" | "infxhost" | 99 | "infxdb"| null // "jdbc:informix-sqli://infxhost:99/infxdb:INFORMIXSERVER=infxsn;user=infxuser;password=PW" | null | "informix-sqli" | null | "infxuser" | "infxhost" | 99 | "infxdb"| null