Skip to content

Commit d081ae3

Browse files
committed
Add rc fetch failed defaults for cpu and memory capturing frequency
1 parent 23f833a commit d081ae3

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/config/ConfigResolver.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ public long getSessionsCpuCaptureFrequencyForegroundMs() {
399399
// 1. If the value exists in Android Manifest, return this value.
400400
// 2. If the value exists through Firebase Remote Config, cache and return this value.
401401
// 3. If the value exists in device cache, return this value.
402-
// 4. Otherwise, return default value.
402+
// 4. If the Firebase Remote Config fetch failed, return default failure value.
403+
// 5. Otherwise, return default value.
403404
SessionsCpuCaptureFrequencyForegroundMs config =
404405
SessionsCpuCaptureFrequencyForegroundMs.getInstance();
405406

@@ -422,7 +423,12 @@ public long getSessionsCpuCaptureFrequencyForegroundMs() {
422423
return deviceCacheValue.get();
423424
}
424425

425-
// 4. Returns default value if there is no valid value from above approaches.
426+
// 4. Check if RC fetch failed.
427+
if (remoteConfigManager.isLastFetchFailed()) {
428+
return config.getDefaultOnRcFetchFail();
429+
}
430+
431+
// 5. Returns default value if there is no valid value from above approaches.
426432
return config.getDefault();
427433
}
428434

@@ -471,7 +477,8 @@ public long getSessionsMemoryCaptureFrequencyForegroundMs() {
471477
// 1. If the value exists in Android Manifest, return this value.
472478
// 2. If the value exists through Firebase Remote Config, cache and return this value.
473479
// 3. If the value exists in device cache, return this value.
474-
// 4. Otherwise, return default value.
480+
// 4. If the Firebase Remote Config fetch failed, return default failure value.
481+
// 5. Otherwise, return default value.
475482
SessionsMemoryCaptureFrequencyForegroundMs config =
476483
SessionsMemoryCaptureFrequencyForegroundMs.getInstance();
477484

@@ -494,7 +501,12 @@ public long getSessionsMemoryCaptureFrequencyForegroundMs() {
494501
return deviceCacheValue.get();
495502
}
496503

497-
// 4. Returns default value if there is no valid value from above approaches.
504+
// 4. Check if RC fetch failed.
505+
if (remoteConfigManager.isLastFetchFailed()) {
506+
return config.getDefaultOnRcFetchFail();
507+
}
508+
509+
// 5. Returns default value if there is no valid value from above approaches.
498510
return config.getDefault();
499511
}
500512

firebase-perf/src/main/java/com/google/firebase/perf/config/ConfigurationConstants.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ protected Long getDefault() {
230230
return 100L;
231231
}
232232

