Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
if no time range set use entity request handler (#132)
Browse files Browse the repository at this point in the history
* if not time range set use entity request handler

* typo

* address comments

* spotless

* make time range fields optional
  • Loading branch information
d-trace authored May 26, 2022
1 parent 6bd4b24 commit 2b307b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import "org/hypertrace/gateway/service/v1/gateway_query.proto";
message ExploreRequest {
// The context of this request eg. APIs, API Traces etc.
string context = 1;
sfixed64 start_time_millis = 2;
sfixed64 end_time_millis = 3;
optional sfixed64 start_time_millis = 2;
optional sfixed64 end_time_millis = 3;

// Filters for the WHERE clause
org.hypertrace.gateway.service.v1.common.Filter filter = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.hypertrace.gateway.service.v1.explore.ExploreResponse;

public class ExploreService {
private static final String NO_TIME_RANGE_SPECIFIED_ERROR_MESSAGE =
"Source has to set to EDS if " + "no time range specified";

private final AttributeMetadataProvider attributeMetadataProvider;
private final ExploreRequestValidator exploreRequestValidator = new ExploreRequestValidator();
Expand Down Expand Up @@ -129,9 +131,12 @@ private IRequestHandler getRequestHandler(
request.getGroupByList());
Optional<String> source =
ExpressionContext.getSingleSourceForAllAttributes(expressionContext);
if (source.isPresent() && EDS.toString().equals(source.get())) {
if ((source.isPresent() && EDS.toString().equals(source.get())) || !hasTimeRange(request)) {
return entityRequestHandler;
}
if ((source.isPresent() && !EDS.toString().equals(source.get())) && !hasTimeRange(request)) {
throw new IllegalArgumentException(NO_TIME_RANGE_SPECIFIED_ERROR_MESSAGE);
}
}

if (hasTimeAggregationsAndGroupBy(request)) {
Expand All @@ -140,6 +145,7 @@ private IRequestHandler getRequestHandler(
if (hasTimeAggregations(request)) {
return timeAggregationsRequestHandler;
}

return normalRequestHandler;
}

Expand All @@ -150,4 +156,8 @@ private boolean hasTimeAggregations(ExploreRequest request) {
private boolean hasTimeAggregationsAndGroupBy(ExploreRequest request) {
return !request.getTimeAggregationList().isEmpty() && !request.getGroupByList().isEmpty();
}

private boolean hasTimeRange(ExploreRequest request) {
return request.hasStartTimeMillis() && request.hasEndTimeMillis();
}
}

0 comments on commit 2b307b8

Please sign in to comment.