Skip to content

Commit

Permalink
restore data residency region from error minidump files
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailSuendukov committed Aug 16, 2023
1 parent bafad1f commit 2ac5300
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ public void run() {
mChannel.enqueue(errorLog, ERROR_GROUP, Flags.DEFAULTS);

/* Then attachments if any. */
for (ErrorAttachmentLog attachment : attachments) {
attachment.setDataResidencyRegion(dataResidencyRegion);
}
sendErrorAttachment(errorId, attachments);
}
});
Expand Down Expand Up @@ -784,6 +787,7 @@ private void processSingleMinidump(File minidumpFile, File minidumpFolder) {
errorLog.setProcessName("");
try {
String savedUserId = ErrorLogHelper.getStoredUserInfo(minidumpFolder);
String dataResidencyRegion = ErrorLogHelper.getStoredDataResidencyRegion(minidumpFolder);
Device savedDeviceInfo = ErrorLogHelper.getStoredDeviceInfo(minidumpFolder);
if (savedDeviceInfo == null) {

Expand All @@ -796,7 +800,7 @@ private void processSingleMinidump(File minidumpFile, File minidumpFolder) {
}
errorLog.setDevice(savedDeviceInfo);
errorLog.setUserId(savedUserId);
// TODO add data residency region.
errorLog.setDataResidencyRegion(dataResidencyRegion);
saveErrorLogFiles(new NativeException(), errorLog);
if (!minidumpFile.renameTo(dest)) {
throw new IOException("Failed to move file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ public static String getStoredUserInfo(File logFolder) {
return parseUserId(userInformationString);
}

/**
* Get data residency region.
*
* @param logFolder folder where to look for stored data residency region.
* @return a data residency region or null.
*/
@Nullable
public static String getStoredDataResidencyRegion(File logFolder) {
String context = getContextInformation(logFolder);
if (context == null) {
return null;
}
return parseDataResidencyRegion(context);
}

/**
* Get data about userId and deviceInfo in JSON format.
* @param logFolder - path to folder where placed file with data about userId and deviceId.
Expand Down Expand Up @@ -450,6 +465,24 @@ static Device parseDevice(String contextInformation) {
return null;
}

/**
* Look for 'dataResidencyRegion' data in file inside the minidump folder and parse it.
* @param contextInformation - data with information about userId.
* @return dataResidencyRegion or null.
*/
@VisibleForTesting
static String parseDataResidencyRegion(String contextInformation) {
try {
JSONObject jsonObject = new JSONObject(contextInformation);
if (jsonObject.has(DATA_RESIDENCY_REGION_KEY)) {
return jsonObject.getString(DATA_RESIDENCY_REGION_KEY);
}
} catch (JSONException e) {
AppCenterLog.error(Crashes.LOG_TAG, "Failed to deserialize data residency region.", e);
}
return null;
}

/**
* Remove the minidump sub-folders from previous sessions in the 'minidump/new' folder.
* Minidumps from these folders should already be moved to the 'minidump/pending' folder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;

import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.CancellationException;
import com.microsoft.appcenter.http.HttpClient;
import com.microsoft.appcenter.http.HttpResponse;
Expand Down Expand Up @@ -648,6 +649,11 @@ public void enqueue(@NonNull Log log, @NonNull final String groupName, int flags
log.setDevice(mDevice);
}

/* Attach data residency region property to every log if its not already attached by a service. */
if (log.getDataResidencyRegion() == null) {
log.setDataResidencyRegion(AppCenter.getDataResidencyRegion());
}

/* Set date to current if not explicitly set in the past by a module (such as a crash). */
if (log.getTimestamp() == null) {
log.setTimestamp(new Date());
Expand Down

0 comments on commit 2ac5300

Please sign in to comment.