Skip to content

Commit f56c6a2

Browse files
committed
fix(data-drains): address PR review comments
1 parent 536ba91 commit f56c6a2

4 files changed

Lines changed: 39 additions & 6 deletions

File tree

apps/sim/ee/data-drains/destinations/registry.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,12 @@ const DATADOG_SITE_OPTIONS = [
211211
{ value: 'us5', label: 'US5 (us5.datadoghq.com)' },
212212
{ value: 'eu1', label: 'EU1 (datadoghq.eu)' },
213213
{ value: 'ap1', label: 'AP1 (ap1.datadoghq.com)' },
214+
{ value: 'ap2', label: 'AP2 (ap2.datadoghq.com)' },
214215
{ value: 'gov', label: 'Gov (ddog-gov.com)' },
215216
]
216217

217218
interface DatadogState {
218-
site: 'us1' | 'us3' | 'us5' | 'eu1' | 'ap1' | 'gov'
219+
site: 'us1' | 'us3' | 'us5' | 'eu1' | 'ap1' | 'ap2' | 'gov'
219220
service: string
220221
tags: string
221222
apiKey: string

apps/sim/lib/api/contracts/data-drains.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const azureBlobCredentialsBodySchema = z.object({
5252
})
5353

5454
const datadogConfigBodySchema = z.object({
55-
site: z.enum(['us1', 'us3', 'us5', 'eu1', 'ap1', 'gov']),
55+
site: z.enum(['us1', 'us3', 'us5', 'eu1', 'ap1', 'ap2', 'gov']),
5656
service: z.string().min(1).max(100).optional(),
5757
tags: z.string().max(1024).optional(),
5858
})

apps/sim/lib/data-drains/destinations/bigquery.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createLogger } from '@sim/logger'
22
import { toError } from '@sim/utils/errors'
3-
import { sleep } from '@sim/utils/helpers'
43
import { JWT } from 'google-auth-library'
54
import { z } from 'zod'
65
import type { DeliveryMetadata, DrainDestination } from '@/lib/data-drains/types'
@@ -216,6 +215,21 @@ const RETRYABLE_STATUSES = new Set([408, 429, 500, 502, 503, 504])
216215
const MAX_RETRY_ATTEMPTS = 3
217216
const BASE_RETRY_DELAY_MS = 250
218217

218+
function sleepUntilAborted(ms: number, signal: AbortSignal): Promise<void> {
219+
if (signal.aborted) return Promise.resolve()
220+
return new Promise((resolve) => {
221+
const onAbort = () => {
222+
clearTimeout(timeoutId)
223+
resolve()
224+
}
225+
const timeoutId = setTimeout(() => {
226+
signal.removeEventListener('abort', onAbort)
227+
resolve()
228+
}, ms)
229+
signal.addEventListener('abort', onAbort, { once: true })
230+
})
231+
}
232+
219233
function parseRetryAfter(header: string | null): number | null {
220234
if (!header) return null
221235
const seconds = Number(header)
@@ -286,7 +300,8 @@ async function insertAll(input: InsertAllInput): Promise<void> {
286300
})
287301
// Drain the body so the connection can be reused.
288302
await response.text().catch(() => '')
289-
await sleep(retryAfterMs)
303+
await sleepUntilAborted(retryAfterMs, input.signal)
304+
if (input.signal.aborted) throw input.signal.reason ?? new Error('Aborted')
290305
}
291306
if (!response.ok) {
292307
const text = await response.text().catch(() => '')

apps/sim/lib/data-drains/destinations/gcs.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,25 @@ interface ParsedServiceAccount {
9898
}
9999

100100
function parseServiceAccount(json: string): ParsedServiceAccount {
101-
const parsed = JSON.parse(json) as { client_email: string; private_key: string }
102-
return { clientEmail: parsed.client_email, privateKey: parsed.private_key }
101+
let parsed: unknown
102+
try {
103+
parsed = JSON.parse(json)
104+
} catch {
105+
throw new Error('serviceAccountJson must be valid JSON')
106+
}
107+
if (typeof parsed !== 'object' || parsed === null) {
108+
throw new Error('serviceAccountJson must be a JSON object')
109+
}
110+
const obj = parsed as Record<string, unknown>
111+
const clientEmail = obj.client_email
112+
const privateKey = obj.private_key
113+
if (typeof clientEmail !== 'string' || clientEmail.length === 0) {
114+
throw new Error('serviceAccountJson is missing client_email')
115+
}
116+
if (typeof privateKey !== 'string' || privateKey.length === 0) {
117+
throw new Error('serviceAccountJson is missing private_key')
118+
}
119+
return { clientEmail, privateKey }
103120
}
104121

105122
function normalizePrefix(raw: string | undefined): string {

0 commit comments

Comments
 (0)