Bug 914481 - Patch 4 - Track why we fail to deliver notifications to Service Workers. r=kitcambridge

This commit is contained in:
Nikhil Marathe 2015-09-16 10:28:17 -07:00
parent 95b251e294
commit dd972da1a4
2 changed files with 52 additions and 1 deletions

View File

@ -52,6 +52,16 @@ const PUSH_SERVICE_CONNECTION_DISABLE = 3;
const PUSH_SERVICE_ACTIVE_OFFLINE = 4; const PUSH_SERVICE_ACTIVE_OFFLINE = 4;
const PUSH_SERVICE_RUNNING = 5; const PUSH_SERVICE_RUNNING = 5;
// Telemetry failure to send push notification to Service Worker reasons.
// Key not found in local database.
const kDROP_NOTIFICATION_REASON_KEY_NOT_FOUND = 0;
// User cleared history.
const kDROP_NOTIFICATION_REASON_NO_HISTORY = 1;
// Version of message received not newer than previous one.
const kDROP_NOTIFICATION_REASON_NO_VERSION_INCREMENT = 2;
// Subscription has expired.
const kDROP_NOTIFICATION_REASON_EXPIRED = 3;
/** /**
* State is change only in couple of functions: * State is change only in couple of functions:
* init - change state to PUSH_SERVICE_INIT if state was PUSH_SERVICE_UNINIT * init - change state to PUSH_SERVICE_INIT if state was PUSH_SERVICE_UNINIT
@ -673,6 +683,7 @@ this.PushService = {
scope: record.scope scope: record.scope
}; };
Services.telemetry.getHistogramById("PUSH_API_NOTIFY_REGISTRATION_LOST").add();
this._notifyListeners('pushsubscriptionchange', data); this._notifyListeners('pushsubscriptionchange', data);
}, },
@ -724,6 +735,12 @@ this.PushService = {
.then(record => this._notifySubscriptionChangeObservers(record)); .then(record => this._notifySubscriptionChangeObservers(record));
}, },
_recordDidNotNotify: function(reason) {
Services.telemetry.
getHistogramById("PUSH_API_NOTIFICATION_RECEIVED_BUT_DID_NOT_NOTIFY").
add(reason);
},
/** /**
* Dispatches an incoming message to a service worker, recalculating the * Dispatches an incoming message to a service worker, recalculating the
* quota for the associated push registration. If the quota is exceeded, * quota for the associated push registration. If the quota is exceeded,
@ -740,10 +757,12 @@ this.PushService = {
*/ */
receivedPushMessage: function(keyID, message, updateFunc) { receivedPushMessage: function(keyID, message, updateFunc) {
debug("receivedPushMessage()"); debug("receivedPushMessage()");
Services.telemetry.getHistogramById("PUSH_API_NOTIFICATION_RECEIVED").add();
let shouldNotify = false; let shouldNotify = false;
return this.getByKeyID(keyID).then(record => { return this.getByKeyID(keyID).then(record => {
if (!record) { if (!record) {
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_KEY_NOT_FOUND);
throw new Error("No record for key ID " + keyID); throw new Error("No record for key ID " + keyID);
} }
return record.getLastVisit(); return record.getLastVisit();
@ -751,11 +770,16 @@ this.PushService = {
// As a special case, don't notify the service worker if the user // As a special case, don't notify the service worker if the user
// cleared their history. // cleared their history.
shouldNotify = isFinite(lastVisit); shouldNotify = isFinite(lastVisit);
if (!shouldNotify) {
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_NO_HISTORY);
}
return this._db.update(keyID, record => { return this._db.update(keyID, record => {
let newRecord = updateFunc(record); let newRecord = updateFunc(record);
if (!newRecord) { if (!newRecord) {
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_NO_VERSION_INCREMENT);
return null; return null;
} }
// FIXME(nsm): WHY IS expired checked here but then also checked in the next case?
if (newRecord.isExpired()) { if (newRecord.isExpired()) {
// Because `unregister` is advisory only, we can still receive messages // Because `unregister` is advisory only, we can still receive messages
// for stale registrations from the server. // for stale registrations from the server.
@ -775,6 +799,7 @@ this.PushService = {
notified = this._notifyApp(record, message); notified = this._notifyApp(record, message);
} }
if (record.isExpired()) { if (record.isExpired()) {
this._recordDidNotNotify(kDROP_NOTIFICATION_REASON_EXPIRED);
// Drop the registration in the background. If the user returns to the // Drop the registration in the background. If the user returns to the
// site, the service worker will be notified on the next `idle-daily` // site, the service worker will be notified on the next `idle-daily`
// event. // event.
@ -825,6 +850,7 @@ this.PushService = {
scope: aPushRecord.scope scope: aPushRecord.scope
}; };
Services.telemetry.getHistogramById("PUSH_API_NOTIFY").add();
this._notifyListeners('push', data); this._notifyListeners('push', data);
return true; return true;
}, },

View File

@ -9561,7 +9561,7 @@
"high": "31622400", "high": "31622400",
"n_buckets": 20, "n_buckets": 20,
"description": "Time taken for a push subscription to expire its quota (seconds). The maximum is just over an year." "description": "Time taken for a push subscription to expire its quota (seconds). The maximum is just over an year."
} },
"PUSH_API_QUOTA_RESET_TO": { "PUSH_API_QUOTA_RESET_TO": {
"alert_emails": ["push@mozilla.com"], "alert_emails": ["push@mozilla.com"],
"expires_in_version": "55", "expires_in_version": "55",
@ -9569,5 +9569,30 @@
"high": "200", "high": "200",
"n_buckets": 10, "n_buckets": 10,
"description": "The value a push record quota (a count) is reset to based on the user's browsing history." "description": "The value a push record quota (a count) is reset to based on the user's browsing history."
},
"PUSH_API_NOTIFICATION_RECEIVED": {
"alert_emails": ["push@mozilla.com"],
"expires_in_version": "55",
"kind": "count",
"description": "Push notification was received from server."
},
"PUSH_API_NOTIFICATION_RECEIVED_BUT_DID_NOT_NOTIFY": {
"alert_emails": ["push@mozilla.com"],
"expires_in_version": "55",
"kind": "enumerated",
"n_values": 16,
"description": "Push notification was received from server, but not delivered to ServiceWorker. Enumeration values are defined in dom/push/PushService.jsm as kDROP_NOTIFICATION_REASON_*."
},
"PUSH_API_NOTIFY": {
"alert_emails": ["push@mozilla.com"],
"expires_in_version": "55",
"kind": "count",
"description": "Attempt to notify ServiceWorker of push notification."
},
"PUSH_API_NOTIFY_REGISTRATION_LOST": {
"alert_emails": ["push@mozilla.com"],
"expires_in_version": "55",
"kind": "count",
"description": "Attempt to notify ServiceWorker of push notification resubscription."
} }
} }