Skip to content

Commit 205c2be

Browse files
rupal-bqjoshuali925opensearch-trigger-bot[bot]opensearch-ci-bot
authored
[Backport 1.3] Use front-end report generation instead of chromium (#616)
* Use front-end report generation instead of chromium (#586) Signed-off-by: Rupal Mahajan <[email protected]> * Increment version to 2.4.1-SNAPSHOT (#540) Signed-off-by: opensearch-ci-bot <[email protected]> Signed-off-by: opensearch-ci-bot <[email protected]> Co-authored-by: opensearch-ci-bot <[email protected]> * --wip-- Signed-off-by: Joshua Li <[email protected]> * Add initial implementation of client reporting generation Signed-off-by: Joshua Li <[email protected]> * Fix url with basepath Signed-off-by: Joshua Li <[email protected]> * Update header footer height Signed-off-by: Joshua Li <[email protected]> * Update dialog text to not close dialog Signed-off-by: Joshua Li <[email protected]> * Remove console.log Signed-off-by: Joshua Li <[email protected]> * Remove unused components Signed-off-by: Joshua Li <[email protected]> * Remove chromium references Signed-off-by: Joshua Li <[email protected]> * Add report generation error handling Signed-off-by: Joshua Li <[email protected]> * Minor refactors Signed-off-by: Joshua Li <[email protected]> * Add postinstall patch to support safari for html2canvas Signed-off-by: Joshua Li <[email protected]> * Add dompurify Signed-off-by: Joshua Li <[email protected]> * Fix build error Signed-off-by: Joshua Li <[email protected]> * Remove chromium from CI Signed-off-by: Joshua Li <[email protected]> * Update CI artifact name Signed-off-by: Joshua Li <[email protected]> Signed-off-by: opensearch-ci-bot <[email protected]> Signed-off-by: Joshua Li <[email protected]> Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Co-authored-by: opensearch-ci-bot <[email protected]> * Fix build failure Signed-off-by: Rupal Mahajan <[email protected]> * Remove visual report test with puppeteer Signed-off-by: Rupal Mahajan <[email protected]> * Fix build failure Signed-off-by: Rupal Mahajan <[email protected]> * Fix path in workflow Signed-off-by: Rupal Mahajan <[email protected]> Signed-off-by: opensearch-ci-bot <[email protected]> Signed-off-by: Joshua Li <[email protected]> Signed-off-by: Rupal Mahajan <[email protected]> Co-authored-by: Joshua Li <[email protected]> Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Co-authored-by: opensearch-ci-bot <[email protected]>
1 parent 3240685 commit 205c2be

27 files changed

+955
-887
lines changed

.github/workflows/dashboards-reports-test-and-build-workflow.yml

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ jobs:
3636
- name: Move Dashboards Reports to Plugins Dir
3737
run: mv dashboards-reports ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
3838

39-
- name: Add Chromium Binary to Reporting for Testing
40-
run: |
41-
sudo apt update
42-
sudo apt install -y libnss3-dev fonts-liberation libfontconfig1
43-
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
44-
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-linux-x64.zip
45-
unzip chromium-linux-x64.zip
46-
rm chromium-linux-x64.zip
47-
4839
- name: OpenSearch Dashboards Plugin Bootstrap
4940
uses: nick-invision/retry@v1
5041
with:
@@ -70,114 +61,10 @@ jobs:
7061
run: |
7162
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
7263
yarn build
73-
74-
cd build
75-
mkdir -p ./{linux-x64,linux-arm64}/opensearch-dashboards/${{ env.PLUGIN_NAME }}
76-
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-x64.zip
77-
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-arm64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-arm64.zip
78-
79-
cd linux-x64
80-
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-linux-x64.zip
81-
unzip chromium-linux-x64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
82-
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
83-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
84-
cd ..
85-
86-
cd linux-arm64
87-
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-linux-arm64.zip
88-
unzip chromium-linux-arm64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
89-
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
90-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
91-
cd ..
64+
mv ./build/*.zip ./build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
9265
9366
- name: Upload Artifact For Linux x64
9467
uses: actions/upload-artifact@v1
9568
with:
9669
name: dashboards-reports-linux-x64
97-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-x64.zip
98-
99-
- name: Upload Artifact For Linux arm64
100-
uses: actions/upload-artifact@v1
101-
with:
102-
name: dashboards-reports-linux-arm64
103-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-arm64.zip
104-
105-
windows-build:
106-
runs-on: windows-latest
107-
steps:
108-
- name: Checkout Plugin
109-
uses: actions/checkout@v1
110-
111-
# Enable longer filenames for windows
112-
- name: Enable longer filenames
113-
run: git config --system core.longpaths true
114-
115-
- name: Checkout OpenSearch Dashboards
116-
uses: actions/checkout@v1
117-
with:
118-
repository: opensearch-project/Opensearch-Dashboards
119-
ref: ${{ env.OPENSEARCH_VERSION }}
120-
path: OpenSearch-Dashboards
121-
122-
- name: Get node version
123-
id: versions_step
124-
run:
125-
echo "::set-output name=node_version::$(node -p "(require('../OpenSearch-Dashboards/package.json').engines.node).match(/[.0-9]+/)[0]")"
126-
127-
- name: Setup Node
128-
uses: actions/setup-node@v1
129-
with:
130-
node-version: ${{ steps.versions_step.outputs.node_version }}
131-
registry-url: 'https://registry.npmjs.org'
132-
133-
134-
- name: Move Dashboards Reports to Plugins Dir
135-
run: mv dashboards-reports ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
136-
137-
- name: Add Chromium Binary to Reporting for Testing
138-
run: |
139-
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
140-
curl.exe -LO https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
141-
Expand-Archive -Path 'chromium-windows-x64.zip'
142-
Move-Item -Path "./chromium-windows-x64/.chromium" -Destination "./.chromium"
143-
rd chromium-windows-x64.zip
144-
rd chromium-windows-x64
145-
146-
- name: OpenSearch Dashboards Plugin Bootstrap
147-
uses: nick-invision/retry@v1
148-
with:
149-
timeout_minutes: 30
150-
max_attempts: 3
151-
command: cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} && yarn osd bootstrap
152-
153-
- name: Test
154-
uses: nick-invision/retry@v1
155-
with:
156-
timeout_minutes: 30
157-
max_attempts: 3
158-
command: cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} && yarn test
159-
160-
- name: Build Artifact
161-
run: |
162-
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
163-
yarn build
164-
165-
cd build
166-
mkdir -p ./windows-x64/opensearch-dashboards/${{ env.PLUGIN_NAME }}
167-
mv ./${{ env.PLUGIN_NAME }}-*.zip ./windows-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.zip
168-
169-
cd windows-x64
170-
curl.exe -LO https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
171-
Expand-Archive -Path 'chromium-windows-x64.zip'
172-
Move-Item -Path "./chromium-windows-x64/.chromium" -Destination "./opensearch-dashboards/${{ env.PLUGIN_NAME }}"
173-
rd chromium-windows-x64.zip
174-
rd chromium-windows-x64
175-
Compress-Archive -Path "./${{ env.ARTIFACT_NAME }}-*.zip" -Destination "./opensearch-dashboards"
176-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
177-
cd ..
178-
179-
- name: Upload Artifact For Windows
180-
uses: actions/upload-artifact@v1
181-
with:
182-
name: dashboards-reports-windows-x64
183-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.zip
70+
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip

README.md

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
- [Contributing](#contributing)
77
- [Setup](#setup-&-build)
88
- [Notifications Integration](#notifications-integration)
9-
- [Troubleshooting](#troubleshooting)
109
- [Code of Conduct](#code-of-conduct)
1110
- [Security](#security)
1211
- [License](#license)
@@ -106,39 +105,6 @@ Complete OpenSearch Dashboards Report feature is composed of 2 plugins.
106105

107106
OpenSearch Dashboards Reports integration with [Notifications](https://github.com/opensearch-project/notifications) is currently in progress. Tracking [here](https://github.com/opensearch-project/dashboards-reports/issues/72)
108107

109-
## Troubleshooting
110-
111-
### Fail to launch Chromium
112-
113-
There could be two reasons for this problem
114-
115-
1. You are not having the correct version of headless-chrome matching to the OS that your OpenSearch Dashboards is running. Different versions of headless-chrome can be found [here](https://github.com/opensearch-project/dashboards-reports/releases/tag/chromium-1.12.0.0)
116-
117-
2. Missing additional dependencies. Please refer to [additional dependencies section](./dashboards-reports/rendering-engine/headless-chrome/README.md#additional-libaries) to install required dependencies according to your operating system.
118-
119-
### Missing Font Dependencies
120-
121-
Chromium may not have all of the dependencies you may require to be able to view all of the content of your reports.
122-
123-
If you are using a CentOS/RHEL system, install the following packages:
124-
125-
- [`ipa-gothic-fonts`](https://centos.pkgs.org/7/centos-x86_64/ipa-gothic-fonts-003.03-5.el7.noarch.rpm.html)
126-
- [`xorg-x11-fonts-100dpi`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-100dpi-7.5-9.el7.noarch.rpm.html)
127-
- [`xorg-x11-fonts-75dpi`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-75dpi-7.5-9.el7.noarch.rpm.html)
128-
- [`xorg-x11-utils`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-utils-7.5-23.el7.x86_64.rpm.html)
129-
- [`xorg-x11-fonts-cyrillic`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-cyrillic-7.5-9.el7.noarch.rpm.html)
130-
- [`xorg-x11-fonts-Type1`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-Type1-7.5-9.el7.noarch.rpm.html)
131-
- [`xorg-x11-fonts-misc`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-misc-7.5-9.el7.noarch.rpm.html)
132-
- [`fontconfig`](https://www.freedesktop.org/wiki/Software/fontconfig/)
133-
- [`freetype`](https://freetype.org/)
134-
135-
If you are using a Ubuntu/Debian system, install the following packages:
136-
137-
- [`fonts-liberation`](https://packages.debian.org/search?keywords=fonts-liberation)
138-
- [`libfontconfig1`](https://packages.debian.org/sid/libfontconfig1)
139-
140-
The installation command for both systems can be found [here](./dashboards-reports/rendering-engine/headless-chrome/README.md).
141-
142108
## Code of Conduct
143109

144110
This project has adopted the [Amazon Open Source Code of Conduct](CODE_OF_CONDUCT.md). For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq), or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
@@ -153,4 +119,3 @@ See the [LICENSE](./LICENSE) file for our project's licensing. We will ask you t
153119

154120
## Copyright
155121

156-
Copyright OpenSearch Contributors. See [NOTICE](NOTICE.txt) for details.

dashboards-reports/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ yarn-error.log
1010
.eslintcache
1111
package-lock.json
1212
/target/
13-
.chromium/

dashboards-reports/.opensearch_dashboards-plugin-helpers.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"yarn.lock",
66
".i18nrc.json",
77
"common/**/*",
8+
"scripts/**/*",
89
"public/**/*",
910
"server/**/*",
1011
"translations/**/*"

dashboards-reports/package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@
1313
"test": "../../node_modules/.bin/jest --config ./test/jest.config.js",
1414
"cypress:run": "cypress run",
1515
"cypress:open": "cypress open",
16-
"plugin_helpers": "node ../../scripts/plugin_helpers"
16+
"plugin_helpers": "node ../../scripts/plugin_helpers",
17+
"postinstall": "node ./scripts/patch-html2canvas.js"
1718
},
1819
"dependencies": {
19-
"async-mutex": "^0.2.6",
2020
"babel-polyfill": "^6.26.0",
2121
"cron-validator": "^1.1.1",
22-
"dompurify": "^2.3.8",
22+
"dompurify": "^2.4.1",
2323
"elastic-builder": "^2.7.1",
2424
"enzyme-adapter-react-16": "^1.15.2",
25+
"html2canvas": "1.4.1",
2526
"jest-fetch-mock": "^3.0.3",
2627
"jquery": "^3.5.0",
2728
"jsdom": "^16.5.0",
2829
"json-2-csv": "^3.7.6",
29-
"puppeteer-core": "^13.7.0",
30+
"jspdf": "^2.5.1",
3031
"react-addons-test-utils": "^15.6.2",
3132
"react-id-generator": "^3.0.1",
3233
"react-markdown": "^4.3.1",
@@ -37,14 +38,15 @@
3738
"react-router-dom": "^5.2.0",
3839
"react-toast-notifications": "^2.4.0",
3940
"set-interval-async": "1.0.33",
40-
"showdown": "^1.9.1"
41+
"showdown": "^1.9.1",
42+
"svg-pathdata": "5.0.5"
4143
},
4244
"devDependencies": {
4345
"@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards",
4446
"@types/dompurify": "^2.3.3",
4547
"@types/enzyme-adapter-react-16": "^1.0.6",
4648
"@types/jsdom": "^16.2.3",
47-
"@types/puppeteer-core": "^5.4.0",
49+
"@types/react": "^16.14.23",
4850
"@types/react-addons-test-utils": "^0.14.25",
4951
"@types/react-dom": "^16.9.8",
5052
"@types/react-test-renderer": "^16.9.1",
@@ -59,6 +61,7 @@
5961
"identity-obj-proxy": "^3.0.0",
6062
"jest-dom": "^4.0.0",
6163
"react-test-renderer": "^16.12.0",
64+
"replace-in-file": "^6.3.5",
6265
"ts-jest": "^26.1.0"
6366
},
6467
"resolutions": {
@@ -73,6 +76,7 @@
7376
"json-schema": "0.4.0",
7477
"ws": "^7.4.6",
7578
"minimist": "^1.2.6",
76-
"execa": "^4.0.2"
79+
"execa": "^4.0.2",
80+
"yargs": "^16.2.0"
7781
}
7882
}

