GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [fix][test] Fix flaky OpenTelemetryServiceTest.testJvmRuntimeMetrics by merlimat · Pull Request #27565 · apache/pulsar Conversation
Contributor
Motivation
The metric that is missing is for (int i = 0; i < 100; i++) { byte[] waste = new byte[1024 * 1024]; // 1MB } Runtime.getRuntime().gc(); var metrics = reader.collectAllMetrics(); ... assertThat(metrics).anySatisfy(metric -> assertThat(metric).hasName("jvm.gc.duration")); On a busy runner the notification thread may not have run by then. The histogram has no points yet, so the reader doesn't export it. Reproduced locally with a scratch test, not included in this PR. It adds a GC listener before the service's that holds the notification thread for 2 s, then runs ModificationsBefore triggering the GC, the test adds its own listener for GC notifications to every GC MXBean, with the same notification type filter that var gcNotified = new CountDownLatch(1); NotificationListener gcListener = (notification, handback) -> gcNotified.countDown(); NotificationFilter gcFilter = notification -> notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION); var gcEmitters = ManagementFactory.getGarbageCollectorMXBeans().stream() .filter(NotificationEmitter.class::isInstance) .map(NotificationEmitter.class::cast) .toList(); gcEmitters.forEach(emitter -> emitter.addNotificationListener(gcListener, gcFilter, null)); try { // (the existing GC trigger, unchanged) Runtime.getRuntime().gc(); assertThat(gcNotified.await(30, TimeUnit.SECONDS)).as("GC notification delivered").isTrue(); } finally { for (NotificationEmitter emitter : gcEmitters) { emitter.removeNotificationListener(gcListener); } } var metrics = reader.collectAllMetrics(); The wait is on the event the metric depends on, not on a timeout. The service adds its listeners when it is built in Verifying this change
Does this pull request potentially affect one of the following parts:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsjvm.gc.duration is recorded by RuntimeTelemetry's listener for the JVM's GC notifications, which the JVM delivers on its notification thread after the collection ends. The test collected the metrics as soon as Runtime.gc() returned, so when that thread had not run yet the histogram had no points and jvm.gc.duration was missing. The test now adds its own GC notification listener after the service's and waits for it before collecting. A GC MXBean calls its listeners in the order they were added, on one thread, so once the test's listener has run the service has recorded that collection. …-metrics-flake-30093c
codelipenghui
approved these changes
Uh oh!
There was an error while loading. Please reload this page.
poorbarcode
pushed a commit
to poorbarcode/pulsar
that referenced
this pull request
…pache#27565) (cherry picked from commit 13e1685)
poorbarcode
pushed a commit
to poorbarcode/pulsar
that referenced
this pull request
…pache#27565) (cherry picked from commit 13e1685)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabelsProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |