Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merge and without merge count for the HC #422

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## XX.XX.XX
* Introduced new health checks to monitor how device ID changes are handled.
* Added a config option to content (setZoneTimerInterval) to set content zone timer. (Experimental!)

## 24.7.7
Expand All @@ -7,7 +8,7 @@

## 24.7.6
* Added support for localization of content blocks.

*
* Mitigated an issue where visibility could have been wrongly assigned if a view was closed while going to background. (Experimental!)
* Fixed a bug where passing the global content callback was not possible.
* Mitigated an issue related to content actions navigation.
Expand Down
26 changes: 24 additions & 2 deletions sdk/src/main/java/ly/count/android/sdk/HealthCheckCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ public class HealthCheckCounter implements HealthTracker {
public long countLogError = 0;
public int statusCode = -1;
public String errorMessage = "";

public int mergeCount = 0;
public int withoutMergeCount = 0;

final String keyLogError = "LErr";
final String keyLogWarning = "LWar";
final String keyStatusCode = "RStatC";
final String keyErrorMessage = "REMsg";
final String keyMergeCount = "MCount";
final String keyWithoutMergeCount = "WMCount";

final String requestKeyErrorCount = "el";
final String requestKeyWarningCount = "wl";
final String requestKeyStatusCode = "sc";
final String requestKeyRequestError = "em";
final String requestKeyChangeWithMerge = "mc";
final String requestKeyChangeWithoutMerge = "wmc";

StorageProvider storageProvider;
ModuleLog L;
Expand Down Expand Up @@ -47,6 +53,8 @@ void setupInitialCounters(@NonNull String initialState) {
countLogError = jsonObject.optLong(keyLogError, 0);
statusCode = jsonObject.optInt(keyStatusCode, -1);
errorMessage = jsonObject.optString(keyErrorMessage, "");
mergeCount = jsonObject.optInt(keyMergeCount, 0);
withoutMergeCount = jsonObject.optInt(keyWithoutMergeCount, 0);

L.d("[HealthCheckCounter] Loaded initial health check state: [" + jsonObject.toString() + "]");
} catch (Exception e) {
Expand All @@ -67,7 +75,7 @@ void setupInitialCounters(@NonNull String initialState) {
assert statusCode > 0;
assert statusCode < 1000;
assert errorResponse != null;

this.statusCode = statusCode;

if (errorResponse.length() > 1000) {
Expand Down Expand Up @@ -102,19 +110,31 @@ void setupInitialCounters(@NonNull String initialState) {
jsonObject.put(keyLogError, countLogError);
jsonObject.put(keyStatusCode, statusCode);
jsonObject.put(keyErrorMessage, errorMessage);
jsonObject.put(keyMergeCount, mergeCount);
jsonObject.put(keyWithoutMergeCount, withoutMergeCount);

storageProvider.setHealthCheckCounterState(jsonObject.toString());
} catch (Exception e) {
L.w("[HealthCheckCounter] Failed to save current state, " + e);
}
}

@Override public void logDeviceIdWithMergeChange() {
mergeCount++;
}

@Override public void logDeviceIdWithoutMergeChange() {
withoutMergeCount++;
}

void clearValues() {
L.v("[HealthCheckCounter] Clearing counters");
countLogWarning = 0;
countLogError = 0;
statusCode = -1;
errorMessage = "";
mergeCount = 0;
withoutMergeCount = 0;
}

@NonNull String createRequestParam() {
Expand All @@ -128,6 +148,8 @@ void clearValues() {
jsonObject.put(requestKeyWarningCount, countLogWarning);
jsonObject.put(requestKeyStatusCode, statusCode);
jsonObject.put(requestKeyRequestError, errorMessage);
jsonObject.put(requestKeyChangeWithMerge, mergeCount);
jsonObject.put(requestKeyChangeWithoutMerge, withoutMergeCount);
} catch (JSONException e) {
L.w("[HealthCheckCounter] Failed to create param for hc request, " + e);
}
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/main/java/ly/count/android/sdk/HealthTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ interface HealthTracker {
void clearAndSave();

void saveState();

void logDeviceIdWithMergeChange();

void logDeviceIdWithoutMergeChange();
}
2 changes: 2 additions & 0 deletions sdk/src/main/java/ly/count/android/sdk/ModuleDeviceId.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void changeDeviceIdWithoutMergeInternal(@NonNull String deviceId) {
} else {
// setting a custom device ID
deviceIdInstance.changeToCustomId(deviceId);
healthTracker.logDeviceIdWithoutMergeChange();
}

//clear automated star rating session values because now we have a new user
Expand Down Expand Up @@ -201,6 +202,7 @@ void changeDeviceIdWithMergeInternal(@NonNull String deviceId) {
_cly.moduleRemoteConfig.clearAndDownloadAfterIdChange();
requestQueueProvider.changeDeviceId(deviceId, deviceIdInstance.getCurrentId());
deviceIdInstance.changeToCustomId(deviceId);
healthTracker.logDeviceIdWithMergeChange();
_cly.notifyDeviceIdChange(false);
}
}
Expand Down
Loading