Only change the log folder on enterprise build
This commit is contained in:
parent
2d801a0924
commit
2a67ad4c67
2 changed files with 78 additions and 12 deletions
|
|
@ -93,13 +93,16 @@ class DefaultBugReporter @Inject constructor(
|
||||||
private var currentLogDirectory: File = baseLogDirectory
|
private var currentLogDirectory: File = baseLogDirectory
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val logSubfolder = runBlocking {
|
if (buildMeta.isEnterpriseBuild) {
|
||||||
sessionStore.getLatestSession()
|
val logSubfolder = runBlocking {
|
||||||
}?.userId?.substringAfter(":")
|
sessionStore.getLatestSession()
|
||||||
setCurrentLogDirectory(logSubfolder)
|
}?.userId?.substringAfter(":")
|
||||||
matrixAuthenticationService.listenToNewMatrixClients {
|
setCurrentLogDirectory(logSubfolder)
|
||||||
// When a new Matrix client is created, we update the tracing configuration to write to files
|
matrixAuthenticationService.listenToNewMatrixClients {
|
||||||
setLogDirectorySubfolder(it.userIdServerName())
|
// When a new Matrix client is created, we update the tracing configuration to write
|
||||||
|
// the files in a dedicated subfolders.
|
||||||
|
setLogDirectorySubfolder(it.userIdServerName())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -312,8 +315,10 @@ class DefaultBugReporter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setLogDirectorySubfolder(subfolderName: String?) {
|
override fun setLogDirectorySubfolder(subfolderName: String?) {
|
||||||
setCurrentLogDirectory(subfolderName)
|
if (buildMeta.isEnterpriseBuild) {
|
||||||
tracingService.updateWriteToFilesConfiguration(createWriteToFilesConfiguration())
|
setCurrentLogDirectory(subfolderName)
|
||||||
|
tracingService.updateWriteToFilesConfiguration(createWriteToFilesConfiguration())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setCurrentLogDirectory(subfolderName: String?) {
|
private fun setCurrentLogDirectory(subfolderName: String?) {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import io.element.android.features.rageshake.api.reporter.BugReporterListener
|
||||||
import io.element.android.features.rageshake.impl.crash.CrashDataStore
|
import io.element.android.features.rageshake.impl.crash.CrashDataStore
|
||||||
import io.element.android.features.rageshake.impl.crash.FakeCrashDataStore
|
import io.element.android.features.rageshake.impl.crash.FakeCrashDataStore
|
||||||
import io.element.android.features.rageshake.impl.screenshot.FakeScreenshotHolder
|
import io.element.android.features.rageshake.impl.screenshot.FakeScreenshotHolder
|
||||||
|
import io.element.android.libraries.core.meta.BuildMeta
|
||||||
import io.element.android.libraries.matrix.api.MatrixClientProvider
|
import io.element.android.libraries.matrix.api.MatrixClientProvider
|
||||||
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
||||||
import io.element.android.libraries.matrix.api.tracing.TracingService
|
import io.element.android.libraries.matrix.api.tracing.TracingService
|
||||||
|
|
@ -305,6 +306,7 @@ class DefaultBugReporterTest {
|
||||||
@Test
|
@Test
|
||||||
fun `the log directory is initialized using the last session store data`() = runTest {
|
fun `the log directory is initialized using the last session store data`() = runTest {
|
||||||
val sut = createDefaultBugReporter(
|
val sut = createDefaultBugReporter(
|
||||||
|
buildMeta = aBuildMeta(isEnterpriseBuild = true),
|
||||||
sessionStore = InMemorySessionStore().apply {
|
sessionStore = InMemorySessionStore().apply {
|
||||||
storeData(aSessionData(sessionId = "@alice:domain.com"))
|
storeData(aSessionData(sessionId = "@alice:domain.com"))
|
||||||
}
|
}
|
||||||
|
|
@ -312,6 +314,16 @@ class DefaultBugReporterTest {
|
||||||
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs/domain.com")
|
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs/domain.com")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `foss build - the log directory is initialized to the root log directory`() = runTest {
|
||||||
|
val sut = createDefaultBugReporter(
|
||||||
|
sessionStore = InMemorySessionStore().apply {
|
||||||
|
storeData(aSessionData(sessionId = "@alice:domain.com"))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when the log directory is updated, the tracing service is invoked`() = runTest {
|
fun `when the log directory is updated, the tracing service is invoked`() = runTest {
|
||||||
var param: WriteToFilesConfiguration? = null
|
var param: WriteToFilesConfiguration? = null
|
||||||
|
|
@ -319,9 +331,10 @@ class DefaultBugReporterTest {
|
||||||
param = it
|
param = it
|
||||||
}
|
}
|
||||||
val sut = createDefaultBugReporter(
|
val sut = createDefaultBugReporter(
|
||||||
|
buildMeta = aBuildMeta(isEnterpriseBuild = true),
|
||||||
tracingService = FakeTracingService(
|
tracingService = FakeTracingService(
|
||||||
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
|
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
sut.setLogDirectorySubfolder("my.sub.folder")
|
sut.setLogDirectorySubfolder("my.sub.folder")
|
||||||
updateWriteToFilesConfigurationResult.assertions().isCalledOnce()
|
updateWriteToFilesConfigurationResult.assertions().isCalledOnce()
|
||||||
|
|
@ -333,6 +346,18 @@ class DefaultBugReporterTest {
|
||||||
assertThat((param as WriteToFilesConfiguration.Enabled).filenameSuffix).isEqualTo("log")
|
assertThat((param as WriteToFilesConfiguration.Enabled).filenameSuffix).isEqualTo("log")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `foss build - when the log directory is updated, the tracing service is not invoked`() = runTest {
|
||||||
|
val updateWriteToFilesConfigurationResult = lambdaRecorder<WriteToFilesConfiguration, Unit> {}
|
||||||
|
val sut = createDefaultBugReporter(
|
||||||
|
tracingService = FakeTracingService(
|
||||||
|
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
sut.setLogDirectorySubfolder("my.sub.folder")
|
||||||
|
updateWriteToFilesConfigurationResult.assertions().isNeverCalled()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when the log directory is reset, the tracing service is invoked`() = runTest {
|
fun `when the log directory is reset, the tracing service is invoked`() = runTest {
|
||||||
var param: WriteToFilesConfiguration? = null
|
var param: WriteToFilesConfiguration? = null
|
||||||
|
|
@ -340,9 +365,10 @@ class DefaultBugReporterTest {
|
||||||
param = it
|
param = it
|
||||||
}
|
}
|
||||||
val sut = createDefaultBugReporter(
|
val sut = createDefaultBugReporter(
|
||||||
|
buildMeta = aBuildMeta(isEnterpriseBuild = true),
|
||||||
tracingService = FakeTracingService(
|
tracingService = FakeTracingService(
|
||||||
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
|
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
sut.setLogDirectorySubfolder(null)
|
sut.setLogDirectorySubfolder(null)
|
||||||
updateWriteToFilesConfigurationResult.assertions().isCalledOnce()
|
updateWriteToFilesConfigurationResult.assertions().isCalledOnce()
|
||||||
|
|
@ -354,6 +380,18 @@ class DefaultBugReporterTest {
|
||||||
assertThat((param as WriteToFilesConfiguration.Enabled).filenameSuffix).isEqualTo("log")
|
assertThat((param as WriteToFilesConfiguration.Enabled).filenameSuffix).isEqualTo("log")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `foss build - when the log directory is reset, the tracing service is not invoked`() = runTest {
|
||||||
|
val updateWriteToFilesConfigurationResult = lambdaRecorder<WriteToFilesConfiguration, Unit> {}
|
||||||
|
val sut = createDefaultBugReporter(
|
||||||
|
tracingService = FakeTracingService(
|
||||||
|
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
sut.setLogDirectorySubfolder(null)
|
||||||
|
updateWriteToFilesConfigurationResult.assertions().isNeverCalled()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when a new MatrixClient is created the logs folder is updated`() = runTest {
|
fun `when a new MatrixClient is created the logs folder is updated`() = runTest {
|
||||||
var param: WriteToFilesConfiguration? = null
|
var param: WriteToFilesConfiguration? = null
|
||||||
|
|
@ -368,6 +406,7 @@ class DefaultBugReporterTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val sut = createDefaultBugReporter(
|
val sut = createDefaultBugReporter(
|
||||||
|
buildMeta = aBuildMeta(isEnterpriseBuild = true),
|
||||||
matrixAuthenticationService = matrixAuthenticationService,
|
matrixAuthenticationService = matrixAuthenticationService,
|
||||||
tracingService = FakeTracingService(
|
tracingService = FakeTracingService(
|
||||||
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
|
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
|
||||||
|
|
@ -385,7 +424,30 @@ class DefaultBugReporterTest {
|
||||||
assertThat((param as WriteToFilesConfiguration.Enabled).filenameSuffix).isEqualTo("log")
|
assertThat((param as WriteToFilesConfiguration.Enabled).filenameSuffix).isEqualTo("log")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `foss build - when a new MatrixClient is created the logs folder is not updated`() = runTest {
|
||||||
|
val updateWriteToFilesConfigurationResult = lambdaRecorder<WriteToFilesConfiguration, Unit> {}
|
||||||
|
val matrixAuthenticationService = FakeMatrixAuthenticationService().apply {
|
||||||
|
givenMatrixClient(
|
||||||
|
FakeMatrixClient(
|
||||||
|
userIdServerNameLambda = { "domain.foo.org" },
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val sut = createDefaultBugReporter(
|
||||||
|
matrixAuthenticationService = matrixAuthenticationService,
|
||||||
|
tracingService = FakeTracingService(
|
||||||
|
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs")
|
||||||
|
matrixAuthenticationService.login("alice", "password")
|
||||||
|
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs")
|
||||||
|
updateWriteToFilesConfigurationResult.assertions().isNeverCalled()
|
||||||
|
}
|
||||||
|
|
||||||
private fun TestScope.createDefaultBugReporter(
|
private fun TestScope.createDefaultBugReporter(
|
||||||
|
buildMeta: BuildMeta = aBuildMeta(),
|
||||||
sessionStore: SessionStore = InMemorySessionStore(),
|
sessionStore: SessionStore = InMemorySessionStore(),
|
||||||
matrixClientProvider: MatrixClientProvider = FakeMatrixClientProvider(),
|
matrixClientProvider: MatrixClientProvider = FakeMatrixClientProvider(),
|
||||||
crashDataStore: CrashDataStore = FakeCrashDataStore(),
|
crashDataStore: CrashDataStore = FakeCrashDataStore(),
|
||||||
|
|
@ -393,7 +455,6 @@ class DefaultBugReporterTest {
|
||||||
tracingService: TracingService = FakeTracingService(),
|
tracingService: TracingService = FakeTracingService(),
|
||||||
matrixAuthenticationService: MatrixAuthenticationService = FakeMatrixAuthenticationService(),
|
matrixAuthenticationService: MatrixAuthenticationService = FakeMatrixAuthenticationService(),
|
||||||
): DefaultBugReporter {
|
): DefaultBugReporter {
|
||||||
val buildMeta = aBuildMeta()
|
|
||||||
return DefaultBugReporter(
|
return DefaultBugReporter(
|
||||||
context = RuntimeEnvironment.getApplication(),
|
context = RuntimeEnvironment.getApplication(),
|
||||||
screenshotHolder = FakeScreenshotHolder(),
|
screenshotHolder = FakeScreenshotHolder(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue