Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #245 from zhongnansu/tmp-1
Browse files Browse the repository at this point in the history
Backport from branch opendistro-1.12.0.0 to 7.9.1
  • Loading branch information
zhongnansu authored Dec 18, 2020
2 parents d9857cc + d0c6a05 commit fe47d49
Show file tree
Hide file tree
Showing 76 changed files with 3,743 additions and 2,352 deletions.
56 changes: 46 additions & 10 deletions .github/workflows/kibana-reports-release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release Kibana Reports Artifacts
on:
push:
tags:
- "v*"
- 'v*'

jobs:
build:
Expand All @@ -30,33 +30,69 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: "10.22.0"
node-version: '10.22.0'

- name: Move Kibana Reports to Plugins Dir
run: mv kibana-reports kibana/plugins/${{ env.PLUGIN_NAME }}

- name: Add Chromium Binary to Reporting for Testing
run: |
mkdir kibana/plugins
mv kibana-reports kibana/plugins
sudo apt install -y libnss3-dev fonts-liberation libfontconfig1
cd kibana/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: Kibana Plugin Bootstrap
uses: nick-invision/retry@v1
with:
timeout_minutes: 30
max_attempts: 3
command: cd kibana/plugins/kibana-reports; yarn kbn bootstrap
command: cd kibana/plugins/${{ env.PLUGIN_NAME }}; yarn kbn bootstrap

- name: Test
uses: nick-invision/retry@v1
with:
timeout_minutes: 30
max_attempts: 3
command: cd kibana/plugins/kibana-reports; yarn test
command: cd kibana/plugins/${{ env.PLUGIN_NAME }}; yarn test

- name: Build Artifact
run: |
cd kibana/plugins/kibana-reports
cd kibana/plugins/${{ env.PLUGIN_NAME }}
yarn build
artifact=`ls ./build/*.zip`
# TODO: rename S3 bucket path after infra team assigns one
aws s3 cp $artifact s3://kiabna-reports/kibana-reports-plugin/
cd build
mkdir -p ./{linux-x64,linux-arm64,windows-x64}/kibana/${{ env.PLUGIN_NAME }}
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-x64/${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}.zip
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-arm64/${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}.zip
mv ./${{ env.PLUGIN_NAME }}-*.zip ./windows-x64/${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}.zip
cd linux-x64
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 -d ./kibana/${{ env.PLUGIN_NAME }}
rm chromium-linux-x64.zip
zip -ur ./${{ env.PLUGIN_NAME }}-*.zip ./kibana
linux_artifact=`ls ./${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}.zip`
aws s3 cp $linux_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/kibana-plugins/opendistro-reports/linux/x64/
cd ..
cd linux-arm64
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-linux-arm64.zip
unzip chromium-linux-arm64.zip -d ./kibana/${{ env.PLUGIN_NAME }}
rm chromium-linux-arm64.zip
zip -ur ./${{ env.PLUGIN_NAME }}-*.zip ./kibana
arm_artifact=`ls ./${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}.zip`
aws s3 cp $arm_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/kibana-plugins/opendistro-reports/linux/arm64/
cd ..
cd windows-x64
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
unzip chromium-windows-x64.zip -d ./kibana/${{ env.PLUGIN_NAME }}
rm chromium-windows-x64.zip
zip -ur ./${{ env.PLUGIN_NAME }}-*.zip ./kibana
windows_artifact=`ls ./${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}.zip`
aws s3 cp $windows_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/kibana-plugins/opendistro-reports/windows/x64/
cd ..
aws cloudfront create-invalidation --distribution-id ${{ secrets.DISTRIBUTION_ID }} --paths "/downloads/*"
67 changes: 59 additions & 8 deletions .github/workflows/kibana-reports-test-and-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Test and Build Kibana Reports

on: [pull_request, push]

env:
PLUGIN_NAME: opendistro_kibana_reports
OD_VERSION: 1.11.0.0

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -19,34 +23,81 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: "10.22.0"
node-version: '10.22.0'

- name: Move Kibana Reports to Plugins Dir
run: |
mkdir kibana/plugins
mv kibana-reports kibana/plugins
mv kibana-reports kibana/plugins/${{ env.PLUGIN_NAME }}
- name: Add Chromium Binary to Reporting for Testing
run: |
sudo apt install -y libnss3-dev fonts-liberation libfontconfig1
cd kibana/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: Kibana Plugin Bootstrap
uses: nick-invision/retry@v1
with:
timeout_minutes: 30
max_attempts: 3
command: cd kibana/plugins/kibana-reports; yarn kbn bootstrap
command: cd kibana/plugins/${{ env.PLUGIN_NAME }}; yarn kbn bootstrap

