You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/10/30 06:59:57 UTC
[GitHub] [druid] FrankChen021 opened a new pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
FrankChen021 opened a new pull request #11724:
URL: https://github.com/apache/druid/pull/11724
### Description
We're using supervisor/task HTTP APIs to manage supervisor and tasks in a independent system. Current supervisor/task endpoint return 400 when a supervisor or a task is not found. This status code is not friendly and confusing for the 3rd system. And according to the definition of HTTP status code, 404 is right code for such case. So this PR changes the status code from 400 to 404 to eliminate the ambigiuty.
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [X] 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.
- [ ] 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.
- [X] 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.
- [X] added integration tests.
- [X] 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
[GitHub] [druid] FrankChen021 commented on pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on pull request #11724:
URL: https://github.com/apache/druid/pull/11724#issuecomment-978840943
@jihoonson @asdf2014 @suneet-s @kfaraz Thank you for your 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.
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
[GitHub] [druid] kfaraz commented on a change in pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
kfaraz commented on a change in pull request #11724:
URL: https://github.com/apache/druid/pull/11724#discussion_r723904086
##########
File path: indexing-service/src/test/java/org/apache/druid/indexing/overlord/http/security/OverlordResourceFilterTest.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.indexing.overlord.http.security;
+
+import com.google.common.base.Optional;
+import com.sun.jersey.spi.container.ContainerRequest;
+import org.apache.druid.indexing.overlord.TaskStorageQueryAdapter;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorSpec;
+import org.apache.druid.server.security.AuthorizerMapper;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.easymock.EasyMock.expect;
+
+public class OverlordResourceFilterTest
Review comment:
I think we should call this class `TaskResourceFilterTest` as `TaskResourceFilter` is the one used in the tests here.
##########
File path: indexing-service/src/main/java/org/apache/druid/indexing/overlord/supervisor/SupervisorResource.java
##########
@@ -386,6 +386,7 @@ public Response specGetAllHistory(@Context final HttpServletRequest req)
@GET
@Path("/{id}/history")
@Produces(MediaType.APPLICATION_JSON)
+ @ResourceFilters(SupervisorResourceFilter.class)
Review comment:
If we are using the `SupervisorResourceFilter` here, I think it would be safe to remove the filtering done by `AuthorizationUtils.filterAuthorizedResources()` later in this method?
##########
File path: integration-tests/src/test/java/org/apache/druid/tests/TestNGGroup.java
##########
@@ -159,4 +159,6 @@
public static final String SHUFFLE_DEEP_STORE = "shuffle-deep-store";
public static final String CUSTOM_COORDINATOR_DUTIES = "custom-coordinator-duties";
+
+ public static final String OVERLORD_RESOURCE = "overlord-resources";
Review comment:
Could we use a more generic group name here that could later include other tests, say for other resources / HTTP endpoints?
##########
File path: integration-tests/src/main/java/org/apache/druid/testing/clients/OverlordResourceTestClient.java
##########
@@ -136,6 +136,9 @@ public TaskStatusPlus getTaskStatus(String taskID)
);
return taskStatusResponse.getStatus();
}
+ catch (ISE e) {
Review comment:
Would it make sense to catch all `RuntimeException`s here (not just ISE) and re-throw them as is?
(same comment in other places too)
--
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
[GitHub] [druid] kfaraz commented on a change in pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
kfaraz commented on a change in pull request #11724:
URL: https://github.com/apache/druid/pull/11724#discussion_r732511208
##########
File path: integration-tests/src/main/java/org/apache/druid/testing/clients/OverlordResourceTestClient.java
##########
@@ -136,6 +136,9 @@ public TaskStatusPlus getTaskStatus(String taskID)
);
return taskStatusResponse.getStatus();
}
+ catch (ISE e) {
Review comment:
Okay, thanks for the clarification. 👍
--
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
[GitHub] [druid] FrankChen021 commented on pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on pull request #11724:
URL: https://github.com/apache/druid/pull/11724#issuecomment-922599411
> This change seems reasonable. @FrankChen021 can you add some tests for this change?
Sure, I will add some tests later this week.
--
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
[GitHub] [druid] FrankChen021 commented on a change in pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on a change in pull request #11724:
URL: https://github.com/apache/druid/pull/11724#discussion_r730409696
##########
File path: integration-tests/src/main/java/org/apache/druid/testing/clients/OverlordResourceTestClient.java
##########
@@ -136,6 +136,9 @@ public TaskStatusPlus getTaskStatus(String taskID)
);
return taskStatusResponse.getStatus();
}
+ catch (ISE e) {
Review comment:
ISE is specific exception thrown by `makeRequest` function when HTTP response status code is not 200. And when this exceptio occurs, its exception message contains the HTTP status code. Here we catch and re-throw the exception to simplify the exception handling to check the HTTP status code in the message.
##########
File path: integration-tests/src/main/java/org/apache/druid/testing/clients/OverlordResourceTestClient.java
##########
@@ -136,6 +136,9 @@ public TaskStatusPlus getTaskStatus(String taskID)
);
return taskStatusResponse.getStatus();
}
+ catch (ISE e) {
Review comment:
`ISE` is a specific exception thrown by `makeRequest` function when HTTP response status code is not 200. And when this exceptio occurs, its exception message contains the HTTP status code. Here we catch and re-throw the exception to simplify the exception handling to check the HTTP status code in the message.
--
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
[GitHub] [druid] FrankChen021 merged pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
FrankChen021 merged pull request #11724:
URL: https://github.com/apache/druid/pull/11724
--
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
[GitHub] [druid] FrankChen021 commented on a change in pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on a change in pull request #11724:
URL: https://github.com/apache/druid/pull/11724#discussion_r730410917
##########
File path: integration-tests/src/test/java/org/apache/druid/tests/TestNGGroup.java
##########
@@ -159,4 +159,6 @@
public static final String SHUFFLE_DEEP_STORE = "shuffle-deep-store";
public static final String CUSTOM_COORDINATOR_DUTIES = "custom-coordinator-duties";
+
+ public static final String OVERLORD_RESOURCE = "overlord-resources";
Review comment:
how about `http-endpoint` ?
--
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
[GitHub] [druid] FrankChen021 closed pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
FrankChen021 closed pull request #11724:
URL: https://github.com/apache/druid/pull/11724
--
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
[GitHub] [druid] FrankChen021 commented on a change in pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on a change in pull request #11724:
URL: https://github.com/apache/druid/pull/11724#discussion_r730410033
##########
File path: indexing-service/src/main/java/org/apache/druid/indexing/overlord/supervisor/SupervisorResource.java
##########
@@ -386,6 +386,7 @@ public Response specGetAllHistory(@Context final HttpServletRequest req)
@GET
@Path("/{id}/history")
@Produces(MediaType.APPLICATION_JSON)
+ @ResourceFilters(SupervisorResourceFilter.class)
Review comment:
Thanks for pointing out this, this causes problem. And since `SupervisorResourceFilter` requires WRITE permission, and the function requires READ permission, I will delete the filter. I added this filter to hope the tests can have same exception message handling.
--
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
[GitHub] [druid] kfaraz commented on a change in pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
kfaraz commented on a change in pull request #11724:
URL: https://github.com/apache/druid/pull/11724#discussion_r723904086
##########
File path: indexing-service/src/test/java/org/apache/druid/indexing/overlord/http/security/OverlordResourceFilterTest.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.indexing.overlord.http.security;
+
+import com.google.common.base.Optional;
+import com.sun.jersey.spi.container.ContainerRequest;
+import org.apache.druid.indexing.overlord.TaskStorageQueryAdapter;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorSpec;
+import org.apache.druid.server.security.AuthorizerMapper;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.easymock.EasyMock.expect;
+
+public class OverlordResourceFilterTest
Review comment:
I think we should call this class `TaskResourceFilterTest` as `TaskResourceFilter` is the one used in the tests here.
##########
File path: indexing-service/src/main/java/org/apache/druid/indexing/overlord/supervisor/SupervisorResource.java
##########
@@ -386,6 +386,7 @@ public Response specGetAllHistory(@Context final HttpServletRequest req)
@GET
@Path("/{id}/history")
@Produces(MediaType.APPLICATION_JSON)
+ @ResourceFilters(SupervisorResourceFilter.class)
Review comment:
If we are using the `SupervisorResourceFilter` here, I think it would be safe to remove the filtering done by `AuthorizationUtils.filterAuthorizedResources()` later in this method?
##########
File path: integration-tests/src/test/java/org/apache/druid/tests/TestNGGroup.java
##########
@@ -159,4 +159,6 @@
public static final String SHUFFLE_DEEP_STORE = "shuffle-deep-store";
public static final String CUSTOM_COORDINATOR_DUTIES = "custom-coordinator-duties";
+
+ public static final String OVERLORD_RESOURCE = "overlord-resources";
Review comment:
Could we use a more generic group name here that could later include other tests, say for other resources / HTTP endpoints?
##########
File path: integration-tests/src/main/java/org/apache/druid/testing/clients/OverlordResourceTestClient.java
##########
@@ -136,6 +136,9 @@ public TaskStatusPlus getTaskStatus(String taskID)
);
return taskStatusResponse.getStatus();
}
+ catch (ISE e) {
Review comment:
Would it make sense to catch all `RuntimeException`s here (not just ISE) and re-throw them as is?
(same comment in other places too)
--
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
[GitHub] [druid] FrankChen021 commented on a change in pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on a change in pull request #11724:
URL: https://github.com/apache/druid/pull/11724#discussion_r730410522
##########
File path: indexing-service/src/test/java/org/apache/druid/indexing/overlord/http/security/OverlordResourceFilterTest.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.indexing.overlord.http.security;
+
+import com.google.common.base.Optional;
+import com.sun.jersey.spi.container.ContainerRequest;
+import org.apache.druid.indexing.overlord.TaskStorageQueryAdapter;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorSpec;
+import org.apache.druid.server.security.AuthorizerMapper;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.easymock.EasyMock.expect;
+
+public class OverlordResourceFilterTest
Review comment:
fixed
--
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
[GitHub] [druid] FrankChen021 commented on pull request #11724: Return HTTP 404 instead of 400 for supervisor/task endpoints
Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on pull request #11724:
URL: https://github.com/apache/druid/pull/11724#issuecomment-977874264
@jihoonson Do you have any other comments?
--
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