Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

ci: report memory overflow to posthog (#4747)

Wenzhao Hu4b3db9ef62d6
diff --git a/.github/workflows/dev-performance-log.yml b/.github/workflows/dev-performance-log.yml
new file mode 100644
index 0000000000..12ae6b27bf
--- /dev/null
+++ b/.github/workflows/dev-performance-log.yml
@@ -0,0 +1,37 @@
+name: 🔭 Dev Performance Report
+
+on:
+ push:
+ branches:
+ - dev
+
+jobs:
+ e2e-test:
+ runs-on: ubuntu-latest
+
+ env:
+ GH_TOKEN: ${{ github.token }}
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Set Env
+ run: |
+ if [ "$GITHUB_EVENT_NAME" == "push" ] && [ "$GITHUB_REF" == "refs/heads/dev" ]; then
+ echo "SHOULD_REPORT_TO_POSTHOG=true" >> $GITHUB_ENV
+ elif [ "$GITHUB_EVENT_NAME" == "pull_request" ] && [ "$GITHUB_BASE_REF" == "dev" ]; then
+ echo "SHOULD_REPORT_TO_POSTHOG=true" >> $GITHUB_ENV
+ fi
+
+ - name: Setup Node.js
+ uses: ./.github/actions/setup-node
+
+ - name: Install Playwright Browsers
+ run: pnpm exec playwright install --with-deps chromium
+
+ - name: Build E2E Client
+ run: pnpm build:e2e
+
+ - name: Run Playwright Tests
+ run: pnpm exec playwright test
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 37a69460d3..b11049c324 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -101,6 +101,7 @@
"pnmp",
"Polyton",
"ponyfill",
+ "Posthog",
"prst",
"PWDEBUG",
"Quan",
diff --git a/e2e/memory/memory.spec.ts b/e2e/memory/memory.spec.ts
index 79f4296d2c..5b4c9e90a4 100644
--- a/e2e/memory/memory.spec.ts
+++ b/e2e/memory/memory.spec.ts
@@ -17,6 +17,7 @@
import type { CDPSession } from '@playwright/test';
import { createWriteStream } from 'node:fs';
import { expect, test } from '@playwright/test';
+import { flushPosthog, reportToPosthog } from '../utils/report-performance';
import { getMetrics } from './util';
const MAX_UNIT_MEMORY_OVERFLOW = 1_000_000; // 1MB
@@ -134,6 +135,8 @@ test('memory', async ({ page }) => {
await page.evaluate(() => window.E2EControllerAPI.loadAndRelease(2));
await page.waitForTimeout(2000);
const memoryAfterSecondLoad = (await getMetrics(page)).JSHeapUsedSize;
+
+ reportToPosthog('unit_memory_workflow', { value: memoryAfterSecondLoad - memoryAfterFirstLoad });
expect(memoryAfterSecondLoad - memoryAfterFirstLoad)
.toBeLessThanOrEqual(MAX_UNIT_MEMORY_OVERFLOW);
@@ -143,7 +146,6 @@ test('memory', async ({ page }) => {
await takeHeapSnapshot(client, 'memory-first.heapsnapshot');
const memoryAfterDisposingFirstInstance = (await getMetrics(page)).JSHeapUsedSize;
-
await page.evaluate(() => window.createNewInstance());
await page.waitForTimeout(2000);
await page.evaluate(() => window.univer.dispose());
@@ -152,11 +154,15 @@ test('memory', async ({ page }) => {
await takeHeapSnapshot(client, 'memory-second.heapsnapshot');
const memoryAfterDisposingSecondUniver = (await getMetrics(page)).JSHeapUsedSize;
+ reportToPosthog('instance_memory_workflow', { value: memoryAfterDisposingSecondUniver - memoryAfterDisposingFirstInstance });
expect(memoryAfterDisposingSecondUniver - memoryAfterDisposingFirstInstance)
.toBeLessThanOrEqual(MAX_SECOND_INSTANCE_OVERFLOW);
+ reportToPosthog('univer_memory_workflow', { value: memoryAfterDisposingSecondUniver - memoryAfterFirstInstance });
expect(memoryAfterDisposingSecondUniver - memoryAfterFirstInstance)
.toBeLessThanOrEqual(MAX_UNIVER_MEMORY_OVERFLOW);
+
+ flushPosthog();
});
declare global {
diff --git a/e2e/utils/report-performance.ts b/e2e/utils/report-performance.ts
new file mode 100644
index 0000000000..5a656bf137
--- /dev/null
+++ b/e2e/utils/report-performance.ts
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* eslint-disable node/prefer-global/process */
+
+import { PostHog } from 'posthog-node';
+
+const SHOULD_REPORT_TO_POSTHOG = process.env.SHOULD_REPORT_TO_POSTHOG === 'true';
+const GIT_HASH = process.env.GITHUB_SHA;
+
+let client: PostHog | null = null;
+
+export function reportToPosthog(event: string, properties: Record<string | number, any>) {
+ if (!SHOULD_REPORT_TO_POSTHOG) {
+ return;
+ }
+
+ if (!client) {
+ const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY;
+ client = new PostHog(POSTHOG_API_KEY, { host: 'https://us.i.posthog.com' });
+ }
+
+ client.capture({
+ timestamp: new Date(),
+ event,
+ distinctId: 'CI',
+ properties: {
+ ...properties,
+ git_hash: GIT_HASH,
+ },
+ });
+}
+
+export function flushPosthog() {
+ if (client) {
+ client.flush();
+ client.shutdown();
+
+ client = null;
+ }
+}
diff --git a/package.json b/package.json
index 0244b438c6..3c8a138685 100644
--- a/package.json
+++ b/package.json
@@ -69,6 +69,7 @@
"eslint-plugin-react-refresh": "^0.4.19",
"husky": "^9.1.7",
"lint-staged": "^15.4.3",
+ "posthog-node": "^4.8.1",
"react": "19.0.0",
"react-dom": "19.0.0",
"release-it": "^17.11.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 55db2b5a3b..b7129184e2 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -89,6 +89,9 @@ importers:
lint-staged:
specifier: ^15.4.3
version: 15.4.3
+ posthog-node:
+ specifier: ^4.8.1
+ version: 4.8.1
react:
specifier: 19.0.0
version: 19.0.0
@@ -5974,6 +5977,9 @@ packages:
resolution: {integrity: sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==}
engines: {node: '>= 0.4'}
+ resolution: {integrity: sha512-NN+fvwH/kV01dYUQ3PTOZns4LWtWhOFCAhQ/pHb88WQ1hNe5V/dvFwc4VJcDL11LT9xSX0QtsR8sWUuyOuOq7g==}
+
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
@@ -7505,6 +7511,15 @@ packages:
resolution: {integrity: sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==}
+ resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==}
+ engines: {node: '>=4.0'}
+ peerDependencies:
+ debug: '*'
+ peerDependenciesMeta:
+ debug:
+ optional: true
+
resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==}
@@ -9457,6 +9472,10 @@ packages:
resolution: {integrity: sha512-dle9A3yYxlBSrt8Fu+IpjGT8SY8hN0mlaA6GY8t0P5PjIOZemULz/E2Bnm/2dcUOena75OTNkHI76uZBNUUq3A==}
engines: {node: ^10 || ^12 || >=14}
+ resolution: {integrity: sha512-ApMEC1+DbctP/88+VhaCl8SRKpIoReibMf7Mb3rxw3yMthr1rKaM4opbHdZJ0buLhwS5zX8B2ckqLjpwpSjRPg==}
+ engines: {node: '>=15.0.0'}
+
resolution: {integrity: sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==}
engines: {node: '>= 0.8.0'}
@@ -14092,6 +14111,14 @@ snapshots:
dependencies:
possible-typed-array-names: 1.0.0
+ dependencies:
+ follow-redirects: 1.15.9
+ form-data: 4.0.0
+ proxy-from-env: 1.1.0
+ transitivePeerDependencies:
+ - debug
+
@@ -15833,6 +15860,8 @@ snapshots:
+
dependencies:
is-callable: 1.2.7
@@ -18064,6 +18093,12 @@ snapshots:
picocolors: 1.1.1
source-map-js: 1.2.1
+ dependencies:
+ axios: 1.8.1
+ transitivePeerDependencies:
+ - debug
+