-
-
Notifications
You must be signed in to change notification settings - Fork 462
feat(logs): Drop log events once buffer hits hard limit #4889
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e557583
Drop log events once buffer hits hard limit
adinauer 3837599
Merge branch 'main' into feat/log-buffer-hard-limit
adinauer a39be4d
changelog
adinauer 004bf19
test hard limit
adinauer 54a5d67
record client report
adinauer ff0b6af
format
adinauer 690c657
Merge branch 'main' into feat/log-buffer-hard-limit
adinauer 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
Some comments aren't visible on the classic Files Changed page.
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
101 changes: 101 additions & 0 deletions
101
sentry/src/test/java/io/sentry/logger/LoggerBatchProcessorTest.kt
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 |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package io.sentry.logger | ||
|
|
||
| import io.sentry.DataCategory | ||
| import io.sentry.ISentryClient | ||
| import io.sentry.SentryLogEvent | ||
| import io.sentry.SentryLogEvents | ||
| import io.sentry.SentryLogLevel | ||
| import io.sentry.SentryNanotimeDate | ||
| import io.sentry.SentryOptions | ||
| import io.sentry.clientreport.ClientReportTestHelper | ||
| import io.sentry.clientreport.DiscardReason | ||
| import io.sentry.clientreport.DiscardedEvent | ||
| import io.sentry.protocol.SentryId | ||
| import io.sentry.test.DeferredExecutorService | ||
| import io.sentry.test.injectForField | ||
| import io.sentry.util.JsonSerializationUtils | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertFalse | ||
| import kotlin.test.assertTrue | ||
| import org.mockito.kotlin.argumentCaptor | ||
| import org.mockito.kotlin.atLeast | ||
| import org.mockito.kotlin.mock | ||
| import org.mockito.kotlin.verify | ||
|
|
||
| class LoggerBatchProcessorTest { | ||
| @Test | ||
| fun `drops log events after reaching MAX_QUEUE_SIZE limit`() { | ||
| // given | ||
| val mockClient = mock<ISentryClient>() | ||
| val mockExecutor = DeferredExecutorService() | ||
| val options = SentryOptions() | ||
| val processor = LoggerBatchProcessor(options, mockClient) | ||
| processor.injectForField("executorService", mockExecutor) | ||
|
|
||
| for (i in 1..1001) { | ||
| val logEvent = | ||
| SentryLogEvent(SentryId(), SentryNanotimeDate(), "log message $i", SentryLogLevel.INFO) | ||
| processor.add(logEvent) | ||
| } | ||
|
|
||
| // run twice since a non full batch would be scheduled at the end | ||
| mockExecutor.runAll() | ||
| mockExecutor.runAll() | ||
|
|
||
| // assert that the transport received 1000 log events | ||
| val captor = argumentCaptor<SentryLogEvents>() | ||
| verify(mockClient, atLeast(1)).captureBatchedLogEvents(captor.capture()) | ||
|
|
||
| val allCapturedEvents = mutableListOf<SentryLogEvent>() | ||
| captor.allValues.forEach { logEvents -> allCapturedEvents.addAll(logEvents.items) } | ||
|
|
||
| assertEquals(1000, allCapturedEvents.size) | ||
|
|
||
| // assert that log 1001 did not make it but log 1000 did get sent | ||
| val log1000Found = allCapturedEvents.any { it.body == "log message 1000" } | ||
| val log1001Found = allCapturedEvents.any { it.body == "log message 1001" } | ||
|
|
||
| assertTrue(log1000Found, "Log 1000 should have been sent") | ||
| assertFalse(log1001Found, "Log 1001 should not have been sent") | ||
| } | ||
|
|
||
| @Test | ||
| fun `records client report when log event is dropped due to queue overflow`() { | ||
| // given | ||
| val mockClient = mock<ISentryClient>() | ||
| val mockExecutor = DeferredExecutorService() | ||
| val options = SentryOptions() | ||
| val processor = LoggerBatchProcessor(options, mockClient) | ||
| processor.injectForField("executorService", mockExecutor) | ||
|
|
||
| // fill the queue to MAX_QUEUE_SIZE | ||
| for (i in 1..1000) { | ||
| val logEvent = | ||
| SentryLogEvent(SentryId(), SentryNanotimeDate(), "log message $i", SentryLogLevel.INFO) | ||
| processor.add(logEvent) | ||
| } | ||
|
|
||
| // add one more log event that should be dropped | ||
| val droppedLogEvent = | ||
| SentryLogEvent(SentryId(), SentryNanotimeDate(), "dropped log", SentryLogLevel.INFO) | ||
| processor.add(droppedLogEvent) | ||
|
|
||
| // calculate expected bytes for the dropped log event | ||
| val expectedBytes = | ||
| JsonSerializationUtils.byteSizeOf(options.serializer, options.logger, droppedLogEvent) | ||
|
|
||
| // verify that a client report was recorded for the dropped log item and bytes | ||
| val expectedEvents = | ||
| mutableListOf( | ||
| DiscardedEvent(DiscardReason.QUEUE_OVERFLOW.reason, DataCategory.LogItem.category, 1), | ||
| DiscardedEvent( | ||
| DiscardReason.QUEUE_OVERFLOW.reason, | ||
| DataCategory.Attachment.category, | ||
| expectedBytes, | ||
| ), | ||
| ) | ||
|
|
||
| ClientReportTestHelper.assertClientReport(options.clientReportRecorder, expectedEvents) | ||
| } | ||
| } |
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.