Skip to content

RUM-16394 Pt.2: Implement QuotaChecker for profiling quota HTTP check#3496

Merged
ambushwork merged 1 commit into
feature/continuous-profilingfrom
yl/profiling/add-quota-checker
Jun 12, 2026
Merged

RUM-16394 Pt.2: Implement QuotaChecker for profiling quota HTTP check#3496
ambushwork merged 1 commit into
feature/continuous-profilingfrom
yl/profiling/add-quota-checker

Conversation

@ambushwork

Copy link
Copy Markdown
Member

What does this PR do?

Implement QuotaChecker for profiling quota HTTP check

Motivation

RUM-16394

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@datadog-official

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Implements a profiling quota HTTP check component (QuotaChecker) and updates the quota result model to use a typed QuotaReason enum, with comprehensive unit tests to validate request building, response parsing, error handling, and deduplication behavior.

Changes:

  • Add QuotaChecker to perform async quota checks against the quota endpoint and emit QuotaResult.
  • Introduce QuotaReason enum and migrate QuotaResult.reason from String to QuotaReason (including a new QUOTA_EXCEEDED predefined result).
  • Add/extend unit tests covering parsing, HTTP errors, request construction, deduplication/reset, last-result behavior, and custom-endpoint bypass.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
features/dd-sdk-android-profiling/src/main/java/com/datadog/android/profiling/internal/quota/QuotaChecker.kt New async HTTP quota checker, parsing, and telemetry logging.
features/dd-sdk-android-profiling/src/main/java/com/datadog/android/profiling/internal/quota/QuotaReason.kt New enum encapsulating quota reasons and raw backend values.
features/dd-sdk-android-profiling/src/main/java/com/datadog/android/profiling/internal/quota/QuotaResult.kt Switch reason to QuotaReason and add QUOTA_EXCEEDED constant.
features/dd-sdk-android-profiling/src/test/kotlin/com/datadog/android/profiling/internal/quota/QuotaCheckerTest.kt New test suite validating QuotaChecker behavior end-to-end with mocked OkHttp.
features/dd-sdk-android-profiling/src/test/kotlin/com/datadog/android/profiling/internal/quota/QuotaResultTest.kt Update tests for QuotaReason-based QuotaResult.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ambushwork ambushwork force-pushed the yl/profiling/add-quota-checker branch 3 times, most recently from 146ea0f to 972ded7 Compare June 2, 2026 14:49
@codecov-commenter

codecov-commenter commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.35632% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.44%. Comparing base (1ebad9f) to head (51c0be4).
⚠️ Report is 31 commits behind head on feature/continuous-profiling.

Files with missing lines Patch % Lines
.../profiling/internal/quota/ProfilingQuotaChecker.kt 85.33% 6 Missing and 5 partials ⚠️
Additional details and impacted files
@@                       Coverage Diff                        @@
##           feature/continuous-profiling    #3496      +/-   ##
================================================================
+ Coverage                         72.41%   72.44%   +0.03%     
================================================================
  Files                               980      982       +2     
  Lines                             36268    36352      +84     
  Branches                           6037     6048      +11     
================================================================
+ Hits                              26261    26334      +73     
  Misses                             8361     8361              
