Skip to content

Commit

Permalink
Merge branch 'main' into fix-ratelimit-identifier-input
Browse files Browse the repository at this point in the history
  • Loading branch information
ogzhanolguncu authored Dec 9, 2024
2 parents 097dc23 + a7a2e62 commit 4f47372
Show file tree
Hide file tree
Showing 28 changed files with 505 additions and 213 deletions.
6 changes: 3 additions & 3 deletions .github/actions/install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ runs:
with:
go-version-file: ./apps/agent/go.mod
cache-dependency-path: ./apps/agent/go.sum

- run: go mod download
if: ${{ inputs.go == 'true' }}
shell: bash
Expand All @@ -32,7 +32,7 @@ runs:
- name: Install Task
uses: arduino/setup-task@v2
if: ${{ inputs.go == 'true' }}

- name: Setup Node
if: ${{ inputs.ts == 'true' }}
uses: actions/setup-node@v4
Expand Down Expand Up @@ -69,4 +69,4 @@ runs:
shell: bash
run: |
pnpm install --recursive
npm i -g wrangler
npm i -g wrangler@latest
11 changes: 10 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,23 @@ jobs:
secrets:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

changes:
uses: ./.github/workflows/job_changes.yaml


clickhouse_migration_preview:
needs: api_local_test
if: needs.changes.outputs.clickhouse == 'true'
needs:
- changes
- api_local_test
uses: ./.github/workflows/job_clickhouse_migration_preview.yaml
secrets:
CLICKHOUSE_URL: ${{ secrets.CLICKHOUSE_URL }}

clickhouse_migration_production:
if: needs.changes.outputs.clickhouse == 'true'
needs:
- changes
- api_preview_test
- agent_staging_deployment
- clickhouse_migration_preview
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/job_build_agent_image.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Docker Build Agent
on:
workflow_call:
secrets:
GHCR_TOKEN:
secrets:
GHCR_TOKEN:
required: true
description: "github registrytoken"




jobs:
Expand Down Expand Up @@ -40,4 +40,4 @@ jobs:
platforms: linux/amd64
push: true
tags: ${{ env.TAGS }}
build-args: VERSION=${{env.VERSION}}
build-args: VERSION=${{env.VERSION}}
19 changes: 19 additions & 0 deletions .github/workflows/job_changes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Changes
on:
workflow_call:




jobs:
build:
name: Build Agent
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
clickhouse:
- 'internal/clickhouse/schema/**'
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@vitest/ui": "^1.6.0",
"typescript": "^5.5.3",
"vitest": "^1.6.0",
"wrangler": "^3.80.5"
"wrangler": "^3.92.0"
},
"dependencies": {
"@axiomhq/js": "1.0.0-rc.2",
Expand Down
13 changes: 12 additions & 1 deletion apps/api/src/pkg/middleware/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export function metrics(): MiddlewareHandler<HonoEnv> {

let requestBody = await c.req.raw.clone().text();
requestBody = requestBody.replaceAll(/"key":\s*"[a-zA-Z0-9_]+"/g, '"key": "<REDACTED>"');
requestBody = requestBody.replaceAll(
/"plaintext":\s*"[a-zA-Z0-9_]+"/g,
'"plaintext": "<REDACTED>"',
);
const start = performance.now();
const m = {
isolateId: c.get("isolateId"),
Expand Down Expand Up @@ -92,6 +96,13 @@ export function metrics(): MiddlewareHandler<HonoEnv> {
responseHeaders.push(`${k}: ${v}`);
});

let responseBody = await c.res.clone().text();
responseBody = responseBody.replaceAll(/"key":\s*"[a-zA-Z0-9_]+"/g, '"key": "<REDACTED>"');
responseBody = responseBody.replaceAll(
/"plaintext":\s*"[a-zA-Z0-9_]+"/g,
'"plaintext": "<REDACTED>"',
);

c.executionCtx.waitUntil(
analytics.insertApiRequest({
request_id: c.get("requestId"),
Expand All @@ -109,7 +120,7 @@ export function metrics(): MiddlewareHandler<HonoEnv> {
request_body: requestBody,
response_status: c.res.status,
response_headers: responseHeaders,
response_body: await c.res.clone().text(),
response_body: responseBody,
error: m.error ?? "",
service_latency: Date.now() - c.get("requestStartedAt"),
ip_address: c.req.header("True-Client-IP") ?? c.req.header("CF-Connecting-IP") ?? "",
Expand Down
32 changes: 17 additions & 15 deletions apps/api/src/routes/v1_keys_verifyKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,23 @@ export const registerV1KeysVerifyKey = (app: App) =>
}
: undefined,
};
c.executionCtx.waitUntil(
// new clickhouse
analytics.insertKeyVerification({
request_id: c.get("requestId"),
time: Date.now(),
workspace_id: val.key.workspaceId,
key_space_id: val.key.keyAuthId,
key_id: val.key.id,
// @ts-expect-error
region: c.req.raw.cf.colo ?? "",
outcome: val.code ?? "VALID",
identity_id: val.identity?.id,
tags: req.tags ?? [],
}),
);
if (val.code) {
c.executionCtx.waitUntil(
// new clickhouse
analytics.insertKeyVerification({
request_id: c.get("requestId"),
time: Date.now(),
workspace_id: val.key.workspaceId,
key_space_id: val.key.keyAuthId,
key_id: val.key.id,
// @ts-expect-error
region: c.req.raw.cf.colo ?? "",
outcome: val.code ?? "",
identity_id: val.identity?.id,
tags: req.tags ?? [],
}),
);
}

return c.json(responseBody);
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { useForm } from "react-hook-form";
import { z } from "zod";
const formSchema = z.object({
keyAuthId: z.string(),
workspaceId: z.string(),
defaultBytes: z
.number()
.min(8, "Byte size needs to be at least 8")
Expand All @@ -30,7 +29,6 @@ const formSchema = z.object({
type Props = {
keyAuth: {
id: string;
workspaceId: string;
defaultBytes: number | undefined | null;
};
};
Expand All @@ -42,7 +40,6 @@ export const DefaultBytes: React.FC<Props> = ({ keyAuth }) => {
defaultValues: {
defaultBytes: keyAuth.defaultBytes ?? undefined,
keyAuthId: keyAuth.id,
workspaceId: keyAuth.workspaceId,
},
});

Expand Down Expand Up @@ -78,7 +75,6 @@ export const DefaultBytes: React.FC<Props> = ({ keyAuth }) => {
</CardHeader>
<CardContent>
<div className="flex flex-col space-y-2">
<input type="hidden" name="workspaceId" value={keyAuth.workspaceId} />
<input type="hidden" name="keyAuthId" value={keyAuth.id} />
<label className="hidden sr-only">Default Bytes</label>
<FormField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { z } from "zod";

const formSchema = z.object({
keyAuthId: z.string(),
workspaceId: z.string(),
defaultPrefix: z.string(),
});

type Props = {
keyAuth: {
id: string;
workspaceId: string;
defaultPrefix: string | undefined | null;
};
};
Expand All @@ -38,7 +37,6 @@ export const DefaultPrefix: React.FC<Props> = ({ keyAuth }) => {
defaultValues: {
defaultPrefix: keyAuth.defaultPrefix ?? undefined,
keyAuthId: keyAuth.id,
workspaceId: keyAuth.workspaceId,
},
});

Expand Down Expand Up @@ -71,7 +69,6 @@ export const DefaultPrefix: React.FC<Props> = ({ keyAuth }) => {
</CardHeader>
<CardContent>
<div className="flex flex-col space-y-2">
<input type="hidden" name="workspaceId" value={keyAuth.workspaceId} />
<input type="hidden" name="keyAuthId" value={keyAuth.id} />
<label className="hidden sr-only">Default Prefix</label>
<FormField
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/desktop-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const DesktopSidebar: React.FC<Props> = ({ workspace, className }) => {
)}
>
<div className="flex min-w-full mt-2 -mx-2">
<WorkspaceSwitcher />
<WorkspaceSwitcher workspace={workspace} />
</div>
{workspace.planDowngradeRequest ? (
<div className="flex justify-center w-full mt-2">
Expand Down
3 changes: 0 additions & 3 deletions apps/dashboard/app/(app)/logs/logs-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import type { Log } from "./types";

export function LogsPage({
initialLogs,
workspaceId,
}: {
initialLogs: Log[];
workspaceId: string;
}) {
const { searchParams } = useLogSearchParams();
const [logs, setLogs] = useState(initialLogs);
Expand All @@ -24,7 +22,6 @@ export function LogsPage({

const { data: newData, isLoading } = trpc.logs.queryLogs.useQuery(
{
workspaceId,
limit: 100,
startTime: searchParams.startTime,
endTime,
Expand Down
8 changes: 2 additions & 6 deletions apps/dashboard/app/(app)/logs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ export default async function Page({
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)),
});

if (!workspace) {
return <div>Workspace with tenantId: {tenantId} not found</div>;
}

if (!workspace.betaFeatures.logsPage) {
if (!workspace?.betaFeatures.logsPage) {
return notFound();
}

Expand All @@ -48,5 +44,5 @@ export default async function Page({
throw new Error(`Something went wrong when fetching logs from ClickHouse: ${logs.err.message}`);
}

return <LogsPage initialLogs={logs.val} workspaceId={workspace.id} />;
return <LogsPage initialLogs={logs.val} />;
}
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/mobile-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const MobileSideBar = ({ className, workspace }: Props) => {
<SheetTrigger>
<Menu className="w-6 h-6 " />
</SheetTrigger>
<WorkspaceSwitcher />
<WorkspaceSwitcher workspace={workspace} />
</div>
<UserButton />
</div>
Expand Down
Loading

0 comments on commit 4f47372

Please sign in to comment.