Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Commit

Permalink
metrics for new features + maybe some improved transient error handli…
Browse files Browse the repository at this point in the history
…ng (needs monitoring for real world impact)
  • Loading branch information
luckyrat committed May 24, 2015
1 parent b23e0a2 commit 26e719c
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 55 deletions.
13 changes: 7 additions & 6 deletions Firefox addon/KeeFox/chrome/content/framescript/formsFillTab.js
Expand Up @@ -679,7 +679,7 @@ var scanForOrphanedFields = function (doc)
{
var t = (new Date()).getTime();
let orphanedFields = [];
let pseduoForm = null;
let pseudoForm = null;

// much faster than querySelectorAll
//TODO:1.5: Although we probably need to refine our selection criteria somewhat once we get real world feedback
Expand All @@ -692,21 +692,22 @@ var scanForOrphanedFields = function (doc)

if (orphanedFields.length > 0)
{
pseduoForm = {
pseudoForm = {
elements: orphanedFields,
id: "KeeFox-pseduo-form",
name: "KeeFox-pseduo-form",
id: "KeeFox-pseudo-form",
name: "KeeFox-pseudo-form",
ownerDocument: doc,
getElementsByTagName: function() { return this.elements; }, // Only use is for listing input elements
querySelectorAll: function() { return []; }, // Only use is for listing button elements
submit: function() { return; } // Not possible to submit a pseduo form unless a button with custom JS has already been found
submit: function() { return; } // Not possible to submit a pseudo form unless a button with custom JS has already been found
};
metricsManager.adjustAggregate("pseudoFormCreated", 1);
}

var tn = (new Date()).getTime();
Logger.debug("scanForOrphanedFields took: " + (tn-t));

return pseduoForm;
return pseudoForm;
};

var findLoginsCacheHandler = function (convertedResult, findLoginOp, matchResult)
Expand Down
6 changes: 6 additions & 0 deletions Firefox addon/KeeFox/chrome/content/panel.js
Expand Up @@ -949,6 +949,7 @@ keefox_win.panel = {
function (event) {
keefox_org.utils.copyStringToClipboard(usernameField.value);
keefox_win.panel.CustomizableUI.hidePanelForNode(keefox_win.panel._currentWindow.document.getElementById('keefox-panelview'));
keefox_org.metricsManager.adjustAggregate("copyUsername", 1);
});
}

Expand All @@ -960,6 +961,7 @@ keefox_win.panel = {
function (event) {
keefox_org.utils.copyStringToClipboard(passwordField.value);
keefox_win.panel.CustomizableUI.hidePanelForNode(keefox_win.panel._currentWindow.document.getElementById('keefox-panelview'));
keefox_org.metricsManager.adjustAggregate("copyPassword", 1);
});
}
if (otherFieldCount > 1 || passwordFieldCount > 1) {
Expand All @@ -981,6 +983,7 @@ keefox_win.panel = {
function (event) {
keefox_org.utils.copyStringToClipboard(o.value);
keefox_win.panel.CustomizableUI.hidePanelForNode(keefox_win.panel._currentWindow.document.getElementById('keefox-panelview'));
keefox_org.metricsManager.adjustAggregate("copyOther", 1);
});
}
});
Expand All @@ -996,6 +999,7 @@ keefox_win.panel = {
function (event) {
keefox_org.utils.copyStringToClipboard(p.value);
keefox_win.panel.CustomizableUI.hidePanelForNode(keefox_win.panel._currentWindow.document.getElementById('keefox-panelview'));
keefox_org.metricsManager.adjustAggregate("copyOther", 1);
});
}
});
Expand Down Expand Up @@ -1332,6 +1336,7 @@ keefox_win.panel = {
keefox_win.panel.CustomizableUI.hidePanelForNode(
keefox_win.panel._currentWindow.document.getElementById('keefox-panelview'));
keefox_win.panel.hideSubSections();
keefox_org.metricsManager.adjustAggregate("searchResultSelected", 1);
}, false);
loginItem.addEventListener("keefoxContext", function (event) {
keefox_win.panel.addLoginContextActions(document, this.getAttribute('data-uuid'), this.getAttribute('data-fileName'));
Expand Down Expand Up @@ -1373,6 +1378,7 @@ keefox_win.panel = {
layerY: this.offsetTop + event.layerY
},
'KeeFox-login-context');
keefox_org.metricsManager.adjustAggregate("loginContextButton", 1);
}, false);
optionsMenuTrigger.setAttribute("id", "optionsMenuTrigger");
event.target.appendChild(optionsMenuTrigger);
Expand Down
2 changes: 1 addition & 1 deletion Firefox addon/KeeFox/install.rdf
Expand Up @@ -5,7 +5,7 @@

