-
-
Notifications
You must be signed in to change notification settings - Fork 461
Avoid ExecutorService for DefaultCompositePerformanceCollector timeout #4841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stefanosiano
merged 10 commits into
main
from
stefanosiano/fix/performance-data-collection-timeout
Oct 29, 2025
+125
−57
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
08a56a3
DefaultCompositePerformanceCollector now stops the performance data c…
stefanosiano cde1aa1
updated changelog
stefanosiano 4b38884
DefaultCompositePerformanceCollector timeout also stops span data col…
stefanosiano 8e1836d
Merge branch 'main' into stefanosiano/fix/performance-data-collection…
stefanosiano d8e3b35
updated changelog
stefanosiano 8a41cbd
Format code
getsentry-bot 0e114b7
format code
stefanosiano 8dacb2f
Merge remote-tracking branch 'origin/stefanosiano/fix/performance-dat…
stefanosiano 27b3c61
moved transaction stop out of map loop
stefanosiano f252272
Merge branch 'main' into stefanosiano/fix/performance-data-collection…
stefanosiano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| package io.sentry | ||
|
|
||
| import io.sentry.test.DeferredExecutorService | ||
| import io.sentry.test.getCtor | ||
| import io.sentry.test.getProperty | ||
| import io.sentry.test.injectForField | ||
| import io.sentry.util.thread.ThreadChecker | ||
| import java.util.Date | ||
| import java.util.Timer | ||
| import java.util.concurrent.RejectedExecutionException | ||
| import java.util.concurrent.TimeUnit | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertFailsWith | ||
|
|
@@ -36,7 +36,6 @@ class DefaultCompositePerformanceCollectorTest { | |
| val scopes: IScopes = mock() | ||
| val options = SentryOptions() | ||
| var mockTimer: Timer? = null | ||
| val deferredExecutorService = DeferredExecutorService() | ||
|
|
||
| val mockCpuCollector: IPerformanceSnapshotCollector = | ||
| object : IPerformanceSnapshotCollector { | ||
|
|
@@ -54,16 +53,17 @@ class DefaultCompositePerformanceCollectorTest { | |
| fun getSut( | ||
| memoryCollector: IPerformanceSnapshotCollector? = JavaMemoryCollector(), | ||
| cpuCollector: IPerformanceSnapshotCollector? = mockCpuCollector, | ||
| executorService: ISentryExecutorService = deferredExecutorService, | ||
| optionsConfiguration: Sentry.OptionsConfiguration<SentryOptions> = | ||
| Sentry.OptionsConfiguration {}, | ||
| ): CompositePerformanceCollector { | ||
| options.dsn = "https://[email protected]/proj" | ||
| options.executorService = executorService | ||
| if (cpuCollector != null) { | ||
| options.addPerformanceCollector(cpuCollector) | ||
| } | ||
| if (memoryCollector != null) { | ||
| options.addPerformanceCollector(memoryCollector) | ||
| } | ||
| optionsConfiguration.configure(options) | ||
| transaction1 = SentryTracer(TransactionContext("", ""), scopes) | ||
| transaction2 = SentryTracer(TransactionContext("", ""), scopes) | ||
| val collector = DefaultCompositePerformanceCollector(options) | ||
|
|
@@ -184,21 +184,66 @@ class DefaultCompositePerformanceCollectorTest { | |
|
|
||
| @Test | ||
| fun `collector times out after 30 seconds`() { | ||
| val collector = fixture.getSut() | ||
| val mockDateProvider = mock<SentryDateProvider>() | ||
| val dates = | ||
| listOf( | ||
| SentryNanotimeDate( | ||
| Date().apply { time = TimeUnit.SECONDS.toMillis(100) }, | ||
| TimeUnit.SECONDS.toNanos(100), | ||
| ), | ||
| SentryNanotimeDate( | ||
| Date().apply { time = TimeUnit.SECONDS.toMillis(131) }, | ||
| TimeUnit.SECONDS.toNanos(131), | ||
| ), | ||
| ) | ||
| whenever(mockDateProvider.now()).thenReturn(dates[0], dates[0], dates[0], dates[1]) | ||
| val collector = fixture.getSut { it.dateProvider = mockDateProvider } | ||
| collector.start(fixture.transaction1) | ||
| verify(fixture.mockTimer, never())!!.cancel() | ||
|
|
||
| // Let's sleep to make the collector get values | ||
| Thread.sleep(300) | ||
| verify(fixture.mockTimer, never())!!.cancel() | ||
|
|
||
| // Let the timeout job stop the collector | ||
| fixture.deferredExecutorService.runAll() | ||
| // When the collector gets the values, it checks the current date, set 31 seconds after the | ||
| // begin. This means it should stop itself | ||
| verify(fixture.mockTimer)!!.cancel() | ||
|
|
||
| // Data is deleted after the collector times out | ||
| val data1 = collector.stop(fixture.transaction1) | ||
| assertNull(data1) | ||
| } | ||
|
|
||
| @Test | ||
| fun `collector collects for 30 seconds`() { | ||
| val mockDateProvider = mock<SentryDateProvider>() | ||
| val dates = | ||
| listOf( | ||
| SentryNanotimeDate( | ||
| Date().apply { time = TimeUnit.SECONDS.toMillis(100) }, | ||
| TimeUnit.SECONDS.toNanos(100), | ||
| ), | ||
| SentryNanotimeDate( | ||
| Date().apply { time = TimeUnit.SECONDS.toMillis(130) }, | ||
| TimeUnit.SECONDS.toNanos(130), | ||
| ), | ||
| ) | ||
| whenever(mockDateProvider.now()).thenReturn(dates[0], dates[0], dates[0], dates[1]) | ||
| val collector = fixture.getSut { it.dateProvider = mockDateProvider } | ||
| collector.start(fixture.transaction1) | ||
| verify(fixture.mockTimer, never())!!.cancel() | ||
|
|
||
| // Let's sleep to make the collector get values | ||
| Thread.sleep(300) | ||
|
|
||
| // When the collector gets the values, it checks the current date, set 30 seconds after the | ||
| // begin. This means it should continue without being cancelled | ||
| verify(fixture.mockTimer, never())!!.cancel() | ||
|
|
||
| // Data is deleted after the collector times out | ||
| val data1 = collector.stop(fixture.transaction1) | ||
| assertNotNull(data1) | ||
| } | ||
|
|
||
| @Test | ||
| fun `collector has no IPerformanceCollector by default`() { | ||
| val collector = fixture.getSut(null, null) | ||
|
|
@@ -270,25 +315,6 @@ class DefaultCompositePerformanceCollectorTest { | |
| assertNull(collector.stop(fixture.transaction1)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `start does not throw on executor shut down`() { | ||
| val executorService = mock<ISentryExecutorService>() | ||
| whenever(executorService.schedule(any(), any())).thenThrow(RejectedExecutionException()) | ||
| val logger = mock<ILogger>() | ||
| fixture.options.setLogger(logger) | ||
| fixture.options.isDebug = true | ||
| val sut = fixture.getSut(executorService = executorService) | ||
| sut.start(fixture.transaction1) | ||
| verify(logger) | ||
| .log( | ||
| eq(SentryLevel.ERROR), | ||
| eq( | ||
| "Failed to call the executor. Performance collector will not be automatically finished. Did you call Sentry.close()?" | ||
| ), | ||
| any(), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Continuous collectors are notified properly`() { | ||
| val collector = mock<IPerformanceContinuousCollector>() | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.