Skip to content

Commit

Permalink
Use front-end report generation instead of chromium (#586)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Dec 22, 2022
1 parent fb301e2 commit faf8c19
Show file tree
Hide file tree
Showing 28 changed files with 614 additions and 1,063 deletions.
84 changes: 6 additions & 78 deletions .github/workflows/dashboards-reports-test-and-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ jobs:
- name: Move Dashboards Reports to Plugins Dir
run: mv dashboards-reports ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}

- name: Add Chromium Binary to Reporting for Testing
run: |
sudo apt update
sudo apt install -y libnss3-dev fonts-liberation libfontconfig1
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-linux-x64.zip
unzip chromium-linux-x64.zip
rm chromium-linux-x64.zip
- name: OpenSearch Dashboards Plugin Bootstrap
uses: nick-invision/retry@v1
with:
Expand All @@ -72,37 +63,13 @@ jobs:
run: |
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
yarn build
cd build
mkdir -p ./{linux-x64,linux-arm64}/opensearch-dashboards/${{ env.PLUGIN_NAME }}
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-x64.zip
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-arm64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-arm64.zip
cd linux-x64
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-linux-x64.zip
unzip chromium-linux-x64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
cd ..
cd linux-arm64
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-linux-arm64.zip
unzip chromium-linux-arm64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
cd ..
mv ./build/*.zip ./build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
- name: Upload Artifact For Linux x64
uses: actions/upload-artifact@v1
with:
name: dashboards-reports-linux-x64
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-x64.zip

- name: Upload Artifact For Linux arm64
uses: actions/upload-artifact@v1
with:
name: dashboards-reports-linux-arm64
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-linux-arm64.zip
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip

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

- name: Add Chromium Binary to Reporting for Testing
run: |
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
curl.exe -LO https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
Expand-Archive -Path 'chromium-windows-x64.zip'
Move-Item -Path "./chromium-windows-x64/.chromium" -Destination "./.chromium"
rd chromium-windows-x64.zip
rd chromium-windows-x64
- name: OpenSearch Dashboards Plugin Bootstrap
uses: nick-invision/retry@v1
with:
Expand All @@ -163,26 +121,13 @@ jobs:
run: |
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
yarn build
cd build
mkdir -p ./windows-x64/opensearch-dashboards/${{ env.PLUGIN_NAME }}
mv ./${{ env.PLUGIN_NAME }}-*.zip ./windows-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.zip
cd windows-x64
curl.exe -LO https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
Expand-Archive -Path 'chromium-windows-x64.zip'
Move-Item -Path "./chromium-windows-x64/.chromium" -Destination "./opensearch-dashboards/${{ env.PLUGIN_NAME }}"
rd chromium-windows-x64.zip
rd chromium-windows-x64
Compress-Archive -Path "./${{ env.ARTIFACT_NAME }}-*.zip" -Destination "./opensearch-dashboards"
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
cd ..
mv ./build/*.zip ./build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
- name: Upload Artifact For Windows
uses: actions/upload-artifact@v1
with:
name: dashboards-reports-windows-x64
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-windows-x64.zip
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip

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

- name: Add Chromium Binary to Reporting for Testing
run: |
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-macos-x64.zip
unzip chromium-macos-x64.zip
rm chromium-macos-x64.zip
- name: OpenSearch Dashboards Plugin Bootstrap
uses: nick-invision/retry@v1
with:
Expand All @@ -237,20 +175,10 @@ jobs:
run: |
cd ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
yarn build
cd build
mkdir -p ./macos-x64/opensearch-dashboards/${{ env.PLUGIN_NAME }}
mv ./${{ env.PLUGIN_NAME }}-*.zip ./macos-x64/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-macos-x64.zip
cd macos-x64
wget https://github.com/opensearch-project/dashboards-reports/releases/download/chromium-1.12.0.0/chromium-macos-x64.zip
unzip chromium-macos-x64.zip -d ./opensearch-dashboards/${{ env.PLUGIN_NAME }}
zip -ur ./${{ env.ARTIFACT_NAME }}-*.zip ./opensearch-dashboards
mv ./${{ env.ARTIFACT_NAME }}-*.zip ..
cd ..
mv ./build/*.zip ./build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
- name: Upload Artifact For MacOS x64
uses: actions/upload-artifact@v1
with:
name: dashboards-reports-macosx-x64
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}-macos-x64.zip
path: ../OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.ARTIFACT_NAME }}-${{ env.OPENSEARCH_PLUGIN_VERSION }}.zip
42 changes: 0 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
- [Contributing](#contributing)
- [Setup](#setup-&-build)
- [Notifications Integration](#notifications-integration)
- [Troubleshooting](#troubleshooting)
- [Code of Conduct](#code-of-conduct)
- [Security](#security)
- [License](#license)
Expand Down Expand Up @@ -106,46 +105,6 @@ Complete OpenSearch Dashboards Report feature is composed of 2 plugins.

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)

## Troubleshooting

### Fail to launch Chromium

There could be two reasons for this problem

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)

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.

### Missing Font Dependencies

Chromium may not have all of the dependencies you may require to be able to view all of the content of your reports.

If you are using a CentOS/RHEL system, install the following packages:

- [`ipa-gothic-fonts`](https://centos.pkgs.org/7/centos-x86_64/ipa-gothic-fonts-003.03-5.el7.noarch.rpm.html)
- [`xorg-x11-fonts-100dpi`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-100dpi-7.5-9.el7.noarch.rpm.html)
- [`xorg-x11-fonts-75dpi`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-75dpi-7.5-9.el7.noarch.rpm.html)
- [`xorg-x11-utils`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-utils-7.5-23.el7.x86_64.rpm.html)
- [`xorg-x11-fonts-cyrillic`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-cyrillic-7.5-9.el7.noarch.rpm.html)
- [`xorg-x11-fonts-Type1`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-Type1-7.5-9.el7.noarch.rpm.html)
- [`xorg-x11-fonts-misc`](https://centos.pkgs.org/7/centos-x86_64/xorg-x11-fonts-misc-7.5-9.el7.noarch.rpm.html)
- [`fontconfig`](https://www.freedesktop.org/wiki/Software/fontconfig/)
- [`freetype`](https://freetype.org/)

If you are using a Ubuntu/Debian system, install the following packages:

- [`fonts-liberation`](https://packages.debian.org/search?keywords=fonts-liberation)
- [`libfontconfig1`](https://packages.debian.org/sid/libfontconfig1)

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

### Download Error:

If you see Error: net::ERR_ADDRESS_INVALID in the logs while downlaoding report, add the following configurations in opensearch_dashboards.yml
```
opensearch_reporting.osd_server.hostname: '127.0.0.1'
```

## Code of Conduct

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

## Copyright

Copyright OpenSearch Contributors. See [NOTICE](NOTICE.txt) for details.
1 change: 0 additions & 1 deletion dashboards-reports/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ yarn-error.log
.eslintcache
package-lock.json
/target/
.chromium/
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"yarn.lock",
".i18nrc.json",
"common/**/*",
"scripts/**/*",
"public/**/*",
"server/**/*",
"translations/**/*"
Expand Down
9 changes: 5 additions & 4 deletions dashboards-reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@
"test": "../../node_modules/.bin/jest --config ./test/jest.config.js",
"cypress:run": "cypress run",
"cypress:open": "cypress open",
"plugin_helpers": "node ../../scripts/plugin_helpers"
"plugin_helpers": "node ../../scripts/plugin_helpers",
"postinstall": "node ./scripts/patch-html2canvas.js"
},
"dependencies": {
"async-mutex": "^0.2.6",
"babel-polyfill": "^6.26.0",
"cron-validator": "^1.1.1",
"dompurify": "^2.4.1",
"elastic-builder": "^2.7.1",
"enzyme-adapter-react-16": "^1.15.5",
"html2canvas": "1.4.1",
"jest-fetch-mock": "^3.0.3",
"jquery": "^3.5.0",
"jsdom": "16.5.0",
"json-2-csv": "^3.7.6",
"puppeteer-core": "^13.7.0",
"jspdf": "^2.5.1",
"react-addons-test-utils": "^15.6.2",
"react-id-generator": "^3.0.1",
"react-markdown": "^4.3.1",
Expand All @@ -44,7 +45,6 @@
"@types/dompurify": "^2.3.3",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/jsdom": "^16.2.3",
"@types/puppeteer-core": "^5.4.0",
"@types/react": "^16.14.23",
"@types/react-addons-test-utils": "^0.14.25",
"@types/react-dom": "^16.9.8",
Expand All @@ -60,6 +60,7 @@
"identity-obj-proxy": "^3.0.0",
"jest-dom": "^4.0.0",
"react-test-renderer": "^16.12.0",
"replace-in-file": "^6.3.5",
"ts-jest": "^26.1.0"
},
"resolutions": {
Expand Down
72 changes: 54 additions & 18 deletions dashboards-reports/public/components/context_menu/context_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@
*/

/* eslint-disable no-restricted-globals */
import $ from 'jquery';
//@ts-check
import { i18n } from '@osd/i18n';
import $ from 'jquery';
import { parse } from 'url';
import { readStreamToFile } from '../main/main_utils';
import { uiSettingsService } from '../utils/settings_service';
import {
GENERATE_REPORT_PARAM,
GENERATE_REPORT_PARAM_REGEX,
} from '../visual_report/constants';
import { generateReport } from '../visual_report/generate_report';
import {
contextMenuCreateReportDefinition,
getTimeFieldsFromUrl,
displayLoadingModal,
addSuccessOrFailureToast,
contextMenuCreateReportDefinition,
contextMenuViewReports,
displayLoadingModal,
getTimeFieldsFromUrl,
replaceQueryURL,
} from './context_menu_helpers';
import {
getMenuItem,
popoverMenu,
popoverMenuDiscover,
getMenuItem,
} from './context_menu_ui';
import { parse } from 'url';
import { uiSettingsService } from '../utils/settings_service';

const generateInContextReport = async (
timeRanges,
Expand Down Expand Up @@ -102,23 +108,28 @@ const generateInContextReport = async (
credentials: 'include',
}
)
.then((response) => {
if (response.status === 200) {
$('#reportGenerationProgressModal').remove();
addSuccessOrFailureToast('success');
} else {
if (response.status === 403) {
.then(async (response) => [response.status, await response.json()])
.then(async ([status, data]) => {
if (status !== 200) {
if (status === 403) {
addSuccessOrFailureToast('permissionsFailure');
} else if (response.status === 503) {
} else if (status === 503) {
addSuccessOrFailureToast('timeoutFailure', reportSource);
} else {
addSuccessOrFailureToast('failure');
}
} else if (fileFormat === 'pdf' || fileFormat === 'png') {
try {
await generateReport(data.reportId);
addSuccessOrFailureToast('success');
} catch (error) {
console.error(error);
addSuccessOrFailureToast('failure');
}
} else if (data.data) {
await readStreamToFile(data.data, fileFormat, data.filename);
}
return response.json();
})
.then(async (data) => {
await readStreamToFile(data.data, fileFormat, data.filename);
$('#reportGenerationProgressModal').remove();
});
};

Expand Down Expand Up @@ -213,9 +224,34 @@ $(function () {
});
});

checkURLParams();
locationHashChanged();
});

/* generate a report if flagged in URL params */
const checkURLParams = async () => {
const [hash, query] = location.href.split('#')[1].split('?');
const params = new URLSearchParams(query);
const id = params.get(GENERATE_REPORT_PARAM);
if (!id) return;
await new Promise((resolve) => setTimeout(resolve, 1000));
displayLoadingModal();
try {
await generateReport(id, 30000);
window.history.replaceState(
{},
'',
`#${hash}?${query.replace(GENERATE_REPORT_PARAM_REGEX, '')}`
);
addSuccessOrFailureToast('success');
} catch (error) {
console.error(error);
addSuccessOrFailureToast('failure');
} finally {
$('#reportGenerationProgressModal').remove();
}
};

const isDiscoverNavMenu = (navMenu) => {
return (
navMenu[0].children.length === 5 &&
Expand Down
Loading

0 comments on commit faf8c19

Please sign in to comment.