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

Enhance and refactor the Brave Ads component updater #8502

Merged
merged 2 commits into from
Apr 22, 2021
Merged

Conversation

moritzhaller
Copy link
Contributor

@moritzhaller moritzhaller commented Apr 12, 2021

Resolves brave/brave-browser#12856

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
  • 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:

Run with staging endpoint for component updater --use-dev-goupdater-url and confirm all resources load for Beta and Nightly, e.g. for locale en-GB the following output is expected

Beta for en-GB:

[user_model_file_service.cc(103)] Registering Brave User Model Installer (GB) with id cdjnpippjnphaeahihhpafnneefcnnfh
[user_model_file_service.cc(122)] Registering Brave User Model Installer (en) with id emgmepnebbddgnkhfmhdhmjifkglkamo

[ads_service_impl.cc(1894)] Loading user model from ...1.0.4/mfkqmxibrlzgfrjwkqmdhghtaxjwnqgr
[purchase_intent_resource.cc(54)] Successfully loaded cdjnpippjnphaeahihhpafnneefcnnfh purchase intent resource
[purchase_intent_resource.cc(64)] Successfully initialized cdjnpippjnphaeahihhpafnneefcnnfh purchase intent resource

[ads_service_impl.cc(1894)] Loading user model from ...1.0.4/uhejtseyzmttezfpldlmvlxqfmsuaevc
[anti_targeting_resource.cc(42)] Successfully loaded resource mkdhnfmjhklfnamlheoliekgeohamoig
[anti_targeting_resource.cc(52)] Successfully initialized resource mkdhnfmjhklfnamlheoliekgeohamoig

[ads_service_impl.cc(1894)] Loading user model from .../1.0.4/yvcznhuwztjxmsrnuluqobxvstpzayhd
[text_classification_resource.cc(55)] Successfully loaded emgmepnebbddgnkhfmhdhmjifkglkamo text classification resource
[text_classification_resource.cc(63)] Successfully initialized emgmepnebbddgnkhfmhdhmjifkglkamo text classification resource

Nightly for en-GB:

[resource_component.cc(103)] Registering Brave Ads Resources (GB) with id cmdlemldhabgmejfognbhdejendfeikd
[resource_component.cc(122)] Registering Brave Ads Resources (en) with id ocilmpijebaopmdifcomolmpigakocmo

[ads_service_impl.cc(1910)] Loading ads resource from .../1.0.4/mfkqmxibrlzgfrjwkqmdhghtaxjwnqgr
[purchase_intent_resource.cc(44)] Successfully loaded bejenkminijgplakmkmcgkhjjnkelbld purchase intent resource
[purchase_intent_resource.cc(56)] Successfully initialized bejenkminijgplakmkmcgkhjjnkelbld purchase intent resource

[ads_service_impl.cc(1910)] Loading ads resource from .../1.0.4/uhejtseyzmttezfpldlmvlxqfmsuaevc
[anti_targeting_resource.cc(43)] Successfully loaded resource mkdhnfmjhklfnamlheoliekgeohamoig
[anti_targeting_resource.cc(53)] Successfully initialized resource mkdhnfmjhklfnamlheoliekgeohamoig

[ads_service_impl.cc(1910)] Loading ads resource from .../1.0.4/yvcznhuwztjxmsrnuluqobxvstpzayhd
[text_classification_resource.cc(48)] Successfully loaded feibnmjhecfbjpeciancnchbmlobenjn text classification resource
[text_classification_resource.cc(57)] Successfully initialized feibnmjhecfbjpeciancnchbmlobenjn text classification resource

Then verify that the models work by spot-checking one purchase intent site/keyword and one text classification on each Beta and Nightly, e.g.:

  • visit brave.com and verify output [text_classification_processor.cc(62)] Classified text with the top segment as technology & computing-software
  • visit ebay.co.uk and verify output [purchase_intent_processor.cc(99)] Extracted purchase intent signal from visited URL

Analogous for iOS, verify that resources load for old and new versions:

