Skip to content

Add metrics support for idle jdbc connections #17504

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

Closed
wants to merge 5 commits into from

Conversation

ayudovin
Copy link
Contributor

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 13, 2019
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

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

Thanks again for the PR @ayudovin. I don't see a change in metrics using that new data point, have I missed something?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Jul 15, 2019
@ayudovin
Copy link
Contributor Author

@snicoll, sorry, you are right, I just forgot to update it, I will fix it

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 15, 2019
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I've added a few suggestions and I am wondering why some tests were modified with no apparent reason.

@@ -185,6 +193,27 @@ private static HikariDataSource createHikariDataSource(String poolName) {
return hikariDataSource;
}

@Configuration
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why initializing the pool here is necessary. Can you please clarify why this is done as part of this PR?

@@ -51,6 +57,27 @@ void dataSourceIsInstrumented() {
});
}

@Configuration
static class HikariPool {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

/**
* Return the number of established but idle connections. Can also return {@code null}
* if that information is not available.
* @return the number of established but idle connections or {@code null}
Copy link
Member

Choose a reason for hiding this comment

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

This method should have a @since 2.2.0 on it

return pool.getIdleConnections();
}

return super.getIdle();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think calling super is what I'd do here

* if that information is not available.
* @return the number of established but idle connections or {@code null}
*/
default Integer getIdle() {
Copy link
Member

Choose a reason for hiding this comment

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

Rather than adding this method at the end I'd group it logically with a similar concept. Right below getActive sounds good. As a result, methods in implementations and tests should be reordered accordingly.

@@ -69,4 +72,14 @@ public Boolean getDefaultAutoCommit() {
return getDataSource().isAutoCommit();
}

@Override
public Integer getIdle() {
HikariPool pool = getHikariPool();
Copy link
Member

Choose a reason for hiding this comment

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

I'd do the same as what we do in getActive()

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jul 16, 2019
@ayudovin
Copy link
Contributor Author

ayudovin commented Jul 16, 2019

@snicoll, thank you for suggestions, I pushed changes to follow by this suggestion. Regarding the tests, it was just my mistake and I have fixed it now. Could you please check that I don't forget something else?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 16, 2019
// Make sure the pool is initialized
JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> null);
assertThat(getDataSourceMetadata().getIdle()).isEqualTo(Integer.valueOf(1));
Copy link

@tgeens tgeens Jul 16, 2019

Choose a reason for hiding this comment

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

This assumes that an Hikari connection pool with min=0; max=2 has 1 initial connection.

The other connection pools seem to default to 0 - or is that because the other connection pools are not initiliazed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it's because the other connection pools are not initialized

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 guess I need to add the same tests with initialization pool for other connection pools, what do you think about it?

Copy link
Member

Choose a reason for hiding this comment

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

We should configure the pool explicitly so that the idle connection stays in the pool indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, I'm not sure that I catch you, Is this way of initializing pool good for the tests?

Copy link
Member

@snicoll snicoll Jul 16, 2019

Choose a reason for hiding this comment

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

We could use a dedicated HikariDataSource dataSource = createDataSource(0, 2); in the test itself. If there is a setting that we could set to increase the time an idle connection stays in the pool, that would be nice too as we ensure that our test is asserting the conditions as we expect them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I have got it.

@snicoll snicoll self-assigned this Jul 17, 2019
@snicoll snicoll removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Jul 17, 2019
@snicoll snicoll modified the milestones: 2.2.x, 2.2.0.M5 Jul 17, 2019
snicoll pushed a commit that referenced this pull request Jul 17, 2019
@snicoll snicoll closed this in 470e1d6 Jul 17, 2019
@snicoll snicoll changed the title add idle count to DataSourcePoolMetadata and DataSourcePoolMetrics Add metrics support for idle jdbc connections Jul 17, 2019
@snicoll
Copy link
Member

snicoll commented Jul 17, 2019

Thanks again for the PR @ayudovin. That's not exactly what I had in mind for the test, I've updated your proposal with what I had in mind.

@ayudovin
Copy link
Contributor Author

@snicoll, ok, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants