Skip to content

Commit 976265a

Browse files
rupal-bqjoshuali925opensearch-trigger-bot[bot]opensearch-ci-bot
authored
[Backport 1.2] Use front-end report generation instead of chromium (#610)
* 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]> * Update yarn.lock Signed-off-by: Rupal Mahajan <[email protected]> * Fix build failure Signed-off-by: Rupal Mahajan <[email protected]> * Fix workflow Signed-off-by: Rupal Mahajan <[email protected]> * Update yarn.lock 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 3182b86 commit 976265a

28 files changed

+587
-1049
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
@@ -30,15 +30,6 @@ jobs:
3030
- name: Move Dashboards Reports to Plugins Dir
3131
run: mv dashboards-reports ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
3232

33-
- name: Add Chromium Binary to Reporting for Testing
34-
run: |
35-
sudo apt update
36-
sudo apt install -y libnss3-dev fonts-liberation libfontconfig1
37-
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
38-
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-linux-x64.zip
39-
unzip chromium-linux-x64.zip
40-
rm chromium-linux-x64.zip
41-
4233
- name: OpenSearch Dashboards Plugin Bootstrap
4334
uses: nick-invision/retry@v1
4435
with:
@@ -64,48 +55,10 @@ jobs:
6455
run: |
6556
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
6657
yarn build
67-
68-
cd build
69-
mkdir -p ./{linux-x64,linux-arm64,windows-x64}/opensearch-dashboards/${{ env.PLUGIN_NAME }}
70-
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-x64.zip
71-
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-arm64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-arm64.zip
72-
mv ./${{ env.PLUGIN_NAME }}-*.zip ./windows-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.zip
73-
74-
cd linux-x64
75-
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-linux-x64.zip
76-
unzip chromium-linux-x64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
77-
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
78-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
79-
cd ..
80-
81-
cd linux-arm64
82-
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-linux-arm64.zip
83-
unzip chromium-linux-arm64.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 windows-x64
89-
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
90-
unzip chromium-windows-x64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
91-
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
92-
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
93-
cd ..
58+
mv ./build/*.zip ./build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
9459
9560
- name: Upload Artifact For Linux x64
9661
uses: actions/upload-artifact@v1
9762
with:
9863
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
106-
107-
- name: Upload Artifact For Windows
108-
uses: actions/upload-artifact@v1
109-
with:
110-
name: dashboards-reports-windows-x64
111-
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.zip
64+
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
- [Contributing](#contributing)
1111
- [Setup](#setup-&-build)
1212
- [Notifications Integration](#notifications-integration)
13-
- [Troubleshooting](#troubleshooting)
1413
- [Code of Conduct](#code-of-conduct)
1514
- [Security](#security)
1615
- [License](#license)
@@ -35,6 +34,7 @@ Complete OpenSearch Dashboards Report feature is composed of 2 plugins.
3534

3635
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)
3736

37+
<<<<<<< HEAD
3838
## Troubleshooting
3939

4040
### Fail to launch Chromium
@@ -66,6 +66,8 @@ If you are using a Ubuntu/Debian system, install the following packages:
6666

6767
The installation command for both systems can be found [here](./dashboards-reports/rendering-engine/headless-chrome/README.md).
6868

69+
=======
70+
>>>>>>> 71d843a... Use front-end report generation instead of chromium (#586)
6971
## Code of Conduct
7072

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

8183
## Copyright
8284

83-
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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
"test": "../../node_modules/.bin/jest --config ./test/jest.config.js",
1818
"cypress:run": "cypress run",
1919
"cypress:open": "cypress open",
20-
"plugin_helpers": "node ../../scripts/plugin_helpers"
20+
"plugin_helpers": "node ../../scripts/plugin_helpers",
21+
"postinstall": "node ./scripts/patch-html2canvas.js"
2122
},
2223
"dependencies": {
23-
"async-mutex": "^0.2.6",
2424
"babel-polyfill": "^6.26.0",
2525
"cron-validator": "^1.1.1",
26-
"dompurify": "^2.3.8",
26+
"dompurify": "^2.4.1",
2727
"elastic-builder": "^2.7.1",
2828
"enzyme-adapter-react-16": "^1.15.2",
29+
"html2canvas": "1.4.1",
2930
"jest-fetch-mock": "^3.0.3",
3031
"jquery": "^3.5.0",
3132
"jsdom": "13.1.0",
3233
"json-2-csv": "^3.7.6",
33-
"puppeteer-core": "^13.7.0",
34+
"jspdf": "^2.5.1",
3435
"react-addons-test-utils": "^15.6.2",
3536
"react-id-generator": "^3.0.1",
3637
"react-markdown": "^4.3.1",
@@ -42,14 +43,14 @@
4243
"react-toast-notifications": "^2.4.0",
4344
"set-interval-async": "1.0.33",
4445
"showdown": "^1.9.1",
46+
"svg-pathdata": "^5.0.5",
4547
"ws": "^7.4.6"
4648
},
4749
"devDependencies": {
4850
"@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards",
4951
"@types/dompurify": "^2.3.3",
5052
"@types/enzyme-adapter-react-16": "^1.0.6",
5153
"@types/jsdom": "^16.2.3",
52-
"@types/puppeteer-core": "^5.4.0",
5354
"@types/react": "^16.9.36",
5455
"@types/react-addons-test-utils": "^0.14.25",
5556
"@types/react-dom": "^16.9.8",
@@ -65,6 +66,7 @@
6566
"identity-obj-proxy": "^3.0.0",
6667
"jest-dom": "^4.0.0",
6768
"react-test-renderer": "^16.12.0",
69+
"replace-in-file": "^5.0.2",
6870
"ts-jest": "^26.1.0"
6971
},
7072
"resolutions": {

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

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

66
/* eslint-disable no-restricted-globals */
7-
import $ from 'jquery';
8-
import dateMath from '@elastic/datemath';
7+
//@ts-check
98
import { i18n } from '@osd/i18n';
9+
import $ from 'jquery';
10+
import { parse } from 'url';
1011
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';
1118
import {
12-
contextMenuCreateReportDefinition,
13-
getTimeFieldsFromUrl,
14-
displayLoadingModal,
1519
addSuccessOrFailureToast,
20+
contextMenuCreateReportDefinition,
1621
contextMenuViewReports,
22+
displayLoadingModal,
23+
getTimeFieldsFromUrl,
1724
replaceQueryURL,
1825
} from './context_menu_helpers';
1926
import {
27+
getMenuItem,
2028
popoverMenu,
2129
popoverMenuDiscover,
22-
getMenuItem,
2330
} from './context_menu_ui';
24-
import { timeRangeMatcher } from '../utils/utils';
25-
import { parse } from 'url';
26-
import { unhashUrl } from '../../../../../src/plugins/opensearch_dashboards_utils/public';
27-
import { uiSettingsService } from '../utils/settings_service';
2831

2932
const generateInContextReport = async (
3033
timeRanges,
@@ -105,23 +108,28 @@ const generateInContextReport = async (
105108
credentials: 'include',
106109
}
107110
)
108-
.then((response) => {
109-
if (response.status === 200) {
110-
$('#reportGenerationProgressModal').remove();
111-
addSuccessOrFailureToast('success');
112-
} else {
113-
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) {
114115
addSuccessOrFailureToast('permissionsFailure');
115-
} else if (response.status === 503) {
116+
} else if (status === 503) {
116117
addSuccessOrFailureToast('timeoutFailure', reportSource);
117118
} else {
118119
addSuccessOrFailureToast('failure');
119120
}
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);
120131
}
121-
return response.json();
122-
})
123-
.then(async (data) => {
124-
await readStreamToFile(data.data, fileFormat, data.filename);
132+
$('#reportGenerationProgressModal').remove();
125133
});
126134
};
127135

@@ -218,9 +226,34 @@ $(function () {
218226
});
219227
});
220228

229+
checkURLParams();
221230
locationHashChanged();
222231
});
223232

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