Skip to content

Commit

Permalink
🔥 [RUMF-1089] Cleanup legacy intake URLs (#1214)
Browse files Browse the repository at this point in the history
* 🔥 Cleanup legacy intake URLs

* Use parametrized test
  • Loading branch information
amortemousque authored Dec 15, 2021
1 parent 3f0ab47 commit c5e10d6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 237 deletions.
3 changes: 0 additions & 3 deletions packages/core/src/domain/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ export interface InitConfiguration {
env?: string | undefined
version?: string | undefined

useAlternateIntakeDomains?: boolean | undefined
intakeApiVersion?: 1 | 2 | undefined

useCrossSiteSessionCookie?: boolean | undefined
useSecureSessionCookie?: boolean | undefined
trackSessionAcrossSubdomains?: boolean | undefined
Expand Down
79 changes: 20 additions & 59 deletions packages/core/src/domain/configuration/endpointBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
import { BuildEnv } from '../../boot/init'
import { timeStampNow } from '../../tools/timeUtils'
import { generateUUID, includes } from '../../tools/utils'
import { generateUUID } from '../../tools/utils'
import { InitConfiguration } from './configuration'

export const ENDPOINTS = {
alternate: {
logs: 'logs',
rum: 'rum',
sessionReplay: 'session-replay',
},
classic: {
logs: 'browser',
rum: 'rum',
// session-replay has no classic endpoint
sessionReplay: undefined,
},
}
logs: 'logs',
rum: 'rum',
sessionReplay: 'session-replay',
} as const

const INTAKE_TRACKS = {
logs: 'logs',
rum: 'rum',
sessionReplay: 'replay',
}

export type EndpointType = keyof typeof ENDPOINTS[IntakeType]
type EndpointType = keyof typeof ENDPOINTS

export const INTAKE_SITE_US = 'datadoghq.com'
const INTAKE_SITE_US3 = 'us3.datadoghq.com'
const INTAKE_SITE_GOV = 'ddog-gov.com'
const INTAKE_SITE_EU = 'datadoghq.eu'

const CLASSIC_ALLOWED_SITES = [INTAKE_SITE_US, INTAKE_SITE_EU]
const INTAKE_V1_ALLOWED_SITES = [INTAKE_SITE_US, INTAKE_SITE_US3, INTAKE_SITE_EU, INTAKE_SITE_GOV]

type IntakeType = keyof typeof ENDPOINTS
export type EndpointBuilder = ReturnType<typeof createEndpointBuilder>

export function createEndpointBuilder(
Expand All @@ -43,17 +28,7 @@ export function createEndpointBuilder(
source?: string
) {
const sdkVersion = buildEnv.sdkVersion
const {
site = INTAKE_SITE_US,
clientToken,
env,
proxyHost,
proxyUrl,
service,
version,
intakeApiVersion,
useAlternateIntakeDomains,
} = initConfiguration
const { site = INTAKE_SITE_US, clientToken, env, proxyHost, proxyUrl, service, version } = initConfiguration

const host = buildHost(endpointType)
const path = buildPath(endpointType)
Expand All @@ -75,19 +50,15 @@ export function createEndpointBuilder(
}

function buildHost(endpointType: EndpointType) {
if (shouldUseAlternateDomain(endpointType)) {
const endpoint = ENDPOINTS.alternate[endpointType]
const domainParts = site.split('.')
const extension = domainParts.pop()
const suffix = `${domainParts.join('-')}.${extension!}`
return `${endpoint}.browser-intake-${suffix}`
}
const endpoint = ENDPOINTS.classic[endpointType]!
return `${endpoint}-http-intake.logs.${site}`
const endpoint = ENDPOINTS[endpointType]
const domainParts = site.split('.')
const extension = domainParts.pop()
const suffix = `${domainParts.join('-')}.${extension!}`
return `${endpoint}.browser-intake-${suffix}`
}

function buildPath(endpointType: EndpointType) {
return shouldUseIntakeV2(endpointType) ? `/api/v2/${INTAKE_TRACKS[endpointType]}` : `/v1/input/${clientToken}`
return `/api/v2/${INTAKE_TRACKS[endpointType]}`
}

function buildQueryParameters(endpointType: EndpointType, source?: string) {
Expand All @@ -97,15 +68,13 @@ export function createEndpointBuilder(
`${service ? `,service:${service}` : ''}` +
`${version ? `,version:${version}` : ''}`

let parameters = `ddsource=${source || 'browser'}&ddtags=${encodeURIComponent(tags)}`

if (shouldUseIntakeV2(endpointType)) {
parameters +=
`&dd-api-key=${clientToken}` +
`&dd-evp-origin-version=${encodeURIComponent(sdkVersion)}` +
`&dd-evp-origin=browser` +
`&dd-request-id=${generateUUID()}`
}
let parameters =
`ddsource=${source || 'browser'}` +
`&ddtags=${encodeURIComponent(tags)}` +
`&dd-api-key=${clientToken}` +
`&dd-evp-origin-version=${encodeURIComponent(sdkVersion)}` +
`&dd-evp-origin=browser` +
`&dd-request-id=${generateUUID()}`

if (endpointType === 'rum') {
parameters += `&batch_time=${timeStampNow()}`
Expand All @@ -114,14 +83,6 @@ export function createEndpointBuilder(
return parameters
}

function shouldUseIntakeV2(endpointType?: EndpointType): boolean {
return intakeApiVersion === 2 || !includes(INTAKE_V1_ALLOWED_SITES, site) || endpointType === 'sessionReplay'
}

function shouldUseAlternateDomain(endpointType?: EndpointType): boolean {
return useAlternateIntakeDomains || !includes(CLASSIC_ALLOWED_SITES, site) || endpointType === 'sessionReplay'
}

return {
build,
buildIntakeUrl,
Expand Down
Loading

0 comments on commit c5e10d6

Please sign in to comment.