From 8c890e28f2a488f059832c4c5b2367b986da23f0 Mon Sep 17 00:00:00 2001 From: Ruchi Sharma Date: Sat, 1 Feb 2025 10:52:13 +0000 Subject: [PATCH 1/2] log warning updated Signed-off-by: Ruchi Sharma --- .github/workflows/performance_testing.yml | 45 ++++++++++++ .../osd-optimizer/bundle_size_variations.yml | 30 ++++++++ packages/osd-optimizer/limits.yml | 73 ++++--------------- packages/osd-optimizer/src/limits.ts | 41 +++++++++++ 4 files changed, 131 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/performance_testing.yml create mode 100644 packages/osd-optimizer/bundle_size_variations.yml diff --git a/.github/workflows/performance_testing.yml b/.github/workflows/performance_testing.yml new file mode 100644 index 000000000000..53684bc35928 --- /dev/null +++ b/.github/workflows/performance_testing.yml @@ -0,0 +1,45 @@ +name: Performance Testing + +on: + pull_request: + branches: + - main + +jobs: + lighthouse: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version-file: '.nvmrc' + registry-url: 'https://registry.npmjs.org' + + - name: Setup Yarn + run: | + npm uninstall -g yarn + npm i -g yarn@1.22.10 + + - name: Run bootstrap + # Install dependencies and bootstrap the OpenSearch Dashboards project + run: yarn osd bootstrap + + - name: Build plugins + # Build OpenSearch Dashboards platform plugins without examples using 12 workers + run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 12 + + - name: Update Limit and bundle size variation + # This command updates the limit and bundle size variation for the OpenSearch Dashboards platform plugins + run: node scripts/build_opensearch_dashboards_platform_plugins --update-limits + + - name: Read and comment bundle size variations + run: | + echo "📊 **Bundle Size crossed 20% for below plugins**" > comment.txt + echo "" >> comment.txt + cat packages/osd-optimizer/bundle_size_variations.yml >> comment.txt + gh pr comment ${{ github.event.pull_request.number }} --body "$(cat comment.txt)" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/packages/osd-optimizer/bundle_size_variations.yml b/packages/osd-optimizer/bundle_size_variations.yml new file mode 100644 index 000000000000..a985e707acbf --- /dev/null +++ b/packages/osd-optimizer/bundle_size_variations.yml @@ -0,0 +1,30 @@ +core: + delta: 282239 + deltaPercentage: 40.747943393883745 +dashboard: + delta: 305275 + deltaPercentage: 81.56610120582364 +data: + delta: 1512159 + deltaPercentage: 128.79489780535107 +devTools: + delta: 12394 + deltaPercentage: 31.958948969856372 +discover: + delta: 658643 + deltaPercentage: 626.402084700467 +home: + delta: 19149 + deltaPercentage: 45.96385108374739 +management: + delta: 120423 + deltaPercentage: 261.1532789729355 +navigation: + delta: 11166 + deltaPercentage: 29.845240959024938 +savedObjectsManagement: + delta: 260319 + deltaPercentage: 259.01614877167844 +visDefaultEditor: + delta: 279443 + deltaPercentage: 556.9034238112321 diff --git a/packages/osd-optimizer/limits.yml b/packages/osd-optimizer/limits.yml index 516ebae80abf..c6b2d18f948e 100644 --- a/packages/osd-optimizer/limits.yml +++ b/packages/osd-optimizer/limits.yml @@ -1,88 +1,45 @@ pageLoadAssetSize: advancedSettings: 27596 - alerts: 106936 - apm: 64385 apmOss: 18996 - beatsManagement: 188135 bfetch: 41874 - canvas: 1065624 charts: 159211 - cloud: 21076 console: 46235 + contentManagement: 15000 core: 692646 - crossClusterReplication: 65408 dashboard: 374267 - dashboardEnhanced: 65646 - dashboardMode: 22716 data: 1174083 - dataEnhanced: 50420 + dataExplorer: 15000 + dataSource: 15000 + dataSourceManagement: 462690 devTools: 38781 discover: 105147 - discoverEnhanced: 42730 embeddable: 242671 - embeddableEnhanced: 41145 - enterpriseSearch: 35741 - opensearchUiShared: 326798 expressions: 224120 - features: 31211 - fileUpload: 24717 - globalSearch: 43548 - globalSearchBar: 62888 - globalSearchProviders: 25554 - graph: 31504 - grokdebugger: 26779 home: 41661 - indexLifecycleManagement: 107090 - indexManagement: 662506 indexPatternManagement: 154366 - infra: 197873 - ingestManager: 415829 - ingestPipelines: 58003 inputControlVis: 172819 inspector: 148999 - opensearchDashboardsLegacy: 107855 - opensearchDashboardsOverview: 56426 - opensearchDashboardsReact: 162353 - opensearchDashboardsUtils: 198829 - lens: 96624 - licenseManagement: 41961 - licensing: 39008 - lists: 183665 - logstash: 53548 management: 46112 - maps: 183754 + managementOverview: 15000 mapsLegacy: 116961 - mapsLegacyLicensing: 20214 - ml: 82187 - monitoring: 268758 navigation: 37413 - newsfeed: 42228 - observability: 89709 - painlessLab: 179892 + opensearchDashboardsLegacy: 965853 + opensearchDashboardsOverview: 56426 + opensearchDashboardsReact: 162353 + opensearchDashboardsUtils: 198829 + opensearchUiShared: 326798 + queryEnhancements: 216801 regionMap: 66098 - remoteClusters: 51327 - reporting: 183418 - rollup: 97204 savedObjects: 108662 savedObjectsManagement: 100503 - searchprofiler: 67224 - security: 189428 - securitySolution: 638231 + securityDashboards: 15000 share: 99205 - snapshotRestore: 79176 - spaces: 389643 - telemetry: 91832 - telemetryManagementSection: 52443 tileMap: 65337 - transform: 41151 - triggersActionsUi: 170145 uiActions: 95074 - uiActionsEnhanced: 349799 - upgradeAssistant: 80967 - uptime: 40825 - urlDrilldown: 34174 urlForwarding: 32579 usageCollection: 39762 + visAugmenter: 15000 + visBuilder: 32771 visDefaultEditor: 50178 visTypeMarkdown: 30896 visTypeMetric: 42790 @@ -95,4 +52,4 @@ pageLoadAssetSize: visTypeXy: 20255 visualizations: 295169 visualize: 57433 - watcher: 43742 + workspace: 591590 diff --git a/packages/osd-optimizer/src/limits.ts b/packages/osd-optimizer/src/limits.ts index d81137c3a9a4..286e872e9bac 100644 --- a/packages/osd-optimizer/src/limits.ts +++ b/packages/osd-optimizer/src/limits.ts @@ -29,6 +29,7 @@ */ import Fs from 'fs'; +import path from 'path'; import dedent from 'dedent'; import Yaml from 'js-yaml'; @@ -37,6 +38,7 @@ import { createFailError, ToolingLog } from '@osd/dev-utils'; import { OptimizerConfig, getMetrics, Limits } from './optimizer'; const LIMITS_PATH = require.resolve('../limits.yml'); +const DELTA_FILE_PATH = path.resolve(__dirname, '../bundle_size_variations.yml'); const DEFAULT_BUDGET = 15000; const diff = (a: T[], b: T[]): T[] => a.filter((item) => !b.includes(item)); @@ -90,6 +92,42 @@ export function validateLimitsForAllBundles(log: ToolingLog, config: OptimizerCo log.success('limits.yml file valid'); } +interface Metric { + group: string; + id: string; + value: number; + limit?: number; +} + +const updateBundleSizeVariation = (log: ToolingLog, metric: Metric) => { + if (metric.limit != null && metric.value > metric.limit) { + const delta = metric.value - metric.limit; + const deltaPercentage = (delta / metric.limit) * 100; + + if (deltaPercentage > 20) { + log.warning( + `Metric [${metric.group}] for [${metric.id}] exceeds the limit by more than ${deltaPercentage}%` + ); + + // Read existing data from the file if it exists + let existingData: { [key: string]: any } = {}; + if (Fs.existsSync(DELTA_FILE_PATH)) { + const fileContent = Fs.readFileSync(DELTA_FILE_PATH, 'utf-8'); + existingData = Yaml.load(fileContent) as { [key: string]: any }; + } + + // Update the data with the new metric + existingData[metric.id] = { + delta, + deltaPercentage, + }; + + // Write the updated data back to the file + Fs.writeFileSync(DELTA_FILE_PATH, Yaml.dump(existingData)); + } + } +}; + export function updateBundleLimits(log: ToolingLog, config: OptimizerConfig) { const metrics = getMetrics(log, config); @@ -102,6 +140,9 @@ export function updateBundleLimits(log: ToolingLog, config: OptimizerConfig) { existingLimit != null && existingLimit >= metric.value ? existingLimit : metric.value + DEFAULT_BUDGET; + + // Update the bundle size variation file for bundles that exceed the limit by more than 20%. + updateBundleSizeVariation(log, metric); } } From 7fa18780934afe42271f5e1269da2f879e374143 Mon Sep 17 00:00:00 2001 From: Ruchi Sharma Date: Sat, 1 Feb 2025 20:59:46 +0000 Subject: [PATCH 2/2] update gitignore and peercentage roundoff Signed-off-by: Ruchi Sharma --- .gitignore | 1 + .../osd-optimizer/bundle_size_variations.yml | 30 ------------------- packages/osd-optimizer/src/limits.ts | 8 ++--- 3 files changed, 3 insertions(+), 36 deletions(-) delete mode 100644 packages/osd-optimizer/bundle_size_variations.yml diff --git a/.gitignore b/.gitignore index 0dda8c35b3fd..a5d2e9c67e89 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,7 @@ npm-debug.log* .ci/runbld .ci/bash_standard_lib.sh .gradle +packages/osd-optimizer/bundle_size_variations.yml # apm plugin apm.tsconfig.json diff --git a/packages/osd-optimizer/bundle_size_variations.yml b/packages/osd-optimizer/bundle_size_variations.yml deleted file mode 100644 index a985e707acbf..000000000000 --- a/packages/osd-optimizer/bundle_size_variations.yml +++ /dev/null @@ -1,30 +0,0 @@ -core: - delta: 282239 - deltaPercentage: 40.747943393883745 -dashboard: - delta: 305275 - deltaPercentage: 81.56610120582364 -data: - delta: 1512159 - deltaPercentage: 128.79489780535107 -devTools: - delta: 12394 - deltaPercentage: 31.958948969856372 -discover: - delta: 658643 - deltaPercentage: 626.402084700467 -home: - delta: 19149 - deltaPercentage: 45.96385108374739 -management: - delta: 120423 - deltaPercentage: 261.1532789729355 -navigation: - delta: 11166 - deltaPercentage: 29.845240959024938 -savedObjectsManagement: - delta: 260319 - deltaPercentage: 259.01614877167844 -visDefaultEditor: - delta: 279443 - deltaPercentage: 556.9034238112321 diff --git a/packages/osd-optimizer/src/limits.ts b/packages/osd-optimizer/src/limits.ts index 286e872e9bac..b17348654a33 100644 --- a/packages/osd-optimizer/src/limits.ts +++ b/packages/osd-optimizer/src/limits.ts @@ -39,7 +39,6 @@ import { OptimizerConfig, getMetrics, Limits } from './optimizer'; const LIMITS_PATH = require.resolve('../limits.yml'); const DELTA_FILE_PATH = path.resolve(__dirname, '../bundle_size_variations.yml'); -const DEFAULT_BUDGET = 15000; const diff = (a: T[], b: T[]): T[] => a.filter((item) => !b.includes(item)); @@ -102,7 +101,7 @@ interface Metric { const updateBundleSizeVariation = (log: ToolingLog, metric: Metric) => { if (metric.limit != null && metric.value > metric.limit) { const delta = metric.value - metric.limit; - const deltaPercentage = (delta / metric.limit) * 100; + const deltaPercentage = Math.round((delta / metric.limit) * 100 * 100) / 100; if (deltaPercentage > 20) { log.warning( @@ -118,7 +117,6 @@ const updateBundleSizeVariation = (log: ToolingLog, metric: Metric) => { // Update the data with the new metric existingData[metric.id] = { - delta, deltaPercentage, }; @@ -137,9 +135,7 @@ export function updateBundleLimits(log: ToolingLog, config: OptimizerConfig) { if (metric.group === 'page load bundle size') { const existingLimit = config.limits.pageLoadAssetSize?.[metric.id]; pageLoadAssetSize[metric.id] = - existingLimit != null && existingLimit >= metric.value - ? existingLimit - : metric.value + DEFAULT_BUDGET; + existingLimit != null && existingLimit >= metric.value ? existingLimit : metric.value; // Update the bundle size variation file for bundles that exceed the limit by more than 20%. updateBundleSizeVariation(log, metric);