Skip to content

Commit

Permalink
OPIK-287 fix logical conflicts after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
idoberko2 committed Dec 18, 2024
1 parent d47beac commit 7295cf4
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 92 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.comet.opik.domain.cost.ModelPrice;
import com.comet.opik.infrastructure.auth.RequestContext;
import com.comet.opik.podam.PodamFactoryUtils;
import com.comet.opik.utils.DurationUtils;
import com.comet.opik.utils.JsonUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.NullNode;
Expand All @@ -57,7 +56,6 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;
import org.jdbi.v3.core.Jdbi;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -3398,17 +3396,6 @@ private void assertIgnoredFields(List<Span> actualSpans, List<Span> expectedSpan
assertThat(actualSpan.duration()).isEqualTo(expected, within(0.001));
}

SoftAssertions.assertSoftly(softly -> {
var expected = DurationUtils.getDurationInMillisWithSubMilliPrecision(
expectedSpan.startTime(), expectedSpan.endTime());

if (actualSpan.duration() == null || expected == null) {
softly.assertThat(actualSpan.duration()).isEqualTo(expected);
} else {
softly.assertThat(actualSpan.duration()).isEqualTo(expected, within(0.001));
}
});

if (actualSpan.feedbackScores() != null) {
actualSpan.feedbackScores().forEach(feedbackScore -> {
assertThat(feedbackScore.createdAt()).isAfter(expectedSpan.createdAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.comet.opik.domain.cost.ModelPrice;
import com.comet.opik.infrastructure.auth.RequestContext;
import com.comet.opik.podam.PodamFactoryUtils;
import com.comet.opik.utils.DurationUtils;
import com.comet.opik.utils.JsonUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.uuid.Generators;
Expand All @@ -54,7 +53,6 @@
import jakarta.ws.rs.core.Response;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.http.HttpStatus;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;
import org.jdbi.v3.core.Jdbi;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -6819,83 +6817,6 @@ void getTraceStats__whenFilterByDuration__thenReturnTracesFiltered(Operator oper
getStatsAndAssert(projectName, null, filters, apiKey, workspaceName, expectedStats);
}

Stream<Arguments> getTraceStats__whenFilterByDuration__thenReturnTracesFiltered() {
return Stream.of(
arguments(Operator.EQUAL,
Duration.ofMillis(1L).toNanos() / 1000, 1.0),
arguments(Operator.GREATER_THAN,
Duration.ofMillis(8L).toNanos() / 1000, 7.0),
arguments(Operator.GREATER_THAN_EQUAL,
Duration.ofMillis(1L).toNanos() / 1000, 1.0),
arguments(Operator.GREATER_THAN_EQUAL,
Duration.ofMillis(1L).plusNanos(1000).toNanos() / 1000, 1.0),
arguments(Operator.LESS_THAN,
Duration.ofMillis(1L).plusNanos(1).toNanos() / 1000, 2.0),
arguments(Operator.LESS_THAN_EQUAL,
Duration.ofMillis(1L).toNanos() / 1000, 1.0),
arguments(Operator.LESS_THAN_EQUAL,
Duration.ofMillis(1L).toNanos() / 1000, 2.0));
}

@ParameterizedTest
@MethodSource
void getTraceStats__whenFilterByDuration__thenReturnTracesFiltered(Operator operator, long end,
double duration) {
String workspaceName = UUID.randomUUID().toString();
String workspaceId = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName, workspaceId);

var projectName = generator.generate().toString();
var traces = PodamFactoryUtils.manufacturePojoList(factory, Trace.class)
.stream()
.map(trace -> {
Instant now = Instant.now();
return trace.toBuilder()
.projectId(null)
.usage(null)
.projectName(projectName)
.feedbackScores(null)
.totalEstimatedCost(BigDecimal.ZERO)
.startTime(now)
.endTime(Set.of(Operator.LESS_THAN, Operator.LESS_THAN_EQUAL).contains(operator)
? Instant.now().plusSeconds(2)
: now.plusNanos(1000))
.build();
})
.collect(Collectors.toCollection(ArrayList::new));

var start = Instant.now().truncatedTo(ChronoUnit.MILLIS);
traces.set(0, traces.getFirst().toBuilder()
.startTime(start)
.endTime(start.plus(end, ChronoUnit.MICROS))
.build());

traces.forEach(expectedTrace -> create(expectedTrace, apiKey, workspaceName));

var expectedTraces = List.of(traces.getFirst());

var unexpectedTraces = PodamFactoryUtils.manufacturePojoList(factory, Trace.class).stream()
.map(span -> span.toBuilder()
.projectId(null)
.build())
.toList();

unexpectedTraces.forEach(expectedTrace -> create(expectedTrace, apiKey, workspaceName));

var filters = List.of(
TraceFilter.builder()
.field(TraceField.DURATION)
.operator(operator)
.value(String.valueOf(duration))
.build());

var expectedStats = getProjectTraceStatItems(expectedTraces);

getStatsAndAssert(projectName, null, filters, apiKey, workspaceName, expectedStats);
}

private void getStatsAndAssert(String projectName, UUID projectId, List<? extends TraceFilter> filters,
String apiKey, String workspaceName, List<ProjectStatItem<?>> expectedStats) {
WebTarget webTarget = client.target(URL_TEMPLATE.formatted(baseURI))
Expand Down

0 comments on commit 7295cf4

Please sign in to comment.