Skip to content

Commit 38ec7c3

Browse files
authored
ensure provided tags are reported for fetchExists (#6643)
The default implementation will result in the `time` method being called twice which has the effect of losing the provided tags and no metrics being recorded. This fixes it by overriding the method to avoid timing the internal query used. Resolves gh-6583 Signed-off-by: heechann <[email protected]>
1 parent 8f416d6 commit 38ec7c3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/db/MetricsDSLContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,4 +790,9 @@ public <R extends Record> UpdateSetFirstStep<R> update(Table<R> table) {
790790
return timeCoercable(super.update(table));
791791
}
792792

793+
@Override
794+
public boolean fetchExists(Table<?> table, Condition condition) {
795+
return super.fetchExists(super.selectOne().from(table).where(condition));
796+
}
797+
793798
}

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/db/MetricsDSLContextTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@ void timeTwoStatementsCreatedBeforeEitherIsExecuted() throws SQLException {
173173
}
174174
}
175175

176+
@Test
177+
// gh-6583
178+
void fetchExistsIsTimedWithProvidedTags() throws SQLException {
179+
try (Connection conn = DriverManager.getConnection("jdbc:h2:mem:fetchExists")) {
180+
MetricsDSLContext jooq = createDatabase(conn);
181+
182+
boolean exists = jooq.tag("name", "checkAuthorExists").fetchExists(table("author"), field("id").eq(1));
183+
assertThat(exists).isTrue();
184+
185+
assertThat(meterRegistry.get("jooq.query")
186+
.tag("name", "checkAuthorExists")
187+
.tag("type", "read")
188+
.timer()
189+
.count()).isEqualTo(1);
190+
}
191+
}
192+
176193
@Test
177194
void userExecuteListenerShouldBePreserved() {
178195
ExecuteListener userExecuteListener = mock(ExecuteListener.class);

0 commit comments

Comments
 (0)