Skip to content

Commit

Permalink
✨ [RUM] Support legacy endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
webNeat committed Nov 16, 2020
1 parent 4301386 commit fa30e8c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 20 deletions.
23 changes: 21 additions & 2 deletions packages/core/src/domain/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,27 @@ describe('configuration', () => {
it('should detect intake request for US site', () => {
const configuration = buildConfiguration({ clientToken }, usEnv)
expect(isIntakeRequest('https://rum.browser-intake-datadoghq.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://browser.browser-intake-datadoghq.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://logs.browser-intake-datadoghq.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://trace.browser-intake-datadoghq.com/v1/input/xxx', configuration)).toBe(true)

expect(isIntakeRequest('https://rum-http-intake.logs.datadoghq.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://browser-http-intake.logs.datadoghq.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://public-trace-http-intake.logs.datadoghq.com/v1/input/xxx', configuration)).toBe(
true
)
})

it('should detect intake request for staging US site', () => {
const configuration = buildConfiguration({ clientToken, site: 'datad0g.com' }, usEnv)
expect(isIntakeRequest('https://rum.browser-intake-datad0g.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://logs.browser-intake-datad0g.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://trace.browser-intake-datad0g.com/v1/input/xxx', configuration)).toBe(true)

expect(isIntakeRequest('https://rum-http-intake.logs.datad0g.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://browser-http-intake.logs.datad0g.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://public-trace-http-intake.logs.datad0g.com/v1/input/xxx', configuration)).toBe(
true
)
})

it('should detect proxy intake request', () => {
Expand All @@ -148,7 +167,7 @@ describe('configuration', () => {
expect(isIntakeRequest('https://public-trace-http-intake.logs.foo.com/v1/input/xxx', configuration)).toBe(true)

expect(isIntakeRequest('https://rum.browser-intake-datadoghq.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://browser.browser-intake-datadoghq.com/v1/input/xxx', configuration)).toBe(true)
expect(isIntakeRequest('https://logs.browser-intake-datadoghq.com/v1/input/xxx', configuration)).toBe(true)
})
})
})
56 changes: 38 additions & 18 deletions packages/core/src/domain/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export type Configuration = typeof DEFAULT_CONFIGURATION & {
internalMonitoringEndpoint?: string
proxyHost?: string

legacyEndpoints: string[]

service?: string

isEnabled: (feature: string) => boolean
Expand Down Expand Up @@ -137,6 +139,12 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
rumEndpoint: getEndpoint(EndpointType.RUM, transportConfiguration),
service: userConfiguration.service,
traceEndpoint: getEndpoint(EndpointType.TRACE, transportConfiguration),

legacyEndpoints: [
getEndpoint(EndpointType.BROWSER, transportConfiguration, undefined, true),
getEndpoint(EndpointType.RUM, transportConfiguration, undefined, true),
getEndpoint(EndpointType.TRACE, transportConfiguration, undefined, true),
],
...DEFAULT_CONFIGURATION,
}
if (userConfiguration.internalMonitoringApiKey) {
Expand All @@ -145,6 +153,9 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
transportConfiguration,
'browser-agent-internal-monitoring'
)
configuration.legacyEndpoints.push(
getEndpoint(EndpointType.BROWSER, transportConfiguration, 'browser-agent-internal-monitoring', true)
)
}

if ('allowedTracingOrigins' in userConfiguration) {
Expand Down Expand Up @@ -187,6 +198,11 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
logsEndpoint: getEndpoint(EndpointType.BROWSER, replicaTransportConfiguration),
rumEndpoint: getEndpoint(EndpointType.RUM, replicaTransportConfiguration),
}
configuration.legacyEndpoints.push(
getEndpoint(EndpointType.BROWSER, replicaTransportConfiguration, 'browser-agent-internal-monitoring', true),
getEndpoint(EndpointType.BROWSER, replicaTransportConfiguration, undefined, true),
getEndpoint(EndpointType.RUM, replicaTransportConfiguration, undefined, true)
)
}
}

Expand All @@ -206,40 +222,44 @@ export function buildCookieOptions(userConfiguration: UserConfiguration) {
return cookieOptions
}

function getEndpoint(type: EndpointType, conf: TransportConfiguration, source?: string) {
function getEndpoint(type: EndpointType, conf: TransportConfiguration, source?: string, withLegacyHost = false) {
const tags =
`sdk_version:${conf.sdkVersion}` +
`${conf.env ? `,env:${conf.env}` : ''}` +
`${conf.service ? `,service:${conf.service}` : ''}` +
`${conf.version ? `,version:${conf.version}` : ''}`
const datadogHost = getHost(type, conf)
const datadogHost = getHost(type, conf, withLegacyHost)
const host = conf.proxyHost ? conf.proxyHost : datadogHost
const proxyParameter = conf.proxyHost ? `ddhost=${datadogHost}&` : ''
const applicationIdParameter = conf.applicationId ? `_dd.application_id=${conf.applicationId}&` : ''
const parameters = `${applicationIdParameter}${proxyParameter}ddsource=${source || 'browser'}&ddtags=${tags}`

return `https://${host}/v1/input/${conf.clientToken}?${parameters}`
}
function getHost(type: EndpointType, conf: TransportConfiguration) {
const subdomains = {
[EndpointType.BROWSER]: 'logs',
[EndpointType.RUM]: 'rum',
[EndpointType.TRACE]: 'trace',
}
if (conf.site === INTAKE_SITE[Datacenter.US]) {
return `${subdomains[type]}.browser-intake-datadoghq.com`
}
if (conf.site === STAGING_INTAKE_SITE[Datacenter.US]) {
return `${subdomains[type]}.browser-intake-datad0g.com`
function getHost(type: EndpointType, conf: TransportConfiguration, useLegacyDomain: boolean) {
if (!useLegacyDomain) {
const subdomains = {
[EndpointType.BROWSER]: 'logs',
[EndpointType.RUM]: 'rum',
[EndpointType.TRACE]: 'trace',
}
if (conf.site === INTAKE_SITE[Datacenter.US]) {
return `${subdomains[type]}.browser-intake-datadoghq.com`
}
if (conf.site === STAGING_INTAKE_SITE[Datacenter.US]) {
return `${subdomains[type]}.browser-intake-datad0g.com`
}
}
return `${type}-http-intake.logs.${conf.site}`
}

export function isIntakeRequest(url: string, configuration: Configuration) {
if (!getPathName(url).includes('/v1/input/')) return false
return getIntakeEndpoints(configuration)
.map(getOrigin)
.includes(getOrigin(url))
if (getPathName(url).includes('/v1/input/')) {
return getIntakeEndpoints(configuration)
.map(getOrigin)
.includes(getOrigin(url))
}
return false
}

function getIntakeEndpoints(configuration: Configuration) {
Expand All @@ -254,7 +274,7 @@ function getIntakeEndpoints(configuration: Configuration) {
configuration.replica.internalMonitoringEndpoint
)
}
return endpoints
return endpoints.concat(configuration.legacyEndpoints || [])
}

function mustUseSecureCookie(userConfiguration: UserConfiguration) {
Expand Down

0 comments on commit fa30e8c

Please sign in to comment.