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

fix: add metric for cohort download too large #33

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/main/kotlin/LocalEvaluationConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ interface LocalEvaluationMetrics {
fun onFlagConfigFetchFailure(exception: Exception)
fun onFlagConfigFetchOriginFallback(exception: Exception)
fun onCohortDownload()
fun onCohortDownloadTooLarge(exception: Exception)
fun onCohortDownloadFailure(exception: Exception)
fun onCohortDownloadOriginFallback(exception: Exception)
fun onProxyCohortMembership()
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/cohort/CohortLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ internal class CohortLoader(
} catch (e: CohortNotModifiedException) {
// Do nothing
} catch (e: CohortTooLargeException) {
Logger.e("Cohort too large", e)
metrics.onCohortDownloadTooLarge(e)
throw e
}
}
}, executor).whenComplete { _, _ -> jobs.remove(cohortId) }
Expand Down
9 changes: 7 additions & 2 deletions src/main/kotlin/deployment/DeploymentRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ internal class DeploymentRunner(
try {
val cohortIds = flagConfigStorage.getFlagConfigs().values.getAllCohortIds()
for (cohortId in cohortIds) {
cohortLoader.loadCohort(cohortId)
cohortLoader.loadCohort(cohortId).handle { _, exception ->
if (exception != null) {
Logger.e("Failed to load cohort $cohortId", exception)
}
}
}
} catch (t: Throwable) {
Logger.e("Refresh cohorts failed.", t)
}
}, cohortPollingInterval,
},
cohortPollingInterval,
cohortPollingInterval,
TimeUnit.MILLISECONDS
)
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/util/Metrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ internal class LocalEvaluationMetricsWrapper(
executor?.execute { metrics.onCohortDownload() }
}

override fun onCohortDownloadTooLarge(exception: Exception) {
val metrics = metrics ?: return
executor?.execute { metrics.onCohortDownloadTooLarge(exception) }
}

override fun onCohortDownloadFailure(exception: Exception) {
val metrics = metrics ?: return
executor?.execute { metrics.onCohortDownloadFailure(exception) }
Expand Down
6 changes: 5 additions & 1 deletion src/test/kotlin/cohort/CohortLoaderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class CohortLoaderTest {
`when`(api.getCohort("b", null)).thenReturn(cohortB)
val storage = InMemoryCohortStorage()
val loader = CohortLoader(api, storage)
loader.loadCohort("a").get()
try {
loader.loadCohort("a").get()
} catch (t: Throwable) {
// Expected
}
loader.loadCohort("b").get()
val storageDescriptionA = storage.getCohort("a")
val storageDescriptionB = storage.getCohort("b")
Expand Down
Loading