Bug 1241697 - Upload experiments with core telemetry ping. r=mfinkle

We generate the experiments in the TelemetryPingGenerator, rather than passing
them into the Intent, meaning that if the UploadSerivce gets killed and the
Intent gets redelivered, the experiments will be re-generated and there is a
chance the uploaded document won't be identical to the one that would have been
uploaded (or was uploaded, if the service is killed after the upload occurs).
The way to fix this is to pass the experiments into the Intent so it gets
redelivered identically.

However, it's not worth making the documents identical for the moment. It will
be fixed when we implement the functionality to reupload already-generated
documents which we believe to have failed to upload (which is necessary for us
to specify "counts since last ping").

--HG--
extra : commitid : 7Z6XJSkm5jo
extra : rebase_source : 82de2467c477e07a8f0e38470e91e842ee74354a
This commit is contained in:
Michael Comella 2016-01-27 15:09:08 -08:00
Родитель 25a2950fdc
Коммит e55a022204
3 изменённых файлов: 19 добавлений и 4 удалений

Просмотреть файл

@ -34,6 +34,7 @@ public class TelemetryConstants {
public static final String ARCHITECTURE = "arch";
public static final String CLIENT_ID = "clientId";
public static final String DEVICE = "device";
public static final String EXPERIMENTS = "experiments";
public static final String LOCALE = "locale";
public static final String OS_ATTR = "os";
public static final String OS_VERSION = "osversion";

Просмотреть файл

@ -5,10 +5,13 @@
package org.mozilla.gecko.telemetry;
import android.content.Context;
import android.os.Build;
import java.io.IOException;
import java.util.Locale;
import com.keepsafe.switchboard.SwitchBoard;
import org.json.JSONArray;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.Locales;
import org.mozilla.gecko.sync.ExtendedJSONObject;
@ -57,14 +60,15 @@ public class TelemetryPingGenerator {
* @param serverURLSchemeHostPort The server url with the scheme, host, and port (e.g. "http://mozilla.org:80")
* @throws IOException when client ID could not be created
*/
public static TelemetryPing createCorePing(final String docId, final String clientId,
public static TelemetryPing createCorePing(final Context context, final String docId, final String clientId,
final String serverURLSchemeHostPort, final int seq) {
final String serverURL = getTelemetryServerURL(docId, serverURLSchemeHostPort, CorePing.NAME);
final ExtendedJSONObject payload = createCorePingPayload(clientId, seq);
final ExtendedJSONObject payload = createCorePingPayload(context, clientId, seq);
return new TelemetryPing(serverURL, payload);
}
private static ExtendedJSONObject createCorePingPayload(final String clientId, final int seq) {
private static ExtendedJSONObject createCorePingPayload(final Context context, final String clientId,
final int seq) {
final ExtendedJSONObject ping = new ExtendedJSONObject();
ping.put(CorePing.VERSION_ATTR, CorePing.VERSION_VALUE);
ping.put(CorePing.OS_ATTR, CorePing.OS_VALUE);
@ -81,6 +85,16 @@ public class TelemetryPingGenerator {
ping.put(CorePing.LOCALE, Locales.getLanguageTag(Locale.getDefault()));
ping.put(CorePing.OS_VERSION, Integer.toString(Build.VERSION.SDK_INT)); // A String for cross-platform reasons.
ping.put(CorePing.SEQ, seq);
if (AppConstants.MOZ_SWITCHBOARD) {
ping.put(CorePing.EXPERIMENTS, getActiveExperiments(context));
}
return ping;
}
private static JSONArray getActiveExperiments(final Context context) {
if (!AppConstants.MOZ_SWITCHBOARD) {
throw new IllegalStateException("This method should not be called with switchboard disabled");
}
return new JSONArray(SwitchBoard.getActiveExperiments(context));
}
}

Просмотреть файл

@ -140,7 +140,7 @@ public class TelemetryUploadService extends BackgroundService {
sharedPrefs.getString(TelemetryConstants.PREF_SERVER_URL, TelemetryConstants.DEFAULT_SERVER_URL);
final TelemetryPing corePing =
TelemetryPingGenerator.createCorePing(docId, clientId, serverURLSchemeHostPort, seq);
TelemetryPingGenerator.createCorePing(this, docId, clientId, serverURLSchemeHostPort, seq);
final CorePingResultDelegate resultDelegate = new CorePingResultDelegate();
uploadPing(corePing, resultDelegate);
}