Bug 665805 - Adjust telemetry to work with official metrics server r=Mossop

This commit is contained in:
Taras Glek 2011-06-21 14:39:11 -07:00
parent 84f53e7260
commit 6300397146
3 changed files with 34 additions and 18 deletions

View File

@ -272,8 +272,7 @@ pref("toolkit.scrollbox.clickToScroll.scrollDelay", 150);
// Telemetry
pref("toolkit.telemetry.enabled", false);
// Telemetry test server to be used until the official one is public
pref("toolkit.telemetry.server", "http://telemetry.allizom.org");
pref("toolkit.telemetry.server", "https://data.mozilla.com");
// view source
pref("view_source.syntax_highlight", true);

View File

@ -97,6 +97,7 @@ function getHistograms() {
first = false;
retgram.values[r[i - 1]] = 0;
}
first = false;
last = i + 1;
retgram.values[r[i]] = value;
}
@ -110,8 +111,9 @@ function getHistograms() {
}
function generateUUID() {
return Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator)
.generateUUID().toString();
let str = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID().toString();
// strip {}
return str.substring(1, str.length - 1);
}
/**
@ -236,9 +238,6 @@ TelemetryPing.prototype = {
if (!this._path)
this._path = "/submit/telemetry/" + (isTestPing ? reason : generateUUID());
const TELEMETRY_PING = "telemetry.ping (ms)";
const TELEMETRY_SUCCESS = "telemetry.success (No, Yes)";
let hping = Telemetry.getHistogramById("TELEMETRY_PING");
let hsuccess = Telemetry.getHistogramById("TELEMETRY_SUCCESS");
@ -248,17 +247,24 @@ TelemetryPing.prototype = {
request.mozBackgroundRequest = true;
request.open("POST", url, true);
request.overrideMimeType("text/plain");
request.setRequestHeader("Content-Type", "application/json");
let startTime = new Date()
function finishRequest(success_metric) {
hsuccess.add(success_metric);
function finishRequest(channel) {
let success = false;
try {
success = channel.QueryInterface(Ci.nsIHttpChannel).requestSucceeded;
} catch(e) {
}
hsuccess.add(success ? 1 : 0);
hping.add(new Date() - startTime);
if (isTestPing)
Services.obs.notifyObservers(null, "telemetry-test-xhr-complete", null);
}
request.onerror = function(aEvent) finishRequest(0);
request.onload = function(aEvent) finishRequest(1);
request.onerror = function(aEvent) finishRequest(request.channel);
request.onload = function(aEvent) finishRequest(request.channel);
request.send(nativeJSON.encode(payload));
},

View File

@ -11,7 +11,9 @@
do_load_httpd_js();
Cu.import("resource://gre/modules/Services.jsm");
const PATH = "/submit/telemetry/test-ping"
const PATH = "/submit/telemetry/test-ping";
const SERVER = "http://localhost:4444";
const BinaryInputStream = Components.Constructor(
"@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
@ -21,7 +23,18 @@ var httpserver = new nsHttpServer();
function telemetry_ping () {
let tp = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsIObserver);
tp.observe(tp, "test-ping", "http://localhost:4444");
tp.observe(tp, "test-ping", SERVER);
}
function nonexistentServerObserver(aSubject, aTopic, aData) {
Services.obs.removeObserver(nonexistentServerObserver, aTopic);
httpserver.start(4444);
// Provide a dummy function so it returns 200 instead of 404 to telemetry.
httpserver.registerPathHandler(PATH, function () {});
Services.obs.addObserver(telemetryObserver, "telemetry-test-xhr-complete", false);
telemetry_ping();
}
function telemetryObserver(aSubject, aTopic, aData) {
@ -32,10 +45,7 @@ function telemetryObserver(aSubject, aTopic, aData) {
function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
httpserver.start(4444);
Services.obs.addObserver(telemetryObserver, "telemetry-test-xhr-complete", false);
Services.obs.addObserver(nonexistentServerObserver, "telemetry-test-xhr-complete", false);
telemetry_ping();
// spin the event loop
do_test_pending();
@ -55,6 +65,7 @@ function checkHistograms(request, response) {
let payload = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON)
.decode(readBytesFromInputStream(s))
do_check_eq(request.getHeader("content-type"), "application/json; charset=UTF-8");
do_check_true(payload.simpleMeasurements.uptime >= 0)
// get rid of the non-deterministic field
@ -81,7 +92,7 @@ function checkHistograms(request, response) {
range: [1, 2],
bucket_count: 3,
histogram_type: 2,
values: {0:0, 1:1, 2:0}
values: {0:1, 1:1, 2:0}
}
let tc = payload.histograms[TELEMETRY_SUCCESS]
do_check_eq(uneval(tc),