-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPIK-904: Split find project endpoint into two endpoints find and stats #1176
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.comet.opik.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.Builder; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@Builder(toBuilder = true) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record ProjectStatsSummary(List<ProjectStatsSummaryItem> content) { | ||
|
||
@Builder(toBuilder = true) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record ProjectStatsSummaryItem( | ||
UUID projectId, | ||
List<FeedbackScoreAverage> feedbackScores, | ||
ProjectStats.PercentageValues duration, | ||
Double totalEstimatedCost, | ||
Map<String, Double> usage) { | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import com.comet.opik.api.Project; | ||
import com.comet.opik.api.ProjectCriteria; | ||
import com.comet.opik.api.ProjectRetrieve; | ||
import com.comet.opik.api.ProjectStatsSummary; | ||
import com.comet.opik.api.ProjectUpdate; | ||
import com.comet.opik.api.error.ErrorMessage; | ||
import com.comet.opik.api.metrics.ProjectMetricRequest; | ||
|
@@ -68,6 +69,7 @@ | |
@Tag(name = "Projects", description = "Project related resources") | ||
public class ProjectsResource { | ||
|
||
private static final String PAGE_SIZE = "10"; | ||
private final @NonNull ProjectService projectService; | ||
private final @NonNull Provider<RequestContext> requestContext; | ||
private final @NonNull SortingFactoryProjects sortingFactory; | ||
|
@@ -81,7 +83,7 @@ public class ProjectsResource { | |
@JsonView({Project.View.Public.class}) | ||
public Response find( | ||
@QueryParam("page") @Min(1) @DefaultValue("1") int page, | ||
@QueryParam("size") @Min(1) @DefaultValue("10") int size, | ||
@QueryParam("size") @Min(1) @DefaultValue(PAGE_SIZE) int size, | ||
@QueryParam("name") String name, | ||
@QueryParam("sorting") String sorting) { | ||
|
||
|
@@ -188,7 +190,7 @@ public Response deleteById(@PathParam("id") UUID id) { | |
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(schema = @Schema(implementation = ErrorMessage.class))), | ||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(implementation = ErrorMessage.class))) | ||
}) | ||
@JsonView({Project.View.Public.class}) | ||
@JsonView({Project.View.Detailed.class}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no test that verifies fields marked with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test remains the same since this endpoint didn't change; only the. find was affected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, old test also didn't check it. So we basically never verified that those values(now annotated with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, let me check it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
public Response retrieveProject( | ||
@RequestBody(content = @Content(schema = @Schema(implementation = ProjectRetrieve.class))) @Valid ProjectRetrieve retrieve) { | ||
String workspaceId = requestContext.get().getWorkspaceId(); | ||
|
@@ -268,4 +270,32 @@ private void validate(ProjectMetricRequest request) { | |
throw new BadRequestException(ERR_START_BEFORE_END); | ||
} | ||
} | ||
|
||
@GET | ||
@Path("/stats") | ||
@Operation(operationId = "getProjectStats", summary = "Get Project Stats", description = "Get Project Stats", responses = { | ||
@ApiResponse(responseCode = "200", description = "Project Stats", content = @Content(schema = @Schema(implementation = ProjectStatsSummary.class))), | ||
}) | ||
public Response getProjectStats( | ||
@QueryParam("page") @Min(1) @DefaultValue("1") int page, | ||
@QueryParam("size") @Min(1) @DefaultValue(PAGE_SIZE) int size, | ||
@QueryParam("name") String name, | ||
@QueryParam("sorting") String sorting) { | ||
|
||
var criteria = ProjectCriteria.builder() | ||
.projectName(name) | ||
.build(); | ||
|
||
String workspaceId = requestContext.get().getWorkspaceId(); | ||
|
||
List<SortingField> sortingFields = sortingFactory.newSorting(sorting); | ||
|
||
log.info("Find projects stats by '{}' on workspaceId '{}'", criteria, workspaceId); | ||
ProjectStatsSummary projectStatisticsSummary = projectService.getStats(page, size, criteria, sortingFields); | ||
log.info("Found projects stats by '{}', count '{}' on workspaceId '{}'", criteria, | ||
projectStatisticsSummary.content().size(), workspaceId); | ||
|
||
return Response.ok().entity(projectStatisticsSummary).build(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: this could be a lightweight Page object, with
page
,size
on top of the currentcontent
and withouttotal
. But this works as FE is fine with it. We can always extend it in the future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can add in the next iteration