-
Notifications
You must be signed in to change notification settings - Fork 1k
Add support for per-query metrics in Hibernate statistics(#1006) #1461
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
Conversation
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.java
Outdated
Show resolved
Hide resolved
@shakuzen are you fine with the changes? Should I change smth else? |
...meter-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateQueryMetrics.java
Outdated
Show resolved
Hide resolved
...meter-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateQueryMetrics.java
Outdated
Show resolved
Hide resolved
...meter-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateQueryMetrics.java
Outdated
Show resolved
Hide resolved
...meter-core/src/main/java/io/micrometer/core/instrument/binder/jpa/HibernateQueryMetrics.java
Outdated
Show resolved
Hide resolved
@shakuzen Anything else do you see that would be good to change? |
QueryStatistics queryStatistics = statistics.getQueryStatistics(query); | ||
if (Objects.nonNull(queryStatistics)) { | ||
String queryName = meterRegistry.config().namingConvention().tagValue(query); | ||
if (Objects.isNull(Search.in(meterRegistry).tags("query", queryName).functionCounter())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the point of this check because there could be multiple of the same query returned by statistics.getQueries()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emm If I remember correctly there should not, it is a little bit redundant check
…breaking the meter name
#Remove hibernate.query.executions.avg as is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long delay on getting this merged, and thank you for making the changes requested during review. Great work.
|
||
/** | ||
* A {@link MeterBinder} implementation that provides Hibernate query metrics. It exposes the | ||
* same statistics as would be exposed when calling {@link Statistics#getQueryStatistics(String)}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a warning about potential high cardinality depending on the variety of queries one's application executes. I can add this as a polish commit post merge.
|
||
/** | ||
* Register hibernate loadEvent listener - event trigger the metrics registration, | ||
* only select queries are recorded in QueryStatistics {@link org.hibernate.stat.spi.StatisticsImplementor} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we think it would be helpful to users to have this information, we should add it to one of the public methods or the class JavaDoc. On a private method, it will not be noticed by most users.
} | ||
|
||
private HibernateQueryMetrics.MetricsEventHandler createMetricsEventHandlerMock() { | ||
HibernateQueryMetrics hibernateQueryMetricsMock = Mockito.mock(HibernateQueryMetrics.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like we're mocking too much when we are even mocking the class under test. I will try to rework the tests a bit to get something that feels closer to real usage. We could even make tests that use an in-memory database and normal Hibernate with that. This can be done post-merge, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at this more closely, I see we're essentially testing the MetricsEventHandler
in isolation. That's fine for this. I'll open an issue to add tests with not-mocked Hibernate classes.
Resolves #1006