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 metric configuration and alternative metric attributes #26762

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

DJAndries
Copy link
Collaborator

@DJAndries DJAndries commented Nov 26, 2024

Resolves brave/brave-browser#42541

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • 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 wiki
    • npm run presubmit wiki, 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:

See #20264. Ignore step 1.

@DJAndries DJAndries requested a review from a team as a code owner November 26, 2024 23:36
components/p3a/region.cc Show resolved Hide resolved
}

if (include_refcode) {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we always include the refcode now?
In what cases would we omit the refcode before this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously, we had a small allowlist of a few metrics that included the refcode. In this PR, we only include the refcode is the kRef attribute is provided in the attribute list in the metric config. By default, it's not included.

components/p3a/metric_config.h Show resolved Hide resolved
Base automatically changed from deprec-p3a-metrics to master November 27, 2024 23:57
@@ -88,6 +88,9 @@ class MessageManager : public MetricLogStore::Delegate {
std::string_view histogram_name,
std::optional<bool> only_update_for_constellation = std::nullopt);

const std::optional<MetricConfig>* GetMetricConfig(
Copy link
Contributor

Choose a reason for hiding this comment

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

why not return a reference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The std::optional<MetricConfig> may not exist i.e. in the case of dynamic metrics, which do not have metric configs in metric_names.h.

@DJAndries DJAndries force-pushed the p3a-metric-config branch 2 times, most recently from 7a3dd4b to fccf72d Compare December 14, 2024 00:12
Copy link
Contributor

[puLL-Merge] - brave/brave-core@26762

Description

This PR introduces significant changes to the P3A (Privacy-Preserving Product Analytics) system in Brave Core. It adds more granular control over metric configurations, introduces new region and subregion identifiers, and refactors the way metrics are collected and processed.

Possible Issues

  1. The changes to metric configurations might require updates to existing metrics or data processing pipelines.
  2. The new region and subregion identifiers could potentially impact data analysis if not properly accounted for in downstream processes.

Security Hotspots

  1. The addition of more detailed region information (GetRegionIdentifiers) could potentially lead to more precise user identification if not carefully managed.
Changes

Changes

  1. components/brave_stats/browser/brave_stats_updater_util.cc/h:

    • Added GetGeneralPlatformIdentifier() function to return a more general platform identifier.
  2. components/p3a/metric_config.h:

    • Introduced new MetricConfig structure with various configuration options for metrics.
    • Defined MetricAttribute enum for specifying which attributes to include with metrics.
  3. components/p3a/p3a_message.cc/h:

    • Updated GenerateP3AConstellationMessage to use the new MetricConfig.
    • Added support for new attributes like general platform, region, and subregion.
  4. components/p3a/message_manager.cc/h:

    • Refactored to use the new MetricConfig for determining metric behavior.
    • Added GetMetricConfig method to retrieve configuration for a given metric.
  5. components/p3a/metric_names.h:

    • Updated metric definitions to use the new MetricConfig structure.
    • Removed separate lists for ephemeral, constellation-only, and nebula-only metrics.
  6. components/p3a/region.cc/h:

    • Added new files to handle region and subregion identification based on country codes.
  7. Various test files:

    • Updated to accommodate the new metric configuration system and region identification.
sequenceDiagram
    participant Client
    participant MessageManager
    participant P3AService
    participant MetricConfig
    participant RegionIdentifier

    Client->>P3AService: Report metric
    P3AService->>MessageManager: Handle metric change
    MessageManager->>MetricConfig: Get metric configuration
    MessageManager->>RegionIdentifier: Get region identifiers
    MessageManager->>MessageManager: Generate constellation message
    MessageManager->>Client: Prepare metric for upload
Loading

@DJAndries DJAndries merged commit 783eaa4 into master Dec 20, 2024
18 checks passed
@DJAndries DJAndries deleted the p3a-metric-config branch December 20, 2024 23:03
@github-actions github-actions bot added this to the 1.75.x - Nightly milestone Dec 20, 2024
@brave-builds
Copy link
Collaborator

Released in v1.75.117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

P3A Utility Optimizations
4 participants