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
GEODE-7216 include a timestamp in stack trace logs #4087
Conversation
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.
Hey @mkevo, thanks for the contribution!.
Can you please add tests to verify your changes?.
...src/main/java/org/apache/geode/management/internal/cli/commands/ExportStackTraceCommand.java
Outdated
Show resolved
Hide resolved
...java/org/apache/geode/management/internal/cli/commands/ExportStackTraceCommandDUnitTest.java
Outdated
Show resolved
Hide resolved
...java/org/apache/geode/management/internal/cli/commands/ExportStackTraceCommandDUnitTest.java
Outdated
Show resolved
Hide resolved
...core/src/main/java/org/apache/geode/management/internal/cli/domain/StackTracesPerMember.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/apache/geode/management/internal/cli/functions/GetStackTracesFunction.java
Outdated
Show resolved
Hide resolved
Did you consider using If you do switch to a |
Thanks @aaronlindsey! Great article! I will change it. |
...src/main/java/org/apache/geode/management/internal/cli/functions/GetStackTracesFunction.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/apache/geode/management/internal/cli/commands/ExportStackTraceCommand.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/apache/geode/management/internal/cli/commands/ExportStackTraceCommand.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/apache/geode/management/internal/cli/commands/ExportStackTraceCommand.java
Show resolved
Hide resolved
@@ -470,7 +470,7 @@ org/apache/geode/management/internal/cli/domain/RegionAttributesInfo,true,336184 | |||
org/apache/geode/management/internal/cli/domain/RegionDescription,true,6461449275798378332,cndEvictionAttributes:java/util/Map,cndPartitionAttributes:java/util/Map,cndRegionAttributes:java/util/Map,dataPolicy:org/apache/geode/cache/DataPolicy,isAccessor:boolean,isLocal:boolean,isPartition:boolean,isPersistent:boolean,isReplicate:boolean,name:java/lang/String,regionDescPerMemberMap:java/util/Map,scope:org/apache/geode/cache/Scope | |||
org/apache/geode/management/internal/cli/domain/RegionDescriptionPerMember,true,1,hostingMember:java/lang/String,isAccessor:boolean,name:java/lang/String,regionAttributesInfo:org/apache/geode/management/internal/cli/domain/RegionAttributesInfo,size:int | |||
org/apache/geode/management/internal/cli/domain/RegionInformation,true,1,dataPolicy:org/apache/geode/cache/DataPolicy,isRoot:boolean,name:java/lang/String,parentRegion:java/lang/String,path:java/lang/String,scope:org/apache/geode/cache/Scope,subRegionInformationSet:java/util/Set | |||
org/apache/geode/management/internal/cli/domain/StackTracesPerMember,true,1,memberNameOrId:java/lang/String,stackTraces:byte[] | |||
org/apache/geode/management/internal/cli/domain/StackTracesPerMember,true,1,memberNameOrId:java/lang/String,stackTraces:byte[],timestamp:java/time/Instant |
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.
Would StackTracesPerMember
ever be deserialized from an older version that didn't include the timestamp field? I'm just asking — I don't actually know. Maybe @jujoramos would know. If this could happen, then the timestamp field would be null and the formatter.format(...)
line in ExportStackTraceCommand
could throw a NPE.
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.
@aaronlindsey: good catch, I haven't thought about it but my guess is that it could happen, yes. I'm not a 100% sure, though.
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.
Do we need to use try/catch
on formatter or override toData/fromData
in StackTracesPerMember
?
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.
I would do something like the following: Add package private method in ExportStackTraceCommand
which handles generating the header message. Then you can write a unit test for this more easily. I don't see an easy way to write an integeration (D-unit) test for this case.
@VisibleForTesting
String getHeaderMessage(StackTracesPerMember stackTracesPerMember) {
String headerMessage = stackTracesPerMember.getMemberNameOrId();
Instant timestamp = stackTracesPerMember.getTimestamp();
if (timestamp != null) {
headerMessage += " at " + formatter.format(timestamp);
}
return headerMessage;
}
The issue with overriding readObject
in StackTracesPerMember
is that you wouldn't know which value to assign to the timestamp
field when the object is deserialized.
@Test | ||
public void getHeaderMessage() throws IOException { | ||
StackTracesPerMember stackTracePerMember = | ||
new StackTracesPerMember("server", Instant.now(), | ||
OSProcess.zipStacks()); | ||
String headerMessage = command.getHeaderMessage(stackTracePerMember); | ||
|
||
assertThat(headerMessage).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.
Thanks for addressing my feedback about the possibility of the timestamp field being null when deserializing a StackTracesPerMember
. However, I think the test would be more effective if you split it out into a couple of more specific scenarios. For example:
- When I pass a value of
null
as the timestamp forStackTracesPerMember
, I expect that theheaderMessage
to be exactly "server". - When I pass a specific value like "2000/01/02 03:04:05.006" as the timestamp for
StackTracesPerMember
, I expect theheaderMessage
to be exactly "server at 2000/01/02 03:04:05.006".
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.
Thanks for comments! I added new test with null as the timestamp and modified existing to check if headerMessage
has specific format as expected in output of this command.
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.
Thanks! It looks good.
Since these changes are approved, I will merge this PR. |
Thank you for submitting a contribution to Apache Geode.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
Has your PR been rebased against the latest commit within the target branch (typically
develop
)?Is your initial contribution a single, squashed commit?
Does
gradlew build
run cleanly?Have you written or updated unit tests to verify your changes?
If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
Note:
Please ensure that once the PR is submitted, check Concourse for build issues and
submit an update to your PR as soon as possible. If you need help, please send an
email to dev@geode.apache.org.