Bug 1329620 - Part 1 - Add event names to Events.yaml. r=dexter

--HG--
extra : rebase_source : 484df6e0588f2ddfd876fe3272c10b680e001199
This commit is contained in:
Georg Fritzsche 2017-01-09 18:03:21 +07:00
Родитель fadcc0a39f
Коммит f6171ab27d
2 изменённых файлов: 87 добавлений и 70 удалений

Просмотреть файл

@ -1,68 +1,69 @@
navigation:
- methods: ["search"]
objects: ["about_home", "about_newtab", "contextmenu", "oneoff",
"suggestion", "alias", "enter", "searchbar", "urlbar"]
release_channel_collection: opt-in
description: >
This is recorded on each search navigation.
The value field records the action used to trigger the search:
"enter", "oneoff", "suggestion", "alias", null (for contextmenu)
bug_numbers: [1316281]
notification_emails: ["past@mozilla.com"]
expiry_version: "58.0"
extra_keys:
engine: The id of the search engine used.
search:
objects: ["about_home", "about_newtab", "contextmenu", "oneoff",
"suggestion", "alias", "enter", "searchbar", "urlbar"]
release_channel_collection: opt-in
description: >
This is recorded on each search navigation.
The value field records the action used to trigger the search:
"enter", "oneoff", "suggestion", "alias", null (for contextmenu)
bug_numbers: [1316281]
notification_emails: ["past@mozilla.com"]
expiry_version: "58.0"
extra_keys:
engine: The id of the search engine used.
# This category contains event entries used for Telemetry tests.
# They will not be sent out with any pings.
telemetry.test:
- methods: ["test1", "test2"]
objects: ["object1", "object2"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is a test entry for Telemetry.
expiry_date: never
extra_keys:
key1: This is just a test description.
key2: This is another test description.
- methods: ["optout"]
objects: ["object1", "object2"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is an opt-out test entry.
expiry_date: never
release_channel_collection: opt-out
extra_keys:
key1: This is just a test description.
- methods: ["expired_version"]
objects: ["object1", "object2"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is a test entry with an expired version.
expiry_version: "3.6"
- methods: ["expired_date"]
objects: ["object1", "object2"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is a test entry with an expired date.
expiry_date: 2014-01-28
- methods: ["not_expired_optout"]
objects: ["object1"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is an opt-out test entry with unexpired date and version.
release_channel_collection: opt-out
expiry_date: 2099-01-01
expiry_version: "999.0"
test:
methods: ["test1", "test2"]
objects: ["object1", "object2"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is a test entry for Telemetry.
expiry_date: never
extra_keys:
key1: This is just a test description.
key2: This is another test description.
optout:
objects: ["object1", "object2"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is an opt-out test entry.
expiry_date: never
release_channel_collection: opt-out
extra_keys:
key1: This is just a test description.
expired_version:
objects: ["object1", "object2"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is a test entry with an expired version.
expiry_version: "3.6"
expired_date:
objects: ["object1", "object2"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is a test entry with an expired date.
expiry_date: 2014-01-28
not_expired_optout:
objects: ["object1"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is an opt-out test entry with unexpired date and version.
release_channel_collection: opt-out
expiry_date: 2099-01-01
expiry_version: "999.0"
# This is a secondary category used for Telemetry tests.
# The events here will not be sent out with any pings.
telemetry.test.second:
- methods: ["test"]
objects: ["object1", "object2", "object3"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is a test entry for Telemetry.
expiry_date: never
extra_keys:
key1: This is just a test description.
test:
objects: ["object1", "object2", "object3"]
bug_numbers: [1286606]
notification_emails: ["telemetry-client-dev@mozilla.com"]
description: This is a test entry for Telemetry.
expiry_date: never
extra_keys:
key1: This is just a test description.

Просмотреть файл

@ -73,6 +73,7 @@ class TypeChecker:
(key,
nice_type_name(self._args[0]),
nice_type_name(type(x)))
# Check types of keys and values in dictionaries.
elif self._kind is dict:
if len(value.keys()) < 1:
@ -94,13 +95,13 @@ class TypeChecker:
def type_check_event_fields(category, definition):
"""Perform a type/schema check on the event definition."""
REQUIRED_FIELDS = {
'methods': TypeChecker(list, basestring),
'objects': TypeChecker(list, basestring),
'bug_numbers': TypeChecker(list, int),
'notification_emails': TypeChecker(list, basestring),
'description': TypeChecker(basestring),
}
OPTIONAL_FIELDS = {
'methods': TypeChecker(list, basestring),
'release_channel_collection': TypeChecker(basestring),
'expiry_date': TypeChecker(OneOf, basestring, datetime.date),
'expiry_version': TypeChecker(basestring),
@ -136,11 +137,18 @@ def string_check(category, field_name, value, min_length, max_length, regex=None
class EventData:
"""A class representing one event."""
def __init__(self, category, definition):
def __init__(self, category, name, definition):
type_check_event_fields(category, definition)
string_check(category, 'methods', definition.get('methods')[0], 1, MAX_METHOD_NAME_LENGTH, regex=IDENTIFIER_PATTERN)
string_check(category, 'objects', definition.get('objects')[0], 1, MAX_OBJECT_NAME_LENGTH, regex=IDENTIFIER_PATTERN)
self._category = category
self._name = name
self._definition = definition
# Check method & object string patterns.
for method in self.methods:
string_check(category, 'methods', method, 1, MAX_METHOD_NAME_LENGTH, regex=IDENTIFIER_PATTERN)
for obj in self.objects:
string_check(category, 'objects', obj, 1, MAX_OBJECT_NAME_LENGTH, regex=IDENTIFIER_PATTERN)
# Check release_channel_collection
rcc_key = 'release_channel_collection'
@ -171,8 +179,6 @@ class EventData:
definition['expiry_date'] = datetime.datetime.strptime(expiry_date, '%Y-%m-%d')
# Finish setup.
self._category = category
self._definition = definition
definition['expiry_version'] = add_expiration_postfix(definition.get('expiry_version', 'never'))
@property
@ -184,9 +190,13 @@ class EventData:
# Transform e.g. category.example into CategoryExample.
return convert_to_cpp_identifier(self._category, ".")
@property
def name(self):
return self._name
@property
def methods(self):
return self._definition.get('methods')
return self._definition.get('methods', [self.name])
@property
def objects(self):
@ -256,8 +266,13 @@ def load_events(filename):
event_list = []
# Events are defined in a fixed two-level hierarchy within the definition file.
# The first level contains the category (group name), while the second level contains the
# event definitions (e.g. "category.name: [<event definition>, ...], ...").
# The first level contains the category (group name), while the second level contains
# the event names and definitions, e.g.:
# category.name:
# event_name:
# <event definition>
# ...
# ...
for category_name,category in events.iteritems():
string_check('', 'category', category_name, 1, MAX_CATEGORY_NAME_LENGTH, regex=IDENTIFIER_PATTERN)
@ -265,7 +280,8 @@ def load_events(filename):
if not category or len(category) == 0:
raise ValueError(category_name + ' must contain at least one entry')
for entry in category:
event_list.append(EventData(category_name, entry))
for name,entry in category.iteritems():
string_check(category, 'name', name, 1, MAX_METHOD_NAME_LENGTH, regex=IDENTIFIER_PATTERN)
event_list.append(EventData(category_name, name, entry))
return event_list