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

Use kibana server hostname for puppeteer to access pages #99

Merged
merged 3 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions kibana-reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,8 @@
"@elastic/elasticsearch": "^7.8.0",
"@elastic/eui": "^26.0.0",
"@nteract/markdown": "^4.5.1",
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^10.2.1",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.13",
"@types/reach__router": "^1.3.5",
"@types/react": "^16.9.36",
"@types/react-dom": "^16.9.8",
"@types/react-test-renderer": "^16.9.2",
"axios": "^0.20.0",
"babel-polyfill": "^6.26.0",
"jest-cli": "^26.0.1",
"jest-dom": "^4.0.0",
"jquery": "^3.5.0",
"mocha": "^8.0.1",
"moment": "link:../../packages/moment",
"puppeteer": "^5.3.1",
"react-id-generator": "^3.0.1",
Expand All @@ -54,18 +42,25 @@
"regenerator-runtime": "^0.13.7",
"set-interval-async": "1.0.33",
"showdown": "^1.9.1",
"stream-to-blob": "^2.0.1",
"ts-jest": "^26.1.0",
"tsc": "^1.20150623.0",
"typescript": "^3.9.5",
"utf8": "^3.0.0",
"uuid": "^8.1.0",
"ws": "^7.2.3",
"xmlhttprequest": "^1.8.0",
"elastic-builder": "^2.7.1",
"json-2-csv": "^3.7.6"
},
"devDependencies": {
"ts-jest": "^26.1.0",
"tsc": "^1.20150623.0",
"typescript": "^3.9.5",
"jest-cli": "^26.0.1",
"jest-dom": "^4.0.0",
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^10.2.1",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.13",
"@types/reach__router": "^1.3.5",
"@types/react": "^16.9.36",
"@types/react-dom": "^16.9.8",
"@types/react-test-renderer": "^16.9.2",
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"@babel/preset-react": "^7.10.1",
Expand Down
2 changes: 2 additions & 0 deletions kibana-reports/server/routes/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ export enum TRIGGER_TYPE {
}
// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-from-size.html
export const DEFAULT_MAX_SIZE = 10000;

export const LOCAL_HOST = 'http://localhost:5601';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be hard-coding the host like this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should extract the server host/port from kibana.yml, but the new platform applies some restrictions to access certain fields. More details can be found in this issue #98

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get the local host from a window.location or document method instead? I think those should be fine to access in the new platform.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That window.location won't work on server side. The UI side still keeps the usage of window.location which is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, miss from me- forgot this was on server-side

7 changes: 3 additions & 4 deletions kibana-reports/server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { async } from 'rxjs/internal/scheduler/async';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the changes in this file related to the title of the PR? I feel this is a different optimization refactor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just an unused import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not just this line, I'm referring to the other changes in the file as well- meant to highlight the whole file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other change is just rewriting the import to typescript style.

/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -16,9 +15,9 @@ import { async } from 'rxjs/internal/scheduler/async';

import { DATA_REPORT_CONFIG } from './constants';

const esb = require('elastic-builder');
const moment = require('moment');
const converter = require('json-2-csv');
import esb from 'elastic-builder';
import moment from 'moment';
import converter from 'json-2-csv';

export var metaData = {
saved_search_id: <string>null,
Expand Down
4 changes: 3 additions & 1 deletion kibana-reports/server/routes/utils/reportHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
REPORT_TYPE,
REPORT_STATE,
CONFIG_INDEX_NAME,
LOCAL_HOST,
} from './constants';
import { RequestParams } from '@elastic/elasticsearch';
import { getFileName, callCluster } from './helpers';
Expand Down Expand Up @@ -154,7 +155,8 @@ export const createReport = async (
reportSource === REPORT_TYPE.dashboard ||
reportSource === REPORT_TYPE.visualization
) {
const queryUrl = report.query_url;
const { origin } = new URL(report.query_url);
const queryUrl = report.query_url.replace(origin, LOCAL_HOST);
createReportResult = await createVisualReport(reportParams, queryUrl);
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion kibana-reports/server/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
* permissions and limitations under the License.
*/

export const POLL_INTERVAL = 1000 * 60 * 5; // in milliseconds (5 min)
export const POLL_INTERVAL = 1000 * 60 * 0.5; // in milliseconds (5 min)
1 change: 0 additions & 1 deletion kibana-reports/test/setUpTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@

require('babel-polyfill');
require('core-js/stable');
require('axios/lib/adapters/http');
Loading