Skip to content

Commit d5aa1db

Browse files
committed
cherry-pick from #59152
1 parent 26d1761 commit d5aa1db

8 files changed

Lines changed: 723 additions & 616 deletions

File tree

x-pack/legacy/plugins/apm/e2e/cypress/ingest-data/replay.js

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
/* eslint-disable import/no-extraneous-dependencies */
87
/* eslint-disable no-console */
98

9+
/* eslint-disable import/no-extraneous-dependencies */
10+
1011
/**
1112
* This script is useful for ingesting previously generated APM data into Elasticsearch via APM Server
1213
*
1314
* You can either:
1415
* 1. Download a static test data file from: https://storage.googleapis.com/apm-ui-e2e-static-data/events.json
15-
* 2. Or, generate the test data file yourself by following the steps in: https://github.com/elastic/kibana/blob/5207a0b68a66d4f513fe1b0cedb021b296641712/x-pack/legacy/plugins/apm/cypress/README.md#generate-static-data
16+
* 2. Or, generate the test data file yourself:
17+
* git clone https://github.com/elastic/apm-integration-testing.git
18+
* ./scripts/compose.py start master --no-kibana --with-opbeans-node --apm-server-record
19+
* docker cp localtesting_8.0.0_apm-server-2:/app/events.json . && cat events.json | wc -l
20+
*
21+
*
1622
*
1723
* Run the script:
1824
*
@@ -27,6 +33,7 @@ const axios = require('axios');
2733
const readFile = promisify(fs.readFile);
2834
const pLimit = require('p-limit');
2935
const { argv } = require('yargs');
36+
const ora = require('ora');
3037

3138
const APM_SERVER_URL = argv.serverUrl;
3239
const SECRET_TOKEN = argv.secretToken;
@@ -43,10 +50,27 @@ if (!EVENTS_PATH) {
4350
}
4451

4552
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
53+
54+
const requestProgress = {
55+
succeeded: 0,
56+
failed: 0,
57+
total: 0
58+
};
59+
60+
const spinner = ora({ text: 'Warming up...', stream: process.stdout });
61+
62+
function updateSpinnerText({ success }) {
63+
success ? requestProgress.succeeded++ : requestProgress.failed++;
64+
const remaining =
65+
requestProgress.total -
66+
(requestProgress.succeeded + requestProgress.failed);
67+
68+
spinner.text = `Remaining: ${remaining}. Succeeded: ${requestProgress.succeeded}. Failed: ${requestProgress.failed}.`;
69+
}
70+
4671
async function insertItem(item) {
4772
try {
4873
const url = `${APM_SERVER_URL}${item.url}`;
49-
console.log(Date.now(), url);
5074

5175
const headers = {
5276
'content-type': 'application/x-ndjson'
@@ -63,31 +87,42 @@ async function insertItem(item) {
6387
data: item.body
6488
});
6589

90+
updateSpinnerText({ success: true });
91+
6692
// add delay to avoid flooding the queue
6793
return delay(500);
6894
} catch (e) {
69-
console.log('an error occurred');
70-
if (e.response) {
71-
console.log(e.response.data);
72-
} else {
73-
console.log('error', e);
74-
}
95+
console.error(
96+
`${e.response ? JSON.stringify(e.response.data) : e.message}`
97+
);
98+
updateSpinnerText({ success: false });
7599
}
76100
}
77101

78102
async function init() {
79-
const content = await readFile(path.resolve(__dirname, EVENTS_PATH));
103+
const content = await readFile(path.resolve(EVENTS_PATH));
80104
const items = content
81105
.toString()
82106
.split('\n')
83107
.filter(item => item)
84108
.map(item => JSON.parse(item))
85109
.filter(item => item.url === '/intake/v2/events');
86110

111+
spinner.start();
112+
requestProgress.total = items.length;
113+
87114
const limit = pLimit(20); // number of concurrent requests
88115
await Promise.all(items.map(item => limit(() => insertItem(item))));
89116
}
90117

91-
init().catch(e => {
92-
console.log('An error occurred:', e);
93-
});
118+
init()
119+
.catch(e => {
120+
console.log('An error occurred:', e);
121+
process.exit(1);
122+
})
123+
.then(() => {
124+
spinner.succeed(
125+
`Successfully ingested ${requestProgress.succeeded} of ${requestProgress.total} events`
126+
);
127+
process.exit(0);
128+
});

x-pack/legacy/plugins/apm/e2e/cypress/integration/apm.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ Feature: APM
22

33
Scenario: Transaction duration charts
44
Given a user browses the APM UI application
5-
When the user inspects the opbeans-go service
5+
When the user inspects the opbeans-node service
66
Then should redirect to correct path with correct params
7-
And should have correct y-axis ticks
7+
And should have correct y-axis ticks

x-pack/legacy/plugins/apm/e2e/cypress/integration/helpers.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
/* eslint-disable import/no-extraneous-dependencies */
88

