Skip to content

Commit faf8c19

Browse files
joshuali925opensearch-trigger-bot[bot]opensearch-ci-bot
authored
Use front-end report generation instead of chromium (#586)
* 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]>
1 parent fb301e2 commit faf8c19

28 files changed

+614
-1063
lines changed

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

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

41-
- name: Add Chromium Binary to Reporting for Testing
42-
run: |
43-
sudo apt update
44-
sudo apt install -y libnss3-dev fonts-liberation libfontconfig1
45-
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
46-
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-linux-x64.zip
47-
unzip chromium-linux-x64.zip
48-
rm chromium-linux-x64.zip
49-
5041
- name: OpenSearch Dashboards Plugin Bootstrap
5142
uses: nick-invision/retry@v1
5243
with:
@@ -72,37 +63,13 @@ jobs:
7263
run: |
7364
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
7465
yarn build
75-
76-
cd build
77-
mkdir -p ./{linux-x64,linux-arm64}/opensearch-dashboards/${{ env.PLUGIN_NAME }}
78-
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-x64.zip
79-
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-arm64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-arm64.zip
80-
81-
cd linux-x64
82-
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-linux-x64.zip
83-
unzip chromium-linux-x64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
84-
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
85-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
86-
cd ..
87-
88-
cd linux-arm64
89-
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-linux-arm64.zip
90-
unzip chromium-linux-arm64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
91-
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
92-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
93-
cd ..
66+
mv ./build/*.zip ./build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
9467
9568
- name: Upload Artifact For Linux x64
9669
uses: actions/upload-artifact@v1
9770
with:
9871
name: dashboards-reports-linux-x64
99-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-x64.zip
100-
101-
- name: Upload Artifact For Linux arm64
102-
uses: actions/upload-artifact@v1
103-
with:
104-
name: dashboards-reports-linux-arm64
105-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-arm64.zip
72+
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
10673

10774
windows-build:
10875
runs-on: windows-latest
@@ -136,15 +103,6 @@ jobs:
136103
- name: Move Dashboards Reports to Plugins Dir
137104
run: mv dashboards-reports ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
138105

139-
- name: Add Chromium Binary to Reporting for Testing
140-
run: |
141-
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
142-
curl.exe -LO https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
143-
Expand-Archive -Path 'chromium-windows-x64.zip'
144-
Move-Item -Path "./chromium-windows-x64/.chromium" -Destination "./.chromium"
145-
rd chromium-windows-x64.zip
146-
rd chromium-windows-x64
147-
148106
- name: OpenSearch Dashboards Plugin Bootstrap
149107
uses: nick-invision/retry@v1
150108
with:
@@ -163,26 +121,13 @@ jobs:
163121
run: |
164122
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
165123
yarn build
166-
167-
cd build
168-
mkdir -p ./windows-x64/opensearch-dashboards/${{ env.PLUGIN_NAME }}
169-
mv ./${{ env.PLUGIN_NAME }}-*.zip ./windows-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.zip
170-
171-
cd windows-x64
172-
curl.exe -LO https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
173-
Expand-Archive -Path 'chromium-windows-x64.zip'
174-
Move-Item -Path "./chromium-windows-x64/.chromium" -Destination "./opensearch-dashboards/${{ env.PLUGIN_NAME }}"
175-
rd chromium-windows-x64.zip
176-
rd chromium-windows-x64
177-
Compress-Archive -Path "./${{ env.ARTIFACT_NAME }}-*.zip" -Destination "./opensearch-dashboards"
178-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
179-
cd ..
124+
mv ./build/*.zip ./build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
180125
181126
- name: Upload Artifact For Windows
182127
uses: actions/upload-artifact@v1
183128
with:
184129
name: dashboards-reports-windows-x64
185-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.zip
130+
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
186131

187132
macos-build:
188133
runs-on: macos-latest
@@ -212,13 +157,6 @@ jobs:
212157
- name: Move Dashboards Reports to Plugins Dir
213158
run: mv dashboards-reports ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
214159

215-
- name: Add Chromium Binary to Reporting for Testing
216-
run: |
217-
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
218-
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-macos-x64.zip
219-
unzip chromium-macos-x64.zip
220-
rm chromium-macos-x64.zip
221-
222160
- name: OpenSearch Dashboards Plugin Bootstrap
223161
uses: nick-invision/retry@v1
224162
with:
@@ -237,20 +175,10 @@ jobs:
237175
run: |
238176
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
239177
yarn build
240-
241-
cd build
242-
mkdir -p ./macos-x64/opensearch-dashboards/${{ env.PLUGIN_NAME }}
243-
mv ./${{ env.PLUGIN_NAME }}-*.zip ./macos-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-macos-x64.zip
244-
245-
cd macos-x64
246-
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-macos-x64.zip
247-
unzip chromium-macos-x64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
248-
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
249-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
250-
cd ..
178+
mv ./build/*.zip ./build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
251179
252180
- name: Upload Artifact For MacOS x64
253181
uses: actions/upload-artifact@v1
254182
with:
255183
name: dashboards-reports-macosx-x64
256-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-macos-x64.zip
184+
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip

README.md

Lines changed: 0 additions & 42 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,46 +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-
142-
### Download Error:
143-
144-
If you see Error: net::ERR_ADDRESS_INVALID in the logs while downlaoding report, add the following configurations in opensearch_dashboards.yml
145-
```
146-
opensearch_reporting.osd_server.hostname: '127.0.0.1'
147-
```
148-
149108
## Code of Conduct
150109

151110
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.
@@ -160,4 +119,3 @@ See the [LICENSE](./LICENSE) file for our project's licensing. We will ask you t
160119

161120
## Copyright
162121

163-
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: 5 additions & 4 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",
2222
"dompurify": "^2.4.1",
2323
"elastic-builder": "^2.7.1",
2424
"enzyme-adapter-react-16": "^1.15.5",
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",
@@ -44,7 +45,6 @@
4445
"@types/dompurify": "^2.3.3",
4546
"@types/enzyme-adapter-react-16": "^1.0.6",
4647
"@types/jsdom": "^16.2.3",
47-
"@types/puppeteer-core": "^5.4.0",
4848
"@types/react": "^16.14.23",
4949
"@types/react-addons-test-utils": "^0.14.25",
5050
"@types/react-dom": "^16.9.8",
@@ -60,6 +60,7 @@
6060
"identity-obj-proxy": "^3.0.0",
6161
"jest-dom": "^4.0.0",
6262
"react-test-renderer": "^16.12.0",
63+
"replace-in-file": "^6.3.5",
6364
"ts-jest": "^26.1.0"
6465
},
6566
"resolutions": {

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)