Skip to content

Commit

Permalink
4.x fix pinned meter type (#9657)
Browse files Browse the repository at this point in the history
* Fix error in looking up the recent-pinned virtual threads timer

* Improve tag handling for timer look-up

* Review comment
  • Loading branch information
tjquinno authored Jan 17, 2025
1 parent e2b2587 commit f419a62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;

import io.helidon.common.LazyValue;
Expand All @@ -27,6 +29,7 @@
import io.helidon.metrics.api.Metrics;
import io.helidon.metrics.api.MetricsConfig;
import io.helidon.metrics.api.MetricsFactory;
import io.helidon.metrics.api.SystemTagsManager;
import io.helidon.metrics.api.Timer;
import io.helidon.metrics.spi.MetersProvider;

Expand Down Expand Up @@ -129,10 +132,13 @@ private static void listenFor(RecordingStream rs, Map<String, Consumer<RecordedE
});
}

private Timer findPinned() {
var result = Metrics.globalRegistry().timer(METER_NAME_PREFIX + PINNED, List.of());
// visible for testing
Timer findPinned() {
var result = Metrics.globalRegistry().timer(METER_NAME_PREFIX + RECENT_PINNED,
SystemTagsManager.instance().withScopeTag(Collections.emptyList(),
Optional.of(METER_SCOPE)));
if (result.isEmpty()) {
throw new IllegalStateException(METER_NAME_PREFIX + "pinned meter expected but not registered");
throw new IllegalStateException(METER_NAME_PREFIX + RECENT_PINNED + " meter expected but not registered");
}
return result.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@ void checkPinnedThreadThreshold() {

}

@Test
void checkRecentPinnedTimerLookup() {
Config config = Config.just(ConfigSources.create(Map.of("virtual-threads.pinned.threshold", "PT0.040S")));
MetricsFactory metricsFactory = MetricsFactory.getInstance(config);
VThreadSystemMetersProvider provider = new VThreadSystemMetersProvider();
provider.meterBuilders(metricsFactory);

provider.findPinned();
}

}

0 comments on commit f419a62

Please sign in to comment.