- name: Test
uses: nick-invision/retry@v1
with:
timeout_minutes: 30
max_attempts: 3
command: cd kibana/plugins/kibana-reports; yarn test
command: cd kibana/plugins/${{ env.PLUGIN_NAME }}; yarn test

- name: Build Artifact
run: |
cd kibana/plugins/kibana-reports
cd kibana/plugins/${{ env.PLUGIN_NAME }}
yarn build
- name: Upload Artifact
cd build
mkdir -p ./{linux-x64,linux-arm64,windows-x64}/kibana/${{ env.PLUGIN_NAME }}
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-x64/${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}-linux-x64.zip
cp ./${{ env.PLUGIN_NAME }}-*.zip ./linux-arm64/${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}-linux-arm64.zip
mv ./${{ env.PLUGIN_NAME }}-*.zip ./windows-x64/${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}-windows-x64.zip
cd linux-x64
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 -d ./kibana/${{ env.PLUGIN_NAME }}
zip -ur ./${{ env.PLUGIN_NAME }}-*.zip ./kibana
mv ./${{ env.PLUGIN_NAME }}-*.zip ..
cd ..
cd linux-arm64
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-linux-arm64.zip
unzip chromium-linux-arm64.zip -d ./kibana/${{ env.PLUGIN_NAME }}
zip -ur ./${{ env.PLUGIN_NAME }}-*.zip ./kibana
mv ./${{ env.PLUGIN_NAME }}-*.zip ..
cd ..
cd windows-x64
wget https://github.com/opendistro-for-elasticsearch/kibana-reports/releases/download/chromium-1.12.0.0/chromium-windows-x64.zip
unzip chromium-windows-x64.zip -d ./kibana/${{ env.PLUGIN_NAME }}
zip -ur ./${{ env.PLUGIN_NAME }}-*.zip ./kibana
mv ./${{ env.PLUGIN_NAME }}-*.zip ..
cd ..
- name: Upload Artifact For Linux x64
uses: actions/upload-artifact@v1
with:
name: kibana-reports-linux-x64
path: kibana/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}-linux-x64.zip

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

- name: Upload Artifact For Windows
uses: actions/upload-artifact@v1
with:
name: kibana-reports
path: kibana/plugins/kibana-reports/build
name: kibana-reports-windows-x64
path: kibana/plugins/${{ env.PLUGIN_NAME }}/build/${{ env.PLUGIN_NAME }}-${{ env.OD_VERSION }}-windows-x64.zip
15 changes: 7 additions & 8 deletions .github/workflows/reports-scheduler-release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ jobs:
run: |
cd reports-scheduler
./gradlew build buildDeb buildRpm --no-daemon --refresh-dependencies -Dbuild.snapshot=false
artifact=`ls plugin/build/distributions/*.zip`
rpm_artifact=`ls plugin/build/distributions/*.rpm`
deb_artifact=`ls plugin/build/distributions/*.deb`
artifact=`ls ./build/distributions/*.zip`
rpm_artifact=`ls ./build/distributions/*.rpm`
deb_artifact=`ls ./build/distributions/*.deb`
# TODO: rename S3 bucket path after infra team assigns one
aws s3 cp $artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/elasticsearch-plugins/opendistro-sql/
aws s3 cp $rpm_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/rpms/opendistro-sql/
aws s3 cp $deb_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/debs/opendistro-sql/
aws cloudfront create-invalidation --distribution-id E1VG5HMIWI4SA2 --paths "/downloads/*"
aws s3 cp $artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/elasticsearch-plugins/opendistro-reports-scheduler/
aws s3 cp $rpm_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/rpms/opendistro-reports-scheduler/
aws s3 cp $deb_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/debs/opendistro-reports-scheduler/
aws cloudfront create-invalidation --distribution-id ${{ secrets.DISTRIBUTION_ID }} --paths "/downloads/*"
1 change: 1 addition & 0 deletions kibana-reports/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ yarn-error.log
.history/
.eslintcache
package-lock.json
.chromium/
17 changes: 16 additions & 1 deletion kibana-reports/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
export const PLUGIN_ID = 'opendistroKibanaReports';
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

export const PLUGIN_ID = 'opendistro_kibana_reports';
export const PLUGIN_NAME = 'opendistro_kibana_reports';

