Skip to content

Commit f75f01b

Browse files
authored
e2e: add app version and build number to perf metrics (#9261)
### Summary Updated the payload that we are sending to e2e-test-insights API to include the app version and build #. ### QA Notes n/a
1 parent fb64136 commit f75f01b

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

test/e2e/infra/test-runner/test-setup.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export function prepareTestEnv(rootPath: string, logsRootPath: string) {
4747
/**
4848
* Sets up the test environment for Electron or Web e2e tests.
4949
*/
50-
function initializeTestEnvironment(rootPath = process.env.ROOT_PATH || 'ROOT_PATH not set initTestEnv', logger: Logger): string | null {
51-
let version: string | null = null;
50+
function initializeTestEnvironment(rootPath = process.env.ROOT_PATH || 'ROOT_PATH not set initTestEnv', logger: Logger): PositronVersion | null {
51+
let version: PositronVersion | null = null;
5252

5353
//
5454
// #### E2E: Electron Tests ####
@@ -61,7 +61,9 @@ function initializeTestEnvironment(rootPath = process.env.ROOT_PATH || 'ROOT_PAT
6161
if (testCodePath) {
6262
electronPath = getBuildElectronPath(testCodePath);
6363
version = getPositronVersion(testCodePath);
64-
console.log('POSITRON VERSION:', version);
64+
if (version) {
65+
console.log(`POSITRON VERSION: ${version.positronVersion}-${version.buildNumber}`);
66+
}
6567
} else {
6668
testCodePath = getDevElectronPath();
6769
electronPath = testCodePath;
@@ -117,7 +119,11 @@ function prepareTestDataDirectory() {
117119
mkdirp.sync(TEST_DATA_PATH);
118120
}
119121

120-
function getPositronVersion(testCodePath: string): string | null {
122+
export function getPositronVersion(testCodePath = process.env.BUILD || ''): PositronVersion | null {
123+
if (!testCodePath) {
124+
return null;
125+
}
126+
121127
let productJsonPath;
122128
switch (process.platform) {
123129
case 'darwin':
@@ -133,14 +139,27 @@ function getPositronVersion(testCodePath: string): string | null {
133139
return null;
134140
}
135141

136-
// Read and parse the JSON file
137-
const productJson = JSON.parse(fs.readFileSync(productJsonPath, 'utf8'));
142+
try {
143+
// Read and parse the JSON file
144+
const productJson = JSON.parse(fs.readFileSync(productJsonPath, 'utf8'));
145+
146+
// Return both version and build number properties
147+
const positronVersion = productJson.positronVersion || null;
148+
const buildNumber = productJson.positronBuildNumber || null;
138149

139-
// Return the `positronVersion` property if it exists, otherwise log an error
140-
if (productJson.positronVersion) {
141-
return productJson.positronVersion;
142-
} else {
143-
console.error('positronVersion not found in product.json.');
150+
if (!positronVersion) {
151+
throw new Error('positronVersion not found in product.json.');
152+
}
153+
154+
if (!buildNumber) {
155+
console.error('positronBuildNumber not found in product.json.');
156+
}
157+
158+
return { positronVersion, buildNumber };
159+
} catch (error) {
160+
console.error('Error reading product.json:', error);
144161
return null;
145162
}
146163
}
164+
165+
type PositronVersion = { positronVersion: string | null, buildNumber: string | null };

test/e2e/utils/metrics/api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
LOCAL_API_URL,
1212
platformOs,
1313
platformVersion,
14-
MetricResponse
14+
MetricResponse,
15+
positronVersion
1516
} from './metric-base.js';
1617
import { SPEC_NAME } from '../../fixtures/test-setup/constants.js';
1718

@@ -28,6 +29,8 @@ export type PerfMetric = {
2829

2930
export type MetricPayload = {
3031
timestamp: string;
32+
app_version: string;
33+
build_number: string;
3134
platform_os: string;
3235
platform_version: string;
3336
runtime_env: string;
@@ -99,6 +102,8 @@ function createMetricPayload(metric: PerfMetric, isElectronApp: boolean): Metric
99102
timestamp: new Date().toISOString(),
100103
platform_os: platformOs,
101104
platform_version: platformVersion,
105+
app_version: positronVersion?.positronVersion || 'unknown',
106+
build_number: positronVersion?.buildNumber || 'unknown',
102107
runtime_env: isElectronApp ? 'electron' : 'chromium',
103108
run_id: process.env.GITHUB_RUN_ID ?? process.env.RUN_ID ?? 'unknown',
104109
feature_area,

test/e2e/utils/metrics/metric-base.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55

66
import os from 'os';
77
import { DataExplorerShortcutOptions } from './metric-data-explorer.js';
8+
import { getPositronVersion } from '../../infra/test-runner/test-setup.js';
89

910
export const CONNECT_API_KEY = process.env.CONNECT_API_KEY!;
1011
export const PROD_API_URL = 'https://connect.posit.it/e2e-test-insights-api/metrics';
1112
export const LOCAL_API_URL = 'http://127.0.0.1:8000/metrics';
1213

14+
//-----------------------
15+
// Platform Information
16+
//-----------------------
17+
1318
export const platformOs = (() => {
1419
const osMap = {
1520
darwin: 'macOS',
@@ -22,6 +27,8 @@ export const platformOs = (() => {
2227

2328
export const platformVersion = os.release();
2429

30+
export const positronVersion = getPositronVersion();
31+
2532
//-----------------------
2633
// Base Metric Types
2734
//-----------------------

0 commit comments

Comments
 (0)