[text_classification_resource.cc:57] > Successfully initialized feibnmjhecfbjpeciancnchbmlobenjn text classification resource
[purchase_intent_resource.cc:56] > Successfully initialized bejenkminijgplakmkmcgkhjjnkelbld purchase intent resource
[anti_targeting_resource.cc:53] > Successfully initialized resource mkdhnfmjhklfnamlheoliekgeohamoig

@moritzhaller moritzhaller force-pushed the issues/12856 branch 2 times, most recently from 3051742 to 770d45d Compare April 12, 2021 20:52
@moritzhaller moritzhaller changed the title [WIP] Ads Resource Component Enhance and refactor the Brave Ads component updater Apr 13, 2021
@moritzhaller moritzhaller added this to the 1.25.x - Nightly milestone Apr 13, 2021
@moritzhaller moritzhaller self-assigned this Apr 13, 2021
@moritzhaller moritzhaller marked this pull request as ready for review April 13, 2021 14:53
@@ -1903,17 +1903,19 @@ void AdsServiceImpl::Save(const std::string& name,
std::move(callback)));
}

void AdsServiceImpl::LoadUserModelForId(const std::string& id,
ads::LoadCallback callback) {
// TODO(Moritz Haller): Naming clash with |LoadResource|
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO... :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

const base::Optional<ComponentInfo> component =
GetComponentInfo(country_code);
if (!component) {
VLOG(1) << "no ads resources support for " << country_code;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Ads resource not supported for ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

const base::Optional<ComponentInfo> component =
GetComponentInfo(language_code);
if (!component) {
VLOG(1) << "no ads resources support for " << language_code;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Ads resource not supported for ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


const base::Optional<int> version = manifest->FindIntPath(kSchemaVersionPath);
if (!version) {
VLOG(1) << "resource schema version is missing";
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Capitalize R in resource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

if (*version != kCurrentSchemaVersion) {
VLOG(1) << "resource schema version mismatch";
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Capitalize R in resource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


const std::string* id = resource_value.FindStringPath(kResourceIdPath);
if (!id) {
VLOG(1) << *id << " resource id is missing";
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: instead of *id you id.value()

@@ -0,0 +1,57 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copyright for new files should be 2021

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

virtual void OnUserModelUpdated(const std::string& id) = 0;
// Should be called when a resource component has been updated by
// |brave_ads::ResourceComponent|
virtual void OnResourceComponentUpdate(const std::string& id) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

OnResourceComponentUpdated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

anti_targeting_resource_->Load();
} else {
BLOG(0, "Unknown " << id << " user model");
BLOG(0, "Unknown resource " << id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Unknown resource for ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -33,7 +33,9 @@ class NativeAdsClient : public ads::AdsClient {
void UrlRequest(ads::UrlRequestPtr url_request, ads::UrlRequestCallback callback) override;
void Save(const std::string & name, const std::string & value, ads::ResultCallback callback) override;
void Load(const std::string & name, ads::LoadCallback callback) override;
void LoadUserModelForId(const std::string & id, ads::LoadCallback callback) override;
// TODO(Moritz Haller): Add version
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed :)

Comment on lines 22 to 23
const int kCurrentVersion = 1;
const int kVersion = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the difference between kCurrentVersion and kVersion please. If we could rename kVersion to be more verbose that would be great

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as discussed yesterday - removed redundant version and added as feature parameter

Copy link
Collaborator

@tmancey tmancey left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@fmarier fmarier left a comment

Choose a reason for hiding this comment

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

License script change looks good.

@moritzhaller moritzhaller force-pushed the issues/12856 branch 5 times, most recently from bed7aa3 to 996fa2f Compare April 15, 2021 14:46
@moritzhaller moritzhaller force-pushed the issues/12856 branch 6 times, most recently from 3f38111 to a93442a Compare April 22, 2021 07:17
Moritz Haller and others added 2 commits April 22, 2021 08:40
Enable a/b testing for different versions of a resource, e.g. text classification. Change name from UserModel to AdsResource and move code into the brave ads component. Finally removing the bat-native-usermodel dependency from ads.
@moritzhaller
Copy link
Contributor Author

CI fails with unrelated issues on macos and linux

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.

Enhance and refactor the Brave Ads component updater
4 participants