Skip to content

Commit

Permalink
✨ [RUMF-1251] allow to enable telemetry by site (#1520)
Browse files Browse the repository at this point in the history
* ♻️ add site to configuration

* ✨ allow to enable telemetry by site

* 👌 improve test description
  • Loading branch information
bcaudan authored May 10, 2022
1 parent 26d2d05 commit 6cdb9fc
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/domain/configuration/endpointBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const INTAKE_TRACKS = {
type EndpointType = keyof typeof ENDPOINTS

export const INTAKE_SITE_US = 'datadoghq.com'
export const INTAKE_SITE_US3 = 'us3.datadoghq.com'
export const INTAKE_SITE_US5 = 'us5.datadoghq.com'
export const INTAKE_SITE_EU = 'datadoghq.eu'

export type EndpointBuilder = ReturnType<typeof createEndpointBuilder>

Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/domain/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ export {
DefaultPrivacyLevel,
validateAndBuildConfiguration,
} from './configuration'
export { createEndpointBuilder, EndpointBuilder } from './endpointBuilder'
export {
createEndpointBuilder,
EndpointBuilder,
INTAKE_SITE_US5,
INTAKE_SITE_US,
INTAKE_SITE_US3,
INTAKE_SITE_EU,
} from './endpointBuilder'
export {
isExperimentalFeatureEnabled,
updateExperimentalFeatures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ describe('transportConfiguration', () => {
it('should use US site by default', () => {
const configuration = computeTransportConfiguration({ clientToken })
expect(configuration.rumEndpointBuilder.build()).toContain('datadoghq.com')
expect(configuration.site).toBe('datadoghq.com')
})

it('should use site value when set', () => {
const configuration = computeTransportConfiguration({ clientToken, site: 'foo.com' })
expect(configuration.rumEndpointBuilder.build()).toContain('foo.com')
expect(configuration.site).toBe('foo.com')
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface TransportConfiguration {
internalMonitoringEndpointBuilder?: EndpointBuilder
isIntakeUrl: (url: string) => boolean
replica?: ReplicaConfiguration
site: string
}

export interface ReplicaConfiguration {
Expand All @@ -32,6 +33,7 @@ export function computeTransportConfiguration(initConfiguration: InitConfigurati
{
isIntakeUrl: (url: string) => intakeEndpoints.some((intakeEndpoint) => url.indexOf(intakeEndpoint) === 0),
replica: replicaConfiguration,
site: initConfiguration.site || INTAKE_SITE_US,
},
endpointBuilders
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import type { Context } from '../../tools/context'
import { display } from '../../tools/display'
import type { Configuration } from '../configuration'
import { updateExperimentalFeatures, resetExperimentalFeatures } from '../configuration'
import {
updateExperimentalFeatures,
resetExperimentalFeatures,
INTAKE_SITE_US,
INTAKE_SITE_US3,
INTAKE_SITE_EU,
INTAKE_SITE_US5,
} from '../configuration'
import type { InternalMonitoring, MonitoringMessage } from './internalMonitoring'
import {
monitor,
Expand Down Expand Up @@ -242,6 +249,31 @@ describe('internal monitoring', () => {
let internalMonitoring: InternalMonitoring
let notifySpy: jasmine.Spy<(event: TelemetryEvent & Context) => void>

describe('rollout', () => {
;[
{ site: INTAKE_SITE_US5, enabled: false },
{ site: INTAKE_SITE_US3, enabled: false },
{ site: INTAKE_SITE_EU, enabled: false },
{ site: INTAKE_SITE_US, enabled: false },
].forEach(({ site, enabled }) => {
it(`should be ${enabled ? 'enabled' : 'disabled'} on ${site}`, () => {
internalMonitoring = startInternalMonitoring({ ...configuration, site } as Configuration)
notifySpy = jasmine.createSpy('notified')
internalMonitoring.telemetryEventObservable.subscribe(notifySpy)

callMonitored(() => {
throw new Error('message')
})

if (enabled) {
expect(notifySpy).toHaveBeenCalled()
} else {
expect(notifySpy).not.toHaveBeenCalled()
}
})
})
})

describe('when enabled', () => {
beforeEach(() => {
updateExperimentalFeatures(['telemetry'])
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/domain/internalMonitoring/internalMonitoring.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Context } from '../../tools/context'
import { display } from '../../tools/display'
import { toStackTraceString } from '../../tools/error'
import { assign, combine, jsonStringify, performDraw } from '../../tools/utils'
import { assign, combine, jsonStringify, performDraw, includes } from '../../tools/utils'
import type { Configuration } from '../configuration'
import { computeStackTrace } from '../tracekit'
import { Observable } from '../../tools/observable'
Expand Down Expand Up @@ -34,6 +34,13 @@ export interface MonitoringMessage extends Context {
}
}

const TELEMETRY_ALLOWED_SITES: string[] = [
// INTAKE_SITE_US5,
// INTAKE_SITE_US3,
// INTAKE_SITE_EU,
// INTAKE_SITE_US,
]

const monitoringConfiguration: {
debugMode?: boolean
maxMessagesPerPage: number
Expand All @@ -53,7 +60,10 @@ export function startInternalMonitoring(configuration: Configuration): InternalM

onInternalMonitoringMessageCollected = (message: MonitoringMessage) => {
monitoringMessageObservable.notify(withContext(message))
if (isExperimentalFeatureEnabled('telemetry') && monitoringConfiguration.telemetryEnabled) {
if (
(isExperimentalFeatureEnabled('telemetry') || includes(TELEMETRY_ALLOWED_SITES, configuration.site)) &&
monitoringConfiguration.telemetryEnabled
) {
telemetryEventObservable.notify(toTelemetryEvent(message))
}
}
Expand Down

0 comments on commit 6cdb9fc

Please sign in to comment.