233+
@Override
234+
protected Long getDefaultOnRcFetchFail() {
235+
return getDefault() * 3;
236+
}
237+
233238
@Override
234239
protected String getRemoteConfigFlag() {
235240
return "fpr_session_gauge_cpu_capture_frequency_fg_ms";
@@ -306,6 +311,11 @@ protected Long getDefault() {
306311
return 100L;
307312
}
308313

314+
@Override
315+
protected Long getDefaultOnRcFetchFail() {
316+
return getDefault() * 3;
317+
}
318+
309319
@Override
310320
protected String getRemoteConfigFlag() {
311321
return "fpr_session_gauge_memory_capture_frequency_fg_ms";

firebase-perf/src/test/java/com/google/firebase/perf/config/ConfigResolverTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,18 @@ public void getSessionsCpuCaptureFrequencyForegroundMs_validMetadata_notSaveMeta
647647
assertThat(testConfigResolver.getSessionsCpuCaptureFrequencyForegroundMs()).isEqualTo(100L);
648648
}
649649

650+
@Test
651+
public void
652+
getSessionsCpuCaptureFrequencyForegroundMs_remoteConfigFetchFailed_returnDefaultRCValue() {
653+
when(mockRemoteConfigManager.getLong(SESSIONS_CPU_CAPTURE_FREQUENCY_FG_MS_FRC_KEY))
654+
.thenReturn(Optional.absent());
655+
when(mockDeviceCacheManager.getLong(SESSIONS_CPU_CAPTURE_FREQUENCY_FG_MS_CACHE_KEY))
656+
.thenReturn(Optional.absent());
657+
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(true);
658+
659+
assertThat(testConfigResolver.getSessionsCpuCaptureFrequencyForegroundMs()).isEqualTo(300L);
660+
}
661+
650662
@Test
651663
public void
652664
getSessionsCpuCaptureFrequencyForegroundMs_invalidAndroidMetadataBundle_returnRemoteConfigValue() {
@@ -1051,6 +1063,18 @@ public void getSessionsMemoryCaptureFrequencyForegroundMs_validMetadata_notSaveM
10511063
assertThat(testConfigResolver.getSessionsMemoryCaptureFrequencyForegroundMs()).isEqualTo(100L);
10521064
}
10531065

1066+
@Test
1067+
public void
1068+
getSessionsMemoryCaptureFrequencyForegroundMs_remoteConfigFetchFailed_returnDefaultRCValue() {
1069+
when(mockRemoteConfigManager.getLong(SESSIONS_MEMORY_CAPTURE_FREQUENCY_FG_MS_FRC_KEY))
1070+
.thenReturn(Optional.absent());
1071+
when(mockDeviceCacheManager.getLong(SESSIONS_MEMORY_CAPTURE_FREQUENCY_FG_MS_CACHE_KEY))
1072+
.thenReturn(Optional.absent());
1073+
when(mockRemoteConfigManager.isLastFetchFailed()).thenReturn(true);
1074+
1075+
assertThat(testConfigResolver.getSessionsMemoryCaptureFrequencyForegroundMs()).isEqualTo(300L);
1076+
}
1077+
10541078
@Test
10551079
public void
10561080
getSessionsMemoryCaptureFrequencyForegroundMs_invalidAndroidMetadataBundle_returnRemoteConfigValue() {

firebase-perf/src/test/java/com/google/firebase/perf/config/ConfigurationConstantsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public void getInstance_SessionsCpuCaptureFrequencyForegroundMs_validateConstant
9191
SessionsCpuCaptureFrequencyForegroundMs.getInstance();
9292

9393
assertThat(configFlag.getDefault()).isEqualTo(100L);
94+
assertThat(configFlag.getDefaultOnRcFetchFail()).isEqualTo(300L);
9495
assertThat(configFlag.getDeviceCacheFlag())
9596
.isEqualTo("com.google.firebase.perf.SessionsCpuCaptureFrequencyForegroundMs");
9697
assertThat(configFlag.getRemoteConfigFlag())
@@ -117,6 +118,7 @@ public void getInstance_SessionsMemoryCaptureFrequencyForegroundMs_validateConst
117118
SessionsMemoryCaptureFrequencyForegroundMs.getInstance();
118119

119120
assertThat(configFlag.getDefault()).isEqualTo(100L);
121+
assertThat(configFlag.getDefaultOnRcFetchFail()).isEqualTo(300L);
120122
assertThat(configFlag.getDeviceCacheFlag())
121123
.isEqualTo("com.google.firebase.perf.SessionsMemoryCaptureFrequencyForegroundMs");
122124
assertThat(configFlag.getRemoteConfigFlag())

firebase-perf/src/test/java/com/google/firebase/perf/config/RemoteConfigManagerTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,16 @@ public void isLastFetchFailed_frcIsNonNullAndStatusFailed_returnsTrue() {
812812
}
813813

814814
@Test
815-
public void isLastFetchFailed_frcIsNonNullAndStatusOtherThanFailed_returnsFalse() {
815+
public void isLastFetchFailed_frcIsNonNullAndStatusThrottled_returnsTrue() {
816+
RemoteConfigManager testRemoteConfigManager =
817+
setupTestRemoteConfigManager(createDefaultRcConfigMap());
818+
simulateFirebaseRemoteConfigLastFetchStatus(FirebaseRemoteConfig.LAST_FETCH_STATUS_THROTTLED);
819+
820+
assertThat(testRemoteConfigManager.isLastFetchFailed()).isTrue();
821+
}
822+
823+
@Test
824+
public void isLastFetchFailed_frcIsNonNullAndStatusOtherThanFailedOrThrottled_returnsFalse() {
816825
RemoteConfigManager testRemoteConfigManager =
817826
setupTestRemoteConfigManager(createDefaultRcConfigMap());
818827

@@ -822,9 +831,6 @@ public void isLastFetchFailed_frcIsNonNullAndStatusOtherThanFailed_returnsFalse(
822831

823832
simulateFirebaseRemoteConfigLastFetchStatus(FirebaseRemoteConfig.LAST_FETCH_STATUS_SUCCESS);
824833
assertThat(testRemoteConfigManager.isLastFetchFailed()).isFalse();
825-
826-
simulateFirebaseRemoteConfigLastFetchStatus(FirebaseRemoteConfig.LAST_FETCH_STATUS_THROTTLED);
827-
assertThat(testRemoteConfigManager.isLastFetchFailed()).isFalse();
828834
}
829835

830836
@Test

0 commit comments

Comments
 (0)