Skip to content

Commit 60e35e3

Browse files
committed
Merge branch 'master' into firebase-sessions
2 parents cd8cdec + 7eea13a commit 60e35e3

File tree

16 files changed

+469
-423
lines changed

16 files changed

+469
-423
lines changed

firebase-database/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version=20.1.1
15+
version=20.2.0
1616
latestReleasedVersion=20.1.0
1717
android.enableUnitTestBinaryResources=true

firebase-perf/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22
* [changed] Updated javalite, protoc, protobufjavautil to 3.21.11.
3+
* [changed] Updated [perfmon] to use Double precision for sampling.
34

45
# 20.3.1
56
* [changed] Migrated [perfmon] to use standard Firebase executors.

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -286,22 +286,22 @@ private boolean isFireperfSdkVersionInList(String versions) {
286286
}
287287

288288
/** Returns what percentage of Traces should be collected, range is [0.00f, 1.00f]. */
289-
public float getTraceSamplingRate() {
289+
public double getTraceSamplingRate() {
290290
// Order of precedence is:
291291
// 1. If the value exists through Firebase Remote Config, cache and return this value.
292292
// 2. If the value exists in device cache, return this value.
293293
// 3. Otherwise, return default value.
294294
TraceSamplingRate config = TraceSamplingRate.getInstance();
295295

296296
// 1. Reads value from Firebase Remote Config, saves this value in cache layer if valid.
297-
Optional<Float> rcValue = getRemoteConfigFloat(config);
297+
Optional<Double> rcValue = getRemoteConfigDouble(config);
298298
if (rcValue.isAvailable() && isSamplingRateValid(rcValue.get())) {
299299
deviceCacheManager.setValue(config.getDeviceCacheFlag(), rcValue.get());
300300
return rcValue.get();
301301
}
302302

303303
// 2. Reads value from cache layer.
304-
Optional<Float> deviceCacheValue = getDeviceCacheFloat(config);
304+
Optional<Double> deviceCacheValue = getDeviceCacheDouble(config);
305305
if (deviceCacheValue.isAvailable() && isSamplingRateValid(deviceCacheValue.get())) {
306306
return deviceCacheValue.get();
307307
}
@@ -311,22 +311,22 @@ public float getTraceSamplingRate() {
311311
}
312312

313313
/** Returns what percentage of NetworkRequest should be collected, range is [0.00f, 1.00f]. */
314-
public float getNetworkRequestSamplingRate() {
314+
public double getNetworkRequestSamplingRate() {
315315
// Order of precedence is:
316316
// 1. If the value exists through Firebase Remote Config, cache and return this value.
317317
// 2. If the value exists in device cache, return this value.
318318
// 3. Otherwise, return default value.
319319
NetworkRequestSamplingRate config = NetworkRequestSamplingRate.getInstance();
320320

321321
// 1. Reads value from Firebase Remote Config, saves this value in cache layer if valid.
322-
Optional<Float> rcValue = getRemoteConfigFloat(config);
322+
Optional<Double> rcValue = getRemoteConfigDouble(config);
323323
if (rcValue.isAvailable() && isSamplingRateValid(rcValue.get())) {
324324
deviceCacheManager.setValue(config.getDeviceCacheFlag(), rcValue.get());
325325
return rcValue.get();
326326
}
327327

328328
// 2. Reads value from cache layer.
329-
Optional<Float> deviceCacheValue = getDeviceCacheFloat(config);
329+
Optional<Double> deviceCacheValue = getDeviceCacheDouble(config);
330330
if (deviceCacheValue.isAvailable() && isSamplingRateValid(deviceCacheValue.get())) {
331331
return deviceCacheValue.get();
332332
}
@@ -336,7 +336,7 @@ public float getNetworkRequestSamplingRate() {
336336
}
337337

338338
/** Returns what percentage of Session gauge should be collected, range is [0.00f, 1.00f]. */
339-
public float getSessionsSamplingRate() {
339+
public double getSessionsSamplingRate() {
340340
// Order of precedence is:
341341
// 1. If the value exists in Android Manifest, convert from [0.00f, 100.00f] to [0.00f, 1.00f]
342342
// and return this value.
@@ -346,24 +346,24 @@ public float getSessionsSamplingRate() {
346346
SessionsSamplingRate config = SessionsSamplingRate.getInstance();
347347

348348
// 1. Reads value in Android Manifest (it is set by developers during build time).
349-
Optional<Float> metadataValue = getMetadataFloat(config);
349+
Optional<Double> metadataValue = getMetadataDouble(config);
350350
if (metadataValue.isAvailable()) {
351351
// Sampling percentage from metadata needs to convert from [0.00f, 100.00f] to [0.00f, 1.00f].
352-
float samplingRate = metadataValue.get() / 100.0f;
352+
double samplingRate = metadataValue.get() / 100;
353353
if (isSamplingRateValid(samplingRate)) {
354354
return samplingRate;
355355
}
356356
}
357357

358358
// 2. Reads value from Firebase Remote Config, saves this value in cache layer if valid.
359-
Optional<Float> rcValue = getRemoteConfigFloat(config);
359+
Optional<Double> rcValue = getRemoteConfigDouble(config);
360360
if (rcValue.isAvailable() && isSamplingRateValid(rcValue.get())) {
361361
deviceCacheManager.setValue(config.getDeviceCacheFlag(), rcValue.get());
362362
return rcValue.get();
363363
}
364364

365365
// 3. Reads value from cache layer.
366-
Optional<Float> deviceCacheValue = getDeviceCacheFloat(config);
366+
Optional<Double> deviceCacheValue = getDeviceCacheDouble(config);
367367
if (deviceCacheValue.isAvailable() && isSamplingRateValid(deviceCacheValue.get())) {
368368
return deviceCacheValue.get();
369369
}
@@ -732,7 +732,7 @@ public String getAndCacheLogSourceName() {
732732
}
733733

734734
/** Returns what percentage of fragment traces should be collected, range is [0.00f, 1.00f]. */
735-
public float getFragmentSamplingRate() {
735+
public double getFragmentSamplingRate() {
736736
// Order of precedence is:
737737
// 1. If the value exists in Android Manifest, convert from [0.00f, 100.00f] to [0.00f, 1.00f]
738738
// and return this value.
@@ -742,24 +742,24 @@ public float getFragmentSamplingRate() {
742742
FragmentSamplingRate config = FragmentSamplingRate.getInstance();
743743

744744
// 1. Reads value in Android Manifest (it is set by developers during build time).
745-
Optional<Float> metadataValue = getMetadataFloat(config);
745+
Optional<Double> metadataValue = getMetadataDouble(config);
746746
if (metadataValue.isAvailable()) {
747747
// Sampling percentage from metadata needs to convert from [0.00f, 100.00f] to [0.00f, 1.00f].
748-
float samplingRate = metadataValue.get() / 100.0f;
748+
double samplingRate = metadataValue.get() / 100.0f;
749749
if (isSamplingRateValid(samplingRate)) {
750750
return samplingRate;
751751
}
752752
}
753753

754754
// 2. Reads value from Firebase Remote Config, saves this value in cache layer if valid.
755-
Optional<Float> rcValue = getRemoteConfigFloat(config);
755+
Optional<Double> rcValue = getRemoteConfigDouble(config);
756756
if (rcValue.isAvailable() && isSamplingRateValid(rcValue.get())) {
757757
deviceCacheManager.setValue(config.getDeviceCacheFlag(), rcValue.get());
758758
return rcValue.get();
759759
}
760760

761761
// 3. Reads value from cache layer.
762-
Optional<Float> deviceCacheValue = getDeviceCacheFloat(config);
762+
Optional<Double> deviceCacheValue = getDeviceCacheDouble(config);
763763
if (deviceCacheValue.isAvailable() && isSamplingRateValid(deviceCacheValue.get())) {
764764
return deviceCacheValue.get();
765765
}
@@ -807,17 +807,17 @@ private Optional<Boolean> getMetadataBoolean(ConfigurationFlag<Boolean> config)
807807
return metadataBundle.getBoolean(config.getMetadataFlag());
808808
}
809809

810-
private Optional<Float> getMetadataFloat(ConfigurationFlag<Float> config) {
811-
return metadataBundle.getFloat(config.getMetadataFlag());
810+
private Optional<Double> getMetadataDouble(ConfigurationFlag<Double> config) {
811+
return metadataBundle.getDouble(config.getMetadataFlag());
812812
}
813813

814814
private Optional<Long> getMetadataLong(ConfigurationFlag<Long> config) {
815815
return metadataBundle.getLong(config.getMetadataFlag());
816816
}
817817

818818
// Helper functions for interaction with Firebase Remote Config.
819-
private Optional<Float> getRemoteConfigFloat(ConfigurationFlag<Float> config) {
820-
return remoteConfigManager.getFloat(config.getRemoteConfigFlag());
819+
private Optional<Double> getRemoteConfigDouble(ConfigurationFlag<Double> config) {
820+
return remoteConfigManager.getDouble(config.getRemoteConfigFlag());
821821
}
822822

823823
private Optional<Long> getRemoteConfigLong(ConfigurationFlag<Long> config) {
@@ -841,8 +841,8 @@ private Long getRemoteConfigValue(ConfigurationFlag<Long> configFlag) {
841841
}
842842

843843
// Helper functions for interaction with Device Caching layer.
844-
private Optional<Float> getDeviceCacheFloat(ConfigurationFlag<Float> config) {
845-
return deviceCacheManager.getFloat(config.getDeviceCacheFlag());
844+
private Optional<Double> getDeviceCacheDouble(ConfigurationFlag<Double> config) {
845+
return deviceCacheManager.getDouble(config.getDeviceCacheFlag());
846846
}
847847

848848
private Optional<Long> getDeviceCacheLong(ConfigurationFlag<Long> config) {
@@ -858,7 +858,7 @@ private Optional<String> getDeviceCacheString(ConfigurationFlag<String> config)
858858
}
859859

860860
// Helper functions for config value validation.
861-
private boolean isSamplingRateValid(float samplingRate) {
861+
private boolean isSamplingRateValid(double samplingRate) {
862862
return MIN_SAMPLING_RATE <= samplingRate && samplingRate <= MAX_SAMPLING_RATE;
863863
}
864864

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected String getDeviceCacheFlag() {
130130
}
131131
}
132132

133-
protected static final class TraceSamplingRate extends ConfigurationFlag<Float> {
133+
protected static final class TraceSamplingRate extends ConfigurationFlag<Double> {
134134
private static TraceSamplingRate instance;
135135

136136
private TraceSamplingRate() {
@@ -145,11 +145,11 @@ protected static synchronized TraceSamplingRate getInstance() {
145145
}
146146

147147
@Override
148-
protected Float getDefault() {
148+
protected Double getDefault() {
149149
// Sampling rate range is [0.00f, 1.00f]. By default, sampling rate is 1.00f, which is 100%.
150150
// 0.00f means 0%, Fireperf will not capture any event for trace from the device,
151151
// 1.00f means 100%, Fireperf will capture all events for trace from the device.
152-
return 1.00f;
152+
return 1.0;
153153
}
154154

155155
@Override
@@ -163,7 +163,7 @@ protected String getDeviceCacheFlag() {
163163
}
164164
}
165165

166-
protected static final class NetworkRequestSamplingRate extends ConfigurationFlag<Float> {
166+
protected static final class NetworkRequestSamplingRate extends ConfigurationFlag<Double> {
167167
private static NetworkRequestSamplingRate instance;
168168

169169
private NetworkRequestSamplingRate() {
@@ -178,11 +178,11 @@ protected static synchronized NetworkRequestSamplingRate getInstance() {
178178
}
179179

180180
@Override
181-
protected Float getDefault() {
181+
protected Double getDefault() {
182182
// Sampling rate range is [0.00f, 1.00f]. By default, sampling rate is 1.00f, which is 100%.
183183
// 0.00f means 0%, Fireperf will not capture any event for trace from the device,
184184
// 1.00f means 100%, Fireperf will capture all events for trace from the device.
185-
return 1.00f;
185+
return 1.0;
186186
}
187187

188188
@Override
@@ -534,7 +534,7 @@ protected String getDeviceCacheFlag() {
534534
}
535535
}
536536

537-
protected static final class SessionsSamplingRate extends ConfigurationFlag<Float> {
537+
protected static final class SessionsSamplingRate extends ConfigurationFlag<Double> {
538538
private static SessionsSamplingRate instance;
539539

540540
private SessionsSamplingRate() {
@@ -549,8 +549,8 @@ public static synchronized SessionsSamplingRate getInstance() {
549549
}
550550

551551
@Override
552-
protected Float getDefault() {
553-
return 0.01f;
552+
protected Double getDefault() {
553+
return 0.01;
554554
}
555555

556556
@Override
@@ -624,7 +624,7 @@ protected String getDeviceCacheFlag() {
624624
}
625625
}
626626

627-
protected static final class FragmentSamplingRate extends ConfigurationFlag<Float> {
627+
protected static final class FragmentSamplingRate extends ConfigurationFlag<Double> {
628628
private static FragmentSamplingRate instance;
629629

630630
private FragmentSamplingRate() {
@@ -639,11 +639,11 @@ protected static synchronized FragmentSamplingRate getInstance() {
639639
}
640640

641641
@Override
642-
protected Float getDefault() {
642+
protected Double getDefault() {
643643
// Sampling rate range is [0.00f, 1.00f]. By default, sampling rate is 0.00f, which is 0%.
644644
// 0.00f means 0%, Fireperf will not capture any event for fragment trace from the device,
645645
// 1.00f means 100%, Fireperf will capture all events for fragment trace from the device.
646-
return 0.00f;
646+
return 0.00;
647647
}
648648

649649
@Override

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ public boolean setValue(String key, String value) {
209209
* Retrieves value stored in caching layer for {@code key}, if caching layer is not initialized,
210210
* or value with the desired type doesn't exist in caching layer, return {@code Optional.empty()}.
211211
*/
212-
public Optional<Float> getFloat(String key) {
212+
public Optional<Double> getDouble(String key) {
213213
if (key == null) {
214-
logger.debug("Key is null when getting float value on device cache.");
214+
logger.debug("Key is null when getting double value on device cache.");
215215
return Optional.absent();
216216
}
217217

@@ -227,11 +227,19 @@ public Optional<Float> getFloat(String key) {
227227
}
228228

229229
try {
230+
// SharedPreferences does not allow storing a Double directly. We store the double's bits as a
231+
// long so here we convert that back to a double.
230232
// Default value should never be used because key existence is checked above.
231-
return Optional.of(sharedPref.getFloat(key, 0.0f));
232-
} catch (ClassCastException e) {
233-
logger.debug(
234-
"Key %s from sharedPreferences has type other than float: %s", key, e.getMessage());
233+
return Optional.of(Double.longBitsToDouble(sharedPref.getLong(key, 0)));
234+
} catch (ClassCastException unused) {
235+
// In the past, we used to store a Float here instead of a Double. Before the value is
236+
// overwritten for the first time, it will still have a Float and so this may be expected.
237+
try {
238+
return Optional.of(Float.valueOf(sharedPref.getFloat(key, 0.0f)).doubleValue());
239+
} catch (ClassCastException e) {
240+
logger.debug(
241+
"Key %s from sharedPreferences has type other than double: %s", key, e.getMessage());
242+
}
235243
}
236244
return Optional.absent();
237245
}
@@ -242,18 +250,22 @@ public Optional<Float> getFloat(String key) {
242250
*
243251
* @return whether provided value has been saved to device caching layer.
244252
*/
245-
public boolean setValue(String key, float value) {
253+
public boolean setValue(String key, double value) {
246254
if (key == null) {
247-
logger.debug("Key is null when setting float value on device cache.");
255+
logger.debug("Key is null when setting double value on device cache.");
248256
return false;
249257
}
258+
250259
if (sharedPref == null) {
251260
setContext(getFirebaseApplicationContext());
252261
if (sharedPref == null) {
253262
return false;
254263
}
255264
}
256-
sharedPref.edit().putFloat(key, value).apply();
265+
// SharedPreferences does not allow storing a Double directly. The main way to store it without
266+
// losing precision is to store the double's bits as a long so it can then be converted back to
267+
// a double.
268+
sharedPref.edit().putLong(key, Double.doubleToRawLongBits(value)).apply();
257269
return true;
258270
}
259271

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,23 @@ public void setFirebaseRemoteConfigProvider(
139139
}
140140

141141
/**
142-
* Retrieves the double value of the given key from the remote config, converts to float type and
142+
* Retrieves the double value of the given key from the remote config, converts to double type and
143143
* returns this value.
144144
*
145145
* @implNote Triggers a remote config fetch on a background thread if it hasn't yet been fetched.
146146
* @param key The key to fetch the double value for.
147-
* @return The float value of the key or not present.
147+
* @return The double value of the key or not present.
148148
*/
149-
public Optional<Float> getFloat(String key) {
149+
public Optional<Double> getDouble(String key) {
150150
if (key == null) {
151-
logger.debug("The key to get Remote Config float value is null.");
151+
logger.debug("The key to get Remote Config double value is null.");
152152
return Optional.absent();
153153
}
154154

155155
FirebaseRemoteConfigValue rcValue = getRemoteConfigValue(key);
156156
if (rcValue != null) {
157157
try {
158-
return Optional.of(Double.valueOf(rcValue.asDouble()).floatValue());
158+
return Optional.of(rcValue.asDouble());
159159
} catch (IllegalArgumentException e) {
160160
if (!rcValue.asString().isEmpty()) {
161161
logger.debug("Could not parse value: '%s' for key: '%s'.", rcValue.asString(), key);
@@ -260,8 +260,8 @@ public <T extends Object> T getRemoteConfigValueOrDefault(String key, T defaultV
260260
if (defaultValue instanceof Boolean) {
261261
valueToReturn = rcValue.asBoolean();
262262

263-
} else if (defaultValue instanceof Float) {
264-
valueToReturn = Double.valueOf(rcValue.asDouble()).floatValue();
263+
} else if (defaultValue instanceof Double) {
264+
valueToReturn = rcValue.asDouble();
265265

266266
} else if (defaultValue instanceof Long || defaultValue instanceof Integer) {
267267
valueToReturn = rcValue.asLong();

0 commit comments

Comments
 (0)