Skip to content

Commit 2f19f57

Browse files
authored
Make logs less verbose, especially for sliding sync (#2825)
* Make logs less verbose, especially for sliding sync. Use the same config as iOS for most targets. * Make sure we don't try to upload logs that are larger than the max request size of the bug reporter server. * Display the loading state as soon as the bug reporter starts processing the log files * Add changelog
1 parent 83a22c7 commit 2f19f57

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

appconfig/src/main/kotlin/io/element/android/appconfig/ApplicationConfig.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ object ApplicationConfig {
4040
* For Element, the value is "Element". We use the same name for desktop and mobile for now.
4141
*/
4242
const val DESKTOP_APPLICATION_NAME: String = "Element"
43+
44+
/**
45+
* The maximum size of the upload request. Default value is just below CloudFlare's max request size.
46+
*/
47+
const val MAX_LOG_UPLOAD_SIZE = 50 * 1024 * 1024L
4348
}

changelog.d/2825.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make log less verbose, make sure we upload as many log files as possible before reaching the request size limit of the bug reporting service, discard older logs if they don't fit.

features/rageshake/impl/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ anvil {
3838
dependencies {
3939
implementation(projects.anvilannotations)
4040
anvil(projects.anvilcodegen)
41+
implementation(projects.appconfig)
4142
implementation(projects.services.toolbox.api)
4243
implementation(projects.libraries.androidutils)
4344
implementation(projects.libraries.core)

features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class BugReportPresenter @Inject constructor(
9696
if (formState.value.description.length < 10) {
9797
sendingAction.value = AsyncAction.Failure(BugReportFormError.DescriptionTooShort)
9898
} else {
99+
sendingAction.value = AsyncAction.Loading
99100
appCoroutineScope.sendBugReport(formState.value, crashInfo.isNotEmpty(), uploadListener)
100101
}
101102
}

features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.os.Build
2121
import androidx.core.net.toFile
2222
import androidx.core.net.toUri
2323
import com.squareup.anvil.annotations.ContributesBinding
24+
import io.element.android.appconfig.ApplicationConfig
2425
import io.element.android.features.rageshake.api.crash.CrashDataStore
2526
import io.element.android.features.rageshake.api.reporter.BugReporter
2627
import io.element.android.features.rageshake.api.reporter.BugReporterListener
@@ -83,7 +84,6 @@ class DefaultBugReporter @Inject constructor(
8384
// filenames
8485
private const val LOG_CAT_FILENAME = "logcat.log"
8586
private const val LOG_DIRECTORY_NAME = "logs"
86-
private const val BUFFER_SIZE = 1024 * 1024 * 50
8787
}
8888

8989
// the pending bug report call
@@ -120,7 +120,7 @@ class DefaultBugReporter @Inject constructor(
120120
val gzippedFiles = ArrayList<File>()
121121

122122
if (withDevicesLogs) {
123-
val files = getLogFiles()
123+
val files = getLogFiles().sortedByDescending { it.lastModified() }
124124
files.mapNotNullTo(gzippedFiles) { f ->
125125
when {
126126
isCancelled -> null
@@ -135,7 +135,7 @@ class DefaultBugReporter @Inject constructor(
135135
saveLogCat()
136136
val gzippedLogcat = compressFile(logCatErrFile)
137137
if (null != gzippedLogcat) {
138-
if (gzippedFiles.size == 0) {
138+
if (gzippedFiles.isEmpty()) {
139139
gzippedFiles.add(gzippedLogcat)
140140
} else {
141141
gzippedFiles.add(0, gzippedLogcat)
@@ -166,10 +166,18 @@ class DefaultBugReporter @Inject constructor(
166166
}
167167

168168
// add the gzipped files, don't cancel the whole upload if only some file failed to upload
169+
var totalUploadedSize = 0L
169170
var uploadedSomeLogs = false
170171
for (file in gzippedFiles) {
171172
try {
172-
builder.addFormDataPart("compressed-log", file.name, file.asRequestBody(MimeTypes.OctetStream.toMediaTypeOrNull()))
173+
val requestBody = file.asRequestBody(MimeTypes.OctetStream.toMediaTypeOrNull())
174+
totalUploadedSize += requestBody.contentLength()
175+
// If we are about to upload more than the max request size, stop here
176+
if (totalUploadedSize > ApplicationConfig.MAX_LOG_UPLOAD_SIZE) {
177+
Timber.e("Could not upload file ${file.name} because it would exceed the max request size")
178+
break
179+
}
180+
builder.addFormDataPart("compressed-log", file.name, requestBody)
173181
uploadedSomeLogs = true
174182
} catch (e: CancellationException) {
175183
throw e
@@ -411,7 +419,7 @@ class DefaultBugReporter @Inject constructor(
411419
val separator = System.getProperty("line.separator")
412420
logcatProc.inputStream
413421
.reader()
414-
.buffered(BUFFER_SIZE)
422+
.buffered(ApplicationConfig.MAX_LOG_UPLOAD_SIZE.toInt())
415423
.forEachLine { line ->
416424
streamWriter.append(line)
417425
streamWriter.append(separator)

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/tracing/TracingFilterConfiguration.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ data class TracingFilterConfiguration(
2727
Target.MATRIX_SDK_CRYPTO to LogLevel.DEBUG,
2828
Target.MATRIX_SDK_CRYPTO_ACCOUNT to LogLevel.TRACE,
2929
Target.MATRIX_SDK_HTTP_CLIENT to LogLevel.DEBUG,
30-
Target.MATRIX_SDK_SLIDING_SYNC to LogLevel.TRACE,
31-
Target.MATRIX_SDK_BASE_SLIDING_SYNC to LogLevel.TRACE,
32-
Target.MATRIX_SDK_UI_TIMELINE to LogLevel.TRACE,
30+
Target.MATRIX_SDK_SLIDING_SYNC to LogLevel.INFO,
31+
Target.MATRIX_SDK_BASE_SLIDING_SYNC to LogLevel.INFO,
32+
Target.MATRIX_SDK_UI_TIMELINE to LogLevel.INFO,
3333
)
3434

3535
fun getLogLevel(target: Target): LogLevel {

0 commit comments

Comments
 (0)