Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
* {@link MetricRegistryStoreTimer} over the supplied Codahale {@link MetricRegistry} and
* 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.</li>

Check notice on line 52 in fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/metric/StoreTimerMetricCollector.java

View workflow job for this annotation

GitHub Actions / coverage

File coverage: 97.2% (35/36 lines) | Changed lines: 100.0% (1/1 lines)
* <li>{@link #fromStoreTimer(StoreTimer)} &mdash; hands the supplied {@link StoreTimer} back for
* every event. Suitable for non-transactional paths whose caller owns the timer and publishes
* the metrics itself.</li>
* </ul>
*
* <p>Writes ({@link #increment}, {@link #clock}) resolve the timer per call and no-op if the
Expand Down Expand Up @@ -90,6 +93,14 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading