Skip to content

Commit

Permalink
[OPIK-160] Fix trace and span error during insertion due to input/out…
Browse files Browse the repository at this point in the history
…put size (#362)

* [OPIK-160] Fix trace and span error during insertion due to input/output size

* Fix tests
  • Loading branch information
thiagohora authored Oct 9, 2024
1 parent c4e15fd commit 63d162b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/opik-backend/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ databaseAnalytics:
username: ${ANALYTICS_DB_USERNAME:-opik}
password: ${ANALYTICS_DB_PASS:-opik}
databaseName: ${ANALYTICS_DB_DATABASE_NAME:-opik}
queryParameters: ${ANALYTICS_DB_QUERY_PARAMETERS:-health_check_interval=2000&compress=1&auto_discovery=true&failover=3}
queryParameters: ${ANALYTICS_DB_QUERY_PARAMETERS:-health_check_interval=2000&compress=1&auto_discovery=true&failover=3&custom_http_params=max_query_size=100000000}

health:
healthCheckUrlPaths: [ "/health-check" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,27 @@ void createAndGetById() {
getAndAssert(expectedSpan, API_KEY, TEST_WORKSPACE);
}

@Test
void createAndGet__whenSpanInputIsBig__thenReturnSpan() {

int size = 1000;

Map<String, String> jsonMap = IntStream.range(0, size)
.mapToObj(i -> Map.entry(RandomStringUtils.randomAlphabetic(10), RandomStringUtils.randomAscii(size)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

var expectedSpan = podamFactory.manufacturePojo(Span.class).toBuilder()
.projectId(null)
.parentSpanId(null)
.input(JsonUtils.readTree(jsonMap))
.output(JsonUtils.readTree(jsonMap))
.build();

createAndAssert(expectedSpan, API_KEY, TEST_WORKSPACE);

getAndAssert(expectedSpan, API_KEY, TEST_WORKSPACE);
}

@Test
void createOnlyRequiredFieldsAndGetById() {
var expectedSpan = podamFactory.manufacturePojo(Span.class)
Expand Down Expand Up @@ -3568,7 +3589,7 @@ void when__spanDoesNotExist__thenReturnCreateIt() {
assertThat(actualEntity.metadata()).isEqualTo(spanUpdate.metadata());
assertThat(actualEntity.tags()).isEqualTo(spanUpdate.tags());

assertThat(actualEntity.name()).isEqualTo("");
assertThat(actualEntity.name()).isEmpty();
assertThat(actualEntity.startTime()).isEqualTo(Instant.EPOCH);
assertThat(actualEntity.type()).isNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3422,6 +3422,30 @@ void create__whenProjectNameIsNull__thenAcceptAndUseDefaultProject() {
assertThat(actualEntity.projectId()).isEqualTo(projectId);
}

@Test
@DisplayName("when trace input is big, then accept and create trace")
void createAndGet__whenTraceInputIsBig__thenReturnSpan() {

int size = 1000;

Map<String, String> jsonMap = IntStream.range(0, size)
.mapToObj(i -> Map.entry(RandomStringUtils.randomAlphabetic(10), RandomStringUtils.randomAscii(size)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

var expectedTrace = factory.manufacturePojo(Trace.class).toBuilder()
.projectId(null)
.input(JsonUtils.readTree(jsonMap))
.output(JsonUtils.readTree(jsonMap))
.feedbackScores(null)
.usage(null)
.build();

create(expectedTrace, API_KEY, TEST_WORKSPACE);

UUID projectId = getProjectId(expectedTrace.projectName(), TEST_WORKSPACE, API_KEY);
getAndAssert(expectedTrace, projectId, API_KEY, TEST_WORKSPACE);
}

}

@Nested
Expand Down
2 changes: 1 addition & 1 deletion apps/opik-backend/src/test/resources/config-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ databaseAnalytics:
username: opik
password: opik
databaseName: opik
queryParameters: health_check_interval=2000&compress=1&auto_discovery=true&failover=3
queryParameters: health_check_interval=2000&compress=1&auto_discovery=true&failover=3&custom_http_params=max_query_size=100000000

health:
healthCheckUrlPaths: [ "/health-check" ]
Expand Down

0 comments on commit 63d162b

Please sign in to comment.