Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api v2 init #2832

Merged
merged 24 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/job_test_go_api_local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test GO API Local
on:
workflow_call:



jobs:
test_agent_local:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Rename job to match its purpose.

The job name test_agent_local seems incorrect as this workflow is for testing the Go API (based on the workflow name and file path). Consider renaming it to test_api_local for consistency.

-  test_agent_local:
+  test_api_local:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test_agent_local:
test_api_local:

runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- name: Install
uses: ./.github/actions/install
with:
go: true


- name: Build
run: task build
working-directory: go

- name: Test
run: go test -cover -json -timeout=60m -failfast ./... | tparse -all -progress
working-directory: go
4 changes: 4 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ jobs:
# CLUSTER_TEST: true
# AGENT_BASE_URL: "http://localhost:8080"
# working-directory: apps/agent

test_go_api_local:
name: Test GO API Local
uses: ./.github/workflows/job_test_go_api_local.yaml
6 changes: 6 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ tasks:
cmds:
- task: seed
- pnpm test:integration


generate-sql:
dir: internal/db
cmds:
- pnpm drizzle-kit generate --dialect=mysql
4 changes: 2 additions & 2 deletions apps/agent/pkg/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,9 @@
"tags": ["ratelimit"]
}
},
"/ratelimit.v1.RatelimitService/Ratelimit": {
"/v1/ratelimit.limit": {
"post": {
"operationId": "ratelimit.v1.ratelimit",
"operationId": "v1.ratelimit.limit",
"requestBody": {
"content": {
"application/json": {
Expand Down
17 changes: 17 additions & 0 deletions deployment/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ services:
ports:
- 3900:3900

apiv2:
deploy:
replicas: 1
endpoint_mode: vip

command: [ "api", "--config", "config.docker.json"]
build:
context: ../go
dockerfile: ./Dockerfile
depends_on:
- mysql
- clickhouse
environment:
Comment on lines +34 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add health checks and resource limits.

The service should include health checks and resource constraints for better reliability and resource management.

 apiv2:
   deploy:
     replicas: 1
     endpoint_mode: vip
+    resources:
+      limits:
+        cpus: '1'
+        memory: 512M
+      reservations:
+        cpus: '0.25'
+        memory: 128M
+  healthcheck:
+    test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
+    interval: 30s
+    timeout: 10s
+    retries: 3
+    start_period: 40s
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
apiv2:
deploy:
replicas: 1
endpoint_mode: vip
command: [ "api", "--config", "config.docker.json"]
build:
context: ../go
dockerfile: ./Dockerfile
depends_on:
- mysql
- clickhouse
environment:
apiv2:
deploy:
replicas: 1
endpoint_mode: vip
resources:
limits:
cpus: '1'
memory: 512M
reservations:
cpus: '0.25'
memory: 128M
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
command: [ "api", "--config", "config.docker.json"]
build:
context: ../go
dockerfile: ./Dockerfile
depends_on:
- mysql
- clickhouse
environment:

PORT: 8080
DATABASE_PRIMARY_DSN: "mysql://unkey:password@tcp(mysql:3900)/unkey"
CLICKHOUSE_URL: "clickhouse://default:password@clickhouse:9000"
Comment on lines +47 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Use secrets management for sensitive information.

Hard-coded credentials in environment variables pose a security risk.

Consider using Docker secrets or environment files:

 environment:
   PORT: 8080
-  DATABASE_PRIMARY_DSN: "mysql://unkey:password@tcp(mysql:3900)/unkey"
-  CLICKHOUSE_URL: "clickhouse://default:password@clickhouse:9000"
+  DATABASE_PRIMARY_DSN: "${DATABASE_PRIMARY_DSN}"
+  CLICKHOUSE_URL: "${CLICKHOUSE_URL}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
PORT: 8080
DATABASE_PRIMARY_DSN: "mysql://unkey:password@tcp(mysql:3900)/unkey"
CLICKHOUSE_URL: "clickhouse://default:password@clickhouse:9000"
PORT: 8080
DATABASE_PRIMARY_DSN: "${DATABASE_PRIMARY_DSN}"
CLICKHOUSE_URL: "${CLICKHOUSE_URL}"


agent:
deploy:
replicas: 3
Expand Down
Loading
Loading