Skip to content

Commit ff33a59

Browse files
rupal-bqjoshuali925opensearch-trigger-bot[bot]opensearch-ci-bot
authored
[Backport 2.3.0] Use front-end report generation instead of chromium (#612)
* Bump version 2.3.1 (#500) Signed-off-by: Rupal Mahajan <[email protected]> Signed-off-by: Rupal Mahajan <[email protected]> * 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]> Signed-off-by: Rupal Mahajan <[email protected]> * Fix workflow Signed-off-by: Rupal Mahajan <[email protected]> * Fix dompurify version for build Signed-off-by: Rupal Mahajan <[email protected]> * Revert "Bump version 2.3.1 (#500)" This reverts commit 9ca29ff. Signed-off-by: Rupal Mahajan <[email protected]> Signed-off-by: Rupal Mahajan <[email protected]> Signed-off-by: opensearch-ci-bot <[email protected]> Signed-off-by: Joshua Li <[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 9ca29ff commit ff33a59

28 files changed

+614
-1043
lines changed

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

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

40-
- name: Add Chromium Binary to Reporting for Testing
41-
run: |
42-
sudo apt update
43-
sudo apt install -y libnss3-dev fonts-liberation libfontconfig1
44-
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
45-
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-linux-x64.zip
46-
unzip chromium-linux-x64.zip
47-
rm chromium-linux-x64.zip
48-
4940
- name: OpenSearch Dashboards Plugin Bootstrap
5041
uses: nick-invision/retry@v1
5142
with:
@@ -71,48 +62,10 @@ jobs:
7162
run: |
7263
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
7364
yarn build
74-
75-
cd build
76-
mkdir -p ./{linux-x64,linux-arm64,windows-x64}/opensearch-dashboards/${{ env.PLUGIN_NAME }}
77-
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-x64.zip
78-
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-arm64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-arm64.zip
79-
mv ./${{ env.PLUGIN_NAME }}-*.zip ./windows-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.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 ..
94-
95-
cd windows-x64
96-
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
97-
unzip chromium-windows-x64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
98-
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
99-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
100-
cd ..
65+
mv ./build/*.zip ./build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
10166
10267
- name: Upload Artifact For Linux x64
10368
uses: actions/upload-artifact@v1
10469
with:
10570
name: dashboards-reports-linux-x64
106-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-x64.zip
107-
108-
- name: Upload Artifact For Linux arm64
109-
uses: actions/upload-artifact@v1
110-
with:
111-
name: dashboards-reports-linux-arm64
112-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-arm64.zip
113-
114-
- name: Upload Artifact For Windows
115-
uses: actions/upload-artifact@v1
116-
with:
117-
name: dashboards-reports-windows-x64
118-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.zip
71+
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: 6 additions & 5 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.5",
25+
"html2canvas": "1.4.1",
2526
"jest-fetch-mock": "^3.0.3",
2627
"jquery": "^3.5.0",
2728
"jsdom": "13.1.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 &&

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export const popoverMenuDiscover = (savedObjectAvailable) => {
246246

247247
export const permissionsMissingOnGeneration = () => {
248248
return `
249-
<div class="euiToast euiToast--danger" id="permissionsMissingErrorToast">
249+
<div class="euiToast euiToast--danger" id="permissionsMissingErrorToast" data-html2canvas-ignore>
250250
<p class="euiScreenReaderOnly">${i18n.translate(
251251
'opensearch.reports.menu.newNotificationAppears',
252252
{ defaultMessage: 'A new notification appears' }
@@ -277,7 +277,7 @@ export const permissionsMissingOnGeneration = () => {
277277

278278
export const reportGenerationSuccess = () => {
279279
return `
280-
<div class="euiToast euiToast--success" id="reportSuccessToast">
280+
<div class="euiToast euiToast--success" id="reportSuccessToast" data-html2canvas-ignore>
281281
<p class="euiScreenReaderOnly">A new notification appears</p>
282282
<div class="euiToastHeader euiToastHeader--withBody"
283283
aria-label="Notification" data-test-subj="euiToastHeader">
@@ -319,7 +319,7 @@ export const reportGenerationFailure = (
319319
})
320320
) => {
321321
return `
322-
<div class="euiToast euiToast--danger" id="reportFailureToast">
322+
<div class="euiToast euiToast--danger" id="reportFailureToast" data-html2canvas-ignore>
323323
<p class="euiScreenReaderOnly">A new notification appears</p>
324324
<div class="euiToastHeader euiToastHeader--withBody"
325325
aria-label="Notification" data-test-subj="euiToastHeader">
@@ -346,7 +346,7 @@ export const reportGenerationFailure = (
346346

347347
export const reportGenerationInProgressModal = () => {
348348
return `
349-
<div class="euiOverlayMask" id="reportGenerationProgressModal">
349+
<div class="euiOverlayMask" id="reportGenerationProgressModal" data-html2canvas-ignore>
350350
<div data-focus-guard="true" tabindex="0" style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"></div>
351351
<div data-focus-guard="true" tabindex="1" style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"></div>
352352
<div data-focus-lock-disabled="false">
@@ -377,17 +377,14 @@ export const reportGenerationInProgressModal = () => {
377377
'opensearch.reports.menu.progress.youCanClose',
378378
{
379379
defaultMessage:
380-
'You can close this dialog while we continue in the background.',
380+
'Please keep this dialog open while report is being generated.',
381381
}
382382
)}</div>
383383
<div class="euiSpacer euiSpacer--l"></div>
384384
<div class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--justifyContentCenter euiFlexGroup--directionRow euiFlexGroup--responsive">
385385
<div class="euiFlexItem euiFlexItem--flexGrowZero"><span class="euiLoadingSpinner euiLoadingSpinner--xLarge" style="min-width: 75px; min-height: 75px;"></span></div>
386386
</div>
387387
<div class="euiSpacer euiSpacer--l"></div>
388-
<div class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsFlexEnd euiFlexGroup--justifyContentFlexEnd euiFlexGroup--directionRow euiFlexGroup--responsive">
389-
<div class="euiFlexItem euiFlexItem--flexGrowZero"><button class="euiButton euiButton--primary" type="button" id="closeReportGenerationModalButton"><span class="euiButton__content"><span class="euiButton__text">Close</span></span></button></div>
390-
</div>
391388
</div>
392389
</div>
393390
</div>

dashboards-reports/public/components/main/loading_modal/loading_modal.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function GenerateReportLoadingModal(props: { setShowLoading: any }) {
5959
<EuiText>
6060
{i18n.translate('opensearch.reports.loading.youCanClose', {
6161
defaultMessage:
62-
'You can close this dialog while we continue in the background.',
62+
'Please keep this dialog open while report is being generated.',
6363
})}
6464
</EuiText>
6565
<EuiSpacer />
@@ -72,15 +72,6 @@ export function GenerateReportLoadingModal(props: { setShowLoading: any }) {
7272
</EuiFlexItem>
7373
</EuiFlexGroup>
7474
<EuiSpacer size="l" />
75-
<EuiFlexGroup alignItems="flexEnd" justifyContent="flexEnd">
76-
<EuiFlexItem grow={false}>
77-
<EuiButton onClick={closeModal}>
78-
{i18n.translate('opensearch.reports.loading.close', {
79-
defaultMessage: 'Close',
80-
})}
81-
</EuiButton>
82-
</EuiFlexItem>
83-
</EuiFlexGroup>
8475
</EuiModalBody>
8576
</EuiModal>
8677
</EuiOverlayMask>

0 commit comments

Comments
 (0)