- Partials                           1646     1657      +11     
Files with missing lines Coverage Δ
...og/android/profiling/internal/quota/QuotaReason.kt 100.00% <100.00%> (ø)
...og/android/profiling/internal/quota/QuotaResult.kt 100.00% <100.00%> (ø)
.../profiling/internal/quota/ProfilingQuotaChecker.kt 85.33% <85.33%> (ø)

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ambushwork

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 972ded7447

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ambushwork ambushwork force-pushed the yl/profiling/add-quota-checker branch from 972ded7 to e5d4bc1 Compare June 3, 2026 12:18
@ambushwork ambushwork marked this pull request as ready for review June 3, 2026 12:26
@ambushwork ambushwork requested review from a team as code owners June 3, 2026 12:26
@ambushwork ambushwork force-pushed the yl/profiling/add-quota-checker branch from e5d4bc1 to fdf7907 Compare June 4, 2026 13:31
abrooksv
abrooksv previously approved these changes Jun 4, 2026
@ambushwork ambushwork force-pushed the yl/profiling/add-quota-checker branch from fdf7907 to 4bd33a8 Compare June 5, 2026 13:33
@ambushwork ambushwork requested a review from satween June 5, 2026 13:33
satween
satween previously approved these changes Jun 5, 2026
@ambushwork ambushwork force-pushed the yl/profiling/add-quota-checker branch from 4bd33a8 to 0152785 Compare June 5, 2026 14:42
@ambushwork ambushwork requested review from abrooksv and satween June 5, 2026 15:49
internal const val LOG_UNEXPECTED_ERROR = "Quota check unexpected error: %s"
internal const val LOG_QUOTA_DENIED = "Profiling quota denied: reason=%s"

internal const val QUOTA_URL_TEMPLATE = "https://quota.%s/api/v2/profiling/quota?session_id=%s"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

to confirm that this is deployed in all DCs

var lastResult: QuotaResult? = null
private set

fun checkAsync(sessionId: String, datadogContext: DatadogContext) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what will be the logic behind calling it? for example, we made a call, but got IO exception because there is no network. Obviously, we need to repeat the call, but a) when; b) with back-off?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

With current logic, we make a call only when the session is renewed, and we don't retry if there is a network error, because the network error is a fail open according to the browser profiling logic, which can be changed later ofc.

@0xnm 0xnm Jun 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have a concern that browser logic regarding network errors can be be applied to mobile. The fair share of Browser SDK is on the desktop, there is always a connectivity there. Of course mobile browser can be used as well, but once again it should be a connectivity when page is loaded (and probably RUM session is started at this point).

Also Browser profiling requires a document policy sent by the server https://developer.mozilla.org/en-US/docs/Web/API/JS_Self-Profiling_API#security_requirements, this also implies having a connectivity.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes I agree not to blindly follow browser SDK, we need a clear definition what is fail open for mobile for sure.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you propose to handle this in another PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since there is a ongoing general discussion about Quota API, any decision we make right now on mobile side may affected by the final result of the discussion. so I purpose to merge as it and leave a TODO here.

}
val previousId = lastSessionId.getAndSet(sessionId)
if (previousId == sessionId) return // same session: in-flight check (if any) is still valid
pendingFuture.getAndSet(null)?.cancel(true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nb: if it is BackPressureExecutorService or LoggingScheduledThreadPoolExecutor, .cancel will trigger error log entry

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The plan is to use SingleThreadScheduledExecutor to avoid this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then we are losing the executor observability. Not sure if it is important or not though.

@ambushwork ambushwork force-pushed the yl/profiling/add-quota-checker branch from 0152785 to 55fd32d Compare June 5, 2026 16:53
satween
satween previously approved these changes Jun 8, 2026
@ambushwork ambushwork requested a review from 0xnm June 10, 2026 09:39
@ambushwork ambushwork force-pushed the yl/profiling/add-quota-checker branch from 55fd32d to bbe311c Compare June 10, 2026 13:48
@ambushwork ambushwork force-pushed the yl/profiling/add-quota-checker branch 2 times, most recently from 3c44c84 to 55852d3 Compare June 11, 2026 09:33

// When
testedChecker.checkAsync(fakeSessionId, fakeDatadogContext)
awaitCheck()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we need to await anything, if there are no threads in this setup? same in other similar tests with this call

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The test sets a real newSingleThreadScheduledExecutor so it needs to wait here, moving the FkaeSameThreadExecutorService in this PR so that we can use a fake executor here.

@ambushwork ambushwork force-pushed the yl/profiling/add-quota-checker branch from 55852d3 to 51c0be4 Compare June 12, 2026 08:30
@ambushwork ambushwork merged commit 85caed2 into feature/continuous-profiling Jun 12, 2026
27 checks passed
@ambushwork ambushwork deleted the yl/profiling/add-quota-checker branch June 12, 2026 09:58
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.

6 participants