<Description about="urn:mozilla:install-manifest">
<em:id>keefox@chris.tomlinson</em:id>
<em:version>1.4.101a1</em:version>
<em:version>1.4.102a1</em:version>
<em:type>2</em:type>
<em:unpack>true</em:unpack>
<em:multiprocessCompatible>true</em:multiprocessCompatible>
Expand Down
161 changes: 114 additions & 47 deletions Firefox addon/KeeFox/modules/metrics.js
Expand Up @@ -408,9 +408,33 @@ function mm () {
mm.get("avgOpenDatabases", function (event) {
if (event.target.result)
mm.previousSessionMetrics.avgOpenDatabases = event.target.result.value; // when any are open (so >= 1)
//TODO:2: Try to convert to Promises so we can avoid infinite callback indentation
mm._KFLog.debug("calculatePreviousSessionMetrics finished");
if (cb) cb();
mm.get("copyUsername", function (event) {
if (event.target.result)
mm.previousSessionMetrics.copyUsername = event.target.result.value;
mm.get("copyPassword", function (event) {
if (event.target.result)
mm.previousSessionMetrics.copyPassword = event.target.result.value;
mm.get("copyOther", function (event) {
if (event.target.result)
mm.previousSessionMetrics.copyOther = event.target.result.value;
mm.get("searchResultSelected", function (event) {
if (event.target.result)
mm.previousSessionMetrics.searchResultSelected = event.target.result.value;
mm.get("loginContextButton", function (event) {
if (event.target.result)
mm.previousSessionMetrics.loginContextButton = event.target.result.value;
mm.get("pseudoFormCreated", function (event) {
if (event.target.result)
mm.previousSessionMetrics.pseudoFormCreated = event.target.result.value;
//TODO:2: Try to convert to Promises so we can avoid infinite callback indentation
mm._KFLog.debug("calculatePreviousSessionMetrics finished");
if (cb) cb();
});
});
});
});
});
});
});
});
});
Expand Down Expand Up @@ -487,56 +511,77 @@ function mm () {
.objectStore("keefox@chris.tomlinson-metrics-messages");
let mm = this;

objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
// Don't append exceptionally large messages to the current message
// string - we'll leave it for next time and send it on its own
if (completeMessage !== "" && completeMessage.length + cursor.value.msg.length > 250000)
{
mm.deliverMessage(completeMessage);
return;
}
let cursorReq = objectStore.openCursor();
cursorReq.onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
// Don't append exceptionally large messages to the current message
// string - we'll leave it for next time and send it on its own
if (completeMessage !== "" && completeMessage.length + cursor.value.msg.length > 250000)
{
try {
mm.deliverMessage(completeMessage);
} catch (e) {
mm._KFLog.warn("Metrics processQueue failed to deliverMessage (large). We'll try again later.");
}
// Don't respawn here since deliverMessage should do that.
// Stop iterating this cursor
return;
}

mm.lastSentAttemptId = cursor.value.id;
completeMessage += cursor.value.msg;
cursor.continue();
}
else {
// We've reached the end of the cursor, whether we
// found any results is another matter...
if (completeMessage.length > 0)
mm.deliverMessage(completeMessage);
else
mm.metricsTimerRespawn();
}
mm.lastSentAttemptId = cursor.value.id;
completeMessage += cursor.value.msg;
cursor.continue();
}
else {
// We've reached the end of the cursor, whether we
// found any results is another matter...
if (completeMessage.length > 0)
mm.deliverMessage(completeMessage);
else
mm.metricsTimerRespawn();
}
};

cursorReq.onerror = function(event) {
// Try again later if something forced us to abort
mm._KFLog.warn("Metrics processQueue failed to iterate cursor (" + cursorReq.error.name + ").");
if (cursorReq.error.name == "AbortError") {
mm.metricsTimerRespawn(60);
}
};

};

