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

GEODE-7216 include a timestamp in stack trace logs #4087

Merged
merged 13 commits into from Oct 15, 2019

Conversation

mkevo
Copy link
Contributor

@mkevo mkevo commented Sep 24, 2019

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.

Copy link
Contributor

@jujoramos jujoramos left a 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?.

@aaronlindsey
Copy link

Did you consider using java.time.* classes instead of java.util.Date? I think the best practice is to use the former unless there is a reason why only java.util.Date will do. Jon Skeet has an interesting article about the difference.

If you do switch to a java.time.* class, you'll have to be careful about time zones. By default java.util.Date uses the system-local time zone which in this case happens to be the same as the time zone in the logs so it works out by happenstance. But if you switch to java.time.Instant (basically the analogue to Date), that class defaults to UTC. You'd have to make sure the string version which is output by the command matches the time zone in the logs.

@mkevo
Copy link
Contributor Author

mkevo commented Oct 2, 2019

Thanks @aaronlindsey! Great article! I will change it.

@@ -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

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

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.

Comment on lines 74 to 82
@Test
public void getHeaderMessage() throws IOException {
StackTracesPerMember stackTracePerMember =
new StackTracesPerMember("server", Instant.now(),
OSProcess.zipStacks());
String headerMessage = command.getHeaderMessage(stackTracePerMember);

assertThat(headerMessage).isNotNull();
}

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:

  1. When I pass a value of null as the timestamp for StackTracesPerMember, I expect that the headerMessage to be exactly "server".
  2. When I pass a specific value like "2000/01/02 03:04:05.006" as the timestamp for StackTracesPerMember, I expect the headerMessage to be exactly "server at 2000/01/02 03:04:05.006".

Copy link
Contributor Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It looks good.

@mivanac
Copy link
Contributor

mivanac commented Oct 15, 2019

Since these changes are approved, I will merge this PR.

@mivanac mivanac merged commit d71a615 into apache:develop Oct 15, 2019
@mkevo mkevo deleted the feature/GEODE-7216 branch November 6, 2019 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants