Skip to content

Commit 60612df

Browse files
ruchidhopensearch-changeset-bot[bot]ananzh
authored
Performance scripts fix (#9738)
* scripts Signed-off-by: Ruchi Sharma <[email protected]> * update limits for bundle Signed-off-by: Ruchi Sharma <[email protected]> * update limits for lighthosue baseline Signed-off-by: Ruchi Sharma <[email protected]> * Changeset file for PR #9738 created/updated * Update lighthouse_baseline.json Signed-off-by: Ruchi Sharma <[email protected]> --------- Signed-off-by: Ruchi Sharma <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Co-authored-by: Anan Zhuang <[email protected]>
1 parent 0a2a48d commit 60612df

File tree

5 files changed

+75
-96
lines changed

5 files changed

+75
-96
lines changed

.github/workflows/lighthouse_testing.yml

Lines changed: 35 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
branches:
66
- main
7+
78
permissions:
89
contents: read
910
pull-requests: write
@@ -19,10 +20,10 @@ jobs:
1920
runs-on: ubuntu-latest
2021
steps:
2122
- name: Checkout repository
22-
uses: actions/checkout@v2
23+
uses: actions/checkout@v4
2324

2425
- name: Setup Node
25-
uses: actions/setup-node@v2
26+
uses: actions/setup-node@v4
2627
with:
2728
node-version-file: '.nvmrc'
2829
registry-url: 'https://registry.npmjs.org'
@@ -60,9 +61,6 @@ jobs:
6061
- name: Install Lighthouse CI
6162
run: yarn add --dev @lhci/cli
6263

63-
- name: Run bootstrap
64-
run: yarn osd bootstrap
65-
6664
- name: Build plugins
6765
run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 12
6866

@@ -72,25 +70,21 @@ jobs:
7270
echo "Waiting for OpenSearch..."
7371
sleep 10
7472
done
75-
echo "OpenSearch is up!"
7673
7774
- name: Start OpenSearch Dashboards
7875
run: |
79-
yarn start --no-base-path &
76+
yarn start --no-base-path --opensearch.ignoreVersionMismatch=true &
8077
until curl -s http://localhost:5601 >/dev/null; do
8178
echo "Waiting for OpenSearch Dashboards..."
8279
sleep 10
8380
done
84-
echo "OpenSearch Dashboards is up!"
8581
8682
- name: Mock data
8783
run: |
8884
curl 'http://localhost:5601/api/sample_data/ecommerce' -X 'POST' -H 'osd-version: ${{ env.VERSION }}' -H 'osd-xsrf: osd-fetch'
8985
9086
- name: Run Lighthouse CI
91-
run: |
92-
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
93-
yarn lhci autorun --verbose
87+
run: yarn lhci autorun --verbose
9488
continue-on-error: true
9589

9690
- name: Ensure Lighthouse Reports Exist
@@ -101,68 +95,42 @@ jobs:
10195
echo "[]" > .lighthouseci/assertion-results.json
10296
fi
10397
98+
- name: List contents of .lighthouseci
99+
run: ls -R .lighthouseci || echo "Directory not found"
100+
104101
- name: Verify Lighthouse Results
102+
id: verify_lighthouse
105103
run: |
106-
if [ ! -d ".lighthouseci" ] || [ -z "$(ls -A .lighthouseci)" ]; then
107-
echo "❌ Lighthouse CI did not generate reports."
108-
exit 1
104+
if [ ! -s ".lighthouseci/assertion-results.json" ]; then
105+
echo "❌ Lighthouse assertion-results.json is empty. Skipping further steps."
106+
echo "should_continue=false" >> $GITHUB_OUTPUT
107+
else
108+
echo "✅ Valid Lighthouse results found."
109+
echo "should_continue=true" >> $GITHUB_OUTPUT
109110
fi
110111
111-
- name: Post Lighthouse Results into comment
112+
- name: Save Lighthouse Results as Artifact
113+
if: steps.verify_lighthouse.outputs.should_continue == 'true'
112114
run: |
113-
# Validate if empty
114-
if [ ! -s .lighthouseci/assertion-results.json ]; then
115-
echo "❌ No assertion results found. Skipping PR comment."
116-
exit 0 #Prevents failure
117-
fi
115+
mkdir -p artifacts
116+
cp .lighthouseci/assertion-results.json artifacts/
117+
118+
- name: Upload Lighthouse Results Artifact
119+
if: steps.verify_lighthouse.outputs.should_continue == 'true'
120+
uses: actions/upload-artifact@v4
121+
with:
122+
name: lighthouse-results
123+
path: artifacts/assertion-results.json
118124

119-
# Ensure JSON is properly formatted
120-
if ! jq empty .lighthouseci/assertion-results.json; then
121-
echo "❌ Invalid JSON format in Lighthouse assertion results."
122-
cat .lighthouseci/assertion-results.json # Print for debugging
125+
- name: Fail CI if Lighthouse assertion results indicate failures
126+
if: steps.verify_lighthouse.outputs.should_continue == 'true'
127+
run: |
128+
if jq -e '[.[] | select(.passed==false)] | length > 0' .lighthouseci/assertion-results.json > /dev/null; then
129+
echo "❌ Lighthouse CI detected performance issues. Failing the job."
123130
exit 1
131+
else
132+
echo "✅ All Lighthouse metrics passed."
124133
fi
125134
126-
BASELINE=$(cat ./baselines/lighthouse_baseline.json)
127-
128-
FAILURES=$(jq --argjson baseline "$BASELINE" -r '[.[] | select(.passed==false) | {metric: .auditId, expected: ($baseline[(.url | sub("^.*?//[^/]+"; ""))][.auditId] // "N/A"), actual: (if .actual then (.actual | floor) else "N/A" end), url: .url}]' .lighthouseci/assertion-results.json)
129-
130-
UNIQUE_FAILURE_URLS=$(echo "$FAILURES" | jq '[.[] | .url] | unique')
131-
132-
if [ ! -f ".lighthouseci/links.json" ]; then
133-
echo "⚠️ No .lighthouseci/links.json file found. Creating an empty JSON object..."
134-
echo "{}" > .lighthouseci/links.json
135-
fi
136-
137-
# Load the URL to report mapping from links.json
138-
URL_REPORT_MAP=$(jq -c '.' .lighthouseci/links.json)
139-
140-
# Append report URLs to failed assertions
141-
FAILURES_WITH_REPORTS=$(jq --argjson url_report_map "$URL_REPORT_MAP" '
142-
map(. + {reportUrl: $url_report_map[.url]})
143-
' <<< "$FAILURES")
144-
145-
# Check if there are failures before posting a comment
146-
if [[ "$FAILURES_WITH_REPORTS" == "[]" ]]; then
147-
echo "✅ **All Lighthouse metrics passed!** 🎉"
148-
exit 0
149-
fi
150-
151-
COMMENT="### ⚡ Lighthouse CI Performance Issues ⚡
152-
153-
| Metric | Expected Value | Current Value | Page URL | Report |
154-
|--------|---------------|--------------|----------|--------|"
155-
156-
while IFS= read -r line; do
157-
COMMENT+="\n| $(echo "$line" | jq -r '.metric') | $(echo "$line" | jq -r '.expected') | $(echo "$line" | jq -r '.actual') | $(echo "$line" | jq -r '.url') | [Report]($(echo "$line" | jq -r '.reportUrl')) |"
158-
done <<< "$(echo "$FAILURES_WITH_REPORTS" | jq -c '.[]')"
159-
160-
echo -e "$COMMENT" > comment.txt
161-
162-
gh pr comment ${{ github.event.pull_request.number }} --body "$(cat comment.txt)"
163-
continue-on-error: true
164-
env:
165-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
166-
167-
- name: Cleanup Lighthouse Reports
168-
run: rm -f comment.txt && rm -rf .lighthouseci
135+
- name: Cleanup
136+
run: rm -rf .lighthouseci

.github/workflows/performance_testing.yml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ on:
55
branches:
66
- main
77
paths-ignore:
8-
- '**/*.md' # Ignore documentation files
9-
- '**/*.test.ts' # Ignore test files (TypeScript)
10-
- '**/*.test.js' # Ignore test files (JavaScript)
11-
- '**/__tests__/**' # Ignore test directories
12-
- '.github/workflows/**' # Ignore GitHub workflow files
13-
- 'docs/**' # Ignore entire docs directory
8+
- '**/*.md'
9+
- '**/*.test.ts'
10+
- '**/*.test.js'
11+
- '**/__tests__/**'
12+
- '.github/workflows/**'
13+
- 'docs/**'
1414

1515
permissions:
1616
contents: read
17-
issues: write
1817
pull-requests: write
19-
18+
2019
jobs:
2120
bundle-analyzer:
2221
runs-on: ubuntu-latest
@@ -36,26 +35,34 @@ jobs:
3635
3736
3837
- name: Run bootstrap
39-
# Install dependencies and bootstrap the OpenSearch Dashboards project
4038
run: yarn osd bootstrap
4139

4240
- name: Build plugins
43-
# Build OpenSearch Dashboards platform plugins without examples using 12 workers
4441
run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 12
4542

4643
- name: Update Limit and bundle size variation
47-
# This command updates the limit and bundle size variation for the OpenSearch Dashboards platform plugins
4844
run: node scripts/build_opensearch_dashboards_platform_plugins --update-limits
4945

50-
- name: Read and comment bundle size variations
46+
- name: Check and upload bundle size variations
47+
id: check_bundle_size
5148
run: |
5249
if [ -f packages/osd-optimizer/limits_delta.yml ]; then
53-
echo "📊 **Bundle Size crossed 5% for below plugins**" > comment.txt
54-
echo "" >> comment.txt
55-
cat packages/osd-optimizer/limits_delta.yml >> comment.txt
56-
gh pr comment ${{ github.event.pull_request.number }} --body "$(cat comment.txt)"
50+
echo "Bundle size changes detected."
51+
echo "bundle_size_changed=true" >> $GITHUB_OUTPUT
5752
else
58-
echo "No bundle size variations detected, skipping comment."
53+
echo "No bundle size variations detected."
54+
echo "bundle_size_changed=false" >> $GITHUB_OUTPUT
5955
fi
60-
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Upload limits_delta.yml as artifact
58+
if: steps.check_bundle_size.outputs.bundle_size_changed == 'true'
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: bundle-size-delta
62+
path: packages/osd-optimizer/limits_delta.yml
63+
64+
- name: Fail the CI if bundle size exceeded
65+
if: steps.check_bundle_size.outputs.bundle_size_changed == 'true'
66+
run: |
67+
echo "❌ Bundle size exceeded threshold. Failing the job."
68+
exit 1

baselines/lighthouse_baseline.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"/app/home": {
3-
"first-contentful-paint": 1800,
4-
"speed-index": 15000
3+
"first-contentful-paint": 2800,
4+
"speed-index": 20000
55
},
66
"/app/data-explorer/discover": {
7-
"first-contentful-paint": 1800,
8-
"speed-index": 20000
7+
"first-contentful-paint": 2200,
8+
"speed-index": 26000
99
},
1010
"/app/dashboards": {
11-
"first-contentful-paint": 1800,
12-
"speed-index": 24000
11+
"first-contentful-paint": 2200,
12+
"speed-index": 28000
1313
},
1414
"/app/visualize": {
15-
"first-contentful-paint": 1800,
15+
"first-contentful-paint": 2200,
1616
"speed-index": 22000
1717
}
1818
}

changelogs/fragments/9738.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fix:
2+
- Performance script ([#9738](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9738))

packages/osd-optimizer/limits.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
pageLoadAssetSize:
22
advancedSettings: 27596
33
apmOss: 18996
4+
assistantDashboards: 521995
45
bfetch: 41874
56
charts: 159211
67
console: 46235
78
contentManagement: 189948
8-
core: 989885
9+
core: 995264
910
dashboard: 694542
1011
data: 2701242
1112
dataExplorer: 142726
13+
dataImporter: 22156
1214
dataSource: 24232
1315
dataSourceManagement: 541476
1416
devTools: 66175
15-
discover: 778790
17+
discover: 823326
1618
embeddable: 242671
1719
expressions: 224120
1820
home: 75810
@@ -26,7 +28,7 @@ pageLoadAssetSize:
2628
opensearchDashboardsLegacy: 107855
2729
opensearchDashboardsOverview: 56426
2830
opensearchDashboardsReact: 162353
29-
opensearchDashboardsUtils: 227366
31+
opensearchDashboardsUtils: 233344
3032
opensearchUiShared: 326798
3133
queryEnhancements: 437883
3234
regionMap: 66098

0 commit comments

Comments
 (0)