Skip to content

Commit d0799ce

Browse files
committed
ensure provided tags are reported for fetchExists
Signed-off-by: heechann <[email protected]>
1 parent f4db25d commit d0799ce

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.micrometer.core.instrument.Tags;
2222
import org.jooq.*;
2323
import org.jooq.Record;
24+
import org.jooq.impl.DSL;
2425
import org.jooq.impl.DefaultDSLContext;
2526

2627
import java.util.Arrays;
@@ -792,4 +793,9 @@ public <R extends Record> UpdateSetFirstStep<R> update(Table<R> table) {
792793
return timeCoercable(super.update(table));
793794
}
794795

796+
@Override
797+
public boolean fetchExists(Table<?> table, Condition condition) {
798+
return super.fetchExists(DSL.selectOne().from(table).where(condition));
799+
}
800+
795801
}

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

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

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

0 commit comments

Comments
 (0)