-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'thiagohora/OPIK-68_add_rate_limit' of https://github.co…
…m/comet-ml/opik into thiagohora/OPIK-68_add_rate_limit
- Loading branch information
Showing
78 changed files
with
4,337 additions
and
419 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,11 +2,73 @@ name: SDK E2E Tests | |
run-name: "SDK E2E Tests ${{ github.ref_name }} by @${{ github.actor }}" | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
paths: | ||
- 'sdks/python/**' | ||
- 'apps/opik-backend/**' | ||
push: | ||
branches: | ||
- 'main' | ||
paths: | ||
- 'sdks/python/**' | ||
- 'apps/opik-backend/**' | ||
|
||
jobs: | ||
run-e2e: | ||
name: SDK E2E Tests | ||
name: SDK E2E Tests ${{matrix.python_version}} | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: sdks/python | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
|
||
steps: | ||
- name: echo | ||
run: echo | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
- name: Setup Python ${{matrix.python_version}} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{matrix.python_version}} | ||
|
||
- name: Install opik SDK | ||
run: | | ||
pip install -r tests/test_requirements.txt | ||
pip install . | ||
- name: Run latest opik server | ||
run: | | ||
cd ../../deployment/docker-compose | ||
docker compose up -d | ||
cd - | ||
- name: Run tests | ||
run: | | ||
echo "Waiting for server to come up..." | ||
sleep 30 | ||
export OPIK_URL_OVERRIDE=http://localhost:5173/api | ||
pytest tests/e2e -vv | ||
- name: Keep BE log in case of failure | ||
if: failure() | ||
run: | | ||
docker logs opik-backend-1 > opik-backend_p${{matrix.python_version}}.log | ||
- name: Attach BE log | ||
if: failure() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: opik-backend-log-p${{matrix.python_version}} | ||
path: sdks/python/opik-backend_p${{matrix.python_version}}.log | ||
|
||
- name: Stop opik server | ||
if: always() | ||
run: | | ||
cd ../../deployment/docker-compose | ||
docker compose down | ||
cd - | ||
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
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
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
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
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
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
26 changes: 26 additions & 0 deletions
26
apps/opik-backend/src/main/java/com/comet/opik/api/TraceCountResponse.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,26 @@ | ||
package com.comet.opik.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.Builder; | ||
|
||
import java.util.List; | ||
|
||
@Builder(toBuilder = true) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record TraceCountResponse( | ||
List<WorkspaceTraceCount> workspacesTracesCount) { | ||
public static TraceCountResponse empty() { | ||
return new TraceCountResponse(List.of()); | ||
} | ||
|
||
@Builder(toBuilder = true) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record WorkspaceTraceCount( | ||
String workspace, | ||
int traceCount) { | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
apps/opik-backend/src/main/java/com/comet/opik/api/resources/v1/internal/UsageResource.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,40 @@ | ||
package com.comet.opik.api.resources.v1.internal; | ||
|
||
import com.codahale.metrics.annotation.Timed; | ||
import com.comet.opik.api.TraceCountResponse; | ||
import com.comet.opik.domain.TraceService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Path("/v1/internal/usage") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Timed | ||
@Slf4j | ||
@RequiredArgsConstructor(onConstructor_ = @jakarta.inject.Inject) | ||
@Tag(name = "System usage", description = "System usage related resource") | ||
public class UsageResource { | ||
private final @NonNull TraceService traceService; | ||
|
||
@GET | ||
@Path("/workspace-trace-counts") | ||
@Operation(operationId = "getTracesCountForWorkspaces", summary = "Get traces count on previous day for all available workspaces", description = "Get traces count on previous day for all available workspaces", responses = { | ||
@ApiResponse(responseCode = "200", description = "TraceCountResponse resource", content = @Content(schema = @Schema(implementation = TraceCountResponse.class)))}) | ||
public Response getTracesCountForWorkspaces() { | ||
return traceService.countTracesPerWorkspace() | ||
.map(tracesCountResponse -> Response.ok(tracesCountResponse).build()) | ||
.block(); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
apps/opik-backend/src/main/java/com/comet/opik/domain/NameGenerator.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,28 @@ | ||
package com.comet.opik.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.List; | ||
|
||
@Builder | ||
public class NameGenerator { | ||
|
||
private final @NonNull SecureRandom secureRandom; | ||
|
||
private final @NonNull List<String> adjectives; | ||
private final @NonNull List<String> nouns; | ||
|
||
public String generateName() { | ||
var adjective = getRandom(adjectives); | ||
var noun = getRandom(nouns); | ||
var number = secureRandom.nextInt(0, 10000); | ||
return "%s_%s_%s".formatted(adjective, noun, number); | ||
} | ||
|
||
private String getRandom(List<String> strings) { | ||
int index = secureRandom.nextInt(0, strings.size()); | ||
return strings.get(index); | ||
} | ||
} |
Oops, something went wrong.