Skip to content

HHH-20783 Add a dedicated failed-transactions counter to Statistics - #13206

Open
pjs7678 wants to merge 1 commit into
hibernate:mainfrom
pjs7678:HHH-20783
Open

HHH-20783 Add a dedicated failed-transactions counter to Statistics#13206
pjs7678 wants to merge 1 commit into
hibernate:mainfrom
pjs7678:HHH-20783

Conversation

@pjs7678

@pjs7678 pjs7678 commented Aug 18, 2026

Copy link
Copy Markdown

https://hibernate.atlassian.net/browse/HHH-20783

The failed-transactions value exposed by hibernate-micrometer as hibernate.transactions{result="failure"} was derived as
getTransactionCount() - getSuccessfulTransactionCount(). Since endTransaction() increments the two counters non-atomically, a concurrent reader (e.g. a Prometheus scrape) could transiently observe a negative value - and Micrometer 1.14+ (Prometheus Java client 1.x) rejects negative counters, failing the entire /actuator/prometheus scrape with HTTP 500.

As suggested by Christian Beikov on the forum (https://discourse.hibernate.org/t/12391), this introduces a dedicated counter:

  • Statistics#getFailedTransactionCount() - new default method (derived fallback for custom implementations)
  • StatisticsImpl - a dedicated LongAdder, incremented in endTransaction(false), reset in clear()
  • HibernateMetrics now reads the dedicated counter, so the exposed value is exact, monotonic, and can never go negative (no transient overcount either, which could otherwise trip alerts on the failure counter)

Includes a regression test (deterministic success/rollback/clear cases plus a short concurrency guard). A standalone reproducer against the old derivation is attached to the Jira ticket (observes ~31k negative reads within 10 seconds on 6.6.55.Final).


Please make sure that the following tasks are completed:
Tasks specific to HHH-20783 (Bug):

  • Add test reproducing the bug
  • Add entries as relevant to migration-guide.adoc OR check there are no breaking changes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@hibernate-github-bot

hibernate-github-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@pjs7678 pjs7678 changed the title HHH-20783 Add a dedicated failed-transactions couter to Statistics HHH-20783 Add a dedicated failed-transactions counter to Statistics Aug 18, 2026

@beikov beikov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a section to Statistics.adoc that is similar to the one for getSuccessfulTransactionCount(). As for the test, it's IMO fine to just add asserts to CMTTest and StatelessSessionStatisticsTest analogous to what has been done for getSuccessfulTransactionCount()

@pjs7678

pjs7678 commented Aug 18, 2026

Copy link
Copy Markdown
Author

Thanks! Both addressed: documented getFailedTransactionCount in Statistics.adoc, and replaced the standalone test with asserts in CMTTest and StatelessSessionStatisticsTest.

@gavinking gavinking left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sonarqubecloud

Copy link
Copy Markdown

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.

3 participants