Bug 1623439 - Add the whole active experiments to PingCentre metadata r=andreio

Differential Revision: https://phabricator.services.mozilla.com/D68203

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nan Jiang 2020-03-25 20:05:43 +00:00
parent e4b22f47c2
commit a4f8001e97
7 changed files with 332 additions and 194 deletions

View File

@ -31,10 +31,7 @@ XPCOMUtils.defineLazyGetter(
"browserSessionId",
() => TelemetrySession.getMetadata("").sessionId
);
// This is for PingCentre client to capture "activity-stream" experiment strings.
// Although we could change it to anything else, such as "messaging-system", that would
// require us to have the same value contained in the Normandy slugs.
const ACTIVITY_STREAM_ID = "activity-stream";
const TELEMETRY_TOPIC = "about:welcome";
const PING_TYPE = "onboarding";
const PING_VERSION = "1";
const STRUCTURED_INGESTION_NAMESPACE_MS = "messaging-system";
@ -54,7 +51,7 @@ class AboutWelcomeTelemetry {
*/
get pingCentre() {
Object.defineProperty(this, "pingCentre", {
value: new PingCentre({ topic: ACTIVITY_STREAM_ID }),
value: new PingCentre({ topic: TELEMETRY_TOPIC }),
});
return this.pingCentre;
}
@ -91,8 +88,7 @@ class AboutWelcomeTelemetry {
const ping = await this._createPing(event);
this.pingCentre.sendStructuredIngestionPing(
ping,
this._generateStructuredIngestionEndpoint(),
{ filter: ACTIVITY_STREAM_ID }
this._generateStructuredIngestionEndpoint()
);
}
}

View File

@ -211,7 +211,7 @@ Schema definitions/validations that can be used for tests can be found in `syste
| `card_type` | [Optional] ("bookmark", "pocket", "trending", "pinned", "search", "spoc", "organic") | :one:
| `search_vendor` | [Optional] the vendor of the search shortcut, one of ("google", "amazon", "wikipedia", "duckduckgo", "bing", etc.). This field only exists when `card_type = "search"` | :one:
| `date` | [Auto populated by Onyx] The date in YYYY-MM-DD format. | :three:
| `experiment_id` | [Optional] The unique identifier for a specific experiment. | :one:
| `shield_id` | [Optional] DEPRECATED: use `experiments` instead. The unique identifier for a specific experiment. | :one:
| `event_id` | [Required] An identifier shared by multiple performance pings that describe an entire request flow. | :one:
| `event` | [Required] The type of event. Any user defined string ("click", "share", "delete", "more_items") | :one:
| `event_context` | [Optional] A string to record the context of an AS Router event ping. Compound context values will be stringified by JSON.stringify| :one:
@ -265,6 +265,7 @@ and losing focus. | :one:
| `reason` | [required] The reason if a SPOC is not displayed, "n/a" for the displayed, one of ("frequency_cap", "blocked_by_user", "flight_duplicate", "probability_selection", "below_min_score", "out_of_position", "n/a") | :one:
| `full_recalc` | [required] Is it a full SPOCS recalculation: 0: false; 1: true. Recalculation case: 1). fetch SPOCS from Pocket endpoint. Non-recalculation cases: 1). An impression updates the SPOCS; 2). Any action that triggers the `selectLayoutRender ` | :one:
| `browser_session_id` | [Optional] The unique identifier for a browser session, retrieved from TelemetrySession | :one:
| `experiments` | [Optional] An object to record all active experiments (an empty object will be sent if there is no active experiment). The experiments IDs are stored as keys, and the value object stores the branch information. `Example: {"experiment_1": {"branch": "control"}, "experiment_2": {"branch": "treatment"}}`. This deprecates the `shield_id` used in Activity Stream and Messaging System. | :one:
**Where:**

View File

@ -52,6 +52,10 @@ This ping is submitted once upon Activity Stream initialization if either about:
"browser_session_id": "e7e52665-7db3-f348-9918-e93160eb2ef3",
  "addon_version": "20180710100040",
  "locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7
}
```
@ -85,6 +89,10 @@ A user event ping includes some basic metadata (tab id, addon version, etc.) as
  "addon_version": "20180710100040",
  "locale": "en-US",