dashboards-reports/public/components/context_menu/context_menu.js

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@
44
*/
55

66
/* eslint-disable no-restricted-globals */
7-
import $ from 'jquery';
7+
//@ts-check
88
import { i18n } from '@osd/i18n';
9+
import $ from 'jquery';
10+
import { parse } from 'url';
911
import { readStreamToFile } from '../main/main_utils';
12+
import { uiSettingsService } from '../utils/settings_service';
13+
import {
14+
GENERATE_REPORT_PARAM,
15+
GENERATE_REPORT_PARAM_REGEX,
16+
} from '../visual_report/constants';
17+
import { generateReport } from '../visual_report/generate_report';
1018
import {
11-
contextMenuCreateReportDefinition,
12-
getTimeFieldsFromUrl,
13-
displayLoadingModal,
1419
addSuccessOrFailureToast,
20+
contextMenuCreateReportDefinition,
1521
contextMenuViewReports,
22+
displayLoadingModal,
23+
getTimeFieldsFromUrl,
1624
replaceQueryURL,
1725
} from './context_menu_helpers';
1826
import {
27+
getMenuItem,
1928
popoverMenu,
2029
popoverMenuDiscover,
21-
getMenuItem,
2230
} from './context_menu_ui';
23-
import { parse } from 'url';
24-
import { uiSettingsService } from '../utils/settings_service';
2531

