Bug 1134727 - Add a URL parameter to the Telemetry Submission URL to indicate payload version. r=gfritzsche

This commit is contained in:
Alessio Placitelli 2015-02-25 23:54:34 +01:00
parent 450d6f4085
commit 60dc7923ca
3 changed files with 61 additions and 2 deletions

View File

@ -554,7 +554,9 @@ let Impl = {
doPing: function doPing(ping, isPersisted) {
this._log.trace("doPing - Server " + this._server + ", Persisted " + isPersisted);
let deferred = Promise.defer();
let url = this._server + this.submissionPath(ping);
let isNewPing = isNewPingFormat(ping);
let version = isNewPing ? PING_FORMAT_VERSION : 1;
let url = this._server + this.submissionPath(ping) + "?v=" + version;
let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(Ci.nsIXMLHttpRequest);
request.mozBackgroundRequest = true;
@ -587,7 +589,7 @@ let Impl = {
request.addEventListener("load", handler(true).bind(this), false);
// If that's a legacy ping format, just send its payload.
let networkPayload = isNewPingFormat(ping) ? ping : ping.payload;
let networkPayload = isNewPing ? ping : ping.payload;
request.setRequestHeader("Content-Encoding", "gzip");
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Ci.nsIScriptableUnicodeConverter);

View File

@ -220,6 +220,14 @@ add_task(function* test_simplePing() {
yield sendPing(false, false);
let request = yield gRequestIterator.next();
// Check that we have a version query parameter in the URL.
Assert.notEqual(request.queryString, "");
// Make sure the version in the query string matches the new ping format version.
let params = request.queryString.split("&");
Assert.ok(params.find(p => p == ("v=" + PING_FORMAT_VERSION)));
let ping = decodeRequestPayload(request);
checkPingFormat(ping, TEST_PING_TYPE, false, false);
});

View File

@ -356,6 +356,55 @@ add_task(function* test_overdue_pings_trigger_send() {
yield resetTelemetry();
});
/**
* Create a ping in the old format, send it, and make sure the request URL contains
* the correct version query parameter.
*/
add_task(function* test_overdue_old_format() {
// A test ping in the old, standard format.
const PING_OLD_FORMAT = {
slug: "1234567abcd",
reason: "test-ping",
payload: {
info: {
reason: "test-ping",
OS: "XPCShell",
appID: "SomeId",
appVersion: "1.0",
appName: "XPCShell",
appBuildID: "123456789",
appUpdateChannel: "Test",
platformBuildID: "987654321",
},
},
};
const filePath =
Path.join(Constants.Path.profileDir, PING_SAVE_FOLDER, PING_OLD_FORMAT.slug);
// Write the ping to file and make it overdue.
yield TelemetryFile.savePing(PING_OLD_FORMAT, true);
yield File.setDates(filePath, null, Date.now() - OVERDUE_PING_FILE_AGE);
let receivedPings = 0;
// Register a new prefix handler to validate the URL.
gHttpServer.registerPrefixHandler("/submit/telemetry/", request => {
// Check that we have a version query parameter in the URL.
Assert.notEqual(request.queryString, "");
// Make sure the version in the query string matches the old ping format version.
let params = request.queryString.split("&");
Assert.ok(params.find(p => p == "v=1"));
receivedPings++;
});
yield startTelemetry();
Assert.equal(receivedPings, 1, "We must receive a ping in the old format.");
yield resetTelemetry();
});
add_task(function* teardown() {
yield stopHttpServer();
});