зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1270213 - Update TelemetryPing & builders to use docID. r=sebastian
Future patches will change the remaining code - This is not yet expected to compile. MozReview-Commit-ID: FpqfThcV7dj --HG-- extra : rebase_source : e01ea217aadd88853d6643c5642d866ba796aa81
This commit is contained in:
Родитель
00cba0fcf9
Коммит
efe06ac7a9
|
@ -10,9 +10,8 @@ import org.mozilla.gecko.sync.ExtendedJSONObject;
|
||||||
/**
|
/**
|
||||||
* Container for telemetry data and the data necessary to upload it.
|
* Container for telemetry data and the data necessary to upload it.
|
||||||
*
|
*
|
||||||
* The unique ID is used by a Store to manipulate its internal pings. Some ping
|
* The doc ID is used by a Store to manipulate its internal pings and should
|
||||||
* payloads already contain a unique ID (e.g. sequence number in core ping) and
|
* be the same value found in the urlPath.
|
||||||
* this field can mirror that value.
|
|
||||||
*
|
*
|
||||||
* If you want to create one of these, consider extending
|
* If you want to create one of these, consider extending
|
||||||
* {@link org.mozilla.gecko.telemetry.pingbuilders.TelemetryPingBuilder}
|
* {@link org.mozilla.gecko.telemetry.pingbuilders.TelemetryPingBuilder}
|
||||||
|
@ -21,15 +20,15 @@ import org.mozilla.gecko.sync.ExtendedJSONObject;
|
||||||
public class TelemetryPing {
|
public class TelemetryPing {
|
||||||
private final String urlPath;
|
private final String urlPath;
|
||||||
private final ExtendedJSONObject payload;
|
private final ExtendedJSONObject payload;
|
||||||
private final int uniqueID;
|
private final String docID;
|
||||||
|
|
||||||
public TelemetryPing(final String urlPath, final ExtendedJSONObject payload, final int uniqueID) {
|
public TelemetryPing(final String urlPath, final ExtendedJSONObject payload, final String docID) {
|
||||||
this.urlPath = urlPath;
|
this.urlPath = urlPath;
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
this.uniqueID = uniqueID;
|
this.docID = docID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getURLPath() { return urlPath; }
|
public String getURLPath() { return urlPath; }
|
||||||
public ExtendedJSONObject getPayload() { return payload; }
|
public ExtendedJSONObject getPayload() { return payload; }
|
||||||
public int getUniqueID() { return uniqueID; }
|
public String getDocID() { return docID; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,11 +72,11 @@ public class UploadTelemetryCorePingCallback implements SearchEngineManager.Sear
|
||||||
|
|
||||||
// Each profile can have different telemetry data so we intentionally grab the shared prefs for the profile.
|
// Each profile can have different telemetry data so we intentionally grab the shared prefs for the profile.
|
||||||
final SharedPreferences sharedPrefs = GeckoSharedPrefs.forProfileName(activity, profile.getName());
|
final SharedPreferences sharedPrefs = GeckoSharedPrefs.forProfileName(activity, profile.getName());
|
||||||
final int sequenceNumber = TelemetryCorePingBuilder.getAndIncrementSequenceNumber(sharedPrefs);
|
final TelemetryCorePingBuilder pingBuilder = new TelemetryCorePingBuilder(activity)
|
||||||
final TelemetryCorePingBuilder pingBuilder = new TelemetryCorePingBuilder(activity, sequenceNumber)
|
|
||||||
.setClientID(clientID)
|
.setClientID(clientID)
|
||||||
.setDefaultSearchEngine(TelemetryCorePingBuilder.getEngineIdentifier(engine))
|
.setDefaultSearchEngine(TelemetryCorePingBuilder.getEngineIdentifier(engine))
|
||||||
.setProfileCreationDate(TelemetryCorePingBuilder.getProfileCreationDate(activity, profile));
|
.setProfileCreationDate(TelemetryCorePingBuilder.getProfileCreationDate(activity, profile))
|
||||||
|
.setSequenceNumber(TelemetryCorePingBuilder.getAndIncrementSequenceNumber(sharedPrefs));
|
||||||
final String distributionId = sharedPrefs.getString(DistributionStoreCallback.PREF_DISTRIBUTION_ID, null);
|
final String distributionId = sharedPrefs.getString(DistributionStoreCallback.PREF_DISTRIBUTION_ID, null);
|
||||||
if (distributionId != null) {
|
if (distributionId != null) {
|
||||||
pingBuilder.setOptDistributionID(distributionId);
|
pingBuilder.setOptDistributionID(distributionId);
|
||||||
|
|
|
@ -53,13 +53,11 @@ public class TelemetryCorePingBuilder extends TelemetryPingBuilder {
|
||||||
private static final String OS_VERSION = "osversion";
|
private static final String OS_VERSION = "osversion";
|
||||||
private static final String PING_CREATION_DATE = "created";
|
private static final String PING_CREATION_DATE = "created";
|
||||||
private static final String PROFILE_CREATION_DATE = "profileDate";
|
private static final String PROFILE_CREATION_DATE = "profileDate";
|
||||||
public static final String SEQ = "seq";
|
private static final String SEQ = "seq";
|
||||||
private static final String TIMEZONE_OFFSET = "tz";
|
private static final String TIMEZONE_OFFSET = "tz";
|
||||||
private static final String VERSION_ATTR = "v";
|
private static final String VERSION_ATTR = "v";
|
||||||
|
|
||||||
public TelemetryCorePingBuilder(final Context context, final int sequenceNumber) {
|
public TelemetryCorePingBuilder(final Context context) {
|
||||||
super(sequenceNumber);
|
|
||||||
setSequenceNumber(sequenceNumber);
|
|
||||||
initPayloadConstants(context);
|
initPayloadConstants(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,11 +147,12 @@ public class TelemetryCorePingBuilder extends TelemetryPingBuilder {
|
||||||
/**
|
/**
|
||||||
* @param seq a positive sequence number.
|
* @param seq a positive sequence number.
|
||||||
*/
|
*/
|
||||||
private void setSequenceNumber(final int seq) {
|
public TelemetryCorePingBuilder setSequenceNumber(final int seq) {
|
||||||
if (seq < 0) {
|
if (seq < 0) {
|
||||||
throw new IllegalArgumentException("Expected positive sequence number. Recived: " + seq);
|
throw new IllegalArgumentException("Expected positive sequence number. Recived: " + seq);
|
||||||
}
|
}
|
||||||
payload.put(SEQ, seq);
|
payload.put(SEQ, seq);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,12 +27,12 @@ abstract class TelemetryPingBuilder {
|
||||||
|
|
||||||
private final String serverPath;
|
private final String serverPath;
|
||||||
protected final ExtendedJSONObject payload;
|
protected final ExtendedJSONObject payload;
|
||||||
private final int uniqueID;
|
private final String docID;
|
||||||
|
|
||||||
public TelemetryPingBuilder(final int uniqueID) {
|
public TelemetryPingBuilder() {
|
||||||
serverPath = getTelemetryServerPath(getDocType());
|
docID = UUID.randomUUID().toString();
|
||||||
|
serverPath = getTelemetryServerPath(getDocType(), docID);
|
||||||
payload = new ExtendedJSONObject();
|
payload = new ExtendedJSONObject();
|
||||||
this.uniqueID = uniqueID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +48,7 @@ abstract class TelemetryPingBuilder {
|
||||||
|
|
||||||
public TelemetryPing build() {
|
public TelemetryPing build() {
|
||||||
validatePayload();
|
validatePayload();
|
||||||
return new TelemetryPing(serverPath, payload, uniqueID);
|
return new TelemetryPing(serverPath, payload, docID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validatePayload() {
|
private void validatePayload() {
|
||||||
|
@ -68,8 +68,7 @@ abstract class TelemetryPingBuilder {
|
||||||
* @param docType The name of the ping (e.g. "main")
|
* @param docType The name of the ping (e.g. "main")
|
||||||
* @return a url at which to POST the telemetry data to
|
* @return a url at which to POST the telemetry data to
|
||||||
*/
|
*/
|
||||||
private static String getTelemetryServerPath(final String docType) {
|
private static String getTelemetryServerPath(final String docType, final String docID) {
|
||||||
final String docId = UUID.randomUUID().toString();
|
|
||||||
final String appName = AppConstants.MOZ_APP_BASENAME;
|
final String appName = AppConstants.MOZ_APP_BASENAME;
|
||||||
final String appVersion = AppConstants.MOZ_APP_VERSION;
|
final String appVersion = AppConstants.MOZ_APP_VERSION;
|
||||||
final String appUpdateChannel = AppConstants.MOZ_UPDATE_CHANNEL;
|
final String appUpdateChannel = AppConstants.MOZ_UPDATE_CHANNEL;
|
||||||
|
@ -78,7 +77,7 @@ abstract class TelemetryPingBuilder {
|
||||||
// The compiler will optimize a single String concatenation into a StringBuilder statement.
|
// The compiler will optimize a single String concatenation into a StringBuilder statement.
|
||||||
// If you change this `return`, be sure to keep it as a single statement to keep it optimized!
|
// If you change this `return`, be sure to keep it as a single statement to keep it optimized!
|
||||||
return SERVER_INITIAL_PATH + '/' +
|
return SERVER_INITIAL_PATH + '/' +
|
||||||
docId + '/' +
|
docID + '/' +
|
||||||
docType + '/' +
|
docType + '/' +
|
||||||
appName + '/' +
|
appName + '/' +
|
||||||
appVersion + '/' +
|
appVersion + '/' +
|
||||||
|
|
|
@ -40,8 +40,6 @@ public class TestTelemetryPingBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NoMandatoryFieldsBuilder extends TelemetryPingBuilder {
|
private static class NoMandatoryFieldsBuilder extends TelemetryPingBuilder {
|
||||||
public NoMandatoryFieldsBuilder() { super(1); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDocType() {
|
public String getDocType() {
|
||||||
return "";
|
return "";
|
||||||
|
@ -61,8 +59,6 @@ public class TestTelemetryPingBuilder {
|
||||||
private static class MandatoryFieldsBuilder extends TelemetryPingBuilder {
|
private static class MandatoryFieldsBuilder extends TelemetryPingBuilder {
|
||||||
private static final String MANDATORY_FIELD = "mandatory-field";
|
private static final String MANDATORY_FIELD = "mandatory-field";
|
||||||
|
|
||||||
public MandatoryFieldsBuilder() { super(0); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDocType() {
|
public String getDocType() {
|
||||||
return "";
|
return "";
|
||||||
|
|
Загрузка…
Ссылка в новой задаче