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 News custom RSS feed P3A questions, refactor News P3A #12518

Merged
merged 2 commits into from
Mar 29, 2022
Merged

Conversation

DJAndries
Copy link
Collaborator

@DJAndries DJAndries commented Mar 8, 2022

Resolves brave/brave-browser#21519

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  1. Add two custom RSS feeds.
  2. On the brave://local-state page, verify that the Brave.Today.DirectFeedsTotal metric has a value of 2.
  3. Advance system time by two days.
  4. Add five custom RSS feeds.
  5. Verify that the Brave.Today.DirectFeedsTotal and Brave.Today.WeeklyAddedDirectFeedsCount metrics have a value of 6.
  6. Advance system time by five days.
  7. Verify that the Brave.Today.DirectFeedsTotal metric still has a value of 6 and Brave.Today.DirectFeedsTotal metric has a value of 5.
  8. Advance system time by three days.
  9. Verify that the Brave.Today.DirectFeedsTotal metric still has a value of 6 and Brave.Today.DirectFeedsTotal metric has a value of 0.

@DJAndries DJAndries requested a review from rillian March 8, 2022 00:44
@DJAndries DJAndries requested a review from iefremov as a code owner March 8, 2022 00:44
@rillian
Copy link
Contributor

rillian commented Mar 8, 2022

Two more questions! 🎉 Will look tomorrow.

NB it's much easier to review refactoring if you make is a separate commit with just the refactor and then commit the functional changes on top of that. One less thing to keep track up looking for regressions.

@DJAndries DJAndries force-pushed the news-p3a branch 2 times, most recently from 96557f1 to 5eddb44 Compare March 8, 2022 22:15
@DJAndries
Copy link
Collaborator Author

Two more questions! tada Will look tomorrow.

NB it's much easier to review refactoring if you make is a separate commit with just the refactor and then commit the functional changes on top of that. One less thing to keep track up looking for regressions.

convinced, and done!

Copy link
Contributor

@rillian rillian left a comment

Choose a reason for hiding this comment

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

r=me for P3A with the comment addressed. Thanks for cleaning up the code, looks nicer!

Comment on lines 52 to 53
if (delta == 0)
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Fancy out-of-order logic!

uint64_t day_delta = std::min(daily_value.value, delta);
daily_value.value -= day_delta;
delta -= day_delta;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So this distributes the subtraction across as many available daily values as possible, but it's best-effort because the weekly sum is still clamped to be non-negative? Worth documenting that in a comment I think.

Also, please add a unit test for the new WeeklyStorage method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

your interpretation is correct. good call on the test, will add

@@ -5,6 +5,7 @@

#include "brave/components/weekly_storage/weekly_storage.h"

#include <algorithm>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be in the later commit?

Comment on lines +37 to +41
template <std::size_t N>
void RecordToHistogramBucket(const char* histogram_name,
const int (&buckets)[N],
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this make std::end() faster? I've had reviewers complain about templating before, because of code bloat, although it's probably fine in file-scope as here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure if it makes it faster, the main objective is to let std::end find the end of the array via the non-type param.

@DJAndries DJAndries requested a review from rillian March 11, 2022 21:35
@DJAndries DJAndries force-pushed the news-p3a branch 2 times, most recently from 1522b2a to fc4b592 Compare March 11, 2022 21:39
state_->SubDelta(4000);
EXPECT_EQ(state_->GetWeeklySum(), 4500U);
state_->SubDelta(5000);
EXPECT_EQ(state_->GetWeeklySum(), 0U);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment here about how the overall sum can't go negative and further. Also please advance far enough for an earlier AddDelta value to expire and show that it still saturates properly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

bam. added

@@ -99,6 +99,8 @@ constexpr const char* kCollectedHistograms[] = {
"Brave.Today.WeeklyMaxCardViewsCount",
"Brave.Today.WeeklyMaxCardVisitsCount",
"Brave.Today.WeeklySessionCount",
"Brave.Today.WeeklyAddedDirectFeedsCount",
"Brave.Today.DirectFeedsTotal",
Copy link
Contributor

Choose a reason for hiding this comment

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

let's keep the list sorted

@DJAndries DJAndries added this to the 1.39.x - Nightly milestone Mar 29, 2022
@DJAndries DJAndries merged commit 20ee316 into master Mar 29, 2022
@DJAndries DJAndries deleted the news-p3a branch March 29, 2022 19:25
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.

Add News custom RSS P3A questions
3 participants