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

New histogram ID enum for differentiating use counter types #4703

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions framework/origin_trials_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

from framework import secrets
from framework import utils
from internals.core_enums import BlinkHistogramID
from internals.core_models import Stage
from internals.data_types import OriginTrialInfo
import settings


class UseCounterConfig(TypedDict):
bucket_number: int
histogram_id: str

class RequestTrial(TypedDict):
id: NotRequired[int]
Expand All @@ -46,7 +48,6 @@ class RequestTrial(TypedDict):
type: str
origin_trial_feature_name: NotRequired[str]
blink_use_counter_config: NotRequired[UseCounterConfig]
blink_webdx_use_counter_config: NotRequired[UseCounterConfig]


class InternalRegistrationConfig(TypedDict):
Expand Down Expand Up @@ -184,12 +185,14 @@ def _send_create_trial_request(
if ot_stage.ot_is_deprecation_trial:
json['registration_config']['allow_public_suffix_subdomains'] = True
if ot_stage.ot_use_counter_bucket_number:
config: UseCounterConfig = {'bucket_number': ot_stage.ot_use_counter_bucket_number}
config: UseCounterConfig = {
'bucket_number': ot_stage.ot_use_counter_bucket_number,
'histogram_id': BlinkHistogramID.web_feature.value
}
if (ot_stage.ot_chromium_trial_name
and ot_stage.ot_chromium_trial_name.startswith('WebDXFeature::')):
json['trial']['blink_webdx_use_counter_config'] = config
else:
json['trial']['blink_use_counter_config'] = config
config['histogram_id'] = BlinkHistogramID.webdx_feature.value
json['trial']['blink_use_counter_config'] = config

headers = {'Authorization': f'Bearer {access_token}'}
url = f'{settings.OT_API_URL}/v1/trials:initialize'
Expand Down
7 changes: 3 additions & 4 deletions framework/origin_trials_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def test_create_origin_trial__with_api_key(
'type': 'DEPRECATION',
'blink_use_counter_config': {
'bucket_number': 11,
'histogram_id': 'WEB_FEATURE',
}
}, create_trial_json['trial'])
self.assertEqual({
Expand Down Expand Up @@ -287,11 +288,9 @@ def test_create_origin_trial__webdx_feature(
# Two separate POST requests made.
self.assertEqual(2, mock_requests_post.call_count)
create_trial_json = mock_requests_post.call_args_list[0][1]['json']
# WebFeature config should be null.
self.assertEqual(None, create_trial_json['trial'].get('blink_use_counter_config'))
# WebDXFeature config should be populated.
self.assertEqual({'bucket_number': 11},
create_trial_json['trial']['blink_webdx_use_counter_config'])
self.assertEqual({'bucket_number': 11, 'histogram_id': 'WEBDX_FEATURE'},
create_trial_json['trial']['blink_use_counter_config'])

@mock.patch('framework.secrets.get_ot_api_key')
@mock.patch('requests.post')
Expand Down
7 changes: 7 additions & 0 deletions internals/core_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import collections
import re
from enum import Enum
from typing import Optional


Expand Down Expand Up @@ -503,6 +504,12 @@
OT_CREATED = 5
OT_ACTIVATED = 6

# Histogram IDs used for identifying origin trial use counters.
class BlinkHistogramID(str, Enum):
web_feature = 'WEB_FEATURE'
webdx_feature = 'WEBDX_FEATURE'
css_property_id = 'CSS_PROPERTY_ID'

NO_ACTIVE_DEV = 1
PROPOSED = 2
IN_DEVELOPMENT = 3
Expand Down
Loading