export const API_PREFIX = '/api/reporting';
Expand Down
4 changes: 2 additions & 2 deletions kibana-reports/kibana.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "opendistroKibanaReports",
"version": "1.10.1.0",
"id": "opendistro_kibana_reports",
"version": "1.11.0.0",
"kibanaVersion": "7.9.1",
"requiredPlugins": ["navigation", "data"],
"optionalPlugins": ["share"],
Expand Down
7 changes: 4 additions & 3 deletions kibana-reports/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opendistro_kibana_reports",
"version": "1.10.1.0",
"version": "1.11.0.0",
"description": "Kibana Reporting Plugin",
"license": "Apache-2.0",
"main": "index.js",
Expand Down Expand Up @@ -44,7 +44,7 @@
"jsdom": "^16.4.0",
"json-2-csv": "^3.7.6",
"moment": "link:../../packages/moment",
"puppeteer": "^5.3.1",
"puppeteer-core": "^1.19.0",
"react-addons-test-utils": "^15.6.2",
"react-id-generator": "^3.0.1",
"react-markdown": "^4.3.1",
Expand Down Expand Up @@ -73,9 +73,10 @@
"@testing-library/react": "^10.2.1",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.13",
"@types/puppeteer": "^3.0.2",
"@types/puppeteer-core": "^2.0.0",
"@types/reach__router": "^1.3.5",
"@types/react": "^16.9.36",
"@types/react-addons-test-utils": "^0.14.25",
"@types/react-dom": "^16.9.8",
"@types/react-test-renderer": "^16.9.2",
"@types/set-interval-async": "^1.0.0",
Expand Down
70 changes: 28 additions & 42 deletions kibana-reports/public/components/context_menu/context_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,18 @@ import uuidv4 from 'uuid/v4';

const replaceQueryURL = () => {
let url = location.pathname + location.hash;
let timeString = url.substring(
url.lastIndexOf('time:'),
url.lastIndexOf('))')
let [, fromDateString, toDateString] = url.match(
/time:\(from:(.+),to:(.+?)\)/
);
if (url.includes('visualize') || url.includes('discover')) {
timeString = url.substring(url.lastIndexOf('time:'), url.indexOf('))'));
}

let fromDateString = timeString.substring(
timeString.lastIndexOf('from:') + 5,
timeString.lastIndexOf(',')
);

fromDateString = fromDateString.replace(/[']+/g, '');
let fromDateFormat = dateMath.parse(fromDateString);

let toDateString = timeString.substring(
timeString.lastIndexOf('to:') + 3,
timeString.length
);
// convert time range to from date format in case time range is relative
const fromDateFormat = dateMath.parse(fromDateString);
toDateString = toDateString.replace(/[']+/g, '');
let toDateFormat = dateMath.parse(toDateString);

// replace to and from dates with absolute date

url = url.replace(
fromDateString + '))',
"'" + fromDateFormat.toISOString() + "'"
);

url = url.replace(fromDateString, "'" + fromDateFormat.toISOString() + "'");
url = url.replace(
toDateString + '))',
"'" + toDateFormat.toISOString() + "'))"
Expand Down Expand Up @@ -116,32 +98,36 @@ const generateInContextReport = (
},
};

fetch('/api/reporting/generateReport', {
headers: {
'Content-Type': 'application/json',
'kbn-version': '7.9.1',
accept: '*/*',
'accept-language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6',
pragma: 'no-cache',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
},
method: 'POST',
body: JSON.stringify(contextMenuOnDemandReport),
referrerPolicy: 'strict-origin-when-cross-origin',
mode: 'cors',
credentials: 'include',
})
fetch(
`../api/reporting/generateReport?timezone=${
Intl.DateTimeFormat().resolvedOptions().timeZone
}`,
{
headers: {
'Content-Type': 'application/json',
'kbn-version': '7.9.1',
accept: '*/*',
'accept-language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6',
pragma: 'no-cache',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
},
method: 'POST',
body: JSON.stringify(contextMenuOnDemandReport),
referrerPolicy: 'strict-origin-when-cross-origin',
mode: 'cors',
credentials: 'include',
}
)
.then((response) => {
if (response.status === 200) {
$('#reportGenerationProgressModal').remove();
addSuccessOrFailureToast('success');
} else {
if (response.status === 403) {
addSuccessOrFailureToast('permissionsFailure');
}
else {
} else {
addSuccessOrFailureToast('failure');
}
}
Expand Down
Loading

0 comments on commit fe47d49

Please sign in to comment.