9-
const RANGE_FROM = '2019-09-04T18:00:00.000Z';
10-
const RANGE_TO = '2019-09-05T06:00:00.000Z';
9+
const RANGE_FROM = '2020-03-04T12:30:00.000Z';
10+
const RANGE_TO = '2020-03-04T13:00:00.000Z';
1111
const BASE_URL = Cypress.config().baseUrl;
1212

1313
/** The default time in ms to wait for a Cypress command to complete */
14-
export const DEFAULT_TIMEOUT = 30 * 1000;
14+
export const DEFAULT_TIMEOUT = 60 * 1000;
1515

1616
export function loginAndWaitForPage(url: string) {
1717
const username = Cypress.env('elasticsearch_username');
@@ -25,5 +25,7 @@ export function loginAndWaitForPage(url: string) {
2525
cy.viewport('macbook-15');
2626

2727
// wait for loading spinner to disappear
28-
cy.get('.kibanaLoaderWrap', { timeout: DEFAULT_TIMEOUT }).should('not.exist');
28+
cy.get('#kbn_loading_message', { timeout: DEFAULT_TIMEOUT }).should(
29+
'not.exist'
30+
);
2931
}
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
module.exports = {
2-
"When clicking opbeans-go service": {
3-
"transaction duration charts": {
4-
"should have correct y-axis ticks": {
5-
"1": "3.7 min",
6-
"2": "1.8 min",
7-
"3": "0.0 min"
8-
}
9-
}
10-
},
11-
"__version": "3.8.3",
122
"APM": {
133
"Transaction duration charts": {
14-
"1": "3.7 min",
15-
"2": "1.8 min",
16-
"3": "0.0 min"
4+
"1": "500 ms",
5+
"2": "250 ms",
6+
"3": "0 ms"
177
}
18-
}
8+
},
9+
"__version": "4.2.0"
1910
}

x-pack/legacy/plugins/apm/e2e/cypress/support/step_definitions/apm.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ Given(`a user browses the APM UI application`, () => {
1212
loginAndWaitForPage(`/app/apm#/services`);
1313
});
1414

15-
When(`the user inspects the opbeans-go service`, () => {
16-
// click opbeans-go service
17-
cy.get(':contains(opbeans-go)')
15+
When(`the user inspects the opbeans-node service`, () => {
16+
// click opbeans-node service
17+
cy.get(':contains(opbeans-node)')
1818
.last()
1919
.click({ force: true });
2020
});
2121

2222
Then(`should redirect to correct path with correct params`, () => {
23-
cy.url().should('contain', `/app/apm#/services/opbeans-go/transactions`);
23+
cy.url().should('contain', `/app/apm#/services/opbeans-node/transactions`);
2424
cy.url().should('contain', `transactionType=request`);
2525
});
2626

x-pack/legacy/plugins/apm/e2e/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
},
1010
"dependencies": {
1111
"@cypress/snapshot": "^2.1.3",
12-
"@cypress/webpack-preprocessor": "^4.1.0",
13-
"@types/cypress-cucumber-preprocessor": "^1.14.0",
12+
"@cypress/webpack-preprocessor": "^4.1.3",
13+
"@types/cypress-cucumber-preprocessor": "^1.14.1",
1414
"@types/js-yaml": "^3.12.1",
1515
"@types/node": "^10.12.11",
16-
"cypress": "^3.5.0",
16+
"cypress": "^4.2.0",
1717
"cypress-cucumber-preprocessor": "^2.0.1",
1818
"js-yaml": "^3.13.1",
19+
"ora": "^4.0.3",
1920
"p-limit": "^2.2.1",
20-
"ts-loader": "^6.1.0",
21-
"typescript": "3.7.5",
22-
"webpack": "^4.41.5"
21+
"ts-loader": "^6.2.2",
22+
"typescript": "3.8.3",
23+
"wait-on": "^4.0.1",
24+
"webpack": "^4.42.1"
2325
}
24-
}
26+
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
{
22
"extends": "../../../../tsconfig.json",
3-
"exclude": [],
4-
"include": [
5-
"./**/*"
6-
],
3+
"exclude": ["tmp"],
4+
"include": ["./**/*"],
75
"compilerOptions": {
8-
"types": [
9-
"cypress",
10-
"node"
11-
]
6+
"types": ["cypress", "node"]
127
}
138
}

0 commit comments

Comments
 (0)