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

Enhance JDBC connection string parsing for multiple hosts #1082

Merged
merged 2 commits into from Mar 15, 2020

Conversation

eyalkoren
Copy link
Contributor

@eyalkoren eyalkoren commented Mar 12, 2020

What does this PR do?

Enhance the JDBC connection string parser to support dedicated syntaxes for multiple hosts in Oracle, MySQL and MariaDB.

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related issues

Closes #1031

@codecov-io
Copy link

codecov-io commented Mar 12, 2020

Codecov Report

Merging #1082 into master will decrease coverage by 0.01%.
The diff coverage is 86.18%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1082      +/-   ##
============================================
- Coverage     60.74%   60.72%   -0.02%     
  Complexity       87       87              
============================================
  Files           320      320              
  Lines         14446    14491      +45     
  Branches       1988     2014      +26     
============================================
+ Hits           8775     8800      +25     
- Misses         5091     5102      +11     
- Partials        580      589       +9     
Impacted Files Coverage Δ Complexity Δ
...stic/apm/agent/jdbc/helper/ConnectionMetaData.java 89.00% <86.18%> (-2.14%) 0.00 <0.00> (ø)
...pm/agent/profiler/asyncprofiler/AsyncProfiler.java 60.46% <0.00%> (-4.66%) 0.00% <0.00%> (ø%)
...a/co/elastic/apm/agent/report/ApmServerClient.java 83.00% <0.00%> (-4.33%) 0.00% <0.00%> (ø%)
...o/elastic/apm/agent/profiler/SamplingProfiler.java 77.93% <0.00%> (-0.28%) 0.00% <0.00%> (ø%)
...lastic/apm/agent/report/ReporterConfiguration.java 100.00% <0.00%> (ø) 0.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2870994...420aa57. Read the comment docs.

Copy link
Member

@SylvainJuge SylvainJuge left a comment

Choose a reason for hiding this comment

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

LGTM: Only few really minor things, impressive test suite.

return new ConnectionMetaData(dbVendor, host, port, user);
}

private HostPort parseAddressList(String connectionUrl) {
Copy link
Member

Choose a reason for hiding this comment

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

[minor] maybe return null when HostPort.host == null || HostPort.port < 0

Copy link
Member

Choose a reason for hiding this comment

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

[minor] maybe naming this method with Oracle might be relevant as it's very Oracle-specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe return null when HostPort.host == null || HostPort.port < 0

👍 for HostPort.host == null, however I am pretty sure the port is optional, so one may set a host and not the port (in which case the default will be used- there is a test for that)

maybe naming this method with Oracle might be relevant as it's very Oracle-specific.

It's within the Oracle parser (enum)

}
default: {
if (currentValueBuffer == null) {
logger.warn("Failed to parse Oracle DB address list from: {}", connectionUrl);
Copy link
Member

Choose a reason for hiding this comment

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

do we really want to continue parsing in case of error ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be an error or an unknown use of the connection string. However, I only care about very specific nodes in this tree, so if the parsing yields a valid tree in which I can find the tree nodes I am looking for, I don't care.

return ConnectionUrlParser.defaultParse(connectionUrl, dbVendor, 3306, user);
String host = "localhost";
int port = 3306;
HostPort hostPort = parseMySqlFlavor(connectionUrl);
Copy link
Member

Choose a reason for hiding this comment

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

[minor] same here, having a null return value would avoid duplication of the null check and port > 0 below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think- most (or all) make port configuration optional, each provider using a different default port if not configured.

@eyalkoren eyalkoren merged commit c99e082 into elastic:master Mar 15, 2020
@eyalkoren eyalkoren deleted the jdbc-connection-string-parsing branch March 15, 2020 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enhance destination fields for Oracle
3 participants