// Start the timer ready for the next queue processing operation
this.metricsTimerRespawn = function (retry)
{
let DEFAULT_DELAY = 15;
let secondsUntilNextProcess = DEFAULT_DELAY;
try {
let DEFAULT_DELAY = 15;
let secondsUntilNextProcess = DEFAULT_DELAY;

// retry should have been set on failure but may also be set by server to manage load
if (retry)
{ //TODO:1.6: Don't just listen to the server - do something more useful
secondsUntilNextProcess = retry;
if (secondsUntilNextProcess < DEFAULT_DELAY)
secondsUntilNextProcess = DEFAULT_DELAY;
}
// retry should have been set on failure but may also be set by server to manage load
if (retry)
{ //TODO:1.6: Don't just listen to the server - do something more useful
secondsUntilNextProcess = retry;
if (secondsUntilNextProcess < DEFAULT_DELAY)
secondsUntilNextProcess = DEFAULT_DELAY;
}

var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
var window = wm.getMostRecentWindow("navigator:browser") ||
wm.getMostRecentWindow("mail:3pane");
var mm = window.keefox_org.metricsManager;
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
var window = wm.getMostRecentWindow("navigator:browser") ||
wm.getMostRecentWindow("mail:3pane");
var mm = window.keefox_org.metricsManager;

mm.metricsTimer.initWithCallback(mm.metricsTimerHandler,
secondsUntilNextProcess * 1000,
Components.interfaces.nsITimer.TYPE_ONE_SHOT);
mm.metricsTimer.initWithCallback(mm.metricsTimerHandler,
secondsUntilNextProcess * 1000,
Components.interfaces.nsITimer.TYPE_ONE_SHOT);
} catch (e)
{
//TODO:1.5: Review need for this try/catch
// Do nothing (can't be sure if we can log safely but this is just a test anyway for the moment...
}
};

// Just process the message queue when the timer fires
Expand Down Expand Up @@ -588,16 +633,25 @@ function mm () {
var objectStore = mm.db.transaction("keefox@chris.tomlinson-metrics-messages","readwrite")
.objectStore("keefox@chris.tomlinson-metrics-messages");

objectStore.openCursor(mm.IDBKeyRange.upperBound(mm.lastSentId)).onsuccess = function(event) {
let cursorReq = objectStore.openCursor(mm.IDBKeyRange.upperBound(mm.lastSentId));
cursorReq.onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
objectStore.delete(cursor.primaryKey);
cursor.delete();
// This seemed to work too but maybe susceptible to concurrency bugs? objectStore.delete(cursor.primaryKey);
cursor.continue();
} else
{
mm.metricsTimerRespawn(15);
}
};
cursorReq.onerror = function(event) {
// Try again later if something forced us to abort
mm._KFLog.warn("Metrics deliverMessage failed to iterate cursor (" + cursorReq.error.name + ").");
if (cursorReq.error.name == "AbortError") {
mm.metricsTimerRespawn(60);
}
};

});
request.addEventListener("error", function(event) {
Expand Down Expand Up @@ -629,6 +683,7 @@ function mm () {
} catch (ex)
{
mm._KFLog.error("Metrics error. Could not send because: " + ex);
mm.metricsTimerRespawn(60);
}
};

Expand All @@ -647,9 +702,21 @@ function mm () {
mm.set("contextMenuItemsPressed",{ value: 0.0 }, function () {
mm.set("keyboardShortcutsPressed",{ value: 0.0 }, function () {
mm.set("avgOpenDatabases",{ avg: 0.0, count: 0 }, function () {
mm.aggregatesReady = true;
mm._KFLog.debug("resetAggregates finished");
if (cb) cb();
mm.set("copyUsername",{ value: 0.0 }, function () {
mm.set("copyPassword",{ value: 0.0 }, function () {
mm.set("copyOther",{ value: 0.0 }, function () {
mm.set("searchResultSelected",{ value: 0.0 }, function () {
mm.set("loginContextButton",{ value: 0.0 }, function () {
mm.set("pseudoFormCreated",{ value: 0.0 }, function () {
mm.aggregatesReady = true;
mm._KFLog.debug("resetAggregates finished");
if (cb) cb();
});
});
});
});
});
});
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion KeePassRPC/KeePassRPCExt.cs
Expand Up @@ -576,7 +576,7 @@ private void EnsureDBIconIsInKPRPCIconCache()
/// <summary>
/// Called when [file new].
/// </summary>
/// <remarks>Review whenever private KeePass.MainForm.OnFileNew method changes.</remarks>
/// <remarks>Review whenever private KeePass.MainForm.OnFileNew method changes. Last reviewed 20150523</remarks>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
internal void CreateNewDatabase()
Expand Down

0 comments on commit 26e719c

Please sign in to comment.