"action": "activity_stream_event",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7
}
```
@ -503,6 +511,10 @@ A user event ping includes some basic metadata (tab id, addon version, etc.) as
"browser_session_id": "e7e52665-7db3-f348-9918-e93160eb2ef3",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7
}
```
@ -522,6 +534,10 @@ A user event ping includes some basic metadata (tab id, addon version, etc.) as
"browser_session_id": "e7e52665-7db3-f348-9918-e93160eb2ef3",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7
}
```
@ -545,6 +561,10 @@ All `"activity_stream_session"` pings have the following basic shape. Some field
"page": ["about:newtab" | "about:home" | "about:welcome" | "unknown"],
"session_duration": 4199,
"profile_creation_date": 14786,
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7
}
```
@ -643,6 +663,10 @@ This reports all the Pocket recommended articles (a list of `id`s) when the user
"source": "pocket",
"page": ["about:newtab" | "about:home" | "about:welcome" | "unknown"],
"user_prefs": 7,
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"tiles": [{"id": 10000}, {"id": 10001}, {"id": 10002}]
}
```
@ -663,6 +687,10 @@ This reports the user's interaction with those Pocket tiles.
"locale": "en-US",
"source": "pocket",
"page": ["about:newtab" | "about:home" | "about:welcome" | "unknown"],
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
// "pos" is the 0-based index to record the tile's position in the Pocket section.
@ -688,6 +716,10 @@ This reports the duration of the domain affinity calculation in milliseconds.
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "topstories.domain.affinity.calculation.ms",
"value": 43
@ -706,6 +738,10 @@ These report the duration of the domain affinity v2 calculations in milliseconds
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_TOTAL_DURATION",
"value": 43
@ -720,6 +756,10 @@ These report the duration of the domain affinity v2 calculations in milliseconds
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_GET_RECIPE_DURATION",
"value": 43
@ -734,6 +774,10 @@ These report the duration of the domain affinity v2 calculations in milliseconds
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_RECIPE_EXECUTOR_DURATION",
"value": 43
@ -748,6 +792,10 @@ These report the duration of the domain affinity v2 calculations in milliseconds
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_TAGGERS_DURATION",
"value": 43
@ -762,6 +810,10 @@ These report the duration of the domain affinity v2 calculations in milliseconds
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_CREATE_INTEREST_VECTOR_DURATION",
"value": 43
@ -776,6 +828,10 @@ These report the duration of the domain affinity v2 calculations in milliseconds
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_ITEM_RELEVANCE_SCORE_DURATION",
"value": 43
@ -790,6 +846,10 @@ These report the duration of the domain affinity v2 calculations in milliseconds
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_HISTORY_SIZE",
"value": 43
@ -808,6 +868,10 @@ These report any failures during domain affinity v2 calculations, and where it f
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_GET_RECIPE_ERROR"
}
@ -821,6 +885,10 @@ These report any failures during domain affinity v2 calculations, and where it f
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_GENERATE_RECIPE_EXECUTOR_ERROR"
}
@ -834,6 +902,10 @@ These report any failures during domain affinity v2 calculations, and where it f
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "PERSONALIZATION_V2_CREATE_INTEREST_VECTOR_ERROR"
}
@ -855,6 +927,10 @@ This reports all the loaded content (a list of `id`s and positions) when the use
"locale": "en-US",
"source": ["HERO" | "CARDGRID" | "LIST"],
"page": ["about:newtab" | "about:home" | "about:welcome" | "unknown"],
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
// Indicating this is a `loaded content` ping (as opposed to impression) as well as the size of `tiles`
@ -873,6 +949,10 @@ This reports all the loaded content (a list of `id`s and positions) when the use
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "LAYOUT_REQUEST_TIME",
"value": 42
@ -887,6 +967,10 @@ This reports all the loaded content (a list of `id`s and positions) when the use
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "SPOCS_REQUEST_TIME",
"value": 42
@ -901,6 +985,10 @@ This reports all the loaded content (a list of `id`s and positions) when the use
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "COMPONENT_FEED_REQUEST_TIME",
"value": 42
@ -915,6 +1003,10 @@ This reports all the loaded content (a list of `id`s and positions) when the use
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "DS_FEED_TOTAL_REQUEST_TIME",
"value": 136
@ -929,6 +1021,10 @@ This reports all the loaded content (a list of `id`s and positions) when the use
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "DS_CACHE_AGE_IN_SEC",
"value": 1800 // 30 minutes
@ -949,6 +1045,10 @@ This reports the internal status of Pocket SPOCS (Sponsored Contents).
"locale": "en-US",
"version": "68",
"release_channel": "release",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"spoc_fills": [
{"id": 10000, displayed: 0, reason: "frequency_cap", full_recalc: 1},
{"id": 10001, displayed: 0, reason: "blocked_by_user", full_recalc: 1},
@ -975,6 +1075,10 @@ This reports when the addon fails to initialize
"client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": "ADDON_INIT_FAILED",
"value": -1
@ -998,6 +1102,10 @@ This reports the impression of Activity Stream Router.
"source": "SNIPPETS",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"source": "NEWTAB_FOOTER_BAR",
"message_id": "some_snippet_id",
"event": "IMPRESSION"
@ -1014,6 +1122,10 @@ CFR impression ping has two forms, in which the message_id could be of different
"impression_id": "n/a",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"source": "CFR",
// message_id could be the ID of the recommendation, such as "wikipedia_addon"
"message_id": "wikipedia_addon",
@ -1029,6 +1141,10 @@ CFR impression ping has two forms, in which the message_id could be of different
"impression_id": "{005deed0-e3e4-4c02-a041-17405fd703f6}",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"source": "CFR",
// message_id should be a bucket ID in the release channel, we may not use the
// individual ID, such as addon ID, per legal's request
@ -1046,6 +1162,10 @@ CFR impression ping has two forms, in which the message_id could be of different
"source": "FIRST_RUN",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"message_id": "EXTENDED_TRIPLETS_1",
"event": "IMPRESSION",
"browser_session_id": "e7e52665-7db3-f348-9918-e93160eb2ef3",
@ -1065,6 +1185,10 @@ This reports the user's interaction with Activity Stream Router.
"addon_version": "20180710100040",
"impression_id": "n/a",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"source": "NEWTAB_FOOTER_BAR",
"message_id": "some_snippet_id",
"event": ["CLICK_BUTTION" | "BLOCK"]
@ -1079,6 +1203,10 @@ This reports the user's interaction with Activity Stream Router.
"addon_version": "20180710100040",
"impression_id": "n/a",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"source": "ONBOARDING",
"message_id": "onboarding_message_1",
"event": ["IMPRESSION" | "CLICK_BUTTION" | "INSTALL" | "BLOCK"],
@ -1095,6 +1223,10 @@ This reports the user's interaction with Activity Stream Router.
"addon_version": "20180710100040",
"impression_id": "n/a",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"source": "CFR",
// message_id could be the ID of the recommendation, such as "wikipedia_addon"
"message_id": "wikipedia_addon",
@ -1113,6 +1245,10 @@ This reports the user's interaction with Activity Stream Router.
"addon_version": "20180710100040",
"impression_id": "{005deed0-e3e4-4c02-a041-17405fd703f6}",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"source": "CFR",
// message_id should be a bucket ID in the release channel, we may not use the
// individual ID, such as addon ID, per legal's request
@ -1132,6 +1268,10 @@ This reports when an error has occurred when parsing/evaluating a JEXL targeting
"addon_version": "20180710100040",
"impression_id": "{005deed0-e3e4-4c02-a041-17405fd703f6}",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"message_id": "some_message_id",
"event": "TARGETING_EXPRESSION_ERROR",
"event_context": ["MALFORMED_EXPRESSION" | "OTHER_ERROR"]
@ -1148,6 +1288,10 @@ This reports a failure in the Remote Settings loader to load messages for Activi
"client_id": "n/a",
"addon_version": "20180710100040",
"locale": "en-US",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"user_prefs": 7,
"event": ["ASR_RS_NO_MESSAGES" | "ASR_RS_ERROR"],
// The value is set to the ID of the message provider. For example: remote-cfr, remote-onboarding, etc.
@ -1184,6 +1328,10 @@ This reports when a user has seen or clicked a badge/notification in the browser
"release_channel": "default",
"addon_version": "20190712095934",
"action": "cfr_user_event",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"source": "CFR",
"message_id": "FXA_ACCOUNTS_BADGE",
"event": ["CLICK" | "IMPRESSION"],
@ -1203,6 +1351,10 @@ For message impressions we concatenate the ids of all messages in the panel.
"release_channel": "default",
"addon_version": "20190712095934",
"action": "cfr_user_event",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"source": "CFR",
"message_id": "WHATS_NEW_70",
"event": ["CLICK" | "IMPRESSION"],
@ -1224,6 +1376,10 @@ as other CFR messages.
"bucket_id": "WNP_THANK_YOU"
"event": "MOMENTS_PAGE_SET"
"impression_id": "{d85d2268-b751-9543-b6d7-aad523bf2b26}"
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"locale": "en-US"
"message_id": "n/a"
"source": "CFR"
@ -1236,6 +1392,10 @@ as other CFR messages.
"bucket_id": "WNP_THANK_YOU",
"event": "MOMENTS_PAGE_SET",
"addon_version": "20200225022813",
"experiments": {
"experiment_1": {"branch": "control"},
"experiment_2": {"branch": "treatment"}
},
"locale": "en-US",
"client_id": "21dc1375-b24e-984b-83e9-c8a9660ae4ff"
}

View File

@ -766,8 +766,7 @@ this.TelemetryFeed = class TelemetryFeed {
if (this.telemetryEnabled && this.structuredIngestionTelemetryEnabled) {
this.pingCentre.sendStructuredIngestionPing(
eventObject,
this._generateStructuredIngestionEndpoint(namespace, pingType, version),
{ filter: ACTIVITY_STREAM_ID }
this._generateStructuredIngestionEndpoint(namespace, pingType, version)
);
}
}

View File

@ -32,147 +32,6 @@ const LOGGING_PREF = `${PREF_BRANCH}log`;
const STRUCTURED_INGESTION_SEND_TIMEOUT = 30 * 1000; // 30 seconds
const FHR_UPLOAD_ENABLED_PREF = "datareporting.healthreport.uploadEnabled";
const BROWSER_SEARCH_REGION_PREF = "browser.search.region";
// Only report region for following regions, to ensure that users in countries
// with small user population (less than 10000) cannot be uniquely identified.
// See bug 1421422 for more details.
const REGION_WHITELIST = new Set([
"AE",
"AF",
"AL",
"AM",
"AR",
"AT",
"AU",
"AZ",
"BA",
"BD",
"BE",
"BF",
"BG",
"BJ",
"BO",
"BR",
"BY",
"CA",
"CH",
"CI",
"CL",
"CM",
"CN",
"CO",
"CR",
"CU",
"CY",
"CZ",
"DE",
"DK",
"DO",
"DZ",
"EC",
"EE",
"EG",
"ES",
"ET",
"FI",
"FR",
"GB",
"GE",
"GH",
"GP",
"GR",
"GT",
"HK",
"HN",
"HR",
"HU",
"ID",
"IE",
"IL",
"IN",
"IQ",
"IR",
"IS",
"IT",
"JM",
"JO",
"JP",
"KE",
"KH",
"KR",
"KW",
"KZ",
"LB",
"LK",
"LT",
"LU",
"LV",
"LY",
"MA",
"MD",
"ME",
"MG",
"MK",
"ML",
"MM",
"MN",
"MQ",
"MT",
"MU",
"MX",
"MY",
"MZ",
"NC",
"NG",
"NI",
"NL",
"NO",
"NP",
"NZ",
"OM",
"PA",
"PE",
"PH",
"PK",
"PL",
"PR",
"PS",
"PT",
"PY",
"QA",
"RE",
"RO",
"RS",
"RU",
"RW",
"SA",
"SD",
"SE",
"SG",
"SI",
"SK",
"SN",
"SV",
"SY",
"TG",
"TH",
"TN",
"TR",
"TT",
"TW",
"TZ",
"UA",
"UG",
"US",
"UY",
"UZ",
"VE",
"VN",
"ZA",
"ZM",
"ZW",
]);
/**
* Observe various notifications and send them to a telemetry endpoint.
@ -219,53 +78,32 @@ class PingCentre {
this._fhrEnabled = this._prefs.getBoolPref(prefKey);
}
_createExperimentsString(activeExperiments, filter) {
let experimentsString = "";
_createExperimentsPayload() {
let activeExperiments = TelemetryEnvironment.getActiveExperiments();
let experiments = {};
for (let experimentID in activeExperiments) {
if (
!activeExperiments[experimentID] ||
!activeExperiments[experimentID].branch ||
(filter && !experimentID.includes(filter))
activeExperiments[experimentID] &&
activeExperiments[experimentID].branch
) {
continue;
}
let expString = `${experimentID}:${activeExperiments[experimentID].branch}`;
experimentsString = experimentsString.concat(`${expString};`);
}
return experimentsString;
}
_getRegion() {
let region = "UNSET";
if (Services.prefs.prefHasUserValue(BROWSER_SEARCH_REGION_PREF)) {
region = Services.prefs.getStringPref(BROWSER_SEARCH_REGION_PREF);
if (region === "") {
region = "EMPTY";
} else if (!REGION_WHITELIST.has(region)) {
region = "OTHER";
experiments[experimentID] = {
branch: activeExperiments[experimentID].branch,
};
}
}
return region;
return experiments;
}
_createStructuredIngestionPing(data, options = {}) {
let { filter } = options;
let experiments = TelemetryEnvironment.getActiveExperiments();
let experimentsString = this._createExperimentsString(experiments, filter);
_createStructuredIngestionPing(data) {
let experiments = this._createExperimentsPayload();
let locale = data.locale || Services.locale.appLocaleAsBCP47;
const payload = Object.assign(
{
locale,
version: AppConstants.MOZ_APP_VERSION,
release_channel: UpdateUtils.getUpdateChannel(false),
},
data
);
if (experimentsString) {
payload.shield_id = experimentsString;
}
const payload = {
experiments,
locale,
version: AppConstants.MOZ_APP_VERSION,
release_channel: UpdateUtils.getUpdateChannel(false),
...data,
};
return payload;
}
@ -345,19 +183,18 @@ class PingCentre {
* requires a different endpoint for each ping. It's up to the
* caller to provide that. See more details at
* https://github.com/mozilla/gcp-ingestion/blob/master/docs/edge.md#postput-request
* @param {Object} options Other options for this ping.
*/
sendStructuredIngestionPing(data, endpoint, options) {
sendStructuredIngestionPing(data, endpoint) {
if (!this.enabled) {
return Promise.resolve();
}
const ping = this._createStructuredIngestionPing(data, options);
const ping = this._createStructuredIngestionPing(data);
const payload = JSON.stringify(ping);
if (this.logging) {
Services.console.logStringMessage(
`TELEMETRY PING (STRUCTURED INGESTION): ${payload}\n`
`TELEMETRY PING (${this._topic}): ${payload}\n`
);
}

View File

@ -0,0 +1,144 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { PingCentre, PingCentreConstants } = ChromeUtils.import(
"resource:///modules/PingCentre.jsm"
);
const { TelemetryEnvironment } = ChromeUtils.import(
"resource://gre/modules/TelemetryEnvironment.jsm"
);
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
const { UpdateUtils } = ChromeUtils.import(
"resource://gre/modules/UpdateUtils.jsm"
);
const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
const FAKE_PING = { event: "fake_event", value: "fake_value", locale: "en-US" };
const FAKE_ENDPOINT = "https://www.test.com";
let pingCentre;
let sandbox;
function _setUp() {
Services.prefs.setBoolPref(PingCentreConstants.TELEMETRY_PREF, true);
Services.prefs.setBoolPref(PingCentreConstants.FHR_UPLOAD_ENABLED_PREF, true);
Services.prefs.setBoolPref(PingCentreConstants.LOGGING_PREF, true);
sandbox.restore();
}
add_task(function setup() {
sandbox = sinon.createSandbox();
_setUp();
pingCentre = new PingCentre({ topic: "test_topic" });
registerCleanupFunction(() => {
sandbox.restore();
Services.prefs.clearUserPref(PingCentreConstants.TELEMETRY_PREF);
Services.prefs.clearUserPref(PingCentreConstants.FHR_UPLOAD_ENABLED_PREF);
Services.prefs.clearUserPref(PingCentreConstants.LOGGING_PREF);
});
});
add_task(function test_enabled() {
_setUp();
Assert.ok(pingCentre.enabled, "Telemetry should be on");
});
add_task(function test_disabled_by_pingCentre() {
_setUp();
Services.prefs.setBoolPref(PingCentreConstants.TELEMETRY_PREF, false);
Assert.ok(!pingCentre.enabled, "Telemetry should be off");
});
add_task(function test_disabled_by_FirefoxHealthReport() {
_setUp();
Services.prefs.setBoolPref(
PingCentreConstants.FHR_UPLOAD_ENABLED_PREF,
false
);
Assert.ok(!pingCentre.enabled, "Telemetry should be off");
});
add_task(function test_logging() {
_setUp();
Assert.ok(pingCentre.logging, "Logging should be on");
Services.prefs.setBoolPref(PingCentreConstants.LOGGING_PREF, false);
Assert.ok(!pingCentre.logging, "Logging should be off");
});
add_task(function test_createExperimentsPayload() {
_setUp();
const activeExperiments = {
exp1: { branch: "foo", enrollmentID: "SOME_RANDON_ID" },
exp2: { branch: "bar", type: "PrefStudy" },
exp3: {},
};
sandbox
.stub(TelemetryEnvironment, "getActiveExperiments")
.returns(activeExperiments);
const expected = {
exp1: { branch: "foo" },
exp2: { branch: "bar" },
};
const experiments = pingCentre._createExperimentsPayload();
Assert.deepEqual(
experiments,
expected,
"Should create experiments with all the required context"
);
});
add_task(function test_createExperimentsPayload_without_active_experiments() {
_setUp();
sandbox.stub(TelemetryEnvironment, "getActiveExperiments").returns({});
const experiments = pingCentre._createExperimentsPayload({});
Assert.deepEqual(experiments, {}, "Should send an empty object");
});
add_task(function test_createStructuredIngestionPing() {
_setUp();
sandbox
.stub(TelemetryEnvironment, "getActiveExperiments")
.returns({ exp1: { branch: "foo" } });
const ping = pingCentre._createStructuredIngestionPing(FAKE_PING);
const expected = {
experiments: { exp1: { branch: "foo" } },
locale: "en-US",
version: AppConstants.MOZ_APP_VERSION,
release_channel: UpdateUtils.getUpdateChannel(false),
...FAKE_PING,
};
Assert.deepEqual(ping, expected, "Should create a valid ping");
});
add_task(function test_sendStructuredIngestionPing_disabled() {
_setUp();
sandbox.stub(PingCentre, "_sendInGzip").resolves();
Services.prefs.setBoolPref(PingCentreConstants.TELEMETRY_PREF, false);
pingCentre.sendStructuredIngestionPing(FAKE_PING, FAKE_ENDPOINT);
Assert.ok(PingCentre._sendInGzip.notCalled, "Should not be sent");
});
add_task(function test_sendStructuredIngestionPing_success() {
_setUp();
sandbox.stub(PingCentre, "_sendInGzip").resolves();
pingCentre.sendStructuredIngestionPing(FAKE_PING, FAKE_ENDPOINT);
Assert.equal(PingCentre._sendInGzip.callCount, 1, "Should be sent");
});

View File

@ -12,3 +12,4 @@ skip-if = toolkit == 'android'
[test_SiteDataManager.js]
[test_LaterRun.js]
[test_discovery.js]
[test_PingCentre.js]