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

Add sampling rate to internal metrics #2108

Merged
merged 1 commit into from
Jun 26, 2024
Merged

Conversation

xgouchet
Copy link
Member

What does this PR do?

  • Add sampling rate option for internal metrics
  • Reduce the amount of "Gap between view" telemetry, and discarding gaps above 3 seconds (which most probably denote an app being sent to background instead of an actual gap while navigating inside the tracked app).

Note

This metric will be applied in addition to the telemetry sampling rate, so if a logMetric is created with a sampling rate of 10%, with the global telemetry sampling rate being sampled at 20%, it has a 2% chance of being kept.

@xgouchet xgouchet requested review from a team as code owners June 25, 2024 12:05
@xgouchet xgouchet force-pushed the xgouchet/sample_metrics branch from 72562a2 to 036db34 Compare June 25, 2024 17:03
@xgouchet xgouchet requested a review from ambushwork June 25, 2024 17:03
Copy link
Member

@ambushwork ambushwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines +16 to 17
MEDIUM(rate = 1.0f),
DEFAULT(rate = 0.1f),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think there is a bit of naming clash between MEDIUM and DEFAULT. one can think they are synonyms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'll rename DEFAULT to LOW as it doesn't feel like any sampling rate makes sense as a Default anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like it will be in another PR? this PR was merged without this update

@@ -302,5 +308,7 @@ internal class RumViewManagerScope(

internal const val MESSAGE_UNKNOWN_MISSED_TYPE = "An RUM event was detected, but no view is active, " +
"its missed type is unknown"

internal val THREE_SECONDS_GAP = TimeUnit.SECONDS.toNanos(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
internal val THREE_SECONDS_GAP = TimeUnit.SECONDS.toNanos(3)
internal val THREE_SECONDS_GAP_NS = TimeUnit.SECONDS.toNanos(3)

listOf(InternalLogger.Target.TELEMETRY, InternalLogger.Target.MAINTAINER),
{ MESSAGE_GAP_BETWEEN_VIEWS.format(Locale.US, gap) }
)
if (gap in 1 until THREE_SECONDS_GAP) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the telemetry, we can also have a negative gap by some reason. Do we want to log negative gaps as well? This is something abnormal imo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I'll add a specific metric for that case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like it will be in another PR? this PR was merged without this update

@@ -108,7 +108,8 @@ internal class BatchMetricsDispatcherTest {
argumentCaptor<Map<String, Any?>> {
verify(mockInternalLogger).logMetric(
argThat { this.invoke() == BatchMetricsDispatcher.BATCH_DELETED_MESSAGE },
capture()
capture(),
eq(0.1f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: we could compare to the enum in case this threshold changes in the future

@codecov-commenter
Copy link

codecov-commenter commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Project coverage is 69.65%. Comparing base (29692c8) to head (036db34).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2108      +/-   ##
===========================================
+ Coverage    69.63%   69.65%   +0.02%     
===========================================
  Files          715      715              
  Lines        26566    26571       +5     
  Branches      4454     4455       +1     
===========================================
+ Hits         18497    18507      +10     
+ Misses        6845     6840       -5     
  Partials      1224     1224              
Files Coverage Δ
...n/kotlin/com/datadog/android/api/InternalLogger.kt 100.00% <ø> (ø)
.../android/core/internal/logger/SdkInternalLogger.kt 88.89% <100.00%> (-0.91%) ⬇️
...id/core/internal/metrics/BatchMetricsDispatcher.kt 98.65% <100.00%> (+0.04%) ⬆️
...oid/core/internal/metrics/MethodCalledTelemetry.kt 100.00% <100.00%> (ø)
...dog/android/core/metrics/MethodCallSamplingRate.kt 100.00% <100.00%> (+100.00%) ⬆️
...um/internal/metric/SessionEndedMetricDispatcher.kt 67.74% <100.00%> (+1.08%) ⬆️
...d/rum/internal/domain/scope/RumViewManagerScope.kt 93.79% <83.33%> (-0.61%) ⬇️

... and 34 files with indirect coverage changes

@xgouchet xgouchet requested a review from 0xnm June 26, 2024 10:26
@xgouchet xgouchet merged commit d2a5741 into develop Jun 26, 2024
20 checks passed
@xgouchet xgouchet deleted the xgouchet/sample_metrics branch June 26, 2024 14:00
@xgouchet xgouchet added this to the 2.12.x milestone Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants