Search in sources :

Example 6 with PerfMetric

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();
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) Test(org.junit.Test)

Example 7 with PerfMetric

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();
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) Test(org.junit.Test)

Example 8 with PerfMetric

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();
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) Test(org.junit.Test)

Example 9 with PerfMetric

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();
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) Test(org.junit.Test)

Example 10 with PerfMetric

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();
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) Test(org.junit.Test)

Aggregations

PerfMetric (com.google.firebase.perf.v1.PerfMetric)51 Test (org.junit.Test)50 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)10 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)9 TraceMetric (com.google.firebase.perf.v1.TraceMetric)9 RateLimiterImpl (com.google.firebase.perf.transport.RateLimiter.RateLimiterImpl)6 ArrayList (java.util.ArrayList)4 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)3 Clock (com.google.firebase.perf.util.Clock)2 PerfSession (com.google.firebase.perf.v1.PerfSession)2 WorkerThread (androidx.annotation.WorkerThread)1 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)1 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)1 GaugeMetadata (com.google.firebase.perf.v1.GaugeMetadata)1