2632
const generateInContextReport = async (
2733
timeRanges,
@@ -102,23 +108,28 @@ const generateInContextReport = async (
102108
credentials: 'include',
103109
}
104110
)
105-
.then((response) => {
106-
if (response.status === 200) {
107-
$('#reportGenerationProgressModal').remove();
108-
addSuccessOrFailureToast('success');
109-
} else {
110-
if (response.status === 403) {
111+
.then(async (response) => [response.status, await response.json()])
112+
.then(async ([status, data]) => {
113+
if (status !== 200) {
114+
if (status === 403) {
111115
addSuccessOrFailureToast('permissionsFailure');
112-
} else if (response.status === 503) {
116+
} else if (status === 503) {
113117
addSuccessOrFailureToast('timeoutFailure', reportSource);
114118
} else {
115119
addSuccessOrFailureToast('failure');
116120
}
121+
} else if (fileFormat === 'pdf' || fileFormat === 'png') {
122+
try {
123+
await generateReport(data.reportId);
124+
addSuccessOrFailureToast('success');
125+
} catch (error) {
126+
console.error(error);
127+
addSuccessOrFailureToast('failure');
128+
}
129+
} else if (data.data) {
130+
await readStreamToFile(data.data, fileFormat, data.filename);
117131
}
118-
return response.json();
119-
})
120-
.then(async (data) => {
121-
await readStreamToFile(data.data, fileFormat, data.filename);
132+
$('#reportGenerationProgressModal').remove();
122133
});
123134
};
124135

@@ -213,9 +224,34 @@ $(function () {
213224
});
214225
});
215226

227+
checkURLParams();
216228
locationHashChanged();
217229
});
218230

231+
/* generate a report if flagged in URL params */
232+
const checkURLParams = async () => {
233+
const [hash, query] = location.href.split('#')[1].split('?');
234+
const params = new URLSearchParams(query);
235+
const id = params.get(GENERATE_REPORT_PARAM);
236+
if (!id) return;
237+
await new Promise((resolve) => setTimeout(resolve, 1000));
238+
displayLoadingModal();
239+
try {
240+
await generateReport(id, 30000);
241+
window.history.replaceState(
242+
{},
243+
'',
244+
`#${hash}?${query.replace(GENERATE_REPORT_PARAM_REGEX, '')}`
245+
);
246+
addSuccessOrFailureToast('success');
247+
} catch (error) {
248+
console.error(error);
249+
addSuccessOrFailureToast('failure');
250+
} finally {
251+
$('#reportGenerationProgressModal').remove();
252+
}
253+
};
254+
219255
const isDiscoverNavMenu = (navMenu) => {
220256
return (
221257
navMenu[0].children.length === 5 &&

0 commit comments

Comments
 (0)