Skip to content

Commit

Permalink
[ALS-7475] Add detailed logging for container path and query paramete…
Browse files Browse the repository at this point in the history
…rs (#207)

* Add detailed logging for container path and query parameters

Introduced logging statements to capture container path, ID, body, and query parameters.

* Add HttpHeaders parameter to proxy methods

Updated service interface and tests to reflect this change, allowing for better request source tracking.
  • Loading branch information
Gcolon021 authored Oct 2, 2024
1 parent 1b740f2 commit 5fec463
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.ws.rs.*;
import javax.ws.rs.core.*;

import edu.harvard.dbmi.avillach.data.entity.Query;
import edu.harvard.dbmi.avillach.domain.*;
import edu.harvard.dbmi.avillach.service.*;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
Expand Down Expand Up @@ -154,34 +153,35 @@ public QueryStatus queryStatus(
@POST
@Path("/query/{queryId}/result")
@Operation(
summary = "Returns result for given query",
responses = {@ApiResponse(
responseCode = "200", description = "Query result", content = @Content(schema = @Schema(implementation = Response.class))
)}
summary = "Returns result for given query",
responses = {@ApiResponse(
responseCode = "200", description = "Query result", content = @Content(schema = @Schema(implementation = Response.class))
)}
)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response queryResult(
@Parameter(
description = "The UUID of the query to fetch the status of. The UUID is "
+ "returned by the /query endpoint as the \"picsureResultId\" in the response object"
) @PathParam("queryId") UUID queryId, @Parameter QueryRequest credentialsQueryRequest, @Context HttpHeaders headers
@Parameter(
description = "The UUID of the query to fetch the status of. The UUID is "
+ "returned by the /query endpoint as the \"picsureResultId\" in the response object"
) @PathParam("queryId") UUID queryId, @Parameter QueryRequest credentialsQueryRequest, @Context HttpHeaders headers
) {
return queryService.queryResult(queryId, credentialsQueryRequest, headers);
}

@POST
@Path("/query/{queryId}/signed-url")
@Operation(
summary = "Returns a signed url for given query",
responses = {@ApiResponse(
responseCode = "200", description = "Query result", content = @Content(schema = @Schema(implementation = Response.class))
)}
summary = "Returns a signed url for given query",
responses = {@ApiResponse(
responseCode = "200", description = "Query result", content = @Content(schema = @Schema(implementation = Response.class))
)}
)
@Produces(MediaType.APPLICATION_JSON)
public Response queryResultSignedUrl(
@Parameter(
description = "The UUID of the query to fetch the status of. The UUID is "
+ "returned by the /query endpoint as the \"picsureResultId\" in the response object"
) @PathParam("queryId") UUID queryId, @Parameter QueryRequest credentialsQueryRequest, @Context HttpHeaders headers
@Parameter(
description = "The UUID of the query to fetch the status of. The UUID is "
+ "returned by the /query endpoint as the \"picsureResultId\" in the response object"
) @PathParam("queryId") UUID queryId, @Parameter QueryRequest credentialsQueryRequest, @Context HttpHeaders headers
) {
return queryService.queryResultSignedUrl(queryId, credentialsQueryRequest, headers);
}
Expand Down Expand Up @@ -229,16 +229,20 @@ public Response generateContinuousBin(QueryRequest continuousData, @Context Http
@Path("/proxy/{container}/{request : .+}")
@Operation(hidden = true)
public Response postProxy(
@PathParam("container") String containerId, @PathParam("request") String request, @Context UriInfo uriInfo, String body
@PathParam("container") String containerId, @PathParam("request") String request, @Context UriInfo uriInfo, String body,
@Context HttpHeaders headers
) {
return proxyWebClient.postProxy(containerId, request, body, uriInfo.getQueryParameters());
return proxyWebClient.postProxy(containerId, request, body, uriInfo.getQueryParameters(), headers);
}

@GET
@Path("/proxy/{container}/{request : .+}")
@Operation(hidden = true)
public Response getProxy(@PathParam("container") String containerId, @PathParam("request") String request, @Context UriInfo uriInfo) {
return proxyWebClient.getProxy(containerId, request, uriInfo.getQueryParameters());
public Response getProxy(
@PathParam("container") String containerId, @PathParam("request") String request, @Context UriInfo uriInfo,
@Context HttpHeaders headers
) {
return proxyWebClient.getProxy(containerId, request, uriInfo.getQueryParameters(), headers);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.harvard.dbmi.avillach.data.repository.ResourceRepository;
import edu.harvard.dbmi.avillach.util.HttpClientUtil;
import edu.harvard.dbmi.avillach.util.Utilities;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
Expand All @@ -16,6 +17,7 @@

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import java.io.IOException;
Expand All @@ -34,10 +36,18 @@ public ProxyWebClient() {
client = HttpClientUtil.getConfiguredHttpClient();
}

public Response postProxy(String containerId, String path, String body, MultivaluedMap<String, String> queryParams) {
public Response postProxy(
String containerId, String path, String body, MultivaluedMap<String, String> queryParams, HttpHeaders headers
) {
if (containerIsNOTAResource(containerId)) {
return Response.status(400, "container name not trustworthy").build();
}

String requestSource = Utilities.getRequestSourceFromHeader(headers);
LOG.info(
"path={}, requestSource={}, containerId={}, body={}, queryParams={}, ", path, requestSource, containerId, body, queryParams
);

try {
URI uri =
new URIBuilder().setScheme("http").setHost(containerId).setPath(path).setParameters(processParams(queryParams)).build();
Expand All @@ -53,10 +63,14 @@ public Response postProxy(String containerId, String path, String body, Multival
}
}

public Response getProxy(String containerId, String path, MultivaluedMap<String, String> queryParams) {
public Response getProxy(String containerId, String path, MultivaluedMap<String, String> queryParams, HttpHeaders headers) {
if (containerIsNOTAResource(containerId)) {
return Response.status(400, "container name not trustworthy").build();
}

String requestSource = Utilities.getRequestSourceFromHeader(headers);
LOG.info("path={}, requestSource={}, containerId={}, queryParams={}", path, requestSource, containerId, queryParams);

try {
URI uri =
new URIBuilder().setScheme("http").setHost(containerId).setPath(path).setParameters(processParams(queryParams)).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -50,7 +49,7 @@ public void shouldPostToProxy() throws IOException {
Mockito.when(resourceRepository.getByColumn("name", "foo")).thenReturn(List.of(new Resource()));
subject.client = client;

Response actual = subject.postProxy("foo", "/my/cool/path", "{}", new MultivaluedHashMap<>());
Response actual = subject.postProxy("foo", "/my/cool/path", "{}", new MultivaluedHashMap<>(), null);

Assert.assertEquals(200, actual.getStatus());
}
Expand All @@ -63,7 +62,7 @@ public void shouldGetToProxy() throws IOException {
Mockito.when(resourceRepository.getByColumn("name", "bar")).thenReturn(List.of(new Resource()));
subject.client = client;

Response actual = subject.getProxy("bar", "/my/cool/path", new MultivaluedHashMap<>());
Response actual = subject.getProxy("bar", "/my/cool/path", new MultivaluedHashMap<>(), null);

Assert.assertEquals(200, actual.getStatus());
}
Expand All @@ -72,10 +71,10 @@ public void shouldGetToProxy() throws IOException {
public void shouldRejectNastyHost() {
Mockito.when(resourceRepository.getByColumn("name", "an.evil.domain")).thenReturn(List.of());

Response actual = subject.postProxy("an.evil.domain", "hax", null, new MultivaluedHashMap<>());
Response actual = subject.postProxy("an.evil.domain", "hax", null, new MultivaluedHashMap<>(), null);
assertEquals(400, actual.getStatus());

actual = subject.getProxy("an.evil.domain", "hax", new MultivaluedHashMap<>());
actual = subject.getProxy("an.evil.domain", "hax", new MultivaluedHashMap<>(), null);
assertEquals(400, actual.getStatus());
}

Expand All @@ -89,7 +88,7 @@ public void shouldPostWithParams() throws IOException {

MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>();
params.put("site", List.of("bch"));
Response actual = subject.postProxy("foo", "/my/cool/path", "{}", params);
Response actual = subject.postProxy("foo", "/my/cool/path", "{}", params, null);

Assert.assertEquals(200, actual.getStatus());
}
Expand Down

0 comments on commit 5fec463

Please sign in to comment.