Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle analyzer on plugins #9320

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/performance_testing.yml
Original file line number Diff line number Diff line change
@@ -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 [email protected]

- 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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 15 additions & 58 deletions packages/osd-optimizer/limits.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -95,4 +52,4 @@ pageLoadAssetSize:
visTypeXy: 20255
visualizations: 295169
visualize: 57433
watcher: 43742
workspace: 591590
45 changes: 41 additions & 4 deletions packages/osd-optimizer/src/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

import Fs from 'fs';
import path from 'path';

import dedent from 'dedent';
import Yaml from 'js-yaml';
Expand All @@ -37,7 +38,7 @@ import { createFailError, ToolingLog } from '@osd/dev-utils';
import { OptimizerConfig, getMetrics, Limits } from './optimizer';

const LIMITS_PATH = require.resolve('../limits.yml');
const DEFAULT_BUDGET = 15000;
const DELTA_FILE_PATH = path.resolve(__dirname, '../bundle_size_variations.yml');

const diff = <T>(a: T[], b: T[]): T[] => a.filter((item) => !b.includes(item));

Expand Down Expand Up @@ -90,6 +91,41 @@ 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 = Math.round((delta / metric.limit) * 100 * 100) / 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] = {
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);

Expand All @@ -99,9 +135,10 @@ 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);
}
}

Expand Down