-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OPIK-397] Add trace stats endpoint (#692)
* [OPIK-397] Add trace stats endpoint * Add to string * Test * Fix test quantiles calc
- Loading branch information
1 parent
1d78f1c
commit 6376b74
Showing
6 changed files
with
2,903 additions
and
2 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
apps/opik-backend/src/main/java/com/comet/opik/api/ProjectStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.comet.opik.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import io.swagger.v3.oas.annotations.media.DiscriminatorMapping; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.beans.ConstructorProperties; | ||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
@Builder(toBuilder = true) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record ProjectStats(List<ProjectStatItem<?>> stats) { | ||
|
||
public static ProjectStats empty() { | ||
return new ProjectStats(List.of()); | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = PercentageValueStat.class, name = "PERCENTAGE"), | ||
@JsonSubTypes.Type(value = CountValueStat.class, name = "COUNT"), | ||
@JsonSubTypes.Type(value = AvgValueStat.class, name = "AVG") | ||
}) | ||
@Schema(discriminatorProperty = "type", discriminatorMapping = { | ||
@DiscriminatorMapping(value = "PERCENTAGE", schema = PercentageValueStat.class), | ||
@DiscriminatorMapping(value = "COUNT", schema = CountValueStat.class), | ||
@DiscriminatorMapping(value = "AVG", schema = AvgValueStat.class), | ||
}) | ||
@RequiredArgsConstructor | ||
@Getter | ||
@SuperBuilder(toBuilder = true) | ||
@EqualsAndHashCode | ||
@ToString(callSuper = true) | ||
public abstract static sealed class ProjectStatItem<T> { | ||
private final String name; | ||
private final T value; | ||
private final StatsType type; | ||
} | ||
|
||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
@SuperBuilder(toBuilder = true) | ||
@Getter | ||
public abstract static sealed class SingleValueStat<T extends Number> extends ProjectStatItem<T> { | ||
} | ||
|
||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
@SuperBuilder(toBuilder = true) | ||
@Getter | ||
public static final class CountValueStat extends SingleValueStat<Long> { | ||
|
||
@ConstructorProperties({"name", "value"}) | ||
public CountValueStat(String name, Long value) { | ||
super(CountValueStat.builder().value(value).name(name).type(StatsType.COUNT)); | ||
} | ||
} | ||
|
||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
@SuperBuilder(toBuilder = true) | ||
@Getter | ||
public static final class AvgValueStat extends SingleValueStat<Number> { | ||
|
||
@ConstructorProperties({"name", "value"}) | ||
public AvgValueStat(String name, Number value) { | ||
super(AvgValueStat.builder().value(value).name(name).type(StatsType.AVG)); | ||
} | ||
} | ||
|
||
public record PercentageValues(double p50, double p90, double p99) { | ||
} | ||
|
||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
@SuperBuilder(toBuilder = true) | ||
@Getter | ||
public static final class PercentageValueStat extends ProjectStatItem<PercentageValues> { | ||
|
||
@ConstructorProperties({"name", "value"}) | ||
public PercentageValueStat(String name, PercentageValues value) { | ||
super(PercentageValueStat.builder().value(value).name(name).type(StatsType.PERCENTAGE)); | ||
} | ||
} | ||
|
||
public enum StatsType { | ||
COUNT, | ||
PERCENTAGE, | ||
AVG | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.