You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "rash67 (via GitHub)" <gi...@apache.org> on 2023/11/29 21:06:45 UTC
[PR] Propagate Intervals.of() error message to user (druid)
rash67 opened a new pull request, #15454:
URL: https://github.com/apache/druid/pull/15454
### Description
In SQL, when specifying an interval, eg '2020-01-01T:00:00:00Z/2021-01-01T00:00:00Z', errors in the string are not shown to the user. The give an unknown error and no useful information.
This propagates any errors from Intervals.of() properly by catching and throwing the proper exception
#### Release note
-Improve error message on interval construction in SQL statements
- [ ] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Propagate Intervals.of() error message to user (druid)
Posted by "cheddar (via GitHub)" <gi...@apache.org>.
cheddar merged PR #15454:
URL: https://github.com/apache/druid/pull/15454
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Propagate Intervals.of() error message to user (druid)
Posted by "rash67 (via GitHub)" <gi...@apache.org>.
rash67 commented on code in PR #15454:
URL: https://github.com/apache/druid/pull/15454#discussion_r1428921570
##########
server/src/test/java/org/apache/druid/server/http/DataSourcesResourceTest.java:
##########
@@ -613,19 +614,9 @@
EasyMock.replay(overlordClient, server);
DataSourcesResource dataSourcesResource =
new DataSourcesResource(inventoryView, null, null, overlordClient, null, null);
- try {
- Response response =
- dataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval("datasource", "true", "???");
- // 400 (Bad Request) or an IllegalArgumentException is expected.
- Assert.assertEquals(400, response.getStatus());
- Assert.assertNotNull(response.getEntity());
- Assert.assertTrue(response.getEntity().toString().contains("java.lang.IllegalArgumentException"));
- }
- catch (IllegalArgumentException ignore) {
- // expected
- }
-
- EasyMock.verify(overlordClient, server);
+ DruidExceptionMatcher.invalidInput().assertThrowsAndMatches(
+ () -> dataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval("datasource", "true", "???")
Review Comment:
method is still being offered via HTTP, so we test it in unit tests
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Propagate Intervals.of() error message to user (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #15454:
URL: https://github.com/apache/druid/pull/15454#discussion_r1428579045
##########
server/src/test/java/org/apache/druid/server/http/DataSourcesResourceTest.java:
##########
@@ -613,19 +614,9 @@
EasyMock.replay(overlordClient, server);
DataSourcesResource dataSourcesResource =
new DataSourcesResource(inventoryView, null, null, overlordClient, null, null);
- try {
- Response response =
- dataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval("datasource", "true", "???");
- // 400 (Bad Request) or an IllegalArgumentException is expected.
- Assert.assertEquals(400, response.getStatus());
- Assert.assertNotNull(response.getEntity());
- Assert.assertTrue(response.getEntity().toString().contains("java.lang.IllegalArgumentException"));
- }
- catch (IllegalArgumentException ignore) {
- // expected
- }
-
- EasyMock.verify(overlordClient, server);
+ DruidExceptionMatcher.invalidInput().assertThrowsAndMatches(
+ () -> dataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval("datasource", "true", "???")
Review Comment:
## Deprecated method or constructor invocation
Invoking [DataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/6380)
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Propagate Intervals.of() error message to user (druid)
Posted by "rash67 (via GitHub)" <gi...@apache.org>.
rash67 commented on PR #15454:
URL: https://github.com/apache/druid/pull/15454#issuecomment-1856230291
This broke some unit tests that expected IllegalArgumentException. I updated so they expect DruidException with a proper category and all checks pass
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Propagate Intervals.of() error message to user (druid)
Posted by "imply-cheddar (via GitHub)" <gi...@apache.org>.
imply-cheddar commented on code in PR #15454:
URL: https://github.com/apache/druid/pull/15454#discussion_r1427305594
##########
processing/src/test/java/org/apache/druid/java/util/common/IntervalsTest.java:
##########
@@ -78,4 +79,16 @@ public void testFindOverlappingInterval()
);
}
+ @Test(expected = DruidException.class)
+ public void testInvalidInterval()
+ {
+ try {
+ Intervals.of("invalid string");
+ }
+ catch (DruidException e) {
+ Assert.assertTrue(e.getMessage().contains("Bad Interval[invalid string]"));
+
+ throw e;
+ }
+ }
Review Comment:
There is a `DruidExceptionMatcher` that can be used to validate `DruidException` classes. We try to use it with `Assert.assertThat()`.
You can do an `Assert.assertThrows()` first which will return the Throwable, and then `Assert.assertThat` on the returned throwable to validate with the matcher. This pattern is preferred to expecting an exception be thrown out of the test class as it's a bit more explicit and keeps any instance of an exception exiting the test method as a bad thing always.
##########
server/src/test/java/org/apache/druid/test/utils/TestUtils.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.test.utils;
+
+import org.apache.druid.error.DruidException;
+import org.junit.Assert;
+
+import java.util.function.Function;
+
+public class TestUtils
+{
+ /**
+ * This only validates that IF the expression throws a DruidException, that the assertFunction passes.
+ *
+ * @param expression - any expression that throws a DruidException
+ * @param assertFunction
+ */
+ public static void validateExpressionThrowsDruidException(
+ Runnable expression,
+ Function<DruidException, Void> assertFunction
+ )
+ {
Review Comment:
Can we either
1) make the call sites use the `Assert.assertThrows` -> `Assert.assertMatches` pattern discussed above.
2) Adjust this to take a `DruidExceptionMatcher` instead of the `Function` and then use the `Assert.assertThrows` -> `Assert.assertMatches` pattern in here?
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Propagate Intervals.of() error message to user (druid)
Posted by "imply-cheddar (via GitHub)" <gi...@apache.org>.
imply-cheddar commented on code in PR #15454:
URL: https://github.com/apache/druid/pull/15454#discussion_r1427492644
##########
server/src/test/java/org/apache/druid/metadata/SqlSegmentsMetadataManagerTest.java:
##########
@@ -848,8 +853,12 @@ public void testMarkAsUnusedSegmentsInIntervalWithInvalidInterval() throws IOExc
publisher.publishSegment(newSegment1);
publisher.publishSegment(newSegment2);
// invalid interval start > end
- final Interval theInterval = Intervals.of("2017-10-22T00:00:00.000/2017-10-02T00:00:00.000");
- sqlSegmentsMetadataManager.markAsUnusedSegmentsInInterval(newDataSource, theInterval);
+ DruidExceptionMatcher.invalidInput().assertThrowsAndMatches(
+ () -> {
+ Interval theInterval = Intervals.of("2017-10-22T00:00:00.000/2017-10-02T00:00:00.000");
+ sqlSegmentsMetadataManager.markAsUnusedSegmentsInInterval(newDataSource, theInterval);
+ }
+ );
Review Comment:
I think that this is also pointless. Let's just delete this test
##########
server/src/test/java/org/apache/druid/server/http/DataSourcesResourceTest.java:
##########
@@ -621,7 +622,8 @@ public void testMarkAsUnusedAllSegmentsInDataSource()
Assert.assertNotNull(response.getEntity());
Assert.assertTrue(response.getEntity().toString().contains("java.lang.IllegalArgumentException"));
}
- catch (IllegalArgumentException ignore) {
+ catch (DruidException ignore) {
+ Assert.assertEquals(DruidException.Category.INVALID_INPUT, ignore.getCategory());
// expected
}
Review Comment:
Can you switch this around to `DruidExceptionMatcher.invalidInput().assertThrowsAndMatches()`
##########
server/src/test/java/org/apache/druid/metadata/SqlSegmentsMetadataManagerTest.java:
##########
@@ -712,8 +713,12 @@ public void testMarkAsUsedNonOvershadowedSegmentsInIntervalWithInvalidInterval()
publish(newSegment1, false);
publish(newSegment2, false);
// invalid interval start > end
- final Interval theInterval = Intervals.of("2017-10-22T00:00:00.000/2017-10-02T00:00:00.000");
- sqlSegmentsMetadataManager.markAsUsedNonOvershadowedSegmentsInInterval(newDataSource, theInterval);
+ DruidExceptionMatcher.invalidInput().assertThrowsAndMatches(
+ () -> {
+ Interval theInterval = Intervals.of("2017-10-22T00:00:00.000/2017-10-02T00:00:00.000");
+ sqlSegmentsMetadataManager.markAsUsedNonOvershadowedSegmentsInInterval(newDataSource, theInterval);
+ }
+ );
Review Comment:
Actually, when looking at this test, it seems to be throwing when you read the interval, and that has absolutely no relation to the MetadataManager or any fo the setup. I think this test is just useless and should be deleted whole-hog.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Propagate Intervals.of() error message to user (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #15454:
URL: https://github.com/apache/druid/pull/15454#discussion_r1449724708
##########
server/src/test/java/org/apache/druid/server/http/DataSourcesResourceTest.java:
##########
@@ -611,19 +612,9 @@
EasyMock.replay(overlordClient, server);
DataSourcesResource dataSourcesResource =
new DataSourcesResource(inventoryView, null, null, overlordClient, null, null, auditManager);
- try {
- Response response =
- dataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval("datasource", "true", "???", request);
- // 400 (Bad Request) or an IllegalArgumentException is expected.
- Assert.assertEquals(400, response.getStatus());
- Assert.assertNotNull(response.getEntity());
- Assert.assertTrue(response.getEntity().toString().contains("java.lang.IllegalArgumentException"));
- }
- catch (IllegalArgumentException ignore) {
- // expected
- }
-
- EasyMock.verify(overlordClient, server);
+ DruidExceptionMatcher.invalidInput().assertThrowsAndMatches(
+ () -> dataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval("datasource", "true", "???", request)
Review Comment:
## Deprecated method or constructor invocation
Invoking [DataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/6444)
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org