Skip to content

Commit 4a7b425

Browse files
committed
Test
1 parent b01393d commit 4a7b425

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

benchmark/createBenchmarkTest.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export function createBenchmarkTest(scenarioName: string) {
1919
return {
2020
run(runner: TestRunner) {
2121
const metrics: Record<string, Metrics> = {}
22+
let sdkVersion: string
23+
2224
SCENARIO_CONFIGURATIONS.forEach((scenarioConfiguration) => {
2325
test(`${scenarioName} benchmark ${scenarioConfiguration}`, async ({ page }) => {
2426
await page.setExtraHTTPHeaders({ 'Accept-Language': 'en-US' })
@@ -33,13 +35,16 @@ export function createBenchmarkTest(scenarioName: string) {
3335

3436
await flushEvents(page)
3537
metrics[scenarioConfiguration] = await stopProfiling()
38+
if (!sdkVersion) {
39+
sdkVersion = await getSDKVersion(page)
40+
}
3641
})
3742
})
3843

3944
test.afterAll(async () => {
40-
reportToConsole(metrics)
45+
reportToConsole(metrics, sdkVersion)
4146
if (isContinuousIntegration) {
42-
await reportToDatadog(metrics, scenarioName)
47+
await reportToDatadog(metrics, scenarioName, sdkVersion)
4348
}
4449
})
4550
},
@@ -66,6 +71,7 @@ async function injectSDK(page: Page, scenarioConfiguration: ScenarioConfiguratio
6671
await page.addInitScript(
6772
({ sdkBundleUrl, scenarioConfiguration, scenarioName, configuration }: PageInitScriptParameters) => {
6873
function loadSDK() {
74+
const browserWindow = window as BrowserWindow
6975
;(function (h: any, o: Document, u: string, n: string, d: string) {
7076
h = h[d] = h[d] || {
7177
q: [],
@@ -79,12 +85,12 @@ async function injectSDK(page: Page, scenarioConfiguration: ScenarioConfiguratio
7985
s.src = n
8086
o.head.appendChild(s)
8187
})(window, document, 'script', sdkBundleUrl, 'DD_RUM')
82-
;(window as BrowserWindow).DD_RUM?.onReady(function () {
83-
;(window as BrowserWindow).DD_RUM!.setGlobalContextProperty('scenario', {
88+
browserWindow.DD_RUM?.onReady(function () {
89+
browserWindow.DD_RUM!.setGlobalContextProperty('scenario', {
8490
configuration: scenarioConfiguration,
8591
name: scenarioName,
8692
})
87-
;(window as BrowserWindow).DD_RUM!.init(configuration as RumInitConfiguration)
93+
browserWindow.DD_RUM!.init(configuration as RumInitConfiguration)
8894
})
8995
}
9096

@@ -99,6 +105,10 @@ async function injectSDK(page: Page, scenarioConfiguration: ScenarioConfiguratio
99105
)
100106
}
101107

108+
async function getSDKVersion(page: Page) {
109+
return await page.evaluate(() => (window as BrowserWindow).DD_RUM?.version || '')
110+
}
111+
102112
function shouldInjectSDK(scenarioConfiguration: ScenarioConfiguration): boolean {
103113
return !['none', 'none_with_headers'].includes(scenarioConfiguration)
104114
}

benchmark/reporters/reportToConsole.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const DURATION_UNITS = ['μs', 'ms', 's']
44
const BYTES_UNITS = ['B', 'kB', 'MB']
55
const NO_VALUE = ''
66

7-
export function reportToConsole(metricsTable: Record<string, Metrics>) {
7+
export function reportToConsole(metricsTable: Record<string, Metrics>, sdkVersion: string) {
88
const report: Record<string, Record<string, string>> = {
99
'memory (median)': {},
1010
cpu: {},
@@ -32,6 +32,7 @@ export function reportToConsole(metricsTable: Record<string, Metrics>) {
3232
report['TBT'][scenarioConfiguration] = metrics.TBT ? formatNumberWithUnit(metrics.TBT, DURATION_UNITS) : NO_VALUE
3333
}
3434

35+
console.log(`Results for SDK version: ${sdkVersion}`)
3536
console.table(report)
3637
}
3738

benchmark/reporters/reportToDatadog.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,29 @@ const METRIC_PREFIX = 'browser_sdk.benchmark'
1313

1414
export async function reportToDatadog(
1515
metricsTable: Record<string, Metrics>,
16-
scenarioName: string
16+
scenarioName: string,
17+
sdkVersion: string
1718
) {
18-
const series = convertMetricsToSeries(metricsTable, scenarioName)
19+
const series = convertMetricsToSeries(metricsTable, scenarioName, sdkVersion)
1920
const result = await sendToDatadog(series)
2021

2122
console.log(`✅ Successfully sent ${series.length} metrics to Datadog`)
22-
console.log(`📊 View metrics in Datadog: https://app.${DATADOG_SITE}/metric/explorer?query=${METRIC_PREFIX}.*`)
23-
console.log(`🏷️ Filter by tags: scenario:${scenarioName}`)
23+
console.log(
24+
`📊 View metrics in Datadog: https://app.${DATADOG_SITE}/dashboard/m7i-uke-sa9/rum-browser-sdk-performance`
25+
)
2426
return result
2527
}
2628

2729
function convertMetricsToSeries(
2830
metricsTable: Record<string, Metrics>,
29-
scenarioName: string
31+
scenarioName: string,
32+
sdkVersion: string
3033
): DatadogSeries[] {
3134
const timestamp = Math.floor(Date.now() / 1000)
3235
const series: DatadogSeries[] = []
3336

3437
for (const [configuration, metrics] of Object.entries(metricsTable)) {
35-
const tags = [`scenario:${scenarioName}`, `configuration:${configuration}`]
38+
const tags = [`scenario:${scenarioName}`, `configuration:${configuration}`, `sdk_version:${sdkVersion}`]
3639

3740
for (const [key, value] of Object.entries(metrics)) {
3841
series.push({

0 commit comments

Comments
 (0)