Skip to content

Commit

Permalink
Merge pull request #893 from embrace-io/remove-perf-info-field
Browse files Browse the repository at this point in the history
Remove performance info field
  • Loading branch information
fractalwrench authored May 30, 2024
2 parents 0a9af7c + b5338a6 commit 4d992fc
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ internal fun verifySessionHappened(message: SessionMessage) {

internal fun verifySessionMessage(sessionMessage: SessionMessage) {
assertNotNull(sessionMessage.session)

if (sessionMessage.session.messageType == "en") {
assertNotNull(sessionMessage.performanceInfo)
}
}

internal fun verifyBgActivityHappened(message: SessionMessage) {
Expand All @@ -224,10 +220,6 @@ internal fun verifyBgActivityHappened(message: SessionMessage) {

internal fun verifyBgActivityMessage(message: SessionMessage) {
assertNotNull(message.session)

if (message.session.messageType == "en") {
assertNotNull(message.performanceInfo)
}
}

private const val CHECK_INTERVAL_MS: Int = 10
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.embrace.android.embracesdk.gating

import io.embrace.android.embracesdk.internal.payload.EnvelopeMetadata
import io.embrace.android.embracesdk.internal.payload.EnvelopeResource
import io.embrace.android.embracesdk.payload.SessionMessage

internal class SessionSanitizerFacade(
Expand All @@ -10,14 +11,13 @@ internal class SessionSanitizerFacade(

fun getSanitizedMessage(): SessionMessage {
val sanitizedSession = SessionSanitizer(sessionMessage.session, components).sanitize()
val sanitizedPerformanceInfo = PerformanceInfoSanitizer(sessionMessage.performanceInfo, components).sanitize()
val sanitizedSpans = SpanSanitizer(sessionMessage.spans, components).sanitize()

return sessionMessage.copy(
session = sanitizedSession,
performanceInfo = sanitizedPerformanceInfo,
spans = sanitizedSpans,
metadata = sanitizeMetadata(components)
metadata = sanitizeMetadata(components),
resource = sanitizeResource(components)
)
}

Expand All @@ -31,6 +31,19 @@ internal class SessionSanitizerFacade(
return sessionMessage.metadata
}

private fun sanitizeResource(enabledComponents: Set<String>): EnvelopeResource {
if (sessionMessage.resource == null) {
return EnvelopeResource()
}
if (!shouldSendCurrentDiskUsage(enabledComponents)) {
return sessionMessage.resource.copy(diskTotalCapacity = null)
}
return sessionMessage.resource
}

private fun shouldSendCurrentDiskUsage(enabledComponents: Set<String>) =
enabledComponents.contains(SessionGatingKeys.PERFORMANCE_CURRENT_DISK_USAGE)

private fun shouldSendUserPersonas(enabledComponents: Set<String>) =
enabledComponents.contains(SessionGatingKeys.USER_PERSONAS)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ internal class SessionModuleImpl(
dataContainerModule.eventService,
customerLogModule.logMessageService,
initModule.internalErrorService,
dataContainerModule.performanceInfoService,
dataCaptureServiceModule.webviewService,
nativeModule.nativeThreadSamplerService,
androidServicesModule.preferencesService,
Expand All @@ -70,7 +69,6 @@ internal class SessionModuleImpl(
payloadModule.sessionEnvelopeSource,
dataContainerModule.eventService,
customerLogModule.logMessageService,
dataContainerModule.performanceInfoService,
nativeModule.nativeThreadSamplerService,
androidServicesModule.preferencesService,
openTelemetryModule.spanRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ internal data class SessionMessage @JvmOverloads internal constructor(
@Json(name = "s")
val session: Session,

/**
* The device's performance info, such as power, cpu, network.
*/
@Json(name = "p")
val performanceInfo: PerformanceInfo? = null,

@Json(name = "spans")
val spans: List<EmbraceSpanData>? = null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.embrace.android.embracesdk.anr.AnrOtelMapper
import io.embrace.android.embracesdk.anr.ndk.NativeAnrOtelMapper
import io.embrace.android.embracesdk.anr.ndk.NativeThreadSamplerService
import io.embrace.android.embracesdk.arch.schema.AppTerminationCause
import io.embrace.android.embracesdk.capture.PerformanceInfoService
import io.embrace.android.embracesdk.capture.internal.errors.InternalErrorService
import io.embrace.android.embracesdk.capture.startup.StartupService
import io.embrace.android.embracesdk.capture.webview.WebViewService
Expand All @@ -29,7 +28,6 @@ internal class V1PayloadMessageCollator(
private val eventService: EventService,
private val logMessageService: LogMessageService,
private val internalErrorService: InternalErrorService,
private val performanceInfoService: PerformanceInfoService,
private val webViewService: WebViewService,
private val nativeThreadSamplerService: NativeThreadSamplerService?,
private val preferencesService: PreferencesService,
Expand Down Expand Up @@ -87,7 +85,7 @@ internal class V1PayloadMessageCollator(
startupThreshold = startupInfo?.threshold,
symbols = captureDataSafely(logger) { nativeThreadSamplerService?.getNativeSymbols() }
)
val envelope = buildWrapperEnvelope(params, endSession, initial.startTime, endTime)
val envelope = buildWrapperEnvelope(params, endSession)
return gatingService.gateSessionMessage(envelope)
}

Expand All @@ -98,9 +96,7 @@ internal class V1PayloadMessageCollator(
params: FinalEnvelopeParams.BackgroundActivityParams
): SessionMessage {
val msg = buildFinalBackgroundActivity(params)
val startTime = msg.startTime
val endTime = params.endTime
val envelope = buildWrapperEnvelope(params, msg, startTime, endTime)
val envelope = buildWrapperEnvelope(params, msg)
return gatingService.gateSessionMessage(envelope)
}

Expand Down Expand Up @@ -142,9 +138,7 @@ internal class V1PayloadMessageCollator(

private fun buildWrapperEnvelope(
params: FinalEnvelopeParams,
finalPayload: Session,
startTime: Long,
endTime: Long,
finalPayload: Session
): SessionMessage {
val spans: List<EmbraceSpanData>? = captureDataSafely(logger) {
webViewService.loadDataIntoSession()
Expand Down Expand Up @@ -175,14 +169,6 @@ internal class V1PayloadMessageCollator(

return SessionMessage(
session = finalPayload,
performanceInfo = captureDataSafely(logger) {
performanceInfoService.getSessionPerformanceInfo(
startTime,
endTime,
finalPayload.isColdStart,
null
)
},
spans = spans,
spanSnapshots = spanSnapshots,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.embrace.android.embracesdk.anr.AnrOtelMapper
import io.embrace.android.embracesdk.anr.ndk.NativeAnrOtelMapper
import io.embrace.android.embracesdk.anr.ndk.NativeThreadSamplerService
import io.embrace.android.embracesdk.arch.schema.AppTerminationCause
import io.embrace.android.embracesdk.capture.PerformanceInfoService
import io.embrace.android.embracesdk.capture.envelope.session.SessionEnvelopeSource
import io.embrace.android.embracesdk.capture.startup.StartupService
import io.embrace.android.embracesdk.event.EventService
Expand Down Expand Up @@ -33,7 +32,6 @@ internal class V2PayloadMessageCollator(
private val sessionEnvelopeSource: SessionEnvelopeSource,
private val eventService: EventService,
private val logMessageService: LogMessageService,
private val performanceInfoService: PerformanceInfoService,
private val nativeThreadSamplerService: NativeThreadSamplerService?,
private val preferencesService: PreferencesService,
private val spanRepository: SpanRepository,
Expand Down Expand Up @@ -92,7 +90,7 @@ internal class V2PayloadMessageCollator(
startupThreshold = startupInfo?.threshold,
symbols = captureDataSafely(logger) { nativeThreadSamplerService?.getNativeSymbols() }
)
val envelope = buildWrapperEnvelope(newParams, endSession, initial.startTime, endTime)
val envelope = buildWrapperEnvelope(newParams, endSession)
gatingService.gateSessionMessage(envelope)
}
return obj.convertToV2Payload(newParams.endType)
Expand All @@ -109,9 +107,7 @@ internal class V2PayloadMessageCollator(
logger = logger
)
val msg = buildFinalBackgroundActivity(newParams)
val startTime = msg.startTime
val endTime = newParams.endTime
val envelope = buildWrapperEnvelope(newParams, msg, startTime, endTime)
val envelope = buildWrapperEnvelope(newParams, msg)
val obj = gatingService.gateSessionMessage(envelope)
return obj.convertToV2Payload(newParams.endType)
}
Expand Down Expand Up @@ -151,8 +147,6 @@ internal class V2PayloadMessageCollator(
private fun buildWrapperEnvelope(
params: FinalEnvelopeParams,
finalPayload: Session,
startTime: Long,
endTime: Long,
): SessionMessage {
val spans: List<EmbraceSpanData>? = captureDataSafely(logger) {
val result = when {
Expand Down Expand Up @@ -182,14 +176,6 @@ internal class V2PayloadMessageCollator(

return SessionMessage(
session = finalPayload,
performanceInfo = captureDataSafely(logger) {
performanceInfoService.getSessionPerformanceInfo(
startTime,
endTime,
finalPayload.isColdStart,
null
)
},
spans = spans,
spanSnapshots = spanSnapshots,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import io.embrace.android.embracesdk.gating.SessionGatingKeys.SESSION_USER_TERMI
import io.embrace.android.embracesdk.gating.SessionGatingKeys.STARTUP_MOMENT
import io.embrace.android.embracesdk.gating.SessionGatingKeys.USER_PERSONAS
import io.embrace.android.embracesdk.internal.payload.EnvelopeMetadata
import io.embrace.android.embracesdk.internal.payload.EnvelopeResource
import io.embrace.android.embracesdk.internal.serialization.EmbraceSerializer
import io.embrace.android.embracesdk.internal.utils.Uuid
import io.embrace.android.embracesdk.logging.EmbLogger
import io.embrace.android.embracesdk.logging.EmbLoggerImpl
import io.embrace.android.embracesdk.payload.DiskUsage
import io.embrace.android.embracesdk.payload.Event
import io.embrace.android.embracesdk.payload.EventMessage
import io.embrace.android.embracesdk.payload.Orientation
Expand Down Expand Up @@ -362,8 +362,7 @@ internal class EmbraceGatingServiceV1PayloadTest {
session = fakeSession(),
metadata = EnvelopeMetadata(
personas = setOf("persona")
),
performanceInfo = PerformanceInfo(),
)
)

cfg = buildCustomRemoteConfig(setOf(USER_PERSONAS), null)
Expand All @@ -374,17 +373,10 @@ internal class EmbraceGatingServiceV1PayloadTest {

@Test
fun `test gate performance info for Session`() {
val performanceInfo = PerformanceInfo(
diskUsage = DiskUsage(100, null)
)

val sessionPerformanceInfo = performanceInfo.copy()

val sessionMessage = SessionMessage(
session = fakeSession(),
performanceInfo = sessionPerformanceInfo
resource = EnvelopeResource(diskTotalCapacity = 100)
)

cfg = buildCustomRemoteConfig(
setOf(
PERFORMANCE_ANR,
Expand All @@ -398,8 +390,8 @@ internal class EmbraceGatingServiceV1PayloadTest {

val sanitizedMessage = gatingService.gateSessionMessage(sessionMessage)

val perfInfo = checkNotNull(sanitizedMessage.performanceInfo)
assertNotNull(perfInfo.diskUsage)
val perfInfo = checkNotNull(sanitizedMessage.resource)
assertNotNull(perfInfo.diskTotalCapacity)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ package io.embrace.android.embracesdk
import io.embrace.android.embracesdk.internal.payload.EnvelopeMetadata
import io.embrace.android.embracesdk.internal.payload.EnvelopeResource
import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData
import io.embrace.android.embracesdk.payload.DiskUsage
import io.embrace.android.embracesdk.payload.PerformanceInfo
import io.embrace.android.embracesdk.payload.Session
import io.embrace.android.embracesdk.payload.SessionMessage
import io.opentelemetry.api.trace.StatusCode

internal fun fakeBackgroundActivityMessage(): SessionMessage {
val backgroundActivity = fakeBackgroundActivity()
val spans = listOf(EmbraceSpanData("fake-span-id", "", "", "", 0, 0, StatusCode.OK))
val perfInfo = PerformanceInfo(DiskUsage(1, 2))

return SessionMessage(
backgroundActivity,
perfInfo,
spans,
metadata = EnvelopeMetadata(
userId = "fake-user-id",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.embrace.android.embracesdk

import io.embrace.android.embracesdk.fakes.fakePerformanceInfo
import io.embrace.android.embracesdk.fakes.fakeSession
import io.embrace.android.embracesdk.gating.SessionGatingKeys
import io.embrace.android.embracesdk.gating.SessionSanitizerFacade
import io.embrace.android.embracesdk.internal.payload.EnvelopeMetadata
import io.embrace.android.embracesdk.internal.payload.EnvelopeResource
import io.embrace.android.embracesdk.payload.Orientation
import io.embrace.android.embracesdk.payload.SessionMessage
import org.junit.Assert.assertNotNull
Expand All @@ -13,8 +13,6 @@ import org.junit.Test

internal class SessionSanitizerFacadeTest {

private val sessionPerformanceInfo = fakePerformanceInfo()

private val session = fakeSession().copy(
properties = mapOf("example" to "example"),
orientations = listOf(Orientation(0, 0L)),
Expand All @@ -31,10 +29,12 @@ internal class SessionSanitizerFacadeTest {

private val sessionMessage = SessionMessage(
session = session,
performanceInfo = sessionPerformanceInfo,
metadata = EnvelopeMetadata(
email = "example@embrace.com",
personas = setOf("personas")
),
resource = EnvelopeResource(
diskTotalCapacity = 100
)
)

Expand Down Expand Up @@ -77,8 +77,7 @@ internal class SessionSanitizerFacadeTest {
assertNotNull(sanitizedMessage.session.eventIds)
assertNotNull(sanitizedMessage.session.startupDuration)
assertNotNull(sanitizedMessage.session.startupThreshold)

assertNotNull(sanitizedMessage.performanceInfo?.diskUsage)
assertNotNull(sanitizedMessage.resource?.diskTotalCapacity)
}

@Test
Expand All @@ -100,7 +99,6 @@ internal class SessionSanitizerFacadeTest {
assertNull(sanitizedMessage.session.eventIds)
assertNull(sanitizedMessage.session.startupDuration)
assertNull(sanitizedMessage.session.startupThreshold)

assertNull(sanitizedMessage.performanceInfo?.diskUsage)
assertNull(sanitizedMessage.resource?.diskTotalCapacity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ internal class BackgroundActivityMessageTest {

private val backgroundActivity = fakeBackgroundActivity()
private val spans = listOf(EmbraceSpanData("fake-span-id", "", "", "", 0, 0, StatusCode.OK))
private val perfInfo = PerformanceInfo(DiskUsage(1, 2))

private val info = SessionMessage(
backgroundActivity,
perfInfo,
spans
)
private val info = SessionMessage(backgroundActivity, spans)

@Test
fun testSerialization() {
Expand All @@ -32,9 +26,7 @@ internal class BackgroundActivityMessageTest {
fun testDeserialization() {
val obj = deserializeJsonFromResource<SessionMessage>("bg_activity_message_expected.json")
assertNotNull(obj)

assertEquals(backgroundActivity.startTime, obj.session.startTime)
assertEquals(perfInfo, obj.performanceInfo)
assertEquals(spans, obj.spans)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.junit.Test
internal class SessionMessageTest {

private val session = fakeSession()
private val performanceInfo = PerformanceInfo(DiskUsage(150923409L, 509209823L))
private val spans = listOf(
EmbraceSpanData(
"fake-span-id",
Expand All @@ -37,7 +36,6 @@ internal class SessionMessageTest {

private val info = SessionMessage(
session,
performanceInfo,
spans,
spanSnapshots
)
Expand All @@ -52,7 +50,6 @@ internal class SessionMessageTest {
val obj = deserializeJsonFromResource<SessionMessage>("session_message_expected.json")
assertNotNull(obj)
assertEquals(session, obj.session)
assertEquals(performanceInfo, obj.performanceInfo)
assertEquals(spans, obj.spans)
assertEquals(spanSnapshots, obj.spanSnapshots)
}
Expand Down
Loading

0 comments on commit 4d992fc

Please sign in to comment.