-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1633 from bugsnag/PLAT-8185-delete-old-big-events
[PLAT-8185] Limit retries of event payloads based on size and age, and session payloads based on age
- Loading branch information
Showing
15 changed files
with
449 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
55 changes: 55 additions & 0 deletions
55
bugsnag-android-core/src/main/java/com/bugsnag/android/SessionFilenameInfo.kt
This file contains 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,55 @@ | ||
package com.bugsnag.android | ||
|
||
import java.io.File | ||
import java.util.UUID | ||
|
||
/** | ||
* Represents important information about a session filename. | ||
* Currently the following information is encoded: | ||
* | ||
* uuid - to disambiguate stored error reports | ||
* timestamp - to sort error reports by time of capture | ||
*/ | ||
internal data class SessionFilenameInfo( | ||
val timestamp: Long, | ||
val uuid: String, | ||
) { | ||
|
||
fun encode(): String { | ||
return toFilename(timestamp, uuid) | ||
} | ||
|
||
internal companion object { | ||
|
||
const val uuidLength = 36 | ||
|
||
/** | ||
* Generates a filename for the session in the format | ||
* "[UUID][timestamp]_v2.json" | ||
*/ | ||
fun toFilename(timestamp: Long, uuid: String): String { | ||
return "${uuid}${timestamp}_v2.json" | ||
} | ||
|
||
@JvmStatic | ||
fun defaultFilename(): String { | ||
return toFilename(System.currentTimeMillis(), UUID.randomUUID().toString()) | ||
} | ||
|
||
fun fromFile(file: File): SessionFilenameInfo { | ||
return SessionFilenameInfo( | ||
findTimestampInFilename(file), | ||
findUuidInFilename(file) | ||
) | ||
} | ||
|
||
private fun findUuidInFilename(file: File): String { | ||
return file.name.substring(0, uuidLength - 1) | ||
} | ||
|
||
@JvmStatic | ||
fun findTimestampInFilename(file: File): Long { | ||
return file.name.substring(uuidLength, file.name.indexOf("_")).toLongOrNull() ?: -1 | ||
} | ||
} | ||
} |
This file contains 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 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 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
42 changes: 42 additions & 0 deletions
42
...narios/src/main/java/com/bugsnag/android/mazerunner/scenarios/DiscardBigEventsScenario.kt
This file contains 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,42 @@ | ||
package com.bugsnag.android.mazerunner.scenarios | ||
|
||
import android.content.Context | ||
import com.bugsnag.android.Bugsnag | ||
import com.bugsnag.android.Configuration | ||
import java.io.File | ||
|
||
internal class DiscardBigEventsScenario( | ||
config: Configuration, | ||
context: Context, | ||
eventMetadata: String | ||
) : Scenario(config, context, eventMetadata) { | ||
|
||
init { | ||
config.launchDurationMillis = 0 | ||
config.addOnSend { | ||
it.addMetadata("big", "stuff", generateBigText()) | ||
true | ||
} | ||
} | ||
|
||
fun generateBigText(): String { | ||
return "*".repeat(1024 * 1024) | ||
} | ||
|
||
fun waitForEventFile() { | ||
val dir = File(context.cacheDir, "bugsnag-errors") | ||
while (dir.listFiles()!!.isEmpty()) { | ||
Thread.sleep(100) | ||
} | ||
} | ||
|
||
override fun startScenario() { | ||
super.startScenario() | ||
Bugsnag.markLaunchCompleted() | ||
Bugsnag.notify(MyThrowable("DiscardBigEventsScenario")) | ||
|
||
waitForEventFile() | ||
|
||
Bugsnag.notify(MyThrowable("To keep maze-runner from shutting me down prematurely")) | ||
} | ||
} |
Oops, something went wrong.