The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Log Drains Fixes (#28337)
Jordi Enric91f6fb72c8c1
diff --git a/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx b/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsxindex aadba806269..af63cfe8b12 100644--- a/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx+++ b/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx@@ -36,7 +36,7 @@ import { useForm } from 'react-hook-form'import toast from 'react-hot-toast'import { useEffect, useState } from 'react'import { TrashIcon } from 'lucide-react'-import { LogDrainData } from 'data/log-drains/log-drains-query'+import { LogDrainData, useLogDrainsQuery } from 'data/log-drains/log-drains-query'import { InfoTooltip } from 'ui-patterns/info-tooltip'const FORM_ID = 'log-drain-destination-form'@@ -45,9 +45,9 @@ const formUnion = z.discriminatedUnion('type', [z.object({type: z.literal('webhook'),url: z.string().url('Webhook URL is required and must be a valid URL'),- httpVersion: z.enum(['HTTP1', 'HTTP2']),+ http: z.enum(['http1', 'http2']),gzip: z.boolean(),- headers: z.record(z.string(), z.string()),+ headers: z.record(z.string(), z.string()).optional(),}),z.object({type: z.literal('datadog'),@@ -60,6 +60,12 @@ const formUnion = z.discriminatedUnion('type', [username: z.string().min(1, { message: 'Username is required' }),password: z.string().min(1, { message: 'Password is required' }),}),+ z.object({+ type: z.literal('postgres'),+ }),+ z.object({+ type: z.literal('bigquery'),+ }),])const formSchema = z@@ -78,6 +84,7 @@ function LogDrainFormItem({formControl,placeholder,type,+ defaultValue,}: {value: stringlabel: string@@ -85,6 +92,7 @@ function LogDrainFormItem({placeholder?: stringdescription?: stringtype?: string+ defaultValue?: string}) {return (<FormField_Shadcn_@@ -93,7 +101,12 @@ function LogDrainFormItem({render={({ field }) => (<FormItemLayout layout="horizontal" label={label} description={description || ''}><FormControl_Shadcn_>- <Input_Shadcn_ type={type || 'text'} placeholder={placeholder} {...field} />+ <Input_Shadcn_+ defaultValue={defaultValue}+ type={type || 'text'}+ placeholder={placeholder}+ {...field}+ /></FormControl_Shadcn_></FormItemLayout>)}@@ -101,6 +114,8 @@ function LogDrainFormItem({)}+type DefaultValues = { type: LogDrainType } & Partial<LogDrainData>+export function LogDrainDestinationSheetForm({open,onOpenChange,@@ -111,46 +126,37 @@ export function LogDrainDestinationSheetForm({}: {open: booleanonOpenChange: (v: boolean) => void- defaultValues?: Partial<LogDrainData> & { type: LogDrainType }+ defaultValues?: DefaultValuesisLoading?: booleanonSubmit: (values: z.infer<typeof formSchema>) => voidmode: 'create' | 'update'}) {+ const { ref } = useParams()+ const { data: logDrains } = useLogDrainsQuery({+ ref,+ })+const defaultType = defaultValues?.type || 'webhook'const [newCustomHeader, setNewCustomHeader] = useState({ name: '', value: '' })+const form = useForm<z.infer<typeof formSchema>>({resolver: zodResolver(formSchema),- defaultValues: {+ values: {+ name: defaultValues?.name || '',+ description: defaultValues?.description || '',type: defaultType,- ...defaultValues,+ http: defaultValues?.config?.http || 'http2',+ gzip: defaultValues?.config?.gzip || true,+ headers: defaultValues?.config?.headers || {},+ url: defaultValues?.config?.url || '',+ api_key: defaultValues?.config?.api_key || '',+ region: defaultValues?.config?.region || '',+ username: defaultValues?.config?.username || '',+ password: defaultValues?.config?.password || '',},})const headers = form.watch('headers')-- // IDK why but this useEffect is needed to set the default values- // Suppossedly if you call form.reset() defaultValues is not cached, but I have found it to be very unreliable, and sometimes the form will open with the wrong default values.- // - Jordi- useEffect(() => {- if (form.formState.isDirty) return-- if (mode === 'update') {- form.setValue('type', defaultType)- form.setValue('name', defaultValues?.name || '')- form.setValue('url', defaultValues?.config?.url || '')- form.setValue('api_key', defaultValues?.config?.api_key || '')- form.setValue('region', defaultValues?.config?.region || '')- form.setValue('username', defaultValues?.config?.username || '')- form.setValue('password', defaultValues?.config?.password || '')- form.setValue('httpVersion', defaultValues?.config?.httpVersion || 'HTTP2')- form.setValue('gzip', defaultValues?.config?.gzip || true)- form.setValue('headers', defaultValues?.config?.headers || {})- form.setValue('description', defaultValues?.description || '')- } else {- form.reset()- }- }, [defaultType, form, defaultValues, mode])-const type = form.watch('type')function removeHeader(key: string) {@@ -183,11 +189,17 @@ export function LogDrainDestinationSheetForm({const hasHeaders = Object.keys(headers || {})?.length > 0+ useEffect(() => {+ if (mode === 'create' && !open) {+ form.reset()+ }+ }, [mode, open, form])+return (<Sheetopen={open}onOpenChange={(v) => {- form.reset()+ setNewCustomHeader({ name: '', value: '' })onOpenChange(v)}}>@@ -201,6 +213,15 @@ export function LogDrainDestinationSheetForm({id={FORM_ID}onSubmit={(e) => {e.preventDefault()++ // Temp check to make sure the name is unique+ const logDrainName = form.getValues('name')+ const logDrainExists = logDrains?.find((drain) => drain.name === logDrainName)+ if (logDrainExists && mode === 'create') {+ toast.error('Log drain name already exists')+ return+ }+form.handleSubmit(onSubmit)(e)}}>@@ -211,40 +232,30 @@ export function LogDrainDestinationSheetForm({label="Name"formControl={form.control}/>- <LogDrainFormItem+ {/* <LogDrainFormItemvalue="description"placeholder="My Destination"label="Description"formControl={form.control}- />- <div>- {mode === 'update' && (- <div className="flex items-center gap-2 text-sm text-foreground-light">- <InfoTooltip align="start">- You cannot change the type of an existing log drain. Please, create a new- log drain with the new type.- </InfoTooltip>- Can't update log drain type- </div>- )}- </div>- <RadioGroupStacked- className={cn(mode === 'update' && 'opacity-50')}- value={type}- onValueChange={(v: LogDrainType) => form.setValue('type', v)}- disabled={mode === 'update'}- >- {LOG_DRAIN_TYPES.map((type) => (- <RadioGroupStackedItem- value={type.value}- key={type.value}- id={type.value}- label={type.name}- description={type.description}- className="text-left"- />- ))}- </RadioGroupStacked>+ /> */}+ {mode === 'create' && (+ <RadioGroupStacked+ defaultValue={defaultType}+ value={form.getValues('type')}+ onValueChange={(v: LogDrainType) => form.setValue('type', v)}+ >+ {LOG_DRAIN_TYPES.map((type) => (+ <RadioGroupStackedItem+ value={type.value}+ key={type.value}+ id={type.value}+ label={type.name}+ description={type.description}+ className="text-left"+ />+ ))}+ </RadioGroupStacked>+ )}</div><div className="space-y-4 mt-6">@@ -258,23 +269,19 @@ export function LogDrainDestinationSheetForm({/><FormField_Shadcn_control={form.control}- name="httpVersion"+ name="http"render={({ field }) => (<FormItem_Shadcn_><FormControl_Shadcn_>- <RadioGroupStacked- defaultValue="HTTP2"- onValueChange={field.onChange}- value={field.value}- >+ <RadioGroupStacked onValueChange={field.onChange} value={field.value}><FormItem_Shadcn_ asChild><FormControl_Shadcn_>- <RadioGroupStackedItem value="HTTP1" label="HTTP1" />+ <RadioGroupStackedItem value="http1" label="HTTP/1" /></FormControl_Shadcn_></FormItem_Shadcn_><FormItem_Shadcn_ asChild><FormControl_Shadcn_>- <RadioGroupStackedItem value="HTTP2" label="HTTP2" />+ <RadioGroupStackedItem value="http2" label="HTTP/2" /></FormControl_Shadcn_></FormItem_Shadcn_></RadioGroupStacked>@@ -284,7 +291,7 @@ export function LogDrainDestinationSheetForm({)}/>- <FormField_Shadcn_+ {/* <FormField_Shadcn_control={form.control}name="gzip"render={({ field }) => (@@ -295,14 +302,12 @@ export function LogDrainDestinationSheetForm({</FormControl_Shadcn_><FormLabel_Shadcn_ className="text-base">Gzip</FormLabel_Shadcn_><InfoTooltip align="start">- Gzip can reduce the size of the payload and increase the speed of the- request,- <br /> but it will increase the CPU usage of the destination.+ Gzip compresses logs before sending it to the destination.</InfoTooltip></div></FormItem_Shadcn_>)}- />+ /> */}<div><FormLabel_Shadcn_>Custom Headers</FormLabel_Shadcn_>@@ -313,8 +318,8 @@ export function LogDrainDestinationSheetForm({key={headerKey}><div className="w-full px-1">{headerKey}</div>- <div className="w-full px-1 truncate" title={headers[headerKey]}>- {headers[headerKey]}+ <div className="w-full px-1 truncate" title={headers?.[headerKey]}>+ {headers?.[headerKey]}</div><ButtonclassName="justify-self-end opacity-0 group-hover:opacity-100"diff --git a/apps/studio/components/interfaces/LogDrains/LogDrains.constants.tsx b/apps/studio/components/interfaces/LogDrains/LogDrains.constants.tsxindex f7b4e9a0b20..a268538165b 100644--- a/apps/studio/components/interfaces/LogDrains/LogDrains.constants.tsx+++ b/apps/studio/components/interfaces/LogDrains/LogDrains.constants.tsx@@ -24,7 +24,10 @@ export const LOG_DRAIN_TYPES = [] as constexport const LOG_DRAIN_SOURCE_VALUES = LOG_DRAIN_TYPES.map((source) => source.value)-export type LogDrainType = (typeof LOG_DRAIN_TYPES)[number]['value']++// Added postgres and bigquery here because the generated api types require them but they're not available yet.+// Once we add them they can be removed from this type and added to the LOG_DRAIN_TYPES array.+export type LogDrainType = (typeof LOG_DRAIN_TYPES)[number]['value'] | 'postgres' | 'bigquery'export const DATADOG_REGIONS = [{diff --git a/apps/studio/components/interfaces/LogDrains/LogDrains.tsx b/apps/studio/components/interfaces/LogDrains/LogDrains.tsxindex 0343fd07e82..876b4946faa 100644--- a/apps/studio/components/interfaces/LogDrains/LogDrains.tsx+++ b/apps/studio/components/interfaces/LogDrains/LogDrains.tsx@@ -116,8 +116,8 @@ export function LogDrains({<TableHeader><TableRow><TableHead className="max-w-[200px]">Name</TableHead>- <TableHead>Description</TableHead>- <TableHead className="text-right">Source</TableHead>+ {/* <TableHead>Description</TableHead> */}+ <TableHead className="text-right">Destination</TableHead><TableHead className="text-right"><div className="sr-only">Actions</div></TableHead>@@ -127,7 +127,7 @@ export function LogDrains({{logDrains?.map((drain) => (<TableRow key={drain.id}><TableCell className="font-medium">{drain.name}</TableCell>- <TableCell>{drain.description}</TableCell>+ {/* <TableCell>{drain.description}</TableCell> */}<TableCell className="text-right font-mono">{drain.type}</TableCell><TableCell className="text-right"><DropdownMenu>@@ -164,6 +164,8 @@ export function LogDrains({</TableBody><ConfirmationModal+ confirmLabel="Delete"+ variant="destructive"title="Delete Log Drain"visible={isDeleteModalOpen}onConfirm={() => {diff --git a/apps/studio/pages/project/[ref]/settings/log-drains.tsx b/apps/studio/pages/project/[ref]/settings/log-drains.tsxindex ca9ff783a02..5c98330478a 100644--- a/apps/studio/pages/project/[ref]/settings/log-drains.tsx+++ b/apps/studio/pages/project/[ref]/settings/log-drains.tsx@@ -10,7 +10,7 @@ import { LogDrains } from 'components/interfaces/LogDrains/LogDrains'import { LogDrainDestinationSheetForm } from 'components/interfaces/LogDrains/LogDrainDestinationSheetForm'import { Button } from 'ui'import { useState } from 'react'-import { LogDrainType } from 'components/interfaces/LogDrains/LogDrains.constants'+import { LOG_DRAIN_TYPES, LogDrainType } from 'components/interfaces/LogDrains/LogDrains.constants'import { LogDrainData, useLogDrainsQuery } from 'data/log-drains/log-drains-query'import { useCreateLogDrainMutation } from 'data/log-drains/create-log-drain-mutation'import toast from 'react-hot-toast'@@ -19,8 +19,13 @@ import { useParams } from 'common'import { useCurrentOrgPlan } from 'hooks/misc/useCurrentOrgPlan'import Link from 'next/link'import { ExternalLink } from 'lucide-react'+import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'+import { PermissionAction } from '@supabase/shared-types/out/constants'+import { Alert } from '@ui/components/shadcn/ui/alert'const LogDrainsSettings: NextPageWithLayout = () => {+ const canManageLogDrains = useCheckPermissions(PermissionAction.ANALYTICS_WRITE, 'logflare')+const [open, setOpen] = useState(false)const { ref } = useParams() as { ref: string }const [selectedLogDrain, setSelectedLogDrain] = useState<Partial<LogDrainData> | null>(null)@@ -50,7 +55,7 @@ const LogDrainsSettings: NextPageWithLayout = () => {const { mutate: updateLogDrain, isLoading: updateLoading } = useUpdateLogDrainMutation({onSuccess: () => {- toast.success('Log drain destination updated')+ toast.success('Log drain updated')setOpen(false)},onError: () => {@@ -95,7 +100,7 @@ const LogDrainsSettings: NextPageWithLayout = () => {</Button>{!(logDrains?.length === 0) && (<Button- disabled={!logDrainsEnabled}+ disabled={!logDrainsEnabled || !canManageLogDrains}onClick={() => {setSelectedLogDrain(null)setMode('create')@@ -119,7 +124,10 @@ const LogDrainsSettings: NextPageWithLayout = () => {}setOpen(v)}}- defaultValues={selectedLogDrain as any}+ defaultValues={{+ type: selectedLogDrain?.type || 'webhook',+ ...selectedLogDrain,+ }}isLoading={isLoading}onSubmit={({ name, type, ...values }) => {const logDrainValues = {@@ -137,13 +145,16 @@ const LogDrainsSettings: NextPageWithLayout = () => {if (!logDrainValues.id || !selectedLogDrain?.token) {throw new Error('Log drain ID and token is required')} else {- console.log('logDrainValues', logDrainValues)updateLogDrain(logDrainValues)}}}}/>- <LogDrains onUpdateDrainClick={handleUpdateClick} onNewDrainClick={handleNewClick} />+ {canManageLogDrains ? (+ <LogDrains onUpdateDrainClick={handleUpdateClick} onNewDrainClick={handleNewClick} />+ ) : (+ <Alert variant="default">You do not have permission to manage log drains</Alert>+ )}</ScaffoldContainer></>)