From 58111b1fc589cb241b841aa325f6099e777045dd Mon Sep 17 00:00:00 2001 From: Sergei Pustovykh Date: Tue, 10 Nov 2026 17:11:01 +0000 Subject: [PATCH] Add StoreTimerMetricCollector.fromStoreTimer --- .../metric/StoreTimerMetricCollector.java | 11 +++++++++++ .../query/OfflineStoredQueriesProcessorTest.java | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/metric/StoreTimerMetricCollector.java b/fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/metric/StoreTimerMetricCollector.java index 2e9a3c635e..2eec94c57f 100644 --- a/fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/metric/StoreTimerMetricCollector.java +++ b/fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/metric/StoreTimerMetricCollector.java @@ -50,6 +50,9 @@ * hands the same instance back for every event. Suitable for non-transactional paths (e.g. * engine startup work) that still want their metrics surfaced on the engine-wide * registry. + *
  • {@link #fromStoreTimer(StoreTimer)} — hands the supplied {@link StoreTimer} back for + * every event. Suitable for non-transactional paths whose caller owns the timer and publishes + * the metrics itself.
  • * * *

    Writes ({@link #increment}, {@link #clock}) resolve the timer per call and no-op if the @@ -90,6 +93,14 @@ public static StoreTimerMetricCollector fromMetricRegistry(@Nonnull final Metric return new StoreTimerMetricCollector(event -> timer); } + /** + * Hands {@code timer} back for every event lookup. All metrics land on the supplied timer. + */ + @Nonnull + public static StoreTimerMetricCollector fromStoreTimer(@Nonnull final StoreTimer timer) { + return new StoreTimerMetricCollector(event -> timer); + } + @Override public void increment(@Nonnull final RelationalMetric.RelationalCount count, final int val) { @Nullable final StoreTimer timer = timerLookup.apply(count); diff --git a/fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/query/OfflineStoredQueriesProcessorTest.java b/fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/query/OfflineStoredQueriesProcessorTest.java index 9cc552272c..ab047ab0d9 100644 --- a/fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/query/OfflineStoredQueriesProcessorTest.java +++ b/fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/query/OfflineStoredQueriesProcessorTest.java @@ -25,6 +25,7 @@ import com.apple.foundationdb.record.metadata.IndexTypes; import com.apple.foundationdb.record.metadata.Key; import com.apple.foundationdb.record.metadata.expressions.KeyExpression; +import com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer; import com.apple.foundationdb.relational.api.Options; import com.apple.foundationdb.relational.api.exceptions.RelationalException; import com.apple.foundationdb.relational.api.metadata.DataType; @@ -123,6 +124,20 @@ void planStoredQueriesCountsOnTheMetricRegistry() throws Exception { assertThat(registry.timer(RelationalMetric.RelationalEvent.OFFLINE_STORED_QUERIES_WARM_UP.title()).getCount()).isEqualTo(1); } + @Test + void planStoredQueriesCountsOnTheStoreTimer() throws Exception { + final var template = booksTemplate(false, VERSION, QUERY, List.of()); + final var timer = new FDBStoreTimer(); + + OfflineStoredQueriesProcessor.planStoredQueries(RelationalPlanCache.buildWithDefaults(), template, + booksMetaDataWithYearIndex(), StoreTimerMetricCollector.fromStoreTimer(timer), Options.NONE); + + assertThat(timer.getCount(RelationalMetric.RelationalCount.OFFLINE_STORED_QUERIES_TEMPLATES_PROCESSED)).isEqualTo(1); + assertThat(timer.getCount(RelationalMetric.RelationalCount.OFFLINE_STORED_QUERIES_QUERIES_PROCESSED)).isEqualTo(1); + assertThat(timer.getCount(RelationalMetric.RelationalCount.OFFLINE_STORED_QUERIES_PLANS_WARMED)).isEqualTo(1); + assertThat(timer.getCount(RelationalMetric.RelationalEvent.OFFLINE_STORED_QUERIES_WARM_UP)).isEqualTo(1); + } + private static void planWithCache(@Nonnull final RelationalPlanCache cache, @Nonnull final RecordLayerSchemaTemplate template, @Nonnull final RecordMetaData metaData,