From b44e1540cc1691d73159d84cef9091a05c7ccf68 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 4 May 2020 15:23:13 +0300 Subject: [PATCH 01/24] Import firebase performance lib --- opensrp-app/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opensrp-app/build.gradle b/opensrp-app/build.gradle index a8425a0cba..35360d0c03 100644 --- a/opensrp-app/build.gradle +++ b/opensrp-app/build.gradle @@ -202,6 +202,8 @@ dependencies { exclude group: 'com.android.support', module: 'appcompat-v7' exclude group: 'android.arch.core', module: 'runtime' } + // Add the dependency for the Performance Monitoring library + implementation 'com.google.firebase:firebase-perf:19.0.7' } dependencies { From 6ca2b6e2f9a21fa87e63172bfbdbe6898b245ae4 Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 5 May 2020 10:20:15 +0300 Subject: [PATCH 02/24] Add custom logging --- .../sync/helper/LocationServiceHelper.java | 13 +++++++++++++ .../sync/helper/PlanIntentServiceHelper.java | 11 +++++++++++ .../sync/helper/TaskServiceHelper.java | 13 ++++++++++++- .../sync/intent/SyncIntentService.java | 14 ++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java index 635cd26af8..71769b860f 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java @@ -3,6 +3,8 @@ import android.content.Context; import android.text.TextUtils; +import com.google.firebase.perf.FirebasePerformance; +import com.google.firebase.perf.metrics.Trace; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -52,12 +54,14 @@ public class LocationServiceHelper { private LocationRepository locationRepository; private LocationTagRepository locationTagRepository; private StructureRepository structureRepository; + private Trace locationSyncTrace; public LocationServiceHelper(LocationRepository locationRepository, LocationTagRepository locationTagRepository, StructureRepository structureRepository) { this.context = CoreLibrary.getInstance().context().applicationContext(); this.locationRepository = locationRepository; this.locationTagRepository = locationTagRepository; this.structureRepository = structureRepository; + this.locationSyncTrace = FirebasePerformance.getInstance().newTrace("location_sync"); } public static LocationServiceHelper getInstance() { @@ -124,13 +128,21 @@ private String fetchLocationsOrStructures(boolean isJurisdiction, Long serverVer JSONObject request = new JSONObject(); request.put("is_jurisdiction", isJurisdiction); + String providerId = allSharedPreferences.fetchRegisteredANM(); + String team = allSharedPreferences.fetchDefaultTeam(providerId); + + locationSyncTrace.putAttribute("team", team); + locationSyncTrace.putAttribute("action", "fetch"); if (isJurisdiction) { + locationSyncTrace.putAttribute("type", "location"); String preferenceLocationNames = allSharedPreferences.getPreference(OPERATIONAL_AREAS); request.put("location_names", new JSONArray(Arrays.asList(preferenceLocationNames.split(",")))); } else { + locationSyncTrace.putAttribute("type", "structure"); request.put("parent_id", new JSONArray(Arrays.asList(locationFilterValue.split(",")))); } request.put("serverVersion", serverVersion); + locationSyncTrace.start(); resp = httpAgent.post( MessageFormat.format("{0}{1}", @@ -141,6 +153,7 @@ private String fetchLocationsOrStructures(boolean isJurisdiction, Long serverVer if (resp.isFailure()) { throw new NoHttpResponseException(LOCATION_STRUCTURE_URL + " not returned data"); } + locationSyncTrace.stop(); return resp.payload().toString(); } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java index 8484735037..f4d2586411 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java @@ -2,6 +2,8 @@ import android.content.Context; +import com.google.firebase.perf.FirebasePerformance; +import com.google.firebase.perf.metrics.Trace; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -44,6 +46,8 @@ public class PlanIntentServiceHelper { public static final String SYNC_PLANS_URL = "/rest/plans/sync"; public static final String PLAN_LAST_SYNC_DATE = "plan_last_sync_date"; + private Trace planSyncTrace; + public static PlanIntentServiceHelper getInstance() { if (instance == null) { instance = new PlanIntentServiceHelper(CoreLibrary.getInstance().context().getPlanDefinitionRepository(), @@ -56,6 +60,7 @@ private PlanIntentServiceHelper(PlanDefinitionRepository planRepository, Locatio this.context = CoreLibrary.getInstance().context().applicationContext(); this.planDefinitionRepository = planRepository; this.locationRepository = locationRepository; + this.planSyncTrace = FirebasePerformance.getInstance().newTrace("plan_sync"); } public void syncPlans() { @@ -93,6 +98,10 @@ public void syncPlans() { } private String fetchPlans(List organizationIds, long serverVersion) throws Exception { + String providerId = allSharedPreferences.fetchRegisteredANM(); + String team = allSharedPreferences.fetchDefaultTeam(providerId); + planSyncTrace.putAttribute("team", team); + planSyncTrace.putAttribute("action", "fetch"); HTTPAgent httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); String baseUrl = CoreLibrary.getInstance().context().configuration().dristhiBaseURL(); String endString = "/"; @@ -105,6 +114,7 @@ private String fetchPlans(List organizationIds, long serverVersion) thro request.put("organizations", new JSONArray(organizationIds)); } request.put("serverVersion", serverVersion); + planSyncTrace.start(); if (httpAgent == null) { context.sendBroadcast(Utils.completeSync(FetchStatus.noConnection)); @@ -121,6 +131,7 @@ private String fetchPlans(List organizationIds, long serverVersion) thro context.sendBroadcast(Utils.completeSync(FetchStatus.nothingFetched)); throw new NoHttpResponseException(SYNC_PLANS_URL + " did not return any data"); } + planSyncTrace.stop(); return resp.payload().toString(); } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java index 27c62fad37..eabab8d53c 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java @@ -4,6 +4,8 @@ import android.support.annotation.NonNull; import android.support.annotation.VisibleForTesting; +import com.google.firebase.perf.FirebasePerformance; +import com.google.firebase.perf.metrics.Trace; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -52,6 +54,8 @@ public class TaskServiceHelper { private boolean syncByGroupIdentifier = true; + private Trace taskSyncTrace; + /** * If set to false tasks will sync by owner otherwise defaults to sync by group identifier * @param syncByGroupIdentifier flag for determining if tasks should be synced by group identifier @@ -76,6 +80,7 @@ public static TaskServiceHelper getInstance() { public TaskServiceHelper(TaskRepository taskRepository) { this.context = CoreLibrary.getInstance().context().applicationContext(); this.taskRepository = taskRepository; + this.taskSyncTrace = FirebasePerformance.getInstance().newTrace("task_sync"); } public List syncTasks() { @@ -144,13 +149,19 @@ private String fetchTasks(Set plan, List group, Long serverVersi throw new IllegalArgumentException(SYNC_TASK_URL + " http agent is null"); } + String providerId = allSharedPreferences.fetchRegisteredANM(); + String team = allSharedPreferences.fetchDefaultTeam(providerId); + taskSyncTrace.putAttribute("team", team); + taskSyncTrace.putAttribute("action", "fetch"); + + taskSyncTrace.start(); Response resp = httpAgent.post(MessageFormat.format("{0}{1}", baseUrl, SYNC_TASK_URL), request.toString()); if (resp.isFailure()) { throw new NoHttpResponseException(SYNC_TASK_URL + " not returned data"); } - + taskSyncTrace.stop(); return resp.payload().toString(); } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java index 428a30302d..42257ec078 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java @@ -6,6 +6,9 @@ import android.support.annotation.NonNull; import android.util.Pair; +import com.google.firebase.perf.FirebasePerformance; +import com.google.firebase.perf.metrics.Trace; + import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import org.json.JSONArray; @@ -19,6 +22,7 @@ import org.smartregister.domain.Response; import org.smartregister.domain.db.EventClient; import org.smartregister.receiver.SyncStatusBroadcastReceiver; +import org.smartregister.repository.AllSharedPreferences; import org.smartregister.repository.EventClientRepository; import org.smartregister.service.HTTPAgent; import org.smartregister.sync.helper.ECSyncHelper; @@ -41,6 +45,9 @@ public class SyncIntentService extends BaseSyncIntentService { private Context context; private HTTPAgent httpAgent; private SyncUtils syncUtils; + private Trace eventSyncTrace; + + private AllSharedPreferences allSharedPreferences = CoreLibrary.getInstance().context().allSharedPreferences(); public SyncIntentService() { super("SyncIntentService"); @@ -54,6 +61,7 @@ protected void init(@NonNull Context context) { this.context = context; httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); syncUtils = new SyncUtils(getBaseContext()); + eventSyncTrace = FirebasePerformance.getInstance().newTrace("event_sync"); } @Override @@ -105,7 +113,13 @@ private void doSync() { } protected void pullECFromServer() { + String providerId = allSharedPreferences.fetchRegisteredANM(); + String team = allSharedPreferences.fetchDefaultTeam(providerId); + eventSyncTrace.putAttribute("team", team); + eventSyncTrace.putAttribute("action", "fetch"); + eventSyncTrace.start(); fetchRetry(0); + eventSyncTrace.stop(); } private synchronized void fetchRetry(final int count) { From d0ba5cac4ac93224cf9df97a073db07a51848046 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 6 May 2020 15:49:57 +0300 Subject: [PATCH 03/24] Add custom logging when fetchng and pushing data to/from the server --- .../java/org/smartregister/AllConstants.java | 13 ++++++ .../sync/helper/LocationServiceHelper.java | 45 ++++++++++++++----- .../sync/helper/PlanIntentServiceHelper.java | 26 ++++++++--- .../sync/helper/TaskServiceHelper.java | 33 ++++++++++---- .../sync/intent/SyncIntentService.java | 29 +++++++++--- 5 files changed, 112 insertions(+), 34 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/AllConstants.java b/opensrp-app/src/main/java/org/smartregister/AllConstants.java index 67888227f8..400985c5a3 100644 --- a/opensrp-app/src/main/java/org/smartregister/AllConstants.java +++ b/opensrp-app/src/main/java/org/smartregister/AllConstants.java @@ -459,4 +459,17 @@ public interface JSON { String KEY = "key"; String VALUE = "value"; } + + public interface PerformanceMonitoring { + String TEAM = "team"; + String PUSH = "push"; + String FETCH = "fetch"; + String ACTION = "action"; + String STRUCTURE = "structure"; + String LOCATION = "location"; + String TASK_SYNC = "task_sync"; + String PLAN_SYNC = "plan_sync"; + String EVENT_SYNC = "event_sync"; + String LOCATION_SYNC = "location_sync"; + } } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java index 71769b860f..ea162dc846 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java @@ -36,7 +36,16 @@ import timber.log.Timber; +import static org.smartregister.AllConstants.COUNT; import static org.smartregister.AllConstants.OPERATIONAL_AREAS; +import static org.smartregister.AllConstants.PerformanceMonitoring.ACTION; +import static org.smartregister.AllConstants.PerformanceMonitoring.FETCH; +import static org.smartregister.AllConstants.PerformanceMonitoring.LOCATION; +import static org.smartregister.AllConstants.PerformanceMonitoring.LOCATION_SYNC; +import static org.smartregister.AllConstants.PerformanceMonitoring.PUSH; +import static org.smartregister.AllConstants.PerformanceMonitoring.STRUCTURE; +import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; +import static org.smartregister.AllConstants.TYPE; public class LocationServiceHelper { @@ -55,13 +64,16 @@ public class LocationServiceHelper { private LocationTagRepository locationTagRepository; private StructureRepository structureRepository; private Trace locationSyncTrace; + private String team; public LocationServiceHelper(LocationRepository locationRepository, LocationTagRepository locationTagRepository, StructureRepository structureRepository) { this.context = CoreLibrary.getInstance().context().applicationContext(); this.locationRepository = locationRepository; this.locationTagRepository = locationTagRepository; this.structureRepository = structureRepository; - this.locationSyncTrace = FirebasePerformance.getInstance().newTrace("location_sync"); + this.locationSyncTrace = FirebasePerformance.getInstance().newTrace(LOCATION_SYNC); + String providerId = allSharedPreferences.fetchRegisteredANM(); + team = allSharedPreferences.fetchDefaultTeam(providerId); } public static LocationServiceHelper getInstance() { @@ -82,10 +94,22 @@ protected List syncLocationsStructures(boolean isJurisdiction) { if (serverVersion > 0) serverVersion += 1; try { List parentIds = locationRepository.getAllLocationIds(); + + locationSyncTrace.putAttribute(TEAM, team); + locationSyncTrace.putAttribute(ACTION, FETCH); + if (isJurisdiction) { + locationSyncTrace.putAttribute(TYPE, LOCATION); + } else { + locationSyncTrace.putAttribute(TYPE, STRUCTURE); + } + locationSyncTrace.start(); String featureResponse = fetchLocationsOrStructures(isJurisdiction, serverVersion, TextUtils.join(",", parentIds)); List locations = locationGson.fromJson(featureResponse, new TypeToken>() { }.getType()); + locationSyncTrace.putAttribute(COUNT, String.valueOf(locations.size())); + locationSyncTrace.stop(); + for (Location location : locations) { try { location.setSyncStatus(BaseRepository.TYPE_Synced); @@ -125,24 +149,16 @@ private String fetchLocationsOrStructures(boolean isJurisdiction, Long serverVer } Response resp; - JSONObject request = new JSONObject(); request.put("is_jurisdiction", isJurisdiction); - String providerId = allSharedPreferences.fetchRegisteredANM(); - String team = allSharedPreferences.fetchDefaultTeam(providerId); - - locationSyncTrace.putAttribute("team", team); - locationSyncTrace.putAttribute("action", "fetch"); if (isJurisdiction) { - locationSyncTrace.putAttribute("type", "location"); + String preferenceLocationNames = allSharedPreferences.getPreference(OPERATIONAL_AREAS); request.put("location_names", new JSONArray(Arrays.asList(preferenceLocationNames.split(",")))); } else { - locationSyncTrace.putAttribute("type", "structure"); request.put("parent_id", new JSONArray(Arrays.asList(locationFilterValue.split(",")))); } request.put("serverVersion", serverVersion); - locationSyncTrace.start(); resp = httpAgent.post( MessageFormat.format("{0}{1}", @@ -153,7 +169,6 @@ private String fetchLocationsOrStructures(boolean isJurisdiction, Long serverVer if (resp.isFailure()) { throw new NoHttpResponseException(LOCATION_STRUCTURE_URL + " not returned data"); } - locationSyncTrace.stop(); return resp.payload().toString(); } @@ -238,6 +253,12 @@ public void syncCreatedStructureToServer() { if (!locations.isEmpty()) { String jsonPayload = locationGson.toJson(locations); String baseUrl = CoreLibrary.getInstance().context().configuration().dristhiBaseURL(); + + locationSyncTrace.putAttribute(TEAM, team); + locationSyncTrace.putAttribute(ACTION, PUSH); + locationSyncTrace.putAttribute(TYPE, STRUCTURE); + locationSyncTrace.putAttribute(COUNT, String.valueOf(locations.size())); + locationSyncTrace.start(); Response response = httpAgent.postWithJsonResponse( MessageFormat.format("{0}/{1}", baseUrl, @@ -247,7 +268,7 @@ public void syncCreatedStructureToServer() { Timber.e("Failed to create new locations on server: %s", response.payload()); return; } - + locationSyncTrace.stop(); Set unprocessedIds = new HashSet<>(); if (StringUtils.isNotBlank(response.payload())) { if (response.payload().startsWith(LOCATIONS_NOT_PROCESSED)) { diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java index f4d2586411..e19f601b20 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java @@ -30,6 +30,12 @@ import timber.log.Timber; +import static org.smartregister.AllConstants.COUNT; +import static org.smartregister.AllConstants.PerformanceMonitoring.ACTION; +import static org.smartregister.AllConstants.PerformanceMonitoring.FETCH; +import static org.smartregister.AllConstants.PerformanceMonitoring.PLAN_SYNC; +import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; + /** * Created by Vincent Karuri on 08/05/2019 */ @@ -60,7 +66,7 @@ private PlanIntentServiceHelper(PlanDefinitionRepository planRepository, Locatio this.context = CoreLibrary.getInstance().context().applicationContext(); this.planDefinitionRepository = planRepository; this.locationRepository = locationRepository; - this.planSyncTrace = FirebasePerformance.getInstance().newTrace("plan_sync"); + this.planSyncTrace = FirebasePerformance.getInstance().newTrace(PLAN_SYNC); } public void syncPlans() { @@ -78,9 +84,21 @@ public void syncPlans() { Long maxServerVersion = 0l; String organizationIds = allSharedPreferences.getPreference(AllConstants.ORGANIZATION_IDS); + + String providerId = allSharedPreferences.fetchRegisteredANM(); + String team = allSharedPreferences.fetchDefaultTeam(providerId); + + planSyncTrace.putAttribute(TEAM, team); + planSyncTrace.putAttribute(ACTION, FETCH); + + planSyncTrace.start(); String plansResponse = fetchPlans(Arrays.asList(organizationIds.split(",")), serverVersion); + List plans = gson.fromJson(plansResponse, new TypeToken>() { }.getType()); + + planSyncTrace.putAttribute(COUNT, String.valueOf(plans.size())); + planSyncTrace.stop(); for (PlanDefinition plan : plans) { try { planDefinitionRepository.addOrUpdate(plan); @@ -98,10 +116,6 @@ public void syncPlans() { } private String fetchPlans(List organizationIds, long serverVersion) throws Exception { - String providerId = allSharedPreferences.fetchRegisteredANM(); - String team = allSharedPreferences.fetchDefaultTeam(providerId); - planSyncTrace.putAttribute("team", team); - planSyncTrace.putAttribute("action", "fetch"); HTTPAgent httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); String baseUrl = CoreLibrary.getInstance().context().configuration().dristhiBaseURL(); String endString = "/"; @@ -114,7 +128,6 @@ private String fetchPlans(List organizationIds, long serverVersion) thro request.put("organizations", new JSONArray(organizationIds)); } request.put("serverVersion", serverVersion); - planSyncTrace.start(); if (httpAgent == null) { context.sendBroadcast(Utils.completeSync(FetchStatus.noConnection)); @@ -131,7 +144,6 @@ private String fetchPlans(List organizationIds, long serverVersion) thro context.sendBroadcast(Utils.completeSync(FetchStatus.nothingFetched)); throw new NoHttpResponseException(SYNC_PLANS_URL + " did not return any data"); } - planSyncTrace.stop(); return resp.payload().toString(); } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java index eabab8d53c..07e563d8e9 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java @@ -35,6 +35,13 @@ import timber.log.Timber; +import static org.smartregister.AllConstants.COUNT; +import static org.smartregister.AllConstants.PerformanceMonitoring.ACTION; +import static org.smartregister.AllConstants.PerformanceMonitoring.FETCH; +import static org.smartregister.AllConstants.PerformanceMonitoring.PUSH; +import static org.smartregister.AllConstants.PerformanceMonitoring.TASK_SYNC; +import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; + public class TaskServiceHelper { private AllSharedPreferences allSharedPreferences = CoreLibrary.getInstance().context().allSharedPreferences(); @@ -56,6 +63,8 @@ public class TaskServiceHelper { private Trace taskSyncTrace; + private String team; + /** * If set to false tasks will sync by owner otherwise defaults to sync by group identifier * @param syncByGroupIdentifier flag for determining if tasks should be synced by group identifier @@ -80,7 +89,9 @@ public static TaskServiceHelper getInstance() { public TaskServiceHelper(TaskRepository taskRepository) { this.context = CoreLibrary.getInstance().context().applicationContext(); this.taskRepository = taskRepository; - this.taskSyncTrace = FirebasePerformance.getInstance().newTrace("task_sync"); + this.taskSyncTrace = FirebasePerformance.getInstance().newTrace(TASK_SYNC); + String providerId = allSharedPreferences.fetchRegisteredANM(); + team = allSharedPreferences.fetchDefaultTeam(providerId); } public List syncTasks() { @@ -109,9 +120,17 @@ public List fetchTasksFromServer() { if (serverVersion > 0) serverVersion += 1; try { long maxServerVersion = 0L; + + taskSyncTrace.putAttribute(TEAM, team); + taskSyncTrace.putAttribute(ACTION, FETCH); + + taskSyncTrace.start(); String tasksResponse = fetchTasks(planDefinitions, groups, serverVersion); List tasks = taskGson.fromJson(tasksResponse, new TypeToken>() { }.getType()); + + taskSyncTrace.putAttribute(COUNT, String.valueOf(tasks.size())); + taskSyncTrace.stop(); if (tasks != null && tasks.size() > 0) { for (Task task : tasks) { try { @@ -149,19 +168,12 @@ private String fetchTasks(Set plan, List group, Long serverVersi throw new IllegalArgumentException(SYNC_TASK_URL + " http agent is null"); } - String providerId = allSharedPreferences.fetchRegisteredANM(); - String team = allSharedPreferences.fetchDefaultTeam(providerId); - taskSyncTrace.putAttribute("team", team); - taskSyncTrace.putAttribute("action", "fetch"); - - taskSyncTrace.start(); Response resp = httpAgent.post(MessageFormat.format("{0}{1}", baseUrl, SYNC_TASK_URL), request.toString()); if (resp.isFailure()) { throw new NoHttpResponseException(SYNC_TASK_URL + " not returned data"); } - taskSyncTrace.stop(); return resp.payload().toString(); } @@ -236,6 +248,10 @@ public void syncCreatedTaskToServer() { HTTPAgent httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); List tasks = taskRepository.getAllUnsynchedCreatedTasks(); if (!tasks.isEmpty()) { + taskSyncTrace.putAttribute(TEAM, team); + taskSyncTrace.putAttribute(ACTION, PUSH); + taskSyncTrace.putAttribute(COUNT, String.valueOf(tasks)); + taskSyncTrace.start(); String jsonPayload = taskGson.toJson(tasks); String baseUrl = CoreLibrary.getInstance().context().configuration().dristhiBaseURL(); Response response = httpAgent.postWithJsonResponse( @@ -243,6 +259,7 @@ public void syncCreatedTaskToServer() { baseUrl, ADD_TASK_URL), jsonPayload); + taskSyncTrace.stop(); if (response.isFailure()) { Timber.e("Failed to create new tasks on server.: %s", response.payload()); return; diff --git a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java index 42257ec078..27210d09d0 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java @@ -37,6 +37,13 @@ import timber.log.Timber; +import static org.smartregister.AllConstants.COUNT; +import static org.smartregister.AllConstants.PerformanceMonitoring.ACTION; +import static org.smartregister.AllConstants.PerformanceMonitoring.EVENT_SYNC; +import static org.smartregister.AllConstants.PerformanceMonitoring.FETCH; +import static org.smartregister.AllConstants.PerformanceMonitoring.PUSH; +import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; + public class SyncIntentService extends BaseSyncIntentService { public static final String SYNC_URL = "/rest/event/sync"; protected static final int EVENT_PULL_LIMIT = 250; @@ -46,6 +53,7 @@ public class SyncIntentService extends BaseSyncIntentService { private HTTPAgent httpAgent; private SyncUtils syncUtils; private Trace eventSyncTrace; + private String team; private AllSharedPreferences allSharedPreferences = CoreLibrary.getInstance().context().allSharedPreferences(); @@ -61,7 +69,9 @@ protected void init(@NonNull Context context) { this.context = context; httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); syncUtils = new SyncUtils(getBaseContext()); - eventSyncTrace = FirebasePerformance.getInstance().newTrace("event_sync"); + eventSyncTrace = FirebasePerformance.getInstance().newTrace(EVENT_SYNC); + String providerId = allSharedPreferences.fetchRegisteredANM(); + team = allSharedPreferences.fetchDefaultTeam(providerId); } @Override @@ -113,13 +123,7 @@ private void doSync() { } protected void pullECFromServer() { - String providerId = allSharedPreferences.fetchRegisteredANM(); - String team = allSharedPreferences.fetchDefaultTeam(providerId); - eventSyncTrace.putAttribute("team", team); - eventSyncTrace.putAttribute("action", "fetch"); - eventSyncTrace.start(); fetchRetry(0); - eventSyncTrace.stop(); } private synchronized void fetchRetry(final int count) { @@ -144,6 +148,10 @@ private synchronized void fetchRetry(final int count) { complete(FetchStatus.fetchedFailed); } + eventSyncTrace.putAttribute(TEAM, team); + eventSyncTrace.putAttribute(ACTION, FETCH); + eventSyncTrace.start(); + String url = baseUrl + SYNC_URL; Response resp; if (configs.isSyncUsingPost()) { @@ -201,6 +209,8 @@ private synchronized void fetchRetry(final int count) { } fetchRetry(0); } + eventSyncTrace.putAttribute(COUNT, String.valueOf(eCount)); + eventSyncTrace.stop(); } catch (Exception e) { Timber.e(e, "Fetch Retry Exception: %s", e.getMessage()); fetchFailed(count); @@ -268,6 +278,10 @@ private boolean pushECToServer() { Timber.e(e); } String jsonPayload = request.toString(); + eventSyncTrace.putAttribute(TEAM, team); + eventSyncTrace.putAttribute(ACTION, PUSH); + eventSyncTrace.putAttribute(COUNT, String.valueOf(eventsUploadedCount)); + eventSyncTrace.start(); Response response = httpAgent.post( MessageFormat.format("{0}/{1}", baseUrl, @@ -277,6 +291,7 @@ private boolean pushECToServer() { Timber.e("Events sync failed."); isSuccessfulPushSync = false; } + eventSyncTrace.stop(); db.markEventsAsSynced(pendingEvents); Timber.i("Events synced successfully."); updateProgress(eventsUploadedCount, totalEventCount); From 370f957f06249001a7658107be3c65f2dd6db47f Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 18 Jun 2020 16:01:29 +0300 Subject: [PATCH 04/24] Fix merge conflicts --- .../org/smartregister/sync/helper/LocationServiceHelper.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java index 53c6ad69e7..de35bc36da 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java @@ -38,11 +38,10 @@ import timber.log.Timber; +import static org.smartregister.AllConstants.COUNT; import static org.smartregister.AllConstants.LocationConstants.DISPLAY; -import static org.smartregister.AllConstants.LocationConstants.LOCATION; import static org.smartregister.AllConstants.LocationConstants.LOCATIONS; import static org.smartregister.AllConstants.LocationConstants.SPECIAL_TAG_FOR_OPENMRS_TEAM_MEMBERS; -import static org.smartregister.AllConstants.LocationConstants.TEAM; import static org.smartregister.AllConstants.LocationConstants.UUID; import static org.smartregister.AllConstants.OPERATIONAL_AREAS; import static org.smartregister.AllConstants.PerformanceMonitoring.ACTION; @@ -261,7 +260,7 @@ public void syncCreatedStructureToServer() { locationSyncTrace.putAttribute(TYPE, STRUCTURE); locationSyncTrace.putAttribute(COUNT, String.valueOf(locations.size())); locationSyncTrace.start(); - Response response = httpAgent.postWithJsonResponse( + Response response = getHttpAgent().postWithJsonResponse( MessageFormat.format("{0}/{1}", baseUrl, CREATE_STRUCTURE_URL), From df6e5445ebd040158782b944615c05542ef9d3df Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 22 Jun 2020 11:25:00 +0300 Subject: [PATCH 05/24] Refactor sync trace logic for locations --- .../sync/helper/LocationServiceHelper.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java index a8b3def085..98507f437a 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java @@ -103,12 +103,10 @@ protected List syncLocationsStructures(boolean isJurisdiction) { try { List parentIds = locationRepository.getAllLocationIds(); - locationSyncTrace.putAttribute(TEAM, team); - locationSyncTrace.putAttribute(ACTION, FETCH); if (isJurisdiction) { - locationSyncTrace.putAttribute(TYPE, LOCATION); + startTrace(FETCH, LOCATION, 0); } else { - locationSyncTrace.putAttribute(TYPE, STRUCTURE); + startTrace(FETCH, STRUCTURE, 0); } locationSyncTrace.start(); String featureResponse = fetchLocationsOrStructures(isJurisdiction, serverVersion, TextUtils.join(",", parentIds)); @@ -256,11 +254,7 @@ public void syncCreatedStructureToServer() { if (!locations.isEmpty()) { String jsonPayload = locationGson.toJson(locations); String baseUrl = CoreLibrary.getInstance().context().configuration().dristhiBaseURL(); - locationSyncTrace.putAttribute(TEAM, team); - locationSyncTrace.putAttribute(ACTION, PUSH); - locationSyncTrace.putAttribute(TYPE, STRUCTURE); - locationSyncTrace.putAttribute(COUNT, String.valueOf(locations.size())); - locationSyncTrace.start(); + startTrace(PUSH, STRUCTURE, locations.size()); Response response = getHttpAgent().postWithJsonResponse( MessageFormat.format("{0}/{1}", baseUrl, @@ -284,6 +278,15 @@ public void syncCreatedStructureToServer() { } } + private void startTrace(String action, String type, int count) { + locationSyncTrace.getAttributes().clear(); + locationSyncTrace.putAttribute(TEAM, team); + locationSyncTrace.putAttribute(ACTION, action); + locationSyncTrace.putAttribute(TYPE, type); + locationSyncTrace.putAttribute(COUNT, String.valueOf(count)); + locationSyncTrace.start(); + } + public void syncUpdatedLocationsToServer() { HTTPAgent httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); List locations = locationRepository.getAllUnsynchedLocation(); From 29824dcec361e09883375ab705dd6ab0a276045b Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 22 Jun 2020 13:23:27 +0300 Subject: [PATCH 06/24] Refactor task trace logic --- .../sync/helper/LocationServiceHelper.java | 8 ++++---- .../sync/helper/TaskServiceHelper.java | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java index 98507f437a..b2a3685183 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java @@ -104,9 +104,9 @@ protected List syncLocationsStructures(boolean isJurisdiction) { List parentIds = locationRepository.getAllLocationIds(); if (isJurisdiction) { - startTrace(FETCH, LOCATION, 0); + startLocationTrace(FETCH, LOCATION, 0); } else { - startTrace(FETCH, STRUCTURE, 0); + startLocationTrace(FETCH, STRUCTURE, 0); } locationSyncTrace.start(); String featureResponse = fetchLocationsOrStructures(isJurisdiction, serverVersion, TextUtils.join(",", parentIds)); @@ -254,7 +254,7 @@ public void syncCreatedStructureToServer() { if (!locations.isEmpty()) { String jsonPayload = locationGson.toJson(locations); String baseUrl = CoreLibrary.getInstance().context().configuration().dristhiBaseURL(); - startTrace(PUSH, STRUCTURE, locations.size()); + startLocationTrace(PUSH, STRUCTURE, locations.size()); Response response = getHttpAgent().postWithJsonResponse( MessageFormat.format("{0}/{1}", baseUrl, @@ -278,7 +278,7 @@ public void syncCreatedStructureToServer() { } } - private void startTrace(String action, String type, int count) { + private void startLocationTrace(String action, String type, int count) { locationSyncTrace.getAttributes().clear(); locationSyncTrace.putAttribute(TEAM, team); locationSyncTrace.putAttribute(ACTION, action); diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java index 07e563d8e9..d7dcdf87d8 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java @@ -121,10 +121,7 @@ public List fetchTasksFromServer() { try { long maxServerVersion = 0L; - taskSyncTrace.putAttribute(TEAM, team); - taskSyncTrace.putAttribute(ACTION, FETCH); - - taskSyncTrace.start(); + startTaskTrace(FETCH, 0); String tasksResponse = fetchTasks(planDefinitions, groups, serverVersion); List tasks = taskGson.fromJson(tasksResponse, new TypeToken>() { }.getType()); @@ -248,10 +245,7 @@ public void syncCreatedTaskToServer() { HTTPAgent httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); List tasks = taskRepository.getAllUnsynchedCreatedTasks(); if (!tasks.isEmpty()) { - taskSyncTrace.putAttribute(TEAM, team); - taskSyncTrace.putAttribute(ACTION, PUSH); - taskSyncTrace.putAttribute(COUNT, String.valueOf(tasks)); - taskSyncTrace.start(); + startTaskTrace(PUSH, tasks.size()); String jsonPayload = taskGson.toJson(tasks); String baseUrl = CoreLibrary.getInstance().context().configuration().dristhiBaseURL(); Response response = httpAgent.postWithJsonResponse( @@ -277,5 +271,13 @@ public void syncCreatedTaskToServer() { } } + + private void startTaskTrace(String action, int count) { + taskSyncTrace.getAttributes().clear(); + taskSyncTrace.putAttribute(TEAM, team); + taskSyncTrace.putAttribute(ACTION, action); + taskSyncTrace.putAttribute(COUNT, String.valueOf(count)); + taskSyncTrace.start(); + } } From 0d6dca7f6caed2cbd62ca626c7a50bd4788ab695 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 22 Jun 2020 13:35:39 +0300 Subject: [PATCH 07/24] Refactor trace logic for events --- .../sync/intent/SyncIntentService.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java index 27210d09d0..89ef769fe4 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java @@ -148,9 +148,7 @@ private synchronized void fetchRetry(final int count) { complete(FetchStatus.fetchedFailed); } - eventSyncTrace.putAttribute(TEAM, team); - eventSyncTrace.putAttribute(ACTION, FETCH); - eventSyncTrace.start(); + startEventTrace(FETCH, 0); String url = baseUrl + SYNC_URL; Response resp; @@ -278,10 +276,7 @@ private boolean pushECToServer() { Timber.e(e); } String jsonPayload = request.toString(); - eventSyncTrace.putAttribute(TEAM, team); - eventSyncTrace.putAttribute(ACTION, PUSH); - eventSyncTrace.putAttribute(COUNT, String.valueOf(eventsUploadedCount)); - eventSyncTrace.start(); + startEventTrace(PUSH, eventsUploadedCount); Response response = httpAgent.post( MessageFormat.format("{0}/{1}", baseUrl, @@ -300,6 +295,14 @@ private boolean pushECToServer() { return isSuccessfulPushSync; } + private void startEventTrace(String action, int count) { + eventSyncTrace.getAttributes().clear(); + eventSyncTrace.putAttribute(TEAM, team); + eventSyncTrace.putAttribute(ACTION, action); + eventSyncTrace.putAttribute(COUNT, String.valueOf(count)); + eventSyncTrace.start(); + } + private void sendSyncStatusBroadcastMessage(FetchStatus fetchStatus) { Intent intent = new Intent(); intent.setAction(SyncStatusBroadcastReceiver.ACTION_SYNC_STATUS); From 524721e903c0b9f306bc5e069f40ad0ea731e8c2 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 22 Jun 2020 13:52:12 +0300 Subject: [PATCH 08/24] Refactor trace loggic for plans --- .../sync/helper/PlanIntentServiceHelper.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java index e19f601b20..139d1f0a86 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java @@ -85,13 +85,7 @@ public void syncPlans() { String organizationIds = allSharedPreferences.getPreference(AllConstants.ORGANIZATION_IDS); - String providerId = allSharedPreferences.fetchRegisteredANM(); - String team = allSharedPreferences.fetchDefaultTeam(providerId); - - planSyncTrace.putAttribute(TEAM, team); - planSyncTrace.putAttribute(ACTION, FETCH); - - planSyncTrace.start(); + startPlanTrace(FETCH); String plansResponse = fetchPlans(Arrays.asList(organizationIds.split(",")), serverVersion); List plans = gson.fromJson(plansResponse, new TypeToken>() { @@ -115,6 +109,14 @@ public void syncPlans() { } } + private void startPlanTrace(String action) { + String providerId = allSharedPreferences.fetchRegisteredANM(); + String team = allSharedPreferences.fetchDefaultTeam(providerId); + planSyncTrace.putAttribute(TEAM, team); + planSyncTrace.putAttribute(ACTION, action); + planSyncTrace.start(); + } + private String fetchPlans(List organizationIds, long serverVersion) throws Exception { HTTPAgent httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); String baseUrl = CoreLibrary.getInstance().context().configuration().dristhiBaseURL(); From 75fe0cd493bcdfe5716c65158daecbacc1334c6f Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 25 Jan 2021 14:44:29 +0300 Subject: [PATCH 09/24] Add config for using firebase performance monitoring --- .../src/main/java/org/smartregister/SyncConfiguration.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opensrp-app/src/main/java/org/smartregister/SyncConfiguration.java b/opensrp-app/src/main/java/org/smartregister/SyncConfiguration.java index f49669fcf6..611e270e9e 100644 --- a/opensrp-app/src/main/java/org/smartregister/SyncConfiguration.java +++ b/opensrp-app/src/main/java/org/smartregister/SyncConfiguration.java @@ -184,4 +184,8 @@ public int getMaxAuthenticationRetries() { public abstract Class getAuthenticationActivity(); + public boolean firebasePerformanceMonitoringEnabled() { + return false; + } + } From 7d03efbf9b9cece9fae0ebdeb9c892e064f733aa Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 25 Jan 2021 14:45:09 +0300 Subject: [PATCH 10/24] Add performance monitoring utils --- .../util/PerformanceMonitoringUtils.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 opensrp-app/src/main/java/org/smartregister/util/PerformanceMonitoringUtils.java diff --git a/opensrp-app/src/main/java/org/smartregister/util/PerformanceMonitoringUtils.java b/opensrp-app/src/main/java/org/smartregister/util/PerformanceMonitoringUtils.java new file mode 100644 index 0000000000..61ef0a747d --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/util/PerformanceMonitoringUtils.java @@ -0,0 +1,42 @@ +package org.smartregister.util; + +import com.google.firebase.perf.metrics.Trace; + +import org.smartregister.CoreLibrary; +import org.smartregister.SyncConfiguration; + +/** + * Created by Richard Kareko on 1/25/21. + */ + +public class PerformanceMonitoringUtils { + + public static void startTrace(Trace trace) { + SyncConfiguration configs = CoreLibrary.getInstance().getSyncConfiguration(); + if (configs.firebasePerformanceMonitoringEnabled()) { + trace.start(); + } + } + + public static void stopTrace(Trace trace) { + SyncConfiguration configs = CoreLibrary.getInstance().getSyncConfiguration(); + if (configs.firebasePerformanceMonitoringEnabled()) { + trace.stop(); + } + } + + public static void addAttribute(Trace trace, String attribute, String value) { + SyncConfiguration configs = CoreLibrary.getInstance().getSyncConfiguration(); + if (configs.firebasePerformanceMonitoringEnabled()) { + trace.putAttribute(attribute, value); + } + } + + public static void clearTraceAttributes(Trace trace) { + SyncConfiguration configs = CoreLibrary.getInstance().getSyncConfiguration(); + if (configs.firebasePerformanceMonitoringEnabled()) { + trace.getAttributes().clear(); + } + } + +} From 063dac6418249a72a7e5dadaab66624fcdbb4028 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 25 Jan 2021 14:46:08 +0300 Subject: [PATCH 11/24] Refactor SyncIntentService to use utils --- .../sync/intent/SyncIntentService.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java index 0a16ebf011..067d5f11fb 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java @@ -2,13 +2,12 @@ import android.content.Context; import android.content.Intent; +import android.util.Pair; import androidx.annotation.IntRange; import androidx.annotation.NonNull; import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import android.util.Pair; - import com.google.firebase.perf.FirebasePerformance; import com.google.firebase.perf.metrics.Trace; @@ -50,6 +49,10 @@ import static org.smartregister.AllConstants.PerformanceMonitoring.FETCH; import static org.smartregister.AllConstants.PerformanceMonitoring.PUSH; import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; +import static org.smartregister.util.PerformanceMonitoringUtils.addAttribute; +import static org.smartregister.util.PerformanceMonitoringUtils.clearTraceAttributes; +import static org.smartregister.util.PerformanceMonitoringUtils.startTrace; +import static org.smartregister.util.PerformanceMonitoringUtils.stopTrace; public class SyncIntentService extends BaseSyncIntentService { public static final String SYNC_URL = "/rest/event/sync"; @@ -233,8 +236,8 @@ private void processFetchedEvents(Response resp, ECSyncHelper ecSyncUpdater, fin } sendSyncProgressBroadcast(eCount); fetchRetry(0, false); - eventSyncTrace.putAttribute(COUNT, String.valueOf(eCount)); - eventSyncTrace.stop(); + addAttribute(eventSyncTrace, COUNT, String.valueOf(eCount)); + stopTrace(eventSyncTrace); } } @@ -313,7 +316,7 @@ private boolean pushECToServer(EventClientRepository db) { db.markEventsAsSynced(pendingEvents); Timber.i("Events synced successfully."); } - eventSyncTrace.stop(); + stopTrace(eventSyncTrace); updateProgress(eventsUploadedCount, totalEventCount); } @@ -321,11 +324,14 @@ private boolean pushECToServer(EventClientRepository db) { } private void startEventTrace(String action, int count) { - eventSyncTrace.getAttributes().clear(); - eventSyncTrace.putAttribute(TEAM, team); - eventSyncTrace.putAttribute(ACTION, action); - eventSyncTrace.putAttribute(COUNT, String.valueOf(count)); - eventSyncTrace.start(); + SyncConfiguration configs = CoreLibrary.getInstance().getSyncConfiguration(); + if (configs.firebasePerformanceMonitoringEnabled()) { + clearTraceAttributes(eventSyncTrace); + addAttribute(eventSyncTrace, TEAM, team); + addAttribute(eventSyncTrace, ACTION, action); + addAttribute(eventSyncTrace, COUNT, String.valueOf(count)); + startTrace(eventSyncTrace); + } } private void sendSyncStatusBroadcastMessage(FetchStatus fetchStatus) { From 488eee240135e7812673684a0d902f7cddd534ca Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 25 Jan 2021 15:06:22 +0300 Subject: [PATCH 12/24] Refactor PlanIntentServiceHelper to use utils --- .../sync/helper/PlanIntentServiceHelper.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java index d7efc182bd..923d227ba2 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java @@ -4,8 +4,6 @@ import com.google.firebase.perf.FirebasePerformance; import com.google.firebase.perf.metrics.Trace; -import androidx.annotation.VisibleForTesting; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -40,6 +38,9 @@ import static org.smartregister.AllConstants.PerformanceMonitoring.FETCH; import static org.smartregister.AllConstants.PerformanceMonitoring.PLAN_SYNC; import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; +import static org.smartregister.util.PerformanceMonitoringUtils.addAttribute; +import static org.smartregister.util.PerformanceMonitoringUtils.startTrace; +import static org.smartregister.util.PerformanceMonitoringUtils.stopTrace; /** * Created by Vincent Karuri on 08/05/2019 @@ -111,8 +112,8 @@ private int batchFetchPlansFromServer(boolean returnCount) { List plans = gson.fromJson(plansResponse, new TypeToken>() { }.getType()); - planSyncTrace.putAttribute(COUNT, String.valueOf(plans.size())); - planSyncTrace.stop(); + addAttribute(planSyncTrace, COUNT, String.valueOf(plans.size())); + stopTrace(planSyncTrace); for (PlanDefinition plan : plans) { try { planDefinitionRepository.addOrUpdate(plan); @@ -141,9 +142,9 @@ private int batchFetchPlansFromServer(boolean returnCount) { private void startPlanTrace(String action) { String providerId = allSharedPreferences.fetchRegisteredANM(); String team = allSharedPreferences.fetchDefaultTeam(providerId); - planSyncTrace.putAttribute(TEAM, team); - planSyncTrace.putAttribute(ACTION, action); - planSyncTrace.start(); + addAttribute(planSyncTrace, TEAM, team); + addAttribute(planSyncTrace, ACTION, action); + startTrace(planSyncTrace); } private String fetchPlans(List organizationIds, long serverVersion, boolean returnCount) throws Exception { From 383ce2b8da7a9de191b31102778a6ebc3d4493ef Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 25 Jan 2021 15:11:38 +0300 Subject: [PATCH 13/24] Refactor TaskServiceHelper to use perf monitorig utils --- .../sync/helper/TaskServiceHelper.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java index 8384c1bbf2..18e0b85bdc 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java @@ -46,6 +46,10 @@ import static org.smartregister.AllConstants.PerformanceMonitoring.PUSH; import static org.smartregister.AllConstants.PerformanceMonitoring.TASK_SYNC; import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; +import static org.smartregister.util.PerformanceMonitoringUtils.addAttribute; +import static org.smartregister.util.PerformanceMonitoringUtils.clearTraceAttributes; +import static org.smartregister.util.PerformanceMonitoringUtils.startTrace; +import static org.smartregister.util.PerformanceMonitoringUtils.stopTrace; public class TaskServiceHelper extends BaseHelper { @@ -150,8 +154,8 @@ private List batchFetchTasksFromServer(Set planDefinitions, List tasks = taskGson.fromJson(tasksResponse, new TypeToken>() { }.getType()); - taskSyncTrace.putAttribute(COUNT, String.valueOf(tasks.size())); - taskSyncTrace.stop(); + addAttribute(taskSyncTrace, COUNT, String.valueOf(tasks.size())); + stopTrace(taskSyncTrace); if (tasks != null && tasks.size() > 0) { for (Task task : tasks) { try { @@ -287,7 +291,7 @@ public void syncCreatedTaskToServer() { baseUrl, ADD_TASK_URL), jsonPayload); - taskSyncTrace.stop(); + stopTrace(taskSyncTrace); if (response.isFailure()) { Timber.e("Failed to create new tasks on server.: %s", response.payload()); return; @@ -311,11 +315,11 @@ private HTTPAgent getHttpAgent() { } private void startTaskTrace(String action, int count) { - taskSyncTrace.getAttributes().clear(); - taskSyncTrace.putAttribute(TEAM, team); - taskSyncTrace.putAttribute(ACTION, action); - taskSyncTrace.putAttribute(COUNT, String.valueOf(count)); - taskSyncTrace.start(); + clearTraceAttributes(taskSyncTrace); + addAttribute(taskSyncTrace, TEAM, team); + addAttribute(taskSyncTrace, ACTION, action); + addAttribute(taskSyncTrace, COUNT, String.valueOf(count)); + startTrace(taskSyncTrace); } } From e8a1dfbb35df4281a752d747bc11a2c16969203f Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 25 Jan 2021 15:18:51 +0300 Subject: [PATCH 14/24] Refactor LocationServiceHelper to use perf monitoring utils --- .../sync/helper/LocationServiceHelper.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java index f2442e041e..fd2dc74195 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java @@ -3,10 +3,10 @@ import android.content.Context; import android.text.TextUtils; -import com.google.firebase.perf.FirebasePerformance; -import com.google.firebase.perf.metrics.Trace; import androidx.annotation.Nullable; +import com.google.firebase.perf.FirebasePerformance; +import com.google.firebase.perf.metrics.Trace; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -60,8 +60,12 @@ import static org.smartregister.AllConstants.PerformanceMonitoring.LOCATION_SYNC; import static org.smartregister.AllConstants.PerformanceMonitoring.PUSH; import static org.smartregister.AllConstants.PerformanceMonitoring.STRUCTURE; -import static org.smartregister.AllConstants.TYPE; import static org.smartregister.AllConstants.RETURN_COUNT; +import static org.smartregister.AllConstants.TYPE; +import static org.smartregister.util.PerformanceMonitoringUtils.addAttribute; +import static org.smartregister.util.PerformanceMonitoringUtils.clearTraceAttributes; +import static org.smartregister.util.PerformanceMonitoringUtils.startTrace; +import static org.smartregister.util.PerformanceMonitoringUtils.stopTrace; public class LocationServiceHelper extends BaseHelper { @@ -141,13 +145,13 @@ private List batchSyncLocationsStructures(boolean isJurisdiction, List } else { startLocationTrace(FETCH, STRUCTURE, 0); } - locationSyncTrace.start(); + startTrace(locationSyncTrace); String featureResponse = fetchLocationsOrStructures(isJurisdiction, serverVersion, TextUtils.join(",", parentIds), returnCount); List locations = locationGson.fromJson(featureResponse, new TypeToken>() { }.getType()); - locationSyncTrace.putAttribute(COUNT, String.valueOf(locations.size())); - locationSyncTrace.stop(); + addAttribute(locationSyncTrace, COUNT, String.valueOf(locations.size())); + stopTrace(locationSyncTrace); for (Location location : locations) { try { @@ -313,7 +317,7 @@ public void syncCreatedStructureToServer() { Timber.e("Failed to create new locations on server: %s", response.payload()); return; } - locationSyncTrace.stop(); + stopTrace(locationSyncTrace); Set unprocessedIds = new HashSet<>(); if (StringUtils.isNotBlank(response.payload())) { if (response.payload().startsWith(LOCATIONS_NOT_PROCESSED)) { @@ -328,12 +332,12 @@ public void syncCreatedStructureToServer() { } private void startLocationTrace(String action, String type, int count) { - locationSyncTrace.getAttributes().clear(); - locationSyncTrace.putAttribute(AllConstants.PerformanceMonitoring.TEAM, team); - locationSyncTrace.putAttribute(ACTION, action); - locationSyncTrace.putAttribute(TYPE, type); - locationSyncTrace.putAttribute(COUNT, String.valueOf(count)); - locationSyncTrace.start(); + clearTraceAttributes(locationSyncTrace); + addAttribute(locationSyncTrace, AllConstants.PerformanceMonitoring.TEAM, team); + addAttribute(locationSyncTrace, ACTION, action); + addAttribute(locationSyncTrace, TYPE, type); + addAttribute(locationSyncTrace, COUNT, String.valueOf(count)); + startTrace(locationSyncTrace); } public void syncUpdatedLocationsToServer() { From 4a684e476306f2cd1654c5f1c5c60b917db36b50 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 25 Jan 2021 16:13:02 +0300 Subject: [PATCH 15/24] Move initialization of traces to utils --- .../smartregister/sync/helper/LocationServiceHelper.java | 4 ++-- .../sync/helper/PlanIntentServiceHelper.java | 4 ++-- .../org/smartregister/sync/helper/TaskServiceHelper.java | 4 ++-- .../org/smartregister/sync/intent/SyncIntentService.java | 4 ++-- .../smartregister/util/PerformanceMonitoringUtils.java | 9 +++++++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java index fd2dc74195..3d8d683021 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/LocationServiceHelper.java @@ -5,7 +5,6 @@ import androidx.annotation.Nullable; -import com.google.firebase.perf.FirebasePerformance; import com.google.firebase.perf.metrics.Trace; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -64,6 +63,7 @@ import static org.smartregister.AllConstants.TYPE; import static org.smartregister.util.PerformanceMonitoringUtils.addAttribute; import static org.smartregister.util.PerformanceMonitoringUtils.clearTraceAttributes; +import static org.smartregister.util.PerformanceMonitoringUtils.initTrace; import static org.smartregister.util.PerformanceMonitoringUtils.startTrace; import static org.smartregister.util.PerformanceMonitoringUtils.stopTrace; @@ -101,7 +101,7 @@ public LocationServiceHelper(LocationRepository locationRepository, LocationTagR this.locationRepository = locationRepository; this.locationTagRepository = locationTagRepository; this.structureRepository = structureRepository; - this.locationSyncTrace = FirebasePerformance.getInstance().newTrace(LOCATION_SYNC); + this.locationSyncTrace = initTrace(LOCATION_SYNC); String providerId = allSharedPreferences.fetchRegisteredANM(); team = allSharedPreferences.fetchDefaultTeam(providerId); } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java index 923d227ba2..3e80ad4156 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/PlanIntentServiceHelper.java @@ -2,7 +2,6 @@ import android.content.Context; -import com.google.firebase.perf.FirebasePerformance; import com.google.firebase.perf.metrics.Trace; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -39,6 +38,7 @@ import static org.smartregister.AllConstants.PerformanceMonitoring.PLAN_SYNC; import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; import static org.smartregister.util.PerformanceMonitoringUtils.addAttribute; +import static org.smartregister.util.PerformanceMonitoringUtils.initTrace; import static org.smartregister.util.PerformanceMonitoringUtils.startTrace; import static org.smartregister.util.PerformanceMonitoringUtils.stopTrace; @@ -74,7 +74,7 @@ public static PlanIntentServiceHelper getInstance() { private PlanIntentServiceHelper(PlanDefinitionRepository planRepository) { this.context = CoreLibrary.getInstance().context().applicationContext(); this.planDefinitionRepository = planRepository; - this.planSyncTrace = FirebasePerformance.getInstance().newTrace(PLAN_SYNC); + this.planSyncTrace = initTrace(PLAN_SYNC); this.allSharedPreferences = CoreLibrary.getInstance().context().allSharedPreferences(); } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java index 18e0b85bdc..d8502df5e4 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/TaskServiceHelper.java @@ -5,7 +5,6 @@ import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; -import com.google.firebase.perf.FirebasePerformance; import com.google.firebase.perf.metrics.Trace; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -48,6 +47,7 @@ import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; import static org.smartregister.util.PerformanceMonitoringUtils.addAttribute; import static org.smartregister.util.PerformanceMonitoringUtils.clearTraceAttributes; +import static org.smartregister.util.PerformanceMonitoringUtils.initTrace; import static org.smartregister.util.PerformanceMonitoringUtils.startTrace; import static org.smartregister.util.PerformanceMonitoringUtils.stopTrace; @@ -104,7 +104,7 @@ public TaskServiceHelper(TaskRepository taskRepository) { this.context = CoreLibrary.getInstance().context().applicationContext(); this.taskRepository = taskRepository; this.allSharedPreferences = CoreLibrary.getInstance().context().allSharedPreferences(); - this.taskSyncTrace = FirebasePerformance.getInstance().newTrace(TASK_SYNC); + this.taskSyncTrace = initTrace(TASK_SYNC); String providerId = allSharedPreferences.fetchRegisteredANM(); team = allSharedPreferences.fetchDefaultTeam(providerId); } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java index 067d5f11fb..968de1b13f 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java @@ -8,7 +8,6 @@ import androidx.annotation.NonNull; import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import com.google.firebase.perf.FirebasePerformance; import com.google.firebase.perf.metrics.Trace; import org.apache.commons.lang3.StringUtils; @@ -51,6 +50,7 @@ import static org.smartregister.AllConstants.PerformanceMonitoring.TEAM; import static org.smartregister.util.PerformanceMonitoringUtils.addAttribute; import static org.smartregister.util.PerformanceMonitoringUtils.clearTraceAttributes; +import static org.smartregister.util.PerformanceMonitoringUtils.initTrace; import static org.smartregister.util.PerformanceMonitoringUtils.startTrace; import static org.smartregister.util.PerformanceMonitoringUtils.stopTrace; @@ -83,7 +83,7 @@ protected void init(@NonNull Context context) { this.context = context; httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); syncUtils = new SyncUtils(getBaseContext()); - eventSyncTrace = FirebasePerformance.getInstance().newTrace(EVENT_SYNC); + eventSyncTrace = initTrace(EVENT_SYNC); String providerId = allSharedPreferences.fetchRegisteredANM(); team = allSharedPreferences.fetchDefaultTeam(providerId); validateAssignmentHelper = new ValidateAssignmentHelper(syncUtils); diff --git a/opensrp-app/src/main/java/org/smartregister/util/PerformanceMonitoringUtils.java b/opensrp-app/src/main/java/org/smartregister/util/PerformanceMonitoringUtils.java index 61ef0a747d..5ce30a0c1d 100644 --- a/opensrp-app/src/main/java/org/smartregister/util/PerformanceMonitoringUtils.java +++ b/opensrp-app/src/main/java/org/smartregister/util/PerformanceMonitoringUtils.java @@ -1,5 +1,6 @@ package org.smartregister.util; +import com.google.firebase.perf.FirebasePerformance; import com.google.firebase.perf.metrics.Trace; import org.smartregister.CoreLibrary; @@ -11,6 +12,14 @@ public class PerformanceMonitoringUtils { + public static Trace initTrace(String traceName) { + SyncConfiguration configs = CoreLibrary.getInstance().getSyncConfiguration(); + if (configs.firebasePerformanceMonitoringEnabled()) { + return FirebasePerformance.getInstance().newTrace(traceName); + } + return null; + } + public static void startTrace(Trace trace) { SyncConfiguration configs = CoreLibrary.getInstance().getSyncConfiguration(); if (configs.firebasePerformanceMonitoringEnabled()) { From 88d6e883e8b390828a1c7f43d8a821228ab2bafe Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 29 Jan 2021 12:20:00 +0300 Subject: [PATCH 16/24] Add custom trace for client processing --- .../main/java/org/smartregister/AllConstants.java | 1 + .../sync/intent/SyncIntentService.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/AllConstants.java b/opensrp-app/src/main/java/org/smartregister/AllConstants.java index fc70ffae32..776764cb85 100644 --- a/opensrp-app/src/main/java/org/smartregister/AllConstants.java +++ b/opensrp-app/src/main/java/org/smartregister/AllConstants.java @@ -558,5 +558,6 @@ public interface PerformanceMonitoring { String PLAN_SYNC = "plan_sync"; String EVENT_SYNC = "event_sync"; String LOCATION_SYNC = "location_sync"; + String CLIENT_PROCESSING = "client_processing"; } } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java index 968de1b13f..6576c55cc9 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncIntentService.java @@ -44,6 +44,7 @@ import static org.smartregister.AllConstants.COUNT; import static org.smartregister.AllConstants.PerformanceMonitoring.ACTION; +import static org.smartregister.AllConstants.PerformanceMonitoring.CLIENT_PROCESSING; import static org.smartregister.AllConstants.PerformanceMonitoring.EVENT_SYNC; import static org.smartregister.AllConstants.PerformanceMonitoring.FETCH; import static org.smartregister.AllConstants.PerformanceMonitoring.PUSH; @@ -63,6 +64,7 @@ public class SyncIntentService extends BaseSyncIntentService { private HTTPAgent httpAgent; private SyncUtils syncUtils; private Trace eventSyncTrace; + private Trace processClientTrace; private String team; private AllSharedPreferences allSharedPreferences = CoreLibrary.getInstance().context().allSharedPreferences(); @@ -84,6 +86,7 @@ protected void init(@NonNull Context context) { httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); syncUtils = new SyncUtils(getBaseContext()); eventSyncTrace = initTrace(EVENT_SYNC); + processClientTrace = initTrace(CLIENT_PROCESSING); String providerId = allSharedPreferences.fetchRegisteredANM(); team = allSharedPreferences.fetchDefaultTeam(providerId); validateAssignmentHelper = new ValidateAssignmentHelper(syncUtils); @@ -228,16 +231,22 @@ private void processFetchedEvents(Response resp, ECSyncHelper ecSyncUpdater, fin lastServerVersion = serverVersionPair.second; } + addAttribute(eventSyncTrace, COUNT, String.valueOf(eCount)); + stopTrace(eventSyncTrace); + boolean isSaved = ecSyncUpdater.saveAllClientsAndEvents(jsonObject); //update sync time if all event client is save. if (isSaved) { + startTrace(processClientTrace); processClient(serverVersionPair); + addAttribute(processClientTrace, COUNT, String.valueOf(eCount)); + addAttribute(processClientTrace, TEAM, team); + stopTrace(processClientTrace); ecSyncUpdater.updateLastSyncTimeStamp(lastServerVersion); } sendSyncProgressBroadcast(eCount); fetchRetry(0, false); - addAttribute(eventSyncTrace, COUNT, String.valueOf(eCount)); - stopTrace(eventSyncTrace); + } } From 848dbbe3352df22090865b1c3be61406800120f2 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 29 Jan 2021 12:25:22 +0300 Subject: [PATCH 17/24] Update version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d0fee511c6..5a1fe66cc3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=4.2.0-SNAPSHOT +VERSION_NAME=4.2.1-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application From 820732029019ca23531c57725042bba5b8326c52 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 29 Jan 2021 13:13:25 +0300 Subject: [PATCH 18/24] Increase maxHeapSize to 4g --- opensrp-app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-app/build.gradle b/opensrp-app/build.gradle index 5266ddefd7..6d0feeb610 100644 --- a/opensrp-app/build.gradle +++ b/opensrp-app/build.gradle @@ -138,7 +138,7 @@ tasks.withType(Test) { showCauses true showStackTraces true } - maxHeapSize = "2g" + maxHeapSize = "4g" } def filesToCopy = copySpec { From 4b7c46c554b8bd5780374ecb4070e4c35c1b6302 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 29 Jan 2021 14:01:19 +0300 Subject: [PATCH 19/24] Increase maxheapSize to 6g --- opensrp-app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-app/build.gradle b/opensrp-app/build.gradle index 6d0feeb610..068897bf3f 100644 --- a/opensrp-app/build.gradle +++ b/opensrp-app/build.gradle @@ -138,7 +138,7 @@ tasks.withType(Test) { showCauses true showStackTraces true } - maxHeapSize = "4g" + maxHeapSize = "6g" } def filesToCopy = copySpec { From 2a8ff1e6867c32b226b41129ecb56930fb5b38d8 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 29 Jan 2021 16:14:43 +0300 Subject: [PATCH 20/24] Fix failing tests --- opensrp-app/build.gradle | 2 +- .../java/org/smartregister/repository/FormDataRepository.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/opensrp-app/build.gradle b/opensrp-app/build.gradle index 068897bf3f..6d0feeb610 100644 --- a/opensrp-app/build.gradle +++ b/opensrp-app/build.gradle @@ -138,7 +138,7 @@ tasks.withType(Test) { showCauses true showStackTraces true } - maxHeapSize = "6g" + maxHeapSize = "4g" } def filesToCopy = copySpec { diff --git a/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java b/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java index 1d3ce62bd9..7a71ec8334 100755 --- a/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java @@ -9,6 +9,7 @@ import net.sqlcipher.database.SQLiteDatabase; +import org.apache.commons.lang3.StringUtils; import org.smartregister.Context; import org.smartregister.CoreLibrary; import org.smartregister.domain.SyncStatus; @@ -64,7 +65,7 @@ public FormDataRepository() { .put(MotherRepository.MOTHER_TABLE_NAME, MotherRepository.MOTHER_TABLE_COLUMNS); TABLE_COLUMN_MAP.put(ChildRepository.CHILD_TABLE_NAME, ChildRepository.CHILD_TABLE_COLUMNS); - if (CoreLibrary.getInstance().context().configuration().appName().equals(APP_NAME_INDONESIA)) { + if (StringUtils.isNotBlank(CoreLibrary.getInstance().context().configuration().appName()) && CoreLibrary.getInstance().context().configuration().appName().equals(APP_NAME_INDONESIA)) { return; } From 96cddf96dd64080cd5b45c8bd0e2d6d70f160f7e Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 2 Feb 2021 14:51:58 +0300 Subject: [PATCH 21/24] Update version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 5a1fe66cc3..5c8552da0d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=4.2.1-SNAPSHOT +VERSION_NAME=4.2.2-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application From fdc5e869ae16bf52db2adfe3c06d672baae104e4 Mon Sep 17 00:00:00 2001 From: Rkareko <47570855+Rkareko@users.noreply.github.com> Date: Tue, 2 Feb 2021 18:18:03 +0300 Subject: [PATCH 22/24] Update opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java Co-authored-by: Samuel Githengi --- .../java/org/smartregister/repository/FormDataRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java b/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java index 7a71ec8334..bfdfff6140 100755 --- a/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java @@ -65,7 +65,7 @@ public FormDataRepository() { .put(MotherRepository.MOTHER_TABLE_NAME, MotherRepository.MOTHER_TABLE_COLUMNS); TABLE_COLUMN_MAP.put(ChildRepository.CHILD_TABLE_NAME, ChildRepository.CHILD_TABLE_COLUMNS); - if (StringUtils.isNotBlank(CoreLibrary.getInstance().context().configuration().appName()) && CoreLibrary.getInstance().context().configuration().appName().equals(APP_NAME_INDONESIA)) { + if (APP_NAME_INDONESIA.equals(CoreLibrary.getInstance().context().configuration().appName()) { return; } From d9758f425b0344e87dea9364abc2a33e010d9177 Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 2 Feb 2021 19:02:07 +0300 Subject: [PATCH 23/24] Fix buidl error --- .../java/org/smartregister/repository/FormDataRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java b/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java index bfdfff6140..f6974ef110 100755 --- a/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java @@ -65,7 +65,7 @@ public FormDataRepository() { .put(MotherRepository.MOTHER_TABLE_NAME, MotherRepository.MOTHER_TABLE_COLUMNS); TABLE_COLUMN_MAP.put(ChildRepository.CHILD_TABLE_NAME, ChildRepository.CHILD_TABLE_COLUMNS); - if (APP_NAME_INDONESIA.equals(CoreLibrary.getInstance().context().configuration().appName()) { + if (APP_NAME_INDONESIA.equals(CoreLibrary.getInstance().context().configuration().appName())) { return; } From fdfce8af93897974e2bb38a75260044d01fb110f Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 3 Feb 2021 09:38:29 +0300 Subject: [PATCH 24/24] Remove unused imports --- .../java/org/smartregister/repository/FormDataRepository.java | 1 - 1 file changed, 1 deletion(-) diff --git a/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java b/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java index f6974ef110..53a388b7ca 100755 --- a/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/FormDataRepository.java @@ -9,7 +9,6 @@ import net.sqlcipher.database.SQLiteDatabase; -import org.apache.commons.lang3.StringUtils; import org.smartregister.Context; import org.smartregister.CoreLibrary; import org.smartregister.domain.SyncStatus;