Skip to content
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

Fixes #4335: Addition of support for uploading performance metric logs #4399

Merged
merged 187 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
187 commits
Select commit Hold shift + click to select a range
ac1cb65
qualifiers and constants for metric record and upload times
Sarthak2601 Apr 27, 2022
ee7df23
comments
Sarthak2601 Apr 27, 2022
0adaa4b
dagger provides for flags
Sarthak2601 Apr 27, 2022
fee9bd6
rename to enablePerformanceMetricCollection
Sarthak2601 Apr 29, 2022
d3f746f
initial proto
Sarthak2601 Apr 29, 2022
37a22c5
nit fixes
Sarthak2601 Apr 30, 2022
c33d75f
Merge branch 'performance-metrics-platform-params' into performance-m…
Sarthak2601 Apr 30, 2022
2b3cc6f
nit fixes
Sarthak2601 Apr 30, 2022
8d7ace6
comments.
Sarthak2601 May 1, 2022
49e2a9a
nits
Sarthak2601 May 13, 2022
c9a1840
nit
Sarthak2601 May 13, 2022
5a28ad7
Merge branch 'performance-metrics-platform-params' into performance-m…
Sarthak2601 May 13, 2022
7dc2fa4
updates.
Sarthak2601 Jun 7, 2022
c515e7d
updates.
Sarthak2601 Jun 7, 2022
9e98a40
nits.
Sarthak2601 Jun 7, 2022
c7d75e2
Merge branch 'develop' into performance-metrics-platform-params
Sarthak2601 Jun 7, 2022
3a8929d
Merge branch 'performance-metrics-platform-params' into performance-m…
Sarthak2601 Jun 7, 2022
1ae4e17
metric log inclusion.
Sarthak2601 Jun 7, 2022
16603dd
base setup.
Sarthak2601 Jun 8, 2022
e06979e
Merge branch 'develop' into performance-metrics-platform-params
Sarthak2601 Jun 8, 2022
0d2a668
name correction.
Sarthak2601 Jun 8, 2022
598a6ea
Merge branch 'performance-metrics-platform-params' into performance-m…
Sarthak2601 Jun 8, 2022
52e12eb
nits.
Sarthak2601 Jun 8, 2022
d992388
Merge branch 'performance-metrics-proto' into performance-metrics-log…
Sarthak2601 Jun 8, 2022
dae5990
nits.
Sarthak2601 Jun 8, 2022
f2112a2
storage comment
Sarthak2601 Jun 8, 2022
0b1181f
pss comment
Sarthak2601 Jun 8, 2022
694a987
Merge branch 'develop' into performance-metrics-proto
Sarthak2601 Jun 9, 2022
dbe1740
network usage comment.
Sarthak2601 Jun 9, 2022
c41c2e5
network usage comment - part 2.
Sarthak2601 Jun 9, 2022
629fe3c
metric addition in proto definitions.
Sarthak2601 Jun 9, 2022
4eedd28
Merge branch 'performance-metrics-proto' into performance-metrics-log…
Sarthak2601 Jun 9, 2022
172f98c
metricLog --> loggableMetric
Sarthak2601 Jun 10, 2022
29e38ae
Merge branch 'performance-metrics-proto' into performance-metrics-log…
Sarthak2601 Jun 10, 2022
3f8464f
proto definitions in oppiaLogger
Sarthak2601 Jun 12, 2022
adf9d4a
wording update for transmission
Sarthak2601 Jun 12, 2022
c06c77b
Merge branch 'performance-metrics-proto' into performance-metrics-log…
Sarthak2601 Jun 12, 2022
1776e62
dependency/api updates.
Sarthak2601 Jun 12, 2022
1917ec2
nits.
Sarthak2601 Jun 12, 2022
c7efd2a
metric controller and oppiaLogger
Sarthak2601 Jun 13, 2022
5104036
nits
Sarthak2601 Jun 13, 2022
60400a1
logger-controller pattern, single utils
Sarthak2601 Jun 20, 2022
74fcbf5
nits
Sarthak2601 Jun 20, 2022
db30498
comments
Sarthak2601 Jun 21, 2022
2c454e7
log uploading support
Sarthak2601 Jun 21, 2022
8f92036
nits
Sarthak2601 Jun 21, 2022
52b416c
nits
Sarthak2601 Jun 21, 2022
0062ce3
performance metric event logger nits.
Sarthak2601 Jun 21, 2022
4fb75a0
nits.
Sarthak2601 Jun 21, 2022
96a3ef6
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Jun 21, 2022
bcab311
logger reinstated.
Sarthak2601 Jun 21, 2022
8cecb6d
nits
Sarthak2601 Jun 21, 2022
35464e7
deleting unused interfaces.
Sarthak2601 Jun 21, 2022
76f56de
Merge branch 'develop' into performance-metrics-proto
Sarthak2601 Jun 21, 2022
866c53f
Merge branch 'performance-metrics-proto' into performance-metrics-log…
Sarthak2601 Jun 21, 2022
5fcea9c
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Jun 21, 2022
f4a039b
log generator to metric log scheduler
Sarthak2601 Jun 21, 2022
e57abfe
nits
Sarthak2601 Jun 21, 2022
d611373
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Jun 21, 2022
d51585a
nits -- kdoc, code placing, readability
Sarthak2601 Jun 22, 2022
2ede414
nits -- kdoc, code placing, readability
Sarthak2601 Jun 22, 2022
b92f8e0
worker functions to schedule logging, renaming
Sarthak2601 Jun 22, 2022
7d39973
nits.
Sarthak2601 Jun 22, 2022
8f26c7d
clearing up build errors.
Sarthak2601 Jun 23, 2022
5de3f2d
nits.
Sarthak2601 Jun 23, 2022
78996d6
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Jun 24, 2022
52dd311
fixing build errors.
Sarthak2601 Jun 24, 2022
8835c5b
removal of dependency from oppiaLogger and basing the entire implemen…
Sarthak2601 Jun 24, 2022
4835fac
performanceMetricController tests + fakeLogger
Sarthak2601 Jun 25, 2022
6b4b44f
fakeLogger tests
Sarthak2601 Jun 25, 2022
d70297d
nits
Sarthak2601 Jun 25, 2022
fad8f6b
tests for the new logger.
Sarthak2601 Jun 26, 2022
6c34ffd
tests for the worker + renaming of package to logScheduler
Sarthak2601 Jun 26, 2022
a70da96
tests for work manager initializer
Sarthak2601 Jun 26, 2022
c3a6b96
initial base setup for utils test
Sarthak2601 Jun 27, 2022
456e2f0
nits
Sarthak2601 Jun 27, 2022
cfddbd0
nits
Sarthak2601 Jun 27, 2022
792f128
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Jun 27, 2022
a0154a1
nit
Sarthak2601 Jun 27, 2022
2a5ba96
worker and initializer tests
Sarthak2601 Jun 27, 2022
af51d7d
event bundle creator tests
Sarthak2601 Jun 27, 2022
b569ad7
module tests
Sarthak2601 Jun 29, 2022
8c773f9
nits
Sarthak2601 Jun 29, 2022
5311ed3
performanceMetricsUtils tests
Sarthak2601 Jul 9, 2022
56f8e03
nits
Sarthak2601 Jul 9, 2022
21f5e97
renamed logUpload to logReport + nits
Sarthak2601 Jul 9, 2022
54b8b95
nits
Sarthak2601 Jul 9, 2022
3b3fa6d
nits
Sarthak2601 Jul 9, 2022
f2b685f
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Jul 9, 2022
36978b5
review updates.
Sarthak2601 Jul 14, 2022
69b4356
nit
Sarthak2601 Jul 14, 2022
7215d7b
Merge branch 'develop' into performance-metrics-log-creation
Sarthak2601 Jul 15, 2022
907d6c8
Merge branch 'develop' into performance-metrics-proto
Sarthak2601 Jul 15, 2022
7ea1d75
Merge branch 'performance-metrics-proto' into performance-metrics-log…
Sarthak2601 Jul 15, 2022
6d9af12
review updates - 2
Sarthak2601 Jul 15, 2022
2899d72
isAppInForeground revamp
Sarthak2601 Jul 15, 2022
366705d
isAppInForeground revamp
Sarthak2601 Jul 15, 2022
741a9d5
nits
Sarthak2601 Jul 15, 2022
e61ea0d
domain tests repair
Sarthak2601 Jul 15, 2022
7cd27e0
app tests repair
Sarthak2601 Jul 17, 2022
69e8feb
nits.
Sarthak2601 Jul 17, 2022
fd2e4a4
nits.
Sarthak2601 Jul 17, 2022
c6cac99
nits.
Sarthak2601 Jul 17, 2022
bb22192
nits.
Sarthak2601 Jul 17, 2022
d638928
nit
Sarthak2601 Jul 17, 2022
fb23b3a
test update.
Sarthak2601 Jul 18, 2022
0f70b12
test update.
Sarthak2601 Jul 18, 2022
51d626c
nit
Sarthak2601 Jul 18, 2022
2adb428
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Jul 18, 2022
d56c9cc
todo issue number update -- static check
Sarthak2601 Jul 18, 2022
6d545ef
comments.
Sarthak2601 Jul 19, 2022
11a73bc
nits.
Sarthak2601 Jul 21, 2022
b0cb4d5
utils test + nits
Sarthak2601 Jul 22, 2022
9bc32db
utils test + nits
Sarthak2601 Jul 23, 2022
c657739
nits
Sarthak2601 Jul 23, 2022
bc55877
test rearrangement
Sarthak2601 Jul 23, 2022
61ae44f
nits
Sarthak2601 Jul 23, 2022
bdfaeb3
test fixes.
Sarthak2601 Jul 23, 2022
318c63d
Merge branch 'develop' into performance-metrics-proto
Sarthak2601 Jul 25, 2022
8c03031
Merge branch 'performance-metrics-proto' into performance-metrics-log…
Sarthak2601 Jul 25, 2022
a728d8c
nits
Sarthak2601 Jul 25, 2022
07a9d41
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Jul 25, 2022
2755ff3
nits
Sarthak2601 Jul 25, 2022
b4d37da
nits
Sarthak2601 Jul 25, 2022
6188499
memory and storage tier updates
Sarthak2601 Jul 25, 2022
3cfcd07
Merge branch 'performance-metrics-proto' into performance-metrics-log…
Sarthak2601 Jul 25, 2022
2fca0cb
memory and storage tier updates
Sarthak2601 Jul 25, 2022
9e71c78
Merge branch 'develop' into performance-metrics-log-creation
Sarthak2601 Jul 26, 2022
e8c6959
updates.
Sarthak2601 Jul 27, 2022
5fb46ab
nits
Sarthak2601 Jul 27, 2022
ac38e85
test file exemptions refactor due to file renaming.
Sarthak2601 Jul 27, 2022
b987305
additional tests, nit fixes.
Sarthak2601 Aug 8, 2022
436762e
Merge branch 'develop' into performance-metrics-log-creation
Sarthak2601 Aug 9, 2022
5fffa65
activity manager shadow and assessor test
Sarthak2601 Aug 9, 2022
14091e1
nit
Sarthak2601 Aug 9, 2022
7a2e78f
nit
Sarthak2601 Aug 9, 2022
76ef3e3
shadow traffic stats + assessor test fix.
Sarthak2601 Aug 11, 2022
3feeddb
custom shadow tests
Sarthak2601 Aug 11, 2022
14f9f1d
module deps
Sarthak2601 Aug 11, 2022
cf95756
tests
Sarthak2601 Aug 12, 2022
d684067
nits
Sarthak2601 Aug 12, 2022
96054c7
metricLogScheduler refactor and test
Sarthak2601 Aug 12, 2022
149cbd6
exemption removal
Sarthak2601 Aug 12, 2022
3a8b248
nits
Sarthak2601 Aug 12, 2022
a4bfb65
updates.
Sarthak2601 Aug 16, 2022
4442ebd
variable nits + parameterized test exemption
Sarthak2601 Aug 22, 2022
ca2e764
Merge branch 'develop' into performance-metrics-log-creation
Sarthak2601 Aug 22, 2022
3b1ee7d
app component dependencies.
Sarthak2601 Aug 22, 2022
4c1a351
nits
Sarthak2601 Aug 22, 2022
4efd9e6
logging module bazel build, config module creation
Sarthak2601 Aug 23, 2022
1d011bc
testing robolectric bazel module update
Sarthak2601 Aug 23, 2022
b79853d
domain bazel build fixes
Sarthak2601 Aug 23, 2022
ba19784
working oppia bazel build
Sarthak2601 Aug 24, 2022
650f272
nits.
Sarthak2601 Aug 24, 2022
f519ea1
nits.
Sarthak2601 Aug 24, 2022
d4961e3
nit for bazel building
Sarthak2601 Aug 24, 2022
d9e7d91
addition of test file for module
Sarthak2601 Aug 24, 2022
8dc315f
bazel tests fixes
Sarthak2601 Aug 24, 2022
99e9927
more fixes.
Sarthak2601 Aug 25, 2022
1701780
reformatting
Sarthak2601 Aug 25, 2022
620dc12
nits
Sarthak2601 Aug 25, 2022
28d71ef
nits
Sarthak2601 Aug 25, 2022
013b1cf
Merge branch 'develop' into performance-metrics-log-creation
Sarthak2601 Aug 25, 2022
73aac3f
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Aug 25, 2022
2cc203e
dep fix
Sarthak2601 Aug 25, 2022
1e9018c
deps fix
Sarthak2601 Aug 25, 2022
e6d0209
deps fix
Sarthak2601 Aug 25, 2022
1525c68
nit
Sarthak2601 Aug 25, 2022
66c864c
nits
Sarthak2601 Aug 26, 2022
fa27f74
nits
Sarthak2601 Aug 26, 2022
9163f5c
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Aug 26, 2022
0462b22
gradle test fix.
Sarthak2601 Aug 26, 2022
809decf
bazel oppia build
Sarthak2601 Aug 26, 2022
51a2dd2
Merge branch 'develop' into performance-metrics-log-creation
Sarthak2601 Aug 26, 2022
68fa911
test fixes -- renaming.
Sarthak2601 Aug 26, 2022
b591612
deps addition
Sarthak2601 Aug 26, 2022
8b33234
previous merge correction
Sarthak2601 Aug 26, 2022
ea87846
nits
Sarthak2601 Aug 29, 2022
aa2992c
updates.
Sarthak2601 Aug 31, 2022
2e5f044
nits
Sarthak2601 Aug 31, 2022
dc05e8b
bazel update.
Sarthak2601 Aug 31, 2022
3495a4f
nit
Sarthak2601 Aug 31, 2022
e5f9e5b
nits.
Sarthak2601 Sep 1, 2022
2d39a8b
Merge branch 'develop' into performance-metrics-log-creation
Sarthak2601 Sep 2, 2022
a303293
Merge branch 'performance-metrics-log-creation' into performance-metr…
Sarthak2601 Sep 2, 2022
28ce0b5
Merge branch 'develop' into performance-metric-log-upload
Sarthak2601 Sep 2, 2022
69314c8
Merge branch 'develop' into performance-metric-log-upload
Sarthak2601 Sep 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ kt_android_library(
],
deps = [
"//domain/src/main/java/org/oppia/android/domain/oppialogger/analytics:controller",
"//domain/src/main/java/org/oppia/android/domain/oppialogger/analytics:performance_metrics_controller",
"//domain/src/main/java/org/oppia/android/domain/oppialogger/exceptions:controller",
"//domain/src/main/java/org/oppia/android/domain/util:extensions",
"//third_party:androidx_work_work-runtime-ktx",
"//utility/src/main/java/org/oppia/android/util/logging:console_logger",
"//utility/src/main/java/org/oppia/android/util/logging:event_logger",
"//utility/src/main/java/org/oppia/android/util/logging:exception_logger",
"//utility/src/main/java/org/oppia/android/util/logging/performancemetrics:performance_metrics_event_logger",
"//utility/src/main/java/org/oppia/android/util/threading:annotations",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class LogReportWorkManagerInitializer @Inject constructor(
)
.build()

private val workerCaseForUploadingPerformanceMetrics: Data = Data.Builder()
.putString(
LogUploadWorker.WORKER_CASE_KEY,
LogUploadWorker.PERFORMANCE_METRICS_WORKER
)
.build()

private val workerCaseForSchedulingPeriodicBackgroundMetricLogs: Data = Data.Builder()
.putString(
MetricLogSchedulingWorker.WORKER_CASE_KEY,
Expand Down Expand Up @@ -83,6 +90,12 @@ class LogReportWorkManagerInitializer @Inject constructor(
.setConstraints(logReportWorkerConstraints)
.build()

private val workRequestForUploadingPerformanceMetrics: PeriodicWorkRequest = PeriodicWorkRequest
.Builder(LogUploadWorker::class.java, 6, TimeUnit.HOURS)
.setInputData(workerCaseForUploadingPerformanceMetrics)
.setConstraints(logReportWorkerConstraints)
.build()

private val workRequestForSchedulingPeriodicBackgroundMetricLogs: PeriodicWorkRequest =
PeriodicWorkRequest.Builder(
MetricLogSchedulingWorker::class.java,
Expand Down Expand Up @@ -117,6 +130,10 @@ class LogReportWorkManagerInitializer @Inject constructor(
val workManager = WorkManager.getInstance(context)
logUploader.enqueueWorkRequestForEvents(workManager, workRequestForUploadingEvents)
logUploader.enqueueWorkRequestForExceptions(workManager, workRequestForUploadingExceptions)
logUploader.enqueueWorkRequestForPerformanceMetrics(
workManager,
workRequestForUploadingPerformanceMetrics
)
metricLogScheduler.enqueueWorkRequestForPeriodicBackgroundMetrics(
workManager,
workRequestForSchedulingPeriodicBackgroundMetricLogs
Expand All @@ -140,6 +157,9 @@ class LogReportWorkManagerInitializer @Inject constructor(
/** Returns the [UUID] of the work request that is enqueued for uploading exception logs. */
fun getWorkRequestForExceptionsId(): UUID = workRequestForUploadingExceptions.id

/** Returns the [UUID] of the work request that is enqueued for uploading performance metrics logs. */
fun getWorkRequestForPerformanceMetricsId(): UUID = workRequestForUploadingPerformanceMetrics.id

/**
* Returns the [UUID] of the work request that is enqueued for scheduling memory usage
* performance metrics collection.
Expand Down Expand Up @@ -172,6 +192,9 @@ class LogReportWorkManagerInitializer @Inject constructor(
*/
fun getWorkRequestDataForExceptions(): Data = workerCaseForUploadingExceptions

/** Returns the [Data] that goes into the work request that is enqueued for uploading performance metric logs. */
fun getWorkRequestDataForPerformanceMetrics(): Data = workerCaseForUploadingPerformanceMetrics

/**
* Returns the [Data] that goes into the work request that is enqueued for scheduling storage
* usage performance metrics collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.async
import org.oppia.android.domain.oppialogger.analytics.AnalyticsController
import org.oppia.android.domain.oppialogger.analytics.PerformanceMetricsController
import org.oppia.android.domain.oppialogger.exceptions.ExceptionsController
import org.oppia.android.domain.oppialogger.exceptions.toException
import org.oppia.android.domain.util.getStringFromData
import org.oppia.android.util.logging.ConsoleLogger
import org.oppia.android.util.logging.EventLogger
import org.oppia.android.util.logging.ExceptionLogger
import org.oppia.android.util.logging.SyncStatusManager
import org.oppia.android.util.logging.performancemetrics.PerformanceMetricsEventLogger
import org.oppia.android.util.threading.BackgroundDispatcher
import javax.inject.Inject

Expand All @@ -26,8 +28,10 @@ class LogUploadWorker private constructor(
params: WorkerParameters,
private val analyticsController: AnalyticsController,
private val exceptionsController: ExceptionsController,
private val performanceMetricsController: PerformanceMetricsController,
private val exceptionLogger: ExceptionLogger,
private val eventLogger: EventLogger,
private val performanceMetricsEventLogger: PerformanceMetricsEventLogger,
private val consoleLogger: ConsoleLogger,
private val syncStatusManager: SyncStatusManager,
@BackgroundDispatcher private val backgroundDispatcher: CoroutineDispatcher
Expand All @@ -38,6 +42,7 @@ class LogUploadWorker private constructor(
const val TAG = "LogUploadWorker.tag"
const val EVENT_WORKER = "event_worker"
const val EXCEPTION_WORKER = "exception_worker"
const val PERFORMANCE_METRICS_WORKER = "performance_metrics_worker"
}

@ExperimentalCoroutinesApi
Expand All @@ -47,6 +52,7 @@ class LogUploadWorker private constructor(
when (inputData.getStringFromData(WORKER_CASE_KEY)) {
EVENT_WORKER -> uploadEvents()
EXCEPTION_WORKER -> uploadExceptions()
PERFORMANCE_METRICS_WORKER -> uploadPerformanceMetrics()
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
else -> Result.failure()
}
}
Expand Down Expand Up @@ -97,12 +103,29 @@ class LogUploadWorker private constructor(
}
}

/** Extracts performance metric logs from the cache store and logs them to the remote service. */
private suspend fun uploadPerformanceMetrics(): Result {
return try {
val performanceMetricsLogs = performanceMetricsController.getMetricLogStoreList()
performanceMetricsLogs.forEach { performanceMetricsLog ->
performanceMetricsEventLogger.logPerformanceMetric(performanceMetricsLog)
performanceMetricsController.removeFirstMetricLogFromStore()
}
Result.success()
} catch (e: Exception) {
consoleLogger.e(TAG, e.toString(), e)
Result.failure()
}
}

/** Creates an instance of [LogUploadWorker] by properly injecting dependencies. */
class Factory @Inject constructor(
private val analyticsController: AnalyticsController,
private val exceptionsController: ExceptionsController,
private val performanceMetricsController: PerformanceMetricsController,
private val exceptionLogger: ExceptionLogger,
private val eventLogger: EventLogger,
private val performanceMetricsEventLogger: PerformanceMetricsEventLogger,
private val consoleLogger: ConsoleLogger,
private val syncStatusManager: SyncStatusManager,
@BackgroundDispatcher private val backgroundDispatcher: CoroutineDispatcher
Expand All @@ -114,8 +137,10 @@ class LogUploadWorker private constructor(
params,
analyticsController,
exceptionsController,
performanceMetricsController,
exceptionLogger,
eventLogger,
performanceMetricsEventLogger,
consoleLogger,
syncStatusManager,
backgroundDispatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import javax.inject.Singleton
class FakeLogUploader @Inject constructor() : LogUploader {
private val eventRequestIdList = mutableListOf<UUID>()
private val exceptionRequestIdList = mutableListOf<UUID>()
private val performanceMetricsRequestIdList = mutableListOf<UUID>()

override fun enqueueWorkRequestForEvents(
workManager: WorkManager,
Expand All @@ -27,9 +28,19 @@ class FakeLogUploader @Inject constructor() : LogUploader {
exceptionRequestIdList.add(workRequest.id)
}

override fun enqueueWorkRequestForPerformanceMetrics(
workManager: WorkManager,
workRequest: PeriodicWorkRequest
) {
performanceMetricsRequestIdList.add(workRequest.id)
}

/** Returns the most recent work request id that's stored in the [eventRequestIdList]. */
fun getMostRecentEventRequestId() = eventRequestIdList.last()

/** Returns the most recent work request id that's stored in the [exceptionRequestIdList]. */
fun getMostRecentExceptionRequestId() = exceptionRequestIdList.last()

/** Returns the most recent work request id that's stored in the [performanceMetricsRequestIdList]. */
fun getMostRecentPerformanceMetricsRequestId() = performanceMetricsRequestIdList.last()
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class LogReportWorkManagerInitializerTest {
val enqueuedEventWorkRequestId = logReportWorkManagerInitializer.getWorkRequestForEventsId()
val enqueuedExceptionWorkRequestId =
logReportWorkManagerInitializer.getWorkRequestForExceptionsId()
val enqueuedPerformanceMetricsWorkRequestId =
logReportWorkManagerInitializer.getWorkRequestForPerformanceMetricsId()
val enqueuedSchedulingStorageUsageMetricWorkRequestId =
logReportWorkManagerInitializer.getWorkRequestForSchedulingStorageUsageMetricLogsId()
val enqueuedSchedulingPeriodicUiMetricWorkRequestId =
Expand All @@ -134,6 +136,9 @@ class LogReportWorkManagerInitializerTest {
assertThat(fakeLogUploader.getMostRecentExceptionRequestId()).isEqualTo(
enqueuedExceptionWorkRequestId
)
assertThat(fakeLogUploader.getMostRecentPerformanceMetricsRequestId()).isEqualTo(
enqueuedPerformanceMetricsWorkRequestId
)
assertThat(fakeLogScheduler.getMostRecentStorageUsageMetricLoggingRequestId()).isEqualTo(
enqueuedSchedulingStorageUsageMetricWorkRequestId
)
Expand Down Expand Up @@ -186,6 +191,20 @@ class LogReportWorkManagerInitializerTest {
).isEqualTo(workerCaseForUploadingExceptions)
}

@Test
fun testWorkRequest_verifyWorkRequestDataForPerformanceMetrics() {
val workerCaseForUploadingPerformanceMetrics: Data = Data.Builder()
.putString(
LogUploadWorker.WORKER_CASE_KEY,
LogUploadWorker.PERFORMANCE_METRICS_WORKER
)
.build()

assertThat(logReportWorkManagerInitializer.getWorkRequestDataForPerformanceMetrics()).isEqualTo(
workerCaseForUploadingPerformanceMetrics
)
}

@Test
fun testWorkRequest_verifyWorkRequestData_forSchedulingStorageUsageMetricLogs() {
val workerCaseForSchedulingStorageUsageMetricLogs: Data = Data.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import org.mockito.Mockito.reset
import org.oppia.android.app.model.EventLog
import org.oppia.android.app.model.OppiaMetricLog
import org.oppia.android.domain.oppialogger.EventLogStorageCacheSize
import org.oppia.android.domain.oppialogger.ExceptionLogStorageCacheSize
import org.oppia.android.domain.oppialogger.LoggingIdentifierModule
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.oppialogger.PerformanceMetricsLogStorageCacheSize
import org.oppia.android.domain.oppialogger.analytics.AnalyticsController
import org.oppia.android.domain.oppialogger.analytics.ApplicationLifecycleModule
import org.oppia.android.domain.oppialogger.analytics.PerformanceMetricsController
import org.oppia.android.domain.oppialogger.exceptions.ExceptionsController
import org.oppia.android.domain.platformparameter.PlatformParameterModule
import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModule
import org.oppia.android.domain.testing.oppialogger.loguploader.FakeLogUploader
import org.oppia.android.testing.FakeEventLogger
import org.oppia.android.testing.FakeExceptionLogger
import org.oppia.android.testing.FakePerformanceMetricsEventLogger
import org.oppia.android.testing.logging.FakeSyncStatusManager
import org.oppia.android.testing.logging.SyncStatusTestModule
import org.oppia.android.testing.mockito.anyOrNull
Expand All @@ -58,6 +62,9 @@ import org.oppia.android.util.logging.SyncStatusManager.SyncStatus.DATA_UPLOADED
import org.oppia.android.util.logging.SyncStatusManager.SyncStatus.DATA_UPLOADING
import org.oppia.android.util.logging.SyncStatusManager.SyncStatus.NETWORK_ERROR
import org.oppia.android.util.logging.SyncStatusManager.SyncStatus.NO_CONNECTIVITY
import org.oppia.android.util.logging.performancemetrics.PerformanceMetricsAssessorModule
import org.oppia.android.util.logging.performancemetrics.PerformanceMetricsConfigurationsModule
import org.oppia.android.util.logging.performancemetrics.PerformanceMetricsEventLogger
import org.oppia.android.util.networking.NetworkConnectionDebugUtil
import org.oppia.android.util.networking.NetworkConnectionUtil.ProdConnectionStatus.NONE
import org.oppia.android.util.networking.NetworkConnectionUtilDebugModule
Expand All @@ -69,6 +76,7 @@ import javax.inject.Singleton

private const val TEST_TIMESTAMP = 1556094120000
private const val TEST_TOPIC_ID = "test_topicId"
private const val TEST_APK_SIZE = Long.MAX_VALUE

/** Tests for [LogUploadWorker]. */
// FunctionName: test names are conventionally named with underscores.
Expand All @@ -80,9 +88,11 @@ class LogUploadWorkerTest {
@Inject lateinit var networkConnectionUtil: NetworkConnectionDebugUtil
@Inject lateinit var fakeEventLogger: FakeEventLogger
@Inject lateinit var fakeExceptionLogger: FakeExceptionLogger
@Inject lateinit var fakePerformanceMetricsEventLogger: FakePerformanceMetricsEventLogger
@Inject lateinit var oppiaLogger: OppiaLogger
@Inject lateinit var analyticsController: AnalyticsController
@Inject lateinit var exceptionsController: ExceptionsController
@Inject lateinit var performanceMetricsController: PerformanceMetricsController
@Inject lateinit var logUploadWorkerFactory: LogUploadWorkerFactory
@Inject lateinit var dataProviders: DataProviders
@Inject lateinit var testCoroutineDispatchers: TestCoroutineDispatchers
Expand All @@ -105,6 +115,13 @@ class LogUploadWorkerTest {
.setTimestamp(TEST_TIMESTAMP)
.build()

private val apkSizeTestLoggableMetric = OppiaMetricLog.LoggableMetric.newBuilder()
.setApkSizeMetric(
OppiaMetricLog.ApkSizeMetric.newBuilder()
.setApkSizeBytes(TEST_APK_SIZE)
.build()
).build()

private val exception = Exception("TEST")

@Before
Expand Down Expand Up @@ -203,6 +220,46 @@ class LogUploadWorkerTest {
assertThat(loggedExceptionStackTraceElems).isEqualTo(expectedExceptionStackTraceElems)
}

@Test
fun testWorker_logPerformanceMetric_withoutNetwork_enqueueRequest_verifySuccess() {
networkConnectionUtil.setCurrentConnectionStatus(NONE)
performanceMetricsController.logPerformanceMetricsEvent(
TEST_TIMESTAMP,
OppiaMetricLog.CurrentScreen.SCREEN_UNSPECIFIED,
apkSizeTestLoggableMetric,
OppiaMetricLog.Priority.LOW_PRIORITY
)

val workManager = WorkManager.getInstance(ApplicationProvider.getApplicationContext())

val inputData = Data.Builder().putString(
LogUploadWorker.WORKER_CASE_KEY,
LogUploadWorker.PERFORMANCE_METRICS_WORKER
).build()

val request: OneTimeWorkRequest = OneTimeWorkRequestBuilder<LogUploadWorker>()
.setInputData(inputData)
.build()
workManager.enqueue(request)
testCoroutineDispatchers.runCurrent()

val workInfo = workManager.getWorkInfoById(request.id)
val loggedPerformanceMetric =
fakePerformanceMetricsEventLogger.getMostRecentPerformanceMetricsEvent()
assertThat(workInfo.get().state).isEqualTo(WorkInfo.State.SUCCEEDED)
assertThat(loggedPerformanceMetric.loggableMetric.loggableMetricTypeCase).isEqualTo(
OppiaMetricLog.LoggableMetric.LoggableMetricTypeCase.APK_SIZE_METRIC
)
assertThat(loggedPerformanceMetric.currentScreen).isEqualTo(
OppiaMetricLog.CurrentScreen.SCREEN_UNSPECIFIED
)
assertThat(loggedPerformanceMetric.priority).isEqualTo(OppiaMetricLog.Priority.LOW_PRIORITY)
assertThat(loggedPerformanceMetric.timestampMillis).isEqualTo(TEST_TIMESTAMP)
assertThat(loggedPerformanceMetric.loggableMetric.apkSizeMetric.apkSizeBytes).isEqualTo(
TEST_APK_SIZE
)
}

@Test
fun testWorker_logEvent_withoutNetwork_enqueueRequest_verifyCorrectSyncStatusSequence() {
networkConnectionUtil.setCurrentConnectionStatus(NONE)
Expand Down Expand Up @@ -310,6 +367,11 @@ class LogUploadWorkerTest {

@Provides
fun bindFakeExceptionLogger(fakeLogger: FakeExceptionLogger): ExceptionLogger = fakeLogger

@Provides
fun bindFakePerformanceMetricsLogger(
fakePerformanceMetricsEventLogger: FakePerformanceMetricsEventLogger
): PerformanceMetricsEventLogger = fakePerformanceMetricsEventLogger
}

@Module
Expand All @@ -322,6 +384,10 @@ class LogUploadWorkerTest {
@Provides
@ExceptionLogStorageCacheSize
fun provideExceptionLogStorageSize(): Int = 2

@Provides
@PerformanceMetricsLogStorageCacheSize
fun providePerformanceMetricsLogStorageCacheSize(): Int = 2
}

@Module
Expand All @@ -340,7 +406,9 @@ class LogUploadWorkerTest {
TestFirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
NetworkConnectionUtilDebugModule::class, LocaleProdModule::class, LoggerModule::class,
AssetModule::class, PlatformParameterModule::class, PlatformParameterSingletonModule::class,
LoggingIdentifierModule::class, SyncStatusTestModule::class, ApplicationLifecycleModule::class
LoggingIdentifierModule::class, SyncStatusTestModule::class,
PerformanceMetricsAssessorModule::class, ApplicationLifecycleModule::class,
PerformanceMetricsConfigurationsModule::class
]
)
interface TestApplicationComponent : DataProvidersInjector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ kt_android_library(
visibility = ["//:oppia_api_visibility"],
deps = [
"//model/src/main/proto:event_logger_java_proto_lite",
"//model/src/main/proto:performance_metrics_event_logger_java_proto_lite",
"//third_party:javax_inject_javax_inject",
"//utility",
],
Expand Down
Loading