You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/09/05 19:48:40 UTC
[GitHub] [kafka] manijndl7 opened a new pull request #9255: Consolidate duplicated logic on reset tools
manijndl7 opened a new pull request #9255:
URL: https://github.com/apache/kafka/pull/9255
*Consolidated Duplicate DateTime logic from ConsumerGroupCommand and StreamResetter in common Client Utils*
[https://issues.apache.org/jira/browse/KAFKA-6585](https://issues.apache.org/jira/browse/KAFKA-6585)
*Summary of testing strategy (including ##rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.*
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on pull request #9255: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#issuecomment-687654724
@brary request you to please review
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489515785
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
agreed , i have made code changes for that please have a look if its correct
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489534622
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
@mjsax request you to please review this again.
Thanks !!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
mjsax commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r487321249
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489531741
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
@mjsax please let me know if ur asking anything specific i will try to explore that bt following is my understanding about this fxn : -
-call from (streamResetter/ commandgroup) to reset the offset based on epooch value given timestamp.
- check the format is correct if correct else throw exception.
- append "Z" for UTC timezone if not there.
- parse and get the time.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489531741
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
@mjsax please let me know if ur asking anything specific i will try to explore that bt following is my understanding about this fxn : -
-call from (streamResetter/ commandgroup) to reset the offset based on epooch value given timestamp.
- check the format is correct if correct else throw exception.
- append "Z" for UTC timezone if not there.
- parse and get the time.
But i tested by running all the unit cases.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489515785
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
i have made code changes for that
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
i have made code changes for that
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
mjsax commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r487321249
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] brary commented on a change in pull request #9255: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
brary commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r484028797
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,35 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+
+ /**
+ * Convert a ISO8601 based TimeStamp to Epoch Value
Review comment:
Few nitpicks here:
Convert an ISO8601 based timestamp to an epoch value
....
@return epoch value of a given timestamp
@throws ParseException for timestamp that doesn't follow ISO8601 format
##########
File path: core/src/main/scala/kafka/tools/StreamsResetter.java
##########
@@ -42,13 +42,13 @@
import java.io.IOException;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
+
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
+
Review comment:
nit: Please remove this line new line.
##########
File path: core/src/main/scala/kafka/tools/StreamsResetter.java
##########
@@ -42,13 +42,13 @@
import java.io.IOException;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
+
Review comment:
nit: Please remove this line new line.
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -17,7 +17,7 @@
package kafka.admin
-import java.text.{ParseException, SimpleDateFormat}
+
Review comment:
nit: Please remove this line new line.
##########
File path: streams/src/test/java/org/apache/kafka/streams/tools/StreamsResetterTest.java
##########
@@ -30,11 +30,10 @@
import org.junit.Before;
import org.junit.Test;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
+
import java.time.Duration;
import java.util.Collections;
-import java.util.Date;
+
Review comment:
nit: Please remove this line new line.
##########
File path: streams/src/test/java/org/apache/kafka/streams/tools/StreamsResetterTest.java
##########
@@ -43,7 +42,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+
Review comment:
nit: Please remove this line new line.
##########
File path: streams/src/test/java/org/apache/kafka/streams/tools/StreamsResetterTest.java
##########
@@ -30,11 +30,10 @@
import org.junit.Before;
import org.junit.Test;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
+
Review comment:
nit: Please remove this line new line.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] ijuma commented on a change in pull request #9255: KAFKA-6585: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
ijuma commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r497665907
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
`core` does depend on `clients` generally.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489518181
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
Hi @mjsax thanks for reviewing my PR.
I removed "ISO8601" that from the comment as it is Defined in very Dateformatter. please let me know ur thoughts on that.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489515189
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
@mjsax @guozhangwang request you to please suggest where we can put this common code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489515189
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
@mjsax @guozhangwang can you please suggest where we can put this common code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
mjsax commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r487321249
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ fail("Call to getDateTime should fail");
+ } catch (final Exception e) {
+ e.printStackTrace();
Review comment:
We should not print the stacktrace imho, but verify the exception message using `assertThat`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
nit: I don't know from the top of my head what the standard dictates. Might be worth adding to the comment?
##########
File path: clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
##########
@@ -784,4 +787,39 @@ public void testCloseAllQuietly() {
assertEquals(msg, exception.get().getMessage());
assertEquals(1, count.get());
}
+
+ @Test
+ public void shouldAcceptValidDateFormats() throws ParseException {
+ //check valid formats
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"));
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
+ }
+
+ @Test
+ public void shouldThrowOnInvalidDateFormat() {
+ //check some invalid formats
+ try {
+ invokeGetDateTimeMethod(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
Review comment:
We should update this test and use `assertThrows` instead of `try-fail-catch`.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I know that this is exiting logic that was just moved, but I am not sure if I understand how it works?
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
I am must wondering if we can have a dependency from `core` to `clients` module? \cc @ijuma
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] brary commented on a change in pull request #9255: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
brary commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r484034329
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,35 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+
Review comment:
There is an extra line here.
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,35 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+
+ /**
+ * Convert a ISO8601 based TimeStamp to Epoch Value
Review comment:
This was not addressed, you disagree with the changes suggested?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on pull request #9255: KAFKA-6585: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
mjsax commented on pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#issuecomment-701525468
Thanks for the PR @manijndl7!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on a change in pull request #9255: KAFKA-6585: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
mjsax commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r497669807
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
I was looking up the format in more detail and understand now what going on. The code does not seem to be ideal IMHO, but no need to change it in this PR.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489515189
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
@mjsax @guozhangwang please suggest where we can put this common code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r495786493
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
+ * @param timestamp to be converted
+ * @return epoch value of a given timestamp
+ * @throws ParseException for timestamp that doesn't follow ISO8601 format
+ */
+ public static long getDateTime(String timestamp) throws ParseException {
+ final String[] timestampParts = timestamp.split("T");
+ if (timestampParts.length < 2) {
+ throw new ParseException("Error parsing timestamp. It does not contain a 'T' according to ISO8601 format", timestamp.length());
+ }
+
+ final String secondPart = timestampParts[1];
+ if (secondPart == null || secondPart.isEmpty()) {
+ throw new ParseException("Error parsing timestamp. Time part after 'T' is null or empty", timestamp.length());
+ }
+
+ if (!(secondPart.contains("+") || secondPart.contains("-") || secondPart.contains("Z"))) {
Review comment:
Hi @mjax request you to please review once.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax merged pull request #9255: KAFKA-6585: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
mjsax merged pull request #9255:
URL: https://github.com/apache/kafka/pull/9255
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on pull request #9255: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#issuecomment-687713711
Thanks @brary for Review i have done the changes can you please verify once if things are good.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on a change in pull request #9255: KAFKA-6585: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
mjsax commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r497670496
##########
File path: core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala
##########
@@ -823,7 +809,7 @@ object ConsumerGroupCommand extends Logging {
case (topicPartition, newOffset) => (topicPartition, new OffsetAndMetadata(newOffset))
}
} else if (opts.options.has(opts.resetToDatetimeOpt)) {
- val timestamp = convertTimestamp(opts.options.valueOf(opts.resetToDatetimeOpt))
+ val timestamp = Utils.getDateTime(opts.options.valueOf(opts.resetToDatetimeOpt))
Review comment:
Thanks for clarification. So we are good.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] manijndl7 commented on a change in pull request #9255: MINOR: Consolidate duplicated logic on reset tools
Posted by GitBox <gi...@apache.org>.
manijndl7 commented on a change in pull request #9255:
URL: https://github.com/apache/kafka/pull/9255#discussion_r489518181
##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -1271,4 +1274,34 @@ private static byte checkRange(final byte i) {
}
return map;
}
+
+ /**
+ * Convert an ISO8601 based timestamp to an epoch value
Review comment:
Hi @mjsax thanks for reviewing my PR.
I removed "ISO8601" that from the comment as i checked every formatter library follow same ISO8601 standard. please let me know ur thoughts on that.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org