Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RUMF-1020] enable intake v2 #1048

Merged
merged 4 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/domain/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function buildConfiguration(initConfiguration: InitConfiguration, buildEn
cookieOptions: buildCookieOptions(initConfiguration),
isEnabled,
service: initConfiguration.service,
...computeTransportConfiguration(initConfiguration, buildEnv, isEnabled('support-intake-v2')),
...computeTransportConfiguration(initConfiguration, buildEnv),
...DEFAULT_CONFIGURATION,
}

Expand Down
11 changes: 2 additions & 9 deletions packages/core/src/domain/configuration/endpointBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ const INTAKE_V1_ALLOWED_SITES = [INTAKE_SITE_US, INTAKE_SITE_US3, INTAKE_SITE_EU

type IntakeType = keyof typeof ENDPOINTS

export function createEndpointBuilder(
initConfiguration: InitConfiguration,
buildEnv: BuildEnv,
isIntakeV2Enabled?: boolean
) {
export function createEndpointBuilder(initConfiguration: InitConfiguration, buildEnv: BuildEnv) {
const sdkVersion = buildEnv.sdkVersion
const {
site = INTAKE_SITE_US,
Expand Down Expand Up @@ -108,10 +104,7 @@ export function createEndpointBuilder(
}

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

function shouldUseAlternateDomain(endpointType?: EndpointType): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ describe('transportConfiguration', () => {
})

describe('query parameters', () => {
it('should add new intake query parameters when "support-intake-v2" enabled', () => {
const configuration = computeTransportConfiguration({ clientToken, intakeApiVersion: 2 }, buildEnv, true)
it('should add new intake query parameters when intakeApiVersion 2 is used', () => {
const configuration = computeTransportConfiguration({ clientToken, intakeApiVersion: 2 }, buildEnv)
expect(configuration.rumEndpoint).toMatch(
`&dd-api-key=${clientToken}&dd-evp-origin-version=(.*)&dd-evp-origin=browser`
)
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('transportConfiguration', () => {
})
})

describe('isIntakeUrl when "support-intake-v2" disabled', () => {
describe('isIntakeUrl with intakeApiVersion: 1', () => {
it('should not detect non intake request', () => {
const configuration = computeTransportConfiguration({ clientToken }, buildEnv)
expect(configuration.isIntakeUrl('https://www.foo.com')).toBe(false)
Expand All @@ -121,7 +121,7 @@ describe('transportConfiguration', () => {
const configuration = computeTransportConfiguration({ clientToken, site: 'datadoghq.eu' }, buildEnv)
expect(configuration.isIntakeUrl(`https://rum-http-intake.logs.datadoghq.eu${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://browser-http-intake.logs.datadoghq.eu${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.eu${v1IntakePath}?xxx`)).toBe(
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.eu/api/v2/replay?xxx`)).toBe(
true
)
})
Expand All @@ -131,7 +131,7 @@ describe('transportConfiguration', () => {

expect(configuration.isIntakeUrl(`https://rum-http-intake.logs.datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://browser-http-intake.logs.datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.com/api/v2/replay?xxx`)).toBe(
true
)
})
Expand All @@ -140,7 +140,7 @@ describe('transportConfiguration', () => {
const configuration = computeTransportConfiguration({ clientToken, useAlternateIntakeDomains: true }, buildEnv)
expect(configuration.isIntakeUrl(`https://rum.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://logs.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.com/api/v2/replay?xxx`)).toBe(
true
)
})
Expand All @@ -149,7 +149,7 @@ describe('transportConfiguration', () => {
const configuration = computeTransportConfiguration({ clientToken, useAlternateIntakeDomains: true }, buildEnv)
expect(configuration.isIntakeUrl(`https://rum.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://logs.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.com/api/v2/replay?xxx`)).toBe(
true
)
})
Expand All @@ -172,10 +172,10 @@ describe('transportConfiguration', () => {

it('should handle sites with subdomains', () => {
const configuration = computeTransportConfiguration({ clientToken, site: 'foo.datadoghq.com' }, buildEnv)
expect(configuration.isIntakeUrl(`https://rum.browser-intake-foo-datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://logs.browser-intake-foo-datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://rum.browser-intake-foo-datadoghq.com/api/v2/rum?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://logs.browser-intake-foo-datadoghq.com/api/v2/logs?xxx`)).toBe(true)
expect(
configuration.isIntakeUrl(`https://session-replay.browser-intake-foo-datadoghq.com${v1IntakePath}?xxx`)
configuration.isIntakeUrl(`https://session-replay.browser-intake-foo-datadoghq.com/api/v2/replay?xxx`)
).toBe(true)
})

Expand All @@ -196,41 +196,70 @@ describe('transportConfiguration', () => {
expect(configuration.isIntakeUrl('https://www.proxy.com/foo')).toBe(false)
})

it('should detect replica intake request with alternate intake domains', () => {
it('should detect replica intake request with alternate intake domains and intake v2', () => {
const configuration = computeTransportConfiguration(
{ clientToken, site: 'foo.com', replica: { clientToken } },
{ clientToken, site: 'datadoghq.eu', replica: { clientToken } },
{ ...buildEnv, buildMode: BuildMode.STAGING }
)
expect(configuration.isIntakeUrl(`https://rum.browser-intake-foo.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://logs.browser-intake-foo.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-foo.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://rum-http-intake.logs.datadoghq.eu${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://browser-http-intake.logs.datadoghq.eu${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.eu/api/v2/replay?xxx`)).toBe(
true
)

expect(configuration.isIntakeUrl(`https://rum.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://logs.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://rum.browser-intake-datadoghq.com/api/v2/rum?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://logs.browser-intake-datadoghq.com/api/v2/logs?xxx`)).toBe(true)
})

it('should force intake v1 when "support-intake-v2" disabled', () => {
const configuration = computeTransportConfiguration({ clientToken, intakeApiVersion: 2 }, buildEnv)
expect(configuration.isIntakeUrl(`https://rum-http-intake.logs.datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://browser-http-intake.logs.datadoghq.com${v1IntakePath}?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.com${v1IntakePath}?xxx`)).toBe(
true
)
describe('on us5', () => {
it('should force alternate domains intake v2', () => {
const configuration = computeTransportConfiguration({ clientToken, site: 'us5.datadoghq.com' }, buildEnv)
expect(configuration.isIntakeUrl('https://rum.browser-intake-us5-datadoghq.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-us5-datadoghq.com/api/v2/logs?xxx')).toBe(true)
})
})

describe('when session-replay on all env', () => {
it('should force alternate domains intake v2', () => {
let configuration = computeTransportConfiguration({ clientToken }, buildEnv)
expect(configuration.isIntakeUrl('https://session-replay.browser-intake-datadoghq.com/api/v2/replay?xxx')).toBe(
true
)

configuration = computeTransportConfiguration({ clientToken, site: 'datadoghq.eu' }, buildEnv)
expect(configuration.isIntakeUrl('https://session-replay.browser-intake-datadoghq.eu/api/v2/replay?xxx')).toBe(
true
)

configuration = computeTransportConfiguration({ clientToken, site: 'us3.datadoghq.com' }, buildEnv)
expect(
configuration.isIntakeUrl('https://session-replay.browser-intake-us3-datadoghq.com/api/v2/replay?xxx')
).toBe(true)

configuration = computeTransportConfiguration({ clientToken, site: 'ddog-gov.com' }, buildEnv)
expect(configuration.isIntakeUrl('https://session-replay.browser-intake-ddog-gov.com/api/v2/replay?xxx')).toBe(
true
)

configuration = computeTransportConfiguration({ clientToken, site: 'us5.datadoghq.com' }, buildEnv)
expect(
configuration.isIntakeUrl('https://session-replay.browser-intake-us5-datadoghq.com/api/v2/replay?xxx')
).toBe(true)
})
})
})

describe('isIntakeUrl when "support-intake-v2" enabled', () => {
describe('isIntakeUrl with intakeApiVersion: 2', () => {
describe('when RUM or Logs', () => {
describe('on us1 and eu1', () => {
it('should detect classic domains intake v2', () => {
let configuration = computeTransportConfiguration({ clientToken, intakeApiVersion: 2 }, buildEnv, true)
let configuration = computeTransportConfiguration({ clientToken, intakeApiVersion: 2 }, buildEnv)
expect(configuration.isIntakeUrl('https://rum-http-intake.logs.datadoghq.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://browser-http-intake.logs.datadoghq.com/api/v2/logs?xxx')).toBe(true)

configuration = computeTransportConfiguration(
{ clientToken, site: 'datadoghq.eu', intakeApiVersion: 2 },
buildEnv,
true
buildEnv
)
expect(configuration.isIntakeUrl('https://rum-http-intake.logs.datadoghq.eu/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://browser-http-intake.logs.datadoghq.eu/api/v2/logs?xxx')).toBe(true)
Expand All @@ -239,16 +268,14 @@ describe('transportConfiguration', () => {
it('should detect alternate domains intake v2', () => {
let configuration = computeTransportConfiguration(
{ clientToken, useAlternateIntakeDomains: true, intakeApiVersion: 2 },
buildEnv,
true
buildEnv
)
expect(configuration.isIntakeUrl('https://rum.browser-intake-datadoghq.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-datadoghq.com/api/v2/logs?xxx')).toBe(true)

configuration = computeTransportConfiguration(
{ clientToken, site: 'datadoghq.eu', useAlternateIntakeDomains: true, intakeApiVersion: 2 },
buildEnv,
true
buildEnv
)
expect(configuration.isIntakeUrl('https://rum.browser-intake-datadoghq.eu/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-datadoghq.eu/api/v2/logs?xxx')).toBe(true)
Expand All @@ -259,79 +286,19 @@ describe('transportConfiguration', () => {
it('should detect alternate domains intake v2', () => {
let configuration = computeTransportConfiguration(
{ clientToken, site: 'us3.datadoghq.com', intakeApiVersion: 2 },
buildEnv,
true
buildEnv
)
expect(configuration.isIntakeUrl('https://rum.browser-intake-us3-datadoghq.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-us3-datadoghq.com/api/v2/logs?xxx')).toBe(true)

configuration = computeTransportConfiguration(
{ clientToken, site: 'ddog-gov.com', intakeApiVersion: 2 },
buildEnv,
true
buildEnv
)
expect(configuration.isIntakeUrl('https://rum.browser-intake-ddog-gov.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://rum-http-intake.logs.ddog-gov.com/api/v2/logs?xxx')).toBe(false)
})
})

describe('on us5', () => {
it('should force alternate domains intake v2', () => {
const configuration = computeTransportConfiguration(
{ clientToken, site: 'us5.datadoghq.com' },
buildEnv,
true
)
expect(configuration.isIntakeUrl('https://rum.browser-intake-us5-datadoghq.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-us5-datadoghq.com/api/v2/logs?xxx')).toBe(true)
})
})
})

describe('when session-replay on all env', () => {
it('should force alternate domains intake v2', () => {
let configuration = computeTransportConfiguration({ clientToken }, buildEnv, true)
expect(configuration.isIntakeUrl('https://session-replay.browser-intake-datadoghq.com/api/v2/replay?xxx')).toBe(
true
)

configuration = computeTransportConfiguration({ clientToken, site: 'datadoghq.eu' }, buildEnv, true)
expect(configuration.isIntakeUrl('https://session-replay.browser-intake-datadoghq.eu/api/v2/replay?xxx')).toBe(
true
)

configuration = computeTransportConfiguration({ clientToken, site: 'us3.datadoghq.com' }, buildEnv, true)
expect(
configuration.isIntakeUrl('https://session-replay.browser-intake-us3-datadoghq.com/api/v2/replay?xxx')
).toBe(true)

configuration = computeTransportConfiguration({ clientToken, site: 'ddog-gov.com' }, buildEnv, true)
expect(configuration.isIntakeUrl('https://session-replay.browser-intake-ddog-gov.com/api/v2/replay?xxx')).toBe(
true
)

configuration = computeTransportConfiguration({ clientToken, site: 'us5.datadoghq.com' }, buildEnv, true)
expect(
configuration.isIntakeUrl('https://session-replay.browser-intake-us5-datadoghq.com/api/v2/replay?xxx')
).toBe(true)
})
})

it('should detect replica intake request with alternate intake domains version 2', () => {
const configuration = computeTransportConfiguration(
{ clientToken, site: 'foo.com', replica: { clientToken } },
{ ...buildEnv, buildMode: BuildMode.STAGING },
true
)
expect(configuration.isIntakeUrl('https://rum.browser-intake-foo.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-foo.com/api/v2/logs?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://session-replay.browser-intake-foo.com/api/v2/replay?xxx')).toBe(true)

expect(configuration.isIntakeUrl('https://rum.browser-intake-datadoghq.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-datadoghq.com/api/v2/logs?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://session-replay.browser-intake-datadoghq.com/api/v2/replay?xxx')).toBe(
true
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ export interface ReplicaConfiguration {

export function computeTransportConfiguration(
initConfiguration: InitConfiguration,
buildEnv: BuildEnv,
isIntakeV2Enabled?: boolean
buildEnv: BuildEnv
): TransportConfiguration {
const endpointBuilder = createEndpointBuilder(initConfiguration, buildEnv, isIntakeV2Enabled)
const endpointBuilder = createEndpointBuilder(initConfiguration, buildEnv)
const intakeUrls: string[] = ENDPOINTS_TYPES.map((endpointType) => endpointBuilder.buildIntakeUrl(endpointType))

const configuration: TransportConfiguration = {
Expand All @@ -47,15 +46,15 @@ export function computeTransportConfiguration(
}

if (buildEnv.buildMode === BuildMode.STAGING && initConfiguration.replica !== undefined) {
const replicaConfiguration = {
const replicaConfiguration: InitConfiguration = {
...initConfiguration,
site: INTAKE_SITE_US,
applicationId: initConfiguration.replica.applicationId,
clientToken: initConfiguration.replica.clientToken,
useAlternateIntakeDomains: true,
intakeApiVersion: isIntakeV2Enabled ? 2 : (1 as 1 | 2),
intakeApiVersion: 2,
}
const replicaEndpointBuilder = createEndpointBuilder(replicaConfiguration, buildEnv, isIntakeV2Enabled)
const replicaEndpointBuilder = createEndpointBuilder(replicaConfiguration, buildEnv)

configuration.replica = {
applicationId: initConfiguration.replica.applicationId,
Expand Down
Loading