Skip to content

Commit

Permalink
OPIK-968: Add trace count to project (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagohora authored Feb 12, 2025
1 parent 3cb7c15 commit c9ae181
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public record Project(
@JsonView({
Project.View.Detailed.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) @Nullable Double totalEstimatedCost,
@JsonView({
Project.View.Detailed.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) @Nullable Map<String, Double> usage){
Project.View.Detailed.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) @Nullable Map<String, Double> usage,
@JsonView({
Project.View.Detailed.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) @Nullable Long traceCount){

public static class View {
public static class Write {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public record ProjectStatsSummaryItem(
List<FeedbackScoreAverage> feedbackScores,
ProjectStats.PercentageValues duration,
Double totalEstimatedCost,
Map<String, Double> usage) {
Map<String, Double> usage,
Long traceCount) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ private ProjectStatsSummaryItem getStats(UUID projectId, Map<String, Object> pro
.duration(StatsMapper.getStatsDuration(projectStats))
.totalEstimatedCost(StatsMapper.getStatsTotalEstimatedCost(projectStats))
.usage(StatsMapper.getStatsUsage(projectStats))
.traceCount(StatsMapper.getStatsTraceCount(projectStats))
.build();
}

Expand Down Expand Up @@ -490,6 +491,7 @@ public Project retrieveByName(@NonNull String projectName) {
.duration(StatsMapper.getStatsDuration(projectStats.get(project.id())))
.totalEstimatedCost(
StatsMapper.getStatsTotalEstimatedCost(projectStats.get(project.id())))
.traceCount(StatsMapper.getStatsTraceCount(projectStats.get(project.id())))
.build();
})
.orElseThrow(this::createNotFoundError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class StatsMapper {
public static final String OUTPUT = "output";
public static final String METADATA = "metadata";
public static final String TAGS = "tags";
public static final String TRACE_COUNT = "trace_count";

public static ProjectStats mapProjectStats(Row row, String entityCountLabel) {

Expand Down Expand Up @@ -111,4 +112,10 @@ public static PercentageValues getStatsDuration(Map<String, ?> stats) {
.map(map -> (PercentageValues) map.get(DURATION))
.orElse(null);
}

public static Long getStatsTraceCount(Map<String, Object> projectStats) {
return Optional.ofNullable(projectStats)
.map(map -> (Long) map.get(TRACE_COUNT))
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ProjectsResourceTest {
public static final String URL_TEMPLATE = "%s/v1/private/projects";
public static final String URL_TEMPLATE_TRACE = "%s/v1/private/traces";
public static final String[] IGNORED_FIELDS = {"createdBy", "lastUpdatedBy", "createdAt", "lastUpdatedAt",
"lastUpdatedTraceAt", "feedbackScores", "duration", "totalEstimatedCost", "usage"};
"lastUpdatedTraceAt", "feedbackScores", "duration", "totalEstimatedCost", "usage", "traceCount"};
public static final String[] IGNORED_FIELD_MIN = {"createdBy", "lastUpdatedBy", "createdAt", "lastUpdatedAt",
"lastUpdatedTraceAt"};

Expand Down Expand Up @@ -1254,6 +1254,7 @@ private List<ProjectStatsSummaryItem> getProjectStatsSummaryItems(String apiKey,
.usage(project.usage())
.feedbackScores(project.feedbackScores())
.projectId(project.id())
.traceCount(project.traceCount())
.build())
.toList();
}
Expand Down Expand Up @@ -1495,6 +1496,7 @@ private Project buildProjectStats(Project project, String apiKey, String workspa
.collect(groupingBy(Map.Entry::getKey, averagingDouble(Map.Entry::getValue))))
.feedbackScores(getScoreAverages(traces))
.lastUpdatedTraceAt(traces.stream().map(Trace::lastUpdatedAt).max(Instant::compareTo).orElse(null))
.traceCount((long) traces.size())
.build();
}

Expand Down

0 comments on commit c9ae181

Please sign in to comment.