From 7295cf4fd5e131996e531dd567799c1ff23cee5a Mon Sep 17 00:00:00 2001 From: Ido Berkovich Date: Wed, 18 Dec 2024 18:03:34 +0200 Subject: [PATCH] OPIK-287 fix logical conflicts after rebase --- .../000008_add_duration_columns.sql | 0 .../resources/v1/priv/SpansResourceTest.java | 13 --- .../resources/v1/priv/TracesResourceTest.java | 79 ------------------- 3 files changed, 92 deletions(-) delete mode 100644 apps/opik-backend/src/main/resources/liquibase/db-app-analytics/migrations/000008_add_duration_columns.sql diff --git a/apps/opik-backend/src/main/resources/liquibase/db-app-analytics/migrations/000008_add_duration_columns.sql b/apps/opik-backend/src/main/resources/liquibase/db-app-analytics/migrations/000008_add_duration_columns.sql deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/SpansResourceTest.java b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/SpansResourceTest.java index 560f458971..2b5c224280 100644 --- a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/SpansResourceTest.java +++ b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/SpansResourceTest.java @@ -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; @@ -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; @@ -3398,17 +3396,6 @@ private void assertIgnoredFields(List actualSpans, List 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()); diff --git a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/TracesResourceTest.java b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/TracesResourceTest.java index 680acdb535..bf563902d0 100644 --- a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/TracesResourceTest.java +++ b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/TracesResourceTest.java @@ -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; @@ -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; @@ -6819,83 +6817,6 @@ void getTraceStats__whenFilterByDuration__thenReturnTracesFiltered(Operator oper getStatsAndAssert(projectName, null, filters, apiKey, workspaceName, expectedStats); } - Stream 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 filters, String apiKey, String workspaceName, List> expectedStats) { WebTarget webTarget = client.target(URL_TEMPLATE.formatted(baseURI))