From 5cf80bd24efde0e3f8df89896664c9c3cf4ac156 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 4 Aug 2020 14:01:16 +0200 Subject: [PATCH 1/3] Adding api test for custom link transaction example --- .../basic/tests/settings/custom_link.ts | 13 ++ .../expectation/custom_links_transaction.json | 180 ++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 x-pack/test/apm_api_integration/basic/tests/settings/expectation/custom_links_transaction.json diff --git a/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts b/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts index 9465708db2fba..58b42e319351c 100644 --- a/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts +++ b/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts @@ -7,11 +7,13 @@ import URL from 'url'; import expect from '@kbn/expect'; import { CustomLink } from '../../../../../plugins/apm/common/custom_link/custom_link_types'; import { FtrProviderContext } from '../../../common/ftr_provider_context'; +import expectedTransaction from './expectation/custom_links_transaction.json'; export default function customLinksTests({ getService }: FtrProviderContext) { const supertestRead = getService('supertestAsApmReadUser'); const supertestWrite = getService('supertestAsApmWriteUser'); const log = getService('log'); + const esArchiver = getService('esArchiver'); function searchCustomLinks(filters?: any) { const path = URL.format({ @@ -139,5 +141,16 @@ export default function customLinksTests({ getService }: FtrProviderContext) { expect(status).to.equal(200); expect(body).to.eql([]); }); + + describe('transaction', () => { + before(() => esArchiver.load('8.0.0')); + after(() => esArchiver.unload('8.0.0')); + + it('fetches a transaction sample', async () => { + const response = await supertestRead.get(`/api/apm/settings/custom_links/transaction`); + expect(response.status).to.be(200); + expect(response.body).to.eql(expectedTransaction); + }); + }); }); } diff --git a/x-pack/test/apm_api_integration/basic/tests/settings/expectation/custom_links_transaction.json b/x-pack/test/apm_api_integration/basic/tests/settings/expectation/custom_links_transaction.json new file mode 100644 index 0000000000000..da87d8a64ed57 --- /dev/null +++ b/x-pack/test/apm_api_integration/basic/tests/settings/expectation/custom_links_transaction.json @@ -0,0 +1,180 @@ +{ + "@timestamp":"2020-06-29T06:48:06.862Z", + "agent":{ + "name":"nodejs", + "version":"3.6.1" + }, + "client":{ + "ip":"172.18.0.8" + }, + "container":{ + "id":"41712ded148f30ee09a13421780eec4304bf5049b82a0d8dbc877893be6799e4" + }, + "ecs":{ + "version":"1.5.0" + }, + "event":{ + "ingested":"2020-06-29T06:48:08.305742Z" + }, + "host":{ + "architecture":"x64", + "hostname":"41712ded148f", + "ip":"172.18.0.7", + "name":"41712ded148f", + "os":{ + "platform":"linux" + } + }, + "http":{ + "request":{ + "headers":{ + "Accept":[ + "*/*" + ], + "Accept-Encoding":[ + "gzip, deflate" + ], + "Connection":[ + "keep-alive" + ], + "Host":[ + "opbeans-node:3000" + ], + "Referer":[ + "http://opbeans-node:3000/dashboard" + ], + "Traceparent":[ + "00-ca86ffcac7753ec8733933bd8fd45d11-5dcb98c9c9021cfc-01" + ], + "User-Agent":[ + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/79.0.3945.0 Safari/537.36" + ] + }, + "method":"get", + "socket":{ + "encrypted":false, + "remote_address":"::ffff:172.18.0.8" + } + }, + "response":{ + "headers":{ + "Connection":[ + "close" + ], + "Content-Type":[ + "application/json;charset=UTF-8" + ], + "Date":[ + "Mon, 29 Jun 2020 06:48:06 GMT" + ], + "Transfer-Encoding":[ + "chunked" + ], + "X-Powered-By":[ + "Express" + ] + }, + "status_code":200 + }, + "version":"1.1" + }, + "labels":{ + "foo":"bar", + "lorem":"ipsum dolor sit amet, consectetur adipiscing elit. Nulla finibus, ipsum id scelerisque consequat, enim leo vulputate massa, vel ultricies ante neque ac risus. Curabitur tincidunt vitae sapien id pulvinar. Mauris eu vestibulum tortor. Integer sit amet lorem fringilla, egestas tellus vitae, vulputate purus. Nulla feugiat blandit nunc et semper. Morbi purus libero, mattis sed mauris non, euismod iaculis lacus. Curabitur eleifend ante eros, non faucibus velit lacinia id. Duis posuere libero augue, at dignissim urna consectetur eget. Praesent eu congue est, iaculis finibus augue.", + "multi-line":"foo\nbar\nbaz", + "this-is-a-very-long-tag-name-without-any-spaces":"test" + }, + "observer":{ + "ephemeral_id":"99908b73-9813-4a73-baa6-993db405523a", + "hostname":"aa0bd613aa4c", + "id":"1ccc5210-1e6c-4252-a5c8-1d6571a5fa2e", + "type":"apm-server", + "version":"8.0.0", + "version_major":8 + }, + "parent":{ + "id":"5dcb98c9c9021cfc" + }, + "process":{ + "args":[ + "/usr/local/bin/node", + "/usr/local/lib/node_modules/pm2/lib/ProcessContainer.js", + "ecosystem-workload.config.js" + ], + "pid":137, + "ppid":1, + "title":"node /app/server.js" + }, + "processor":{ + "event":"transaction", + "name":"transaction" + }, + "service":{ + "environment":"production", + "framework":{ + "name":"express", + "version":"4.17.1" + }, + "language":{ + "name":"javascript" + }, + "name":"opbeans-node", + "node":{ + "name":"41712ded148f30ee09a13421780eec4304bf5049b82a0d8dbc877893be6799e4" + }, + "runtime":{ + "name":"node", + "version":"12.18.1" + }, + "version":"1.0.0" + }, + "source":{ + "ip":"172.18.0.8" + }, + "timestamp":{ + "us":1593413286862021 + }, + "trace":{ + "id":"ca86ffcac7753ec8733933bd8fd45d11" + }, + "transaction":{ + "custom":{ + "shoppingBasketCount":42 + }, + "duration":{ + "us":15738 + }, + "id":"c95371db21c6f407", + "name":"GET /api", + "result":"HTTP 2xx", + "sampled":true, + "span_count":{ + "started":1 + }, + "type":"request" + }, + "url":{ + "domain":"opbeans-node", + "full":"http://opbeans-node:3000/api/products/top", + "original":"/api/products/top", + "path":"/api/products/top", + "port":3000, + "scheme":"http" + }, + "user":{ + "email":"kimchy@elastic.co", + "id":"42", + "name":"kimchy" + }, + "user_agent":{ + "device":{ + "name":"Other" + }, + "name":"HeadlessChrome", + "original":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/79.0.3945.0 Safari/537.36", + "os":{ + "name":"Linux" + }, + "version":"79.0.3945" + } +} \ No newline at end of file From 5d4833adb00978de7d43e1bde2c19733ea2df790 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Wed, 5 Aug 2020 10:10:59 +0200 Subject: [PATCH 2/3] expecting specific fields --- .../basic/tests/settings/custom_link.ts | 6 +- .../expectation/custom_links_transaction.json | 180 ------------------ 2 files changed, 4 insertions(+), 182 deletions(-) delete mode 100644 x-pack/test/apm_api_integration/basic/tests/settings/expectation/custom_links_transaction.json diff --git a/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts b/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts index 58b42e319351c..0670b0408519b 100644 --- a/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts +++ b/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts @@ -147,9 +147,11 @@ export default function customLinksTests({ getService }: FtrProviderContext) { after(() => esArchiver.unload('8.0.0')); it('fetches a transaction sample', async () => { - const response = await supertestRead.get(`/api/apm/settings/custom_links/transaction`); + const response = await supertestRead.get( + '/api/apm/settings/custom_links/transaction?service.name=opbeans-java' + ); expect(response.status).to.be(200); - expect(response.body).to.eql(expectedTransaction); + expect(response.body.service.name).to.eql('opbeans-java'); }); }); }); diff --git a/x-pack/test/apm_api_integration/basic/tests/settings/expectation/custom_links_transaction.json b/x-pack/test/apm_api_integration/basic/tests/settings/expectation/custom_links_transaction.json deleted file mode 100644 index da87d8a64ed57..0000000000000 --- a/x-pack/test/apm_api_integration/basic/tests/settings/expectation/custom_links_transaction.json +++ /dev/null @@ -1,180 +0,0 @@ -{ - "@timestamp":"2020-06-29T06:48:06.862Z", - "agent":{ - "name":"nodejs", - "version":"3.6.1" - }, - "client":{ - "ip":"172.18.0.8" - }, - "container":{ - "id":"41712ded148f30ee09a13421780eec4304bf5049b82a0d8dbc877893be6799e4" - }, - "ecs":{ - "version":"1.5.0" - }, - "event":{ - "ingested":"2020-06-29T06:48:08.305742Z" - }, - "host":{ - "architecture":"x64", - "hostname":"41712ded148f", - "ip":"172.18.0.7", - "name":"41712ded148f", - "os":{ - "platform":"linux" - } - }, - "http":{ - "request":{ - "headers":{ - "Accept":[ - "*/*" - ], - "Accept-Encoding":[ - "gzip, deflate" - ], - "Connection":[ - "keep-alive" - ], - "Host":[ - "opbeans-node:3000" - ], - "Referer":[ - "http://opbeans-node:3000/dashboard" - ], - "Traceparent":[ - "00-ca86ffcac7753ec8733933bd8fd45d11-5dcb98c9c9021cfc-01" - ], - "User-Agent":[ - "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/79.0.3945.0 Safari/537.36" - ] - }, - "method":"get", - "socket":{ - "encrypted":false, - "remote_address":"::ffff:172.18.0.8" - } - }, - "response":{ - "headers":{ - "Connection":[ - "close" - ], - "Content-Type":[ - "application/json;charset=UTF-8" - ], - "Date":[ - "Mon, 29 Jun 2020 06:48:06 GMT" - ], - "Transfer-Encoding":[ - "chunked" - ], - "X-Powered-By":[ - "Express" - ] - }, - "status_code":200 - }, - "version":"1.1" - }, - "labels":{ - "foo":"bar", - "lorem":"ipsum dolor sit amet, consectetur adipiscing elit. Nulla finibus, ipsum id scelerisque consequat, enim leo vulputate massa, vel ultricies ante neque ac risus. Curabitur tincidunt vitae sapien id pulvinar. Mauris eu vestibulum tortor. Integer sit amet lorem fringilla, egestas tellus vitae, vulputate purus. Nulla feugiat blandit nunc et semper. Morbi purus libero, mattis sed mauris non, euismod iaculis lacus. Curabitur eleifend ante eros, non faucibus velit lacinia id. Duis posuere libero augue, at dignissim urna consectetur eget. Praesent eu congue est, iaculis finibus augue.", - "multi-line":"foo\nbar\nbaz", - "this-is-a-very-long-tag-name-without-any-spaces":"test" - }, - "observer":{ - "ephemeral_id":"99908b73-9813-4a73-baa6-993db405523a", - "hostname":"aa0bd613aa4c", - "id":"1ccc5210-1e6c-4252-a5c8-1d6571a5fa2e", - "type":"apm-server", - "version":"8.0.0", - "version_major":8 - }, - "parent":{ - "id":"5dcb98c9c9021cfc" - }, - "process":{ - "args":[ - "/usr/local/bin/node", - "/usr/local/lib/node_modules/pm2/lib/ProcessContainer.js", - "ecosystem-workload.config.js" - ], - "pid":137, - "ppid":1, - "title":"node /app/server.js" - }, - "processor":{ - "event":"transaction", - "name":"transaction" - }, - "service":{ - "environment":"production", - "framework":{ - "name":"express", - "version":"4.17.1" - }, - "language":{ - "name":"javascript" - }, - "name":"opbeans-node", - "node":{ - "name":"41712ded148f30ee09a13421780eec4304bf5049b82a0d8dbc877893be6799e4" - }, - "runtime":{ - "name":"node", - "version":"12.18.1" - }, - "version":"1.0.0" - }, - "source":{ - "ip":"172.18.0.8" - }, - "timestamp":{ - "us":1593413286862021 - }, - "trace":{ - "id":"ca86ffcac7753ec8733933bd8fd45d11" - }, - "transaction":{ - "custom":{ - "shoppingBasketCount":42 - }, - "duration":{ - "us":15738 - }, - "id":"c95371db21c6f407", - "name":"GET /api", - "result":"HTTP 2xx", - "sampled":true, - "span_count":{ - "started":1 - }, - "type":"request" - }, - "url":{ - "domain":"opbeans-node", - "full":"http://opbeans-node:3000/api/products/top", - "original":"/api/products/top", - "path":"/api/products/top", - "port":3000, - "scheme":"http" - }, - "user":{ - "email":"kimchy@elastic.co", - "id":"42", - "name":"kimchy" - }, - "user_agent":{ - "device":{ - "name":"Other" - }, - "name":"HeadlessChrome", - "original":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/79.0.3945.0 Safari/537.36", - "os":{ - "name":"Linux" - }, - "version":"79.0.3945" - } -} \ No newline at end of file From f3a164bc88de33b97916f9a4c398fe03a3aa3ffc Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Wed, 5 Aug 2020 10:11:08 +0200 Subject: [PATCH 3/3] expecting specific fields --- .../test/apm_api_integration/basic/tests/settings/custom_link.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts b/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts index 0670b0408519b..2acc6522bf479 100644 --- a/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts +++ b/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts @@ -7,7 +7,6 @@ import URL from 'url'; import expect from '@kbn/expect'; import { CustomLink } from '../../../../../plugins/apm/common/custom_link/custom_link_types'; import { FtrProviderContext } from '../../../common/ftr_provider_context'; -import expectedTransaction from './expectation/custom_links_transaction.json'; export default function customLinksTests({ getService }: FtrProviderContext) { const supertestRead = getService('supertestAsApmReadUser');