use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class RateLimiterTest method testTracesAreNotSampledWhenSessionIsVerboseAndSamplingEnabled.
@Test
public void testTracesAreNotSampledWhenSessionIsVerboseAndSamplingEnabled() {
makeConfigResolverReturnDefaultValues();
when(mockConfigResolver.getTraceSamplingRate()).thenReturn(0.70f);
// Passing a value for samplingBucketId which is greater than the sampling rate ensures that
// the sampling will be enabled causing all the metrics to be dropped
RateLimiter limiter = new RateLimiter(/* rate= */
TWO_TOKENS_PER_SECOND, /* capacity= */
2, mClock, /* samplingBucketId= */
0.71f, /* fragmentBucketId= */
0, mockConfigResolver);
assertThat(limiter.getIsDeviceAllowedToSendTraces()).isFalse();
PerfMetric trace = PerfMetric.newBuilder().setTraceMetric(TraceMetric.newBuilder().addAllPerfSessions(Arrays.asList(createVerbosePerfSessions()))).build();
assertThat(limiter.isEventSampled(trace)).isTrue();
}
use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class RateLimiterTest method isEventSampled_fragmentWithVerboseSessionEnabled_returnsTrue.
@Test
public void isEventSampled_fragmentWithVerboseSessionEnabled_returnsTrue() {
makeConfigResolverReturnDefaultValues();
when(mockConfigResolver.getTraceSamplingRate()).thenReturn(1.0f);
when(mockConfigResolver.getFragmentSamplingRate()).thenReturn(0.70f);
// Passing a value for samplingBucketId which is greater than the sampling rate means that
// the sampling dice roll failed causing all the metrics to be dropped
RateLimiter limiter = new RateLimiter(/* rate= */
TWO_TOKENS_PER_SECOND, /* capacity= */
2, mClock, /* samplingBucketId= */
0, /* fragmentBucketId= */
0.71f, mockConfigResolver);
assertThat(limiter.getIsDeviceAllowedToSendTraces()).isTrue();
assertThat(limiter.getIsDeviceAllowedToSendFragmentScreenTraces()).isFalse();
PerfMetric trace = PerfMetric.newBuilder().setTraceMetric(TraceMetric.newBuilder().setName("_st_TestFragment").putCustomAttributes(Constants.ACTIVITY_ATTRIBUTE_KEY, "TestActivity").addAllPerfSessions(Arrays.asList(createVerbosePerfSessions()))).build();
assertThat(limiter.isFragmentScreenTrace(trace)).isTrue();
assertThat(limiter.isEventSampled(trace)).isTrue();
}
use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class RateLimiterTest method testNetworkRequestsAreSampledWhenSessionIsNonVerboseAndSamplingEnabled.
@Test
public void testNetworkRequestsAreSampledWhenSessionIsNonVerboseAndSamplingEnabled() {
makeConfigResolverReturnDefaultValues();
when(mockConfigResolver.getNetworkRequestSamplingRate()).thenReturn(0.70f);
// Passing a value for samplingBucketId which is greater than the sampling rate ensures that
// the sampling will be enabled causing all the metrics to be dropped
RateLimiter limiter = new RateLimiter(/* rate= */
TWO_TOKENS_PER_SECOND, /* capacity= */
2, mClock, /* samplingBucketId= */
0.71f, /* fragmentBucketId= */
0, mockConfigResolver);
assertThat(limiter.getIsDeviceAllowedToSendNetworkEvents()).isFalse();
PerfMetric network = PerfMetric.newBuilder().setNetworkRequestMetric(NetworkRequestMetric.newBuilder().addAllPerfSessions(Arrays.asList(createNonVerbosePerfSessions()))).build();
assertThat(limiter.isEventSampled(network)).isFalse();
}
use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class RateLimiterTest method testForegroundTraceWithCountersIsNotRateLimitApplicable.
@Test
public void testForegroundTraceWithCountersIsNotRateLimitApplicable() {
makeConfigResolverReturnDefaultValues();
RateLimiter limiter = new RateLimiter(TWO_TOKENS_PER_MINUTE, 2, mClock, 0.99f, 0.99f, mockConfigResolver);
PerfMetric metric = PerfMetric.newBuilder().setTraceMetric(TraceMetric.newBuilder().putCounters("counter1", 10).setName(TraceNames.FOREGROUND_TRACE_NAME.toString())).build();
assertThat(limiter.isRateLimitApplicable(metric)).isFalse();
}
use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class RateLimiterTest method testForegroundTraceWithoutCountersIsRateLimitApplicable.
@Test
public void testForegroundTraceWithoutCountersIsRateLimitApplicable() {
makeConfigResolverReturnDefaultValues();
RateLimiter limiter = new RateLimiter(TWO_TOKENS_PER_MINUTE, 2, mClock, 0.99f, 0.99f, mockConfigResolver);
PerfMetric metric = PerfMetric.newBuilder().setTraceMetric(TraceMetric.newBuilder().setName(TraceNames.FOREGROUND_TRACE_NAME.toString())).build();
assertThat(limiter.isRateLimitApplicable(metric)).isTrue();
}
Aggregations