Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This file contains all changes which are not released yet.
# Fixes
<!--FIXES-START-->
- Fix JVM tool bootstrap check when program arguments contain slashes - [#4269](https://github.com/elastic/apm-agent-java/issues/4269)
- Fix JDBC host and port detection for PostgreSQL and H2 connection URLs with multiple hosts - [#4616](https://github.com/elastic/apm-agent-java/issues/4616)
<!--FIXES-END-->
# Features and enhancements
<!--ENHANCEMENTS-START-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ protected ConnectionMetaData.Builder defaultParse(String vendorUrl, ConnectionMe
authority = authority.substring(0, authorityEnd);
}

// multiple hosts for failover or clustering, for example //host1:666,host2:777/database: use the first one
int hostsSeparator = authority.indexOf(',');
if (hostsSeparator > 0) {
authority = authority.substring(0, hostsSeparator);
}

parseAuthority(authority, builder);
}
} else if (!vendorUrl.equals("/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ void testPostgresql() {
testUrl("jdbc:postgresql://[::1]/", "postgresql", "::1", 5432, null);
testUrl("jdbc:postgresql://[::1]:666/", "postgresql", "::1", 666, null);

// multiple hosts: the first one is used
testUrl("jdbc:postgresql://myhost1:666,myhost2:777/database", "postgresql", "myhost1", 666, "database");
testUrl("jdbc:postgresql://myhost1,myhost2/database?targetServerType=primary", "postgresql", "myhost1", 5432, "database");
testUrl("jdbc:postgresql://myhost1:666,myhost2:777/", "postgresql", "myhost1", 666, null);
testUrl("jdbc:postgresql://[::1]:666,[::2]:777/database", "postgresql", "::1", 666, "database");

testUrl("jdbc:postgresql:database", "postgresql", "localhost", 5432, "database");
testUrl("jdbc:postgresql:/", "postgresql", "localhost", 5432, null);
}
Expand Down Expand Up @@ -300,6 +306,7 @@ void testH2() {
testUrl("jdbc:h2:tcp://dbserv:8084/~/sample", "h2", "dbserv", 8084, "sample");
testUrl("jdbc:h2:ssl://dbserv:8085/~/sample;", "h2", "dbserv", 8085, "sample");
testUrl("jdbc:h2:ssl://dbserv:8085/~/sample;prop1=val1;prop2=val2", "h2", "dbserv", 8085, "sample");
testUrl("jdbc:h2:tcp://server1:9101,server2:9102/~/sample", "h2", "server1", 9101, "sample");
}

@Test
Expand Down
Loading