| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052 |
- import { zodResolver } from '@hookform/resolvers/zod'
- import { IS_PLATFORM, useFlag, useParams } from 'common'
- import Link from 'next/link'
- import { ReactNode, useEffect, useMemo } from 'react'
- import { useForm } from 'react-hook-form'
- import { toast } from 'sonner'
- import {
- Button,
- cn,
- Form,
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- Input,
- RadioGroupCard,
- RadioGroupCardItem,
- Select,
- SelectContent,
- SelectGroup,
- SelectItem,
- SelectLabel,
- SelectTrigger,
- SelectValue,
- Sheet,
- SheetContent,
- SheetFooter,
- SheetHeader,
- SheetSection,
- SheetTitle,
- Switch,
- TextArea,
- } from 'ui'
- import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
- import { KeyValueFieldArray } from 'ui-patterns/form/KeyValueFieldArray/KeyValueFieldArray'
- import { InfoTooltip } from 'ui-patterns/info-tooltip'
- import { z } from 'zod'
- import {
- DATADOG_REGIONS,
- LAST9_REGIONS,
- LOG_DRAIN_TYPES,
- LogDrainType,
- OTLP_PROTOCOLS,
- } from './LogDrains.constants'
- import {
- getDefaultHeadersByType,
- getHeadersSectionDescription as getHeadersDescription,
- headerRecordToRows,
- headerRowsToRecord,
- logDrainHeaderEntriesSchema,
- type LogDrainHeaderRow,
- } from './LogDrains.utils'
- import { TaxDisclaimer } from '@/components/interfaces/Billing/TaxDisclaimer'
- import { LogDrainData, useLogDrainsQuery } from '@/data/log-drains/log-drains-query'
- import { DOCS_URL } from '@/lib/constants'
- import { useTrack } from '@/lib/telemetry/track'
- import { httpEndpointUrlSchema } from '@/lib/validation/http-url'
- const FORM_ID = 'log-drain-destination-form'
- const headerRecordSchema = z.record(z.string(), z.string())
- const webhookFields = {
- type: z.literal('webhook'),
- url: httpEndpointUrlSchema({
- requiredMessage: 'Endpoint URL is required',
- invalidMessage: 'Endpoint URL must be a valid URL',
- prefixMessage: 'Endpoint URL must start with http:// or https://',
- }),
- http: z.enum(['http1', 'http2']),
- gzip: z.boolean(),
- }
- const webhookFormSchema = z.object({
- ...webhookFields,
- headerEntries: logDrainHeaderEntriesSchema.optional(),
- })
- const webhookSubmitSchema = z.object({
- ...webhookFields,
- headers: headerRecordSchema.optional(),
- })
- const datadogSchema = z.object({
- type: z.literal('datadog'),
- api_key: z.string().min(1, { message: 'API key is required' }),
- region: z.string().min(1, { message: 'Region is required' }),
- })
- const lokiFields = {
- type: z.literal('loki'),
- url: httpEndpointUrlSchema({
- requiredMessage: 'Loki URL is required',
- invalidMessage: 'Loki URL must be a valid URL',
- prefixMessage: 'Loki URL must start with http:// or https://',
- }),
- username: z.string().optional(),
- password: z.string().optional(),
- }
- const lokiFormSchema = z.object({
- ...lokiFields,
- headerEntries: logDrainHeaderEntriesSchema.optional(),
- })
- const lokiSubmitSchema = z.object({
- ...lokiFields,
- headers: headerRecordSchema,
- })
- const elasticSchema = z.object({
- type: z.literal('elastic'),
- })
- const postgresSchema = z.object({
- type: z.literal('postgres'),
- })
- const bigquerySchema = z.object({
- type: z.literal('bigquery'),
- })
- const clickhouseSchema = z.object({
- type: z.literal('clickhouse'),
- })
- const s3Schema = z.object({
- type: z.literal('s3'),
- s3_bucket: z.string().min(1, { message: 'Bucket name is required' }),
- storage_region: z.string().min(1, { message: 'Region is required' }),
- access_key_id: z.string().min(1, { message: 'Access Key ID is required' }),
- secret_access_key: z.string().min(1, { message: 'Secret Access Key is required' }),
- batch_timeout: z.coerce
- .number()
- .int({ message: 'Batch timeout must be an integer' })
- .min(1, { message: 'Batch timeout must be a positive integer' }),
- })
- const sentrySchema = z.object({
- type: z.literal('sentry'),
- dsn: z
- .string()
- .min(1, { message: 'Sentry DSN is required' })
- .refine((dsn) => dsn.startsWith('https://'), 'Sentry DSN must start with https://'),
- })
- const axiomSchema = z.object({
- type: z.literal('axiom'),
- api_token: z.string().min(1, { message: 'API token is required' }),
- dataset_name: z.string().min(1, { message: 'Dataset name is required' }),
- })
- const last9Schema = z.object({
- type: z.literal('last9'),
- region: z.string().min(1, { message: 'Region is required' }),
- username: z.string().min(1, { message: 'Username is required' }),
- password: z.string().min(1, { message: 'Password is required' }),
- })
- const otlpFields = {
- type: z.literal('otlp'),
- endpoint: httpEndpointUrlSchema({
- requiredMessage: 'OTLP endpoint is required',
- invalidMessage: 'OTLP endpoint must be a valid URL',
- prefixMessage: 'OTLP endpoint must start with http:// or https://',
- }),
- protocol: z.string().optional().default('http/protobuf'),
- gzip: z.boolean().optional().default(true),
- }
- const otlpFormSchema = z.object({
- ...otlpFields,
- headerEntries: logDrainHeaderEntriesSchema.optional(),
- })
- const otlpSubmitSchema = z.object({
- ...otlpFields,
- headers: headerRecordSchema.optional(),
- })
- const syslogSchema = z.object({
- type: z.literal('syslog'),
- host: z.string().min(1, { message: 'Host is required' }),
- port: z.coerce
- .number()
- .int({ message: 'Port must be an integer' })
- .min(0, { message: 'Port must be between 0 and 65535' })
- .max(65535, { message: 'Port must be between 0 and 65535' }),
- tls: z.boolean().optional().default(false),
- structured_data: z.string().optional(),
- cipher_key: z.string().optional(),
- ca_cert: z.string().optional(),
- client_cert: z.string().optional(),
- client_key: z.string().optional(),
- })
- const formUnion = z.discriminatedUnion('type', [
- webhookFormSchema,
- datadogSchema,
- lokiFormSchema,
- // [Joshen] To fix API types, not supported in the UI
- elasticSchema,
- postgresSchema,
- bigquerySchema,
- clickhouseSchema,
- s3Schema,
- sentrySchema,
- axiomSchema,
- last9Schema,
- otlpFormSchema,
- syslogSchema,
- ])
- const submitUnion = z.discriminatedUnion('type', [
- webhookSubmitSchema,
- datadogSchema,
- lokiSubmitSchema,
- elasticSchema,
- postgresSchema,
- bigquerySchema,
- clickhouseSchema,
- s3Schema,
- sentrySchema,
- axiomSchema,
- last9Schema,
- otlpSubmitSchema,
- syslogSchema,
- ])
- const formSchema = z
- .object({
- name: z.string().min(1, {
- message: 'Destination name is required',
- }),
- description: z.string().optional(),
- })
- .and(formUnion)
- .superRefine((data, ctx) => {
- if (data.type !== 'syslog') return
- if (data.client_cert && !data.client_key) {
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message: 'Client key is required when a client certificate is provided',
- path: ['client_key'],
- })
- }
- if (data.client_key && !data.client_cert) {
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message: 'Client certificate is required when a client key is provided',
- path: ['client_cert'],
- })
- }
- })
- const submitSchema = z
- .object({
- name: z.string().min(1, {
- message: 'Destination name is required',
- }),
- description: z.string().optional(),
- })
- .and(submitUnion)
- type LogDrainDestinationFormValues = z.infer<typeof formSchema>
- type LogDrainDestinationSubmitValues = z.infer<typeof submitSchema>
- const HEADER_ENABLED_TYPES = ['webhook', 'loki', 'otlp'] as const
- function toSubmitValues(values: LogDrainDestinationFormValues): LogDrainDestinationSubmitValues {
- if (!HEADER_ENABLED_TYPES.includes(values.type as (typeof HEADER_ENABLED_TYPES)[number])) {
- return submitSchema.parse(values)
- }
- const { headerEntries = [], ...rest } = values as LogDrainDestinationFormValues & {
- headerEntries?: LogDrainHeaderRow[]
- }
- const headers = headerRowsToRecord(headerEntries)
- const transformedValues =
- rest.type === 'loki'
- ? { ...rest, headers }
- : Object.keys(headers).length > 0
- ? { ...rest, headers }
- : rest
- return submitSchema.parse(transformedValues)
- }
- function LogDrainFormItem({
- value,
- label,
- description,
- formControl,
- placeholder,
- type,
- }: {
- value: string
- label: string
- formControl: any
- placeholder?: string
- description?: ReactNode
- type?: string
- }) {
- return (
- <FormField
- name={value}
- control={formControl}
- render={({ field }) => (
- <FormItemLayout layout="horizontal" label={label} description={description || ''}>
- <FormControl>
- <Input type={type || 'text'} placeholder={placeholder} {...field} />
- </FormControl>
- </FormItemLayout>
- )}
- />
- )
- }
- type DefaultValues = { type: LogDrainType } & Partial<LogDrainData>
- export function LogDrainDestinationSheetForm({
- open,
- onOpenChange,
- defaultValues,
- onSubmit,
- isLoading,
- mode,
- }: {
- open: boolean
- onOpenChange: (v: boolean) => void
- defaultValues?: DefaultValues
- isLoading?: boolean
- onSubmit: (values: LogDrainDestinationSubmitValues) => void
- mode: 'create' | 'update'
- }) {
- // NOTE(kamil): This used to be `any` for a long long time, but after moving to Zod,
- // it produces a correct union type of all possible configs. Unfortunately, this type was not designed correctly
- // and it does not include `type` inside the config itself, so it's not trivial to create `discriminatedUnion`
- // out of it, therefore for an ease of use now, we bail to `any` until the better time come.
- const defaultType = defaultValues?.type || 'webhook'
- const defaultHeaderEntries = useMemo(() => {
- const config = (defaultValues?.config || {}) as any
- const type = defaultValues?.type || 'webhook'
- return headerRecordToRows(
- mode === 'create' ? getDefaultHeadersByType(type) : config?.headers || {}
- )
- }, [defaultValues, mode])
- const sentryEnabled = useFlag('SentryLogDrain')
- const s3Enabled = useFlag('S3logdrain')
- const axiomEnabled = useFlag('axiomLogDrain')
- const otlpEnabled = useFlag('otlpLogDrain')
- const last9Enabled = useFlag('Last9LogDrain')
- const syslogEnabled = useFlag('syslogLogDrain')
- const { ref } = useParams()
- const { data: logDrains } = useLogDrainsQuery({
- ref,
- })
- const track = useTrack()
- const formValues = useMemo(() => {
- const config = (defaultValues?.config || {}) as any
- const type = defaultValues?.type || 'webhook'
- return {
- name: defaultValues?.name || '',
- description: defaultValues?.description || '',
- type,
- http: config?.http || 'http2',
- gzip: mode === 'create' ? true : config?.gzip || false,
- headerEntries: defaultHeaderEntries,
- url: config?.url || '',
- api_key: config?.api_key || '',
- region: config?.region || '',
- username: config?.username || '',
- password: config?.password || '',
- dsn: config?.dsn || '',
- s3_bucket: config?.s3_bucket || '',
- storage_region: config?.storage_region || '',
- access_key_id: config?.access_key_id || '',
- secret_access_key: config?.secret_access_key || '',
- batch_timeout: config?.batch_timeout ?? 3000,
- dataset_name: config?.dataset_name || '',
- api_token: config?.api_token || '',
- endpoint: config?.endpoint || '',
- protocol: config?.protocol || 'http/protobuf',
- host: config?.host || '',
- port: (config?.port ?? '') as number,
- tls: config?.tls ?? false,
- structured_data: config?.structured_data || '',
- cipher_key: config?.cipher_key || '',
- ca_cert: config?.ca_cert || '',
- client_cert: config?.client_cert || '',
- client_key: config?.client_key || '',
- }
- }, [defaultValues, mode, defaultHeaderEntries])
- const form = useForm<LogDrainDestinationFormValues>({
- resolver: zodResolver(formSchema as any),
- values: formValues,
- })
- const type = form.watch('type')
- const tls = form.watch('tls')
- useEffect(() => {
- if (mode === 'create' && !open) {
- form.reset()
- }
- }, [mode, open, form])
- useEffect(() => {
- if (!open || mode !== 'create') return
- form.setValue('headerEntries', headerRecordToRows(getDefaultHeadersByType(type)))
- form.clearErrors('headerEntries')
- }, [form, mode, open, type])
- return (
- <Sheet open={open} onOpenChange={onOpenChange}>
- <SheetContent
- tabIndex={undefined}
- showClose={false}
- size="lg"
- className="overflow-y-auto flex flex-col"
- >
- <SheetHeader>
- <SheetTitle>Add destination</SheetTitle>
- </SheetHeader>
- <SheetSection className="px-0! pb-0!">
- <Form {...form}>
- <form
- id={FORM_ID}
- onSubmit={(e) => {
- e.preventDefault()
- // Temp check to make sure the name is unique
- const logDrainName = form.getValues('name')
- const logDrainExists =
- !!logDrains?.length && logDrains?.find((drain) => drain.name === logDrainName)
- if (logDrainExists && mode === 'create') {
- toast.error('Log drain name already exists')
- return
- }
- form.handleSubmit((values) => onSubmit(toSubmitValues(values)))(e)
- track('log_drain_save_button_clicked', {
- destination: form.getValues('type'),
- })
- }}
- >
- <div className="space-y-8 px-content">
- <LogDrainFormItem
- value="name"
- placeholder="My Destination"
- label="Name"
- formControl={form.control}
- />
- <LogDrainFormItem
- value="description"
- placeholder="Optional description"
- label="Description"
- formControl={form.control}
- />
- {mode === 'create' && (
- <FormItemLayout
- layout="horizontal"
- label="Type"
- description={LOG_DRAIN_TYPES.find((t) => t.value === type)?.description || ''}
- >
- <Select
- defaultValue={defaultType}
- value={form.getValues('type')}
- onValueChange={(v: LogDrainType) => form.setValue('type', v)}
- >
- <SelectTrigger>
- {LOG_DRAIN_TYPES.find((t) => t.value === type)?.name}
- </SelectTrigger>
- <SelectContent>
- {LOG_DRAIN_TYPES.filter((t) => {
- if (t.value === 'sentry') return sentryEnabled
- if (t.value === 's3') return s3Enabled
- if (t.value === 'axiom') return axiomEnabled
- if (t.value === 'otlp') return otlpEnabled
- if (t.value === 'last9') return last9Enabled
- if (t.value === 'syslog') return syslogEnabled
- return true
- }).map((type) => (
- <SelectItem
- value={type.value}
- key={type.value}
- id={type.value}
- className="text-left"
- >
- {type.name}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </FormItemLayout>
- )}
- </div>
- <div className="space-y-8 mt-4">
- {type === 'webhook' && (
- <>
- <div className="px-content space-y-8">
- <LogDrainFormItem
- value="url"
- label="Endpoint URL"
- formControl={form.control}
- placeholder="https://example.com/log-drain"
- />
- <FormField
- control={form.control}
- name="http"
- render={({ field }) => (
- <FormItemLayout layout="horizontal" label="HTTP Version">
- <FormControl>
- <RadioGroupCard
- className="flex gap-2"
- onValueChange={field.onChange}
- value={field.value}
- >
- <FormItem asChild>
- <FormControl>
- <RadioGroupCardItem value="http1" label="HTTP/1" />
- </FormControl>
- </FormItem>
- <FormItem asChild>
- <FormControl>
- <RadioGroupCardItem value="http2" label="HTTP/2" />
- </FormControl>
- </FormItem>
- </RadioGroupCard>
- </FormControl>
- </FormItemLayout>
- )}
- />
- </div>
- <FormField
- control={form.control}
- name="gzip"
- render={({ field }) => (
- <FormItem className="space-y-2 px-4">
- <div className="flex gap-2 items-center">
- <FormControl>
- <Switch checked={field.value} onCheckedChange={field.onChange} />
- </FormControl>
- <FormLabel className="text-base">Gzip</FormLabel>
- <InfoTooltip align="start">
- Gzip compresses logs before sending it to the destination.
- </InfoTooltip>
- </div>
- </FormItem>
- )}
- />
- </>
- )}
- {type === 'datadog' && (
- <div className="grid gap-4 px-content">
- <LogDrainFormItem
- type="password"
- value="api_key"
- label="API Key"
- formControl={form.control}
- description={
- <>
- The API Key obtained from the Datadog dashboard{' '}
- <a
- target="_blank"
- rel="noopener noreferrer"
- className="text-sm underline transition hover:text-foreground"
- href="https://app.datadoghq.com/organization-settings/api-keys"
- >
- here
- </a>
- </>
- }
- />
- <FormField
- name="region"
- control={form.control}
- render={({ field }) => (
- <FormItemLayout
- layout="horizontal"
- label={'Region'}
- description={
- <p>
- The Datadog region to send logs to. Read more about Datadog regions{' '}
- <a
- target="_blank"
- rel="noopener noreferrer"
- className="underline hover:text-foreground transition"
- href="https://docs.datadoghq.com/getting_started/site/#access-the-datadog-site"
- >
- here
- </a>
- .
- </p>
- }
- >
- <FormControl>
- <Select value={field.value} onValueChange={field.onChange}>
- <SelectTrigger className="col-span-3">
- <SelectValue placeholder="Select a region" />
- </SelectTrigger>
- <SelectContent>
- <SelectGroup>
- <SelectLabel>Region</SelectLabel>
- {DATADOG_REGIONS.map((reg) => (
- <SelectItem key={reg.value} value={reg.value}>
- {reg.label}
- </SelectItem>
- ))}
- </SelectGroup>
- </SelectContent>
- </Select>
- </FormControl>
- </FormItemLayout>
- )}
- />
- </div>
- )}
- {type === 'loki' && (
- <div className="grid gap-4 px-content">
- <LogDrainFormItem
- type="url"
- value="url"
- placeholder="https://my-logs-endpoint.grafana.net/loki/api/v1/push"
- label="Loki URL"
- formControl={form.control}
- description="The Loki HTTP(S) endpoint to send events."
- />
- <LogDrainFormItem
- value="username"
- label="Username"
- placeholder="123456789"
- formControl={form.control}
- />
- <LogDrainFormItem
- type="password"
- value="password"
- label="Password"
- placeholder="glc_ABCD1234567890"
- formControl={form.control}
- />
- </div>
- )}
- {type === 'sentry' && (
- <div className="grid gap-4 px-content">
- <LogDrainFormItem
- type="text"
- value="dsn"
- label="DSN"
- placeholder="https://<project_id>@o<organization_id>.ingest.sentry.io/<project_id>"
- formControl={form.control}
- description={
- <>
- The DSN obtained from the Sentry dashboard. Read more about DSNs{' '}
- <a
- target="_blank"
- rel="noopener noreferrer"
- className="text-sm underline transition hover:text-foreground"
- href="https://docs.sentry.io/concepts/key-terms/dsn-explainer/"
- >
- here
- </a>
- .
- </>
- }
- />
- </div>
- )}
- {type === 's3' && (
- <div className="grid gap-4 px-content">
- <LogDrainFormItem
- value="s3_bucket"
- label="S3 Bucket"
- placeholder="my-log-bucket"
- formControl={form.control}
- description="The name of an existing S3 bucket."
- />
- <LogDrainFormItem
- value="storage_region"
- label="Region"
- placeholder="us-east-1"
- formControl={form.control}
- description="AWS region where the bucket is located."
- />
- <LogDrainFormItem
- value="access_key_id"
- label="Access Key ID"
- placeholder="AKIA..."
- formControl={form.control}
- />
- <LogDrainFormItem
- type="password"
- value="secret_access_key"
- label="Secret Access Key"
- placeholder="••••••••••••••••"
- formControl={form.control}
- />
- <LogDrainFormItem
- type="number"
- value="batch_timeout"
- label="Batch Timeout (ms)"
- placeholder="3000"
- formControl={form.control}
- description="Recommended 2000–5000ms."
- />
- <p className="text-xs text-foreground-lighter">
- Ensure the account tied to the Access Key ID can write to the specified
- bucket.
- </p>
- </div>
- )}
- {type === 'axiom' && (
- <div className="grid gap-4 px-content">
- <LogDrainFormItem
- type="text"
- value="dataset_name"
- label="Dataset name"
- placeholder="dataset"
- formControl={form.control}
- description="Name of the dataset in Axiom where the logs will be sent."
- />
- <LogDrainFormItem
- type="text"
- value="api_token"
- label="API Token"
- placeholder="xaat-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
- formControl={form.control}
- description="Token allowing ingest access to the specified dataset"
- />
- </div>
- )}
- {type === 'otlp' && (
- <>
- <div className="grid gap-4 px-content">
- <LogDrainFormItem
- type="url"
- value="endpoint"
- label="OTLP Endpoint"
- placeholder="https://otlp.example.com:4318/v1/logs"
- formControl={form.control}
- description="The HTTP endpoint for OTLP log ingestion (typically ends with /v1/logs)"
- />
- <FormField
- name="protocol"
- control={form.control}
- render={({ field }) => (
- <FormItemLayout
- layout="horizontal"
- label="Protocol"
- description="Only HTTP with Protocol Buffers is currently supported"
- >
- <FormControl>
- <Select value={field.value} onValueChange={field.onChange}>
- <SelectTrigger className="col-span-3">
- <SelectValue placeholder="Select protocol" />
- </SelectTrigger>
- <SelectContent>
- <SelectGroup>
- <SelectLabel>Protocol</SelectLabel>
- {OTLP_PROTOCOLS.map((proto) => (
- <SelectItem key={proto.value} value={proto.value}>
- {proto.label}
- </SelectItem>
- ))}
- </SelectGroup>
- </SelectContent>
- </Select>
- </FormControl>
- </FormItemLayout>
- )}
- />
- </div>
- <FormField
- control={form.control}
- name="gzip"
- render={({ field }) => (
- <FormItem className="space-y-2 px-4">
- <div className="flex gap-2 items-center">
- <FormControl>
- <Switch checked={field.value} onCheckedChange={field.onChange} />
- </FormControl>
- <FormLabel className="text-base">Gzip Compression</FormLabel>
- <InfoTooltip align="start">
- Enable gzip compression for log data sent to the OTLP endpoint.
- </InfoTooltip>
- </div>
- </FormItem>
- )}
- />
- </>
- )}
- {type === 'last9' && (
- <div className="grid gap-4 px-content">
- <FormField
- name="region"
- control={form.control}
- render={({ field }) => (
- <FormItemLayout
- layout="horizontal"
- label={'Region'}
- description={
- <p>
- The Last9 region to send logs to. Credentials can be obtained from the
- Last9 OTEL integration panel.
- </p>
- }
- >
- <FormControl>
- <Select value={field.value} onValueChange={field.onChange}>
- <SelectTrigger className="col-span-3">
- <SelectValue placeholder="Select a region" />
- </SelectTrigger>
- <SelectContent>
- <SelectGroup>
- <SelectLabel>Region</SelectLabel>
- {LAST9_REGIONS.map((reg) => (
- <SelectItem key={reg.value} value={reg.value}>
- {reg.label}
- </SelectItem>
- ))}
- </SelectGroup>
- </SelectContent>
- </Select>
- </FormControl>
- </FormItemLayout>
- )}
- />
- <LogDrainFormItem
- type="text"
- value="username"
- label="Username"
- placeholder="username"
- formControl={form.control}
- description="Username for authentication from Last9 OTEL integration."
- />
- <LogDrainFormItem
- type="password"
- value="password"
- label="Password"
- placeholder="••••••••••••••••"
- formControl={form.control}
- description="Password for authentication from Last9 OTEL integration."
- />
- </div>
- )}
- {type === 'syslog' && (
- <>
- <div className="grid gap-4 px-content">
- <LogDrainFormItem
- value="host"
- label="Host"
- placeholder="logs.example.com"
- formControl={form.control}
- description="Hostname or IP address of the syslog receiver."
- />
- <LogDrainFormItem
- type="number"
- value="port"
- label="Port"
- placeholder="514"
- formControl={form.control}
- description="Port of the syslog receiver (0–65535)."
- />
- <LogDrainFormItem
- value="structured_data"
- label="Structured Data"
- placeholder='[exampleSDID@32473 iut="3" eventSource="Application"]'
- formControl={form.control}
- description="Static RFC 5424 Structured Data included in every log frame."
- />
- <LogDrainFormItem
- type="password"
- value="cipher_key"
- label="Cipher Key"
- placeholder="••••••••••••••••"
- formControl={form.control}
- description="Base64-encoded 32-byte key for AES-256-GCM encryption of the log body."
- />
- </div>
- <FormField
- control={form.control}
- name="tls"
- render={({ field }) => (
- <FormItem className="space-y-2 px-4">
- <div className="flex gap-2 items-center">
- <FormControl>
- <Switch checked={field.value} onCheckedChange={field.onChange} />
- </FormControl>
- <FormLabel className="text-base">TLS</FormLabel>
- <InfoTooltip align="start">
- Connect via SSL/TLS instead of plain TCP.
- </InfoTooltip>
- </div>
- </FormItem>
- )}
- />
- {tls && (
- <div className="grid gap-4 px-content">
- <FormField
- name="ca_cert"
- control={form.control}
- render={({ field }) => (
- <FormItemLayout
- layout="horizontal"
- label="CA Certificate"
- description="PEM encoded CA certificate for verifying the server. Falls back to the system CA bundle if omitted."
- >
- <FormControl>
- <TextArea
- className="font-mono text-xs"
- placeholder="-----BEGIN CERTIFICATE-----"
- rows={4}
- {...field}
- />
- </FormControl>
- </FormItemLayout>
- )}
- />
- <FormField
- name="client_cert"
- control={form.control}
- render={({ field }) => (
- <FormItemLayout
- layout="horizontal"
- label="Client Certificate"
- description="PEM encoded client certificate for mTLS."
- >
- <FormControl>
- <TextArea
- className="font-mono text-xs"
- placeholder="-----BEGIN CERTIFICATE-----"
- rows={4}
- {...field}
- />
- </FormControl>
- </FormItemLayout>
- )}
- />
- <FormField
- name="client_key"
- control={form.control}
- render={({ field }) => (
- <FormItemLayout
- layout="horizontal"
- label="Client Key"
- description="PEM encoded client private key for mTLS. Required when a client certificate is provided."
- >
- <FormControl>
- <TextArea
- className="font-mono text-xs"
- placeholder="-----BEGIN PRIVATE KEY-----"
- rows={4}
- {...field}
- />
- </FormControl>
- </FormItemLayout>
- )}
- />
- </div>
- )}
- </>
- )}
- {HEADER_ENABLED_TYPES.includes(type as (typeof HEADER_ENABLED_TYPES)[number]) && (
- <div className="px-content">
- <FormField
- control={form.control}
- name="headerEntries"
- render={({ fieldState }) => (
- <FormItemLayout
- layout="horizontal"
- label="Custom Headers"
- description={getHeadersDescription(type)}
- hideMessage={!fieldState.error?.message}
- >
- <KeyValueFieldArray
- control={form.control}
- name="headerEntries"
- keyFieldName="key"
- valueFieldName="value"
- createEmptyRow={() => ({ key: '', value: '' })}
- keyPlaceholder="Header name"
- valuePlaceholder="Header value"
- addLabel="Add a new header"
- removeLabel="Remove header"
- />
- </FormItemLayout>
- )}
- />
- </div>
- )}
- </div>
- </form>
- </Form>
- </SheetSection>
- <div className="mt-auto">
- <SheetSection
- className={cn(
- `border-t bg-background-alternative-200 mt-auto py-1.5 ${!IS_PLATFORM && 'hidden'}`
- )}
- >
- <ul className="text-right text-foreground-light divide-y divide-dashed text-sm">
- <li className="flex items-center justify-between gap-2 py-2" translate="no">
- <span className="text-foreground-lighter">Additional drain cost</span>
- <span className="text-foreground">$60 per month</span>
- </li>
- <li className="flex items-center justify-between gap-2 py-2" translate="no">
- <span className="text-foreground-lighter">Per million events</span>
- <span>+$0.20</span>
- </li>
- <li className="flex items-center justify-between gap-2 py-2" translate="no">
- <span className="text-foreground-lighter">Per GB egress</span>
- <span>+$0.09</span>
- </li>
- </ul>
- </SheetSection>
- <SheetFooter className="p-content mt-0! justify-between! flex-row! w-full items-center">
- <div className="flex flex-col gap-0.5">
- <span className="text-sm text-foreground-light">
- <span>See full pricing breakdown</span>{' '}
- <Link
- href={`${DOCS_URL}/guides/platform/manage-your-usage/log-drains`}
- target="_blank"
- className="text-foreground underline underline-offset-2 decoration-foreground-muted hover:decoration-foreground transition-all"
- >
- here
- </Link>
- </span>
- <TaxDisclaimer />
- </div>
- <Button form={FORM_ID} loading={isLoading} htmlType="submit" type="primary">
- Save destination
- </Button>
- </SheetFooter>
- </div>
- </SheetContent>
- </Sheet>
- )
- }
|