-
Notifications
You must be signed in to change notification settings - Fork 8
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
Collect and send custom attributes for capture feature #89
Conversation
@@ -1390,4 +1401,192 @@ public static String getDistributionUserName() { | |||
|
|||
return sInstance.mDistributionUserName; | |||
} | |||
|
|||
public static boolean putBuildEnvironmentValue(String key, String value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add comments each public method.
@jmatsu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach basically looks good. Please check my comments.
@jmatsu
Could you please re-review this PR? Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach looks basically good. Please check my comments.
@satsukies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the same test located in sdk module to checking provide same methods each modules.
@jmatsu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be careful for synchronization, sdk-mock
interfaces and AIDL operations.
if (sBuildEnvironment != null && !sBuildEnvironment.isEmpty()) { | ||
cv.put(DeployGateEvent.ATTRIBUTE_KEY_BUILD_ENVIRONMENT, sBuildEnvironment.toJsonString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for modifying these codes and I noticed a new thing. This code can be decomposed to like the following.
// Be not synchornized by `sLock`
if (sBuildEnvironment != null) {
// These multiple operations are not synchornized by `ConcurrentHashMap`
if (sBuildEnvironment.isEmpty()) {
doSomething(sBuildEnvironment.toJsonString())
}
}
Synchronization issues are here so we need to fix it. And also, isEmpty
check can be shrunken cuz it's just a JSON.
String buildEnvironmentJson = getBuildEnvironment().toJsonString();
if (!buildEnvironmentJson.equals("{}") {
cv.put(DeployGateEvent.ATTRIBUTE_KEY_BUILD_ENVIRONMENT, buildEnvironmentJson);
}
cv.put(DeployGateEvent.ATTRIBUTE_KEY_EVENT_AT, System.currentTimeMillis()); | ||
|
||
ContentResolver cr = mApplicationContext.getContentResolver(); | ||
cr.insert(targetUri, cv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please introduce try-catch
and suppress the error for safer operations.
@@ -179,4 +179,12 @@ public static void composeComment(String defaultComment) { | |||
public static String getDistributionUserName() { | |||
return null; | |||
} | |||
|
|||
public static CustomAttributes getBuildEnvironment() { | |||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make here null. It's always non-null on sdk
so this code means sdk-mock is unreliable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment remind me of you said "must be always non-null for friendly interfaces" in previous review.
I'll fix it.
} | ||
|
||
String toJsonString() { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make here null. It's always non-null on sdk so this code means sdk-mock is unreliable.
@@ -1390,4 +1412,34 @@ public static String getDistributionUserName() { | |||
|
|||
return sInstance.mDistributionUserName; | |||
} | |||
|
|||
public static CustomAttributes getBuildEnvironment() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
private static CustomAttributes sRuntimeExtra = null; | ||
private static CustomAttributes sBuildEnvironment; | ||
private static CustomAttributes sRuntimeExtra; | ||
private static CustomAttributes sSdkRuntimeExtra; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This attrs will be used to collect data for valuable on the debugging.
It is always empty at this point.
@@ -15,7 +13,7 @@ public final class CustomAttributes { | |||
private static final Pattern VALID_KEY_PATTERN = Pattern.compile("^[a-z][_a-z0-9]{2,31}$"); | |||
private static final int MAX_VALUE_LENGTH = 64; | |||
|
|||
private final ConcurrentHashMap<String, Object> attributes; | |||
final ConcurrentHashMap<String, Object> attributes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visibility changed.
we can use attributes
from Deploygate class directly, but users cannot use.
synchronized (getRuntimeExtra().attributes) { | ||
if (!getRuntimeExtra().attributes.isEmpty()) { | ||
for (Map.Entry<String, Object> attr : getRuntimeExtra().attributes.entrySet()) { | ||
String userKey = String.format("%s.%s", mHostApp.packageName, attr.getKey()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to append prefix to attribute keys created by user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add the extra time-consuming processing. If we append the prefix in CustomAttributes, doesn't it work?
} catch (Exception e) { | ||
Truth.assertWithMessage("Failed to parse JSON").fail(); | ||
} | ||
public void size() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add new testcase for checking behavior size() and isEmpty() methods.
@jmatsu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be careful about the device resources.
@@ -0,0 +1 @@ | |||
../../../../../../../sdk/src/test/java/com/deploygate/sdk/CustomAttributesInterfaceTest.java |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -5,6 +5,8 @@ | |||
|
|||
public class DeployGate { | |||
|
|||
private static final CustomAttributes sAttributes = new CustomAttributes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
sdk/src/test/java/com/deploygate/sdk/DeployGateInterfaceTest.java
Outdated
Show resolved
Hide resolved
sdk/src/test/java/com/deploygate/sdk/CustomAttributesInterfaceTest.java
Outdated
Show resolved
Hide resolved
synchronized (getRuntimeExtra().attributes) { | ||
if (!getRuntimeExtra().attributes.isEmpty()) { | ||
for (Map.Entry<String, Object> attr : getRuntimeExtra().attributes.entrySet()) { | ||
String userKey = String.format("%s.%s", mHostApp.packageName, attr.getKey()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add the extra time-consuming processing. If we append the prefix in CustomAttributes, doesn't it work?
We discussed in-person to plan for how to fix current codes.
@jmatsu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost LGTM. Could you please add one important testcase?
|
||
@Test | ||
public void getBuildEnvironment() { | ||
Truth.assertThat(DeployGate.getBuildEnvironment()).isNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
} | ||
|
||
@Test() | ||
public void not_exceed_max_size_multi_thread() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👏
import java.util.concurrent.Executors; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class CustomAttributesTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satsukies Could you please add a testcase for getJSONString
if it's empty? It must return {}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry.
I added testcase for getJSONString
method in 063fc76 .
Logger.w(TAG, "Attributes already reached max size. Ignored: " + key); | ||
return false; | ||
} | ||
} catch (JSONException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Thank you for the tough work.
Thanks for comment. |
You too, thank you for your review many times and careful feedback. |
I added an implementation that will be used to enhance the capture function provided after the next version.
CustomAttributes
class .BuildEnvironment
orRuntimeExtra
.CustomAttriutes
of each groups.ACTION_COLLECT_DEVICE_STATES
event, SDK will write values via content provider.