From 7976e2bda4c395adc5c9587d95e498d482a92eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Marcondes?= <55978943+cauemarcondes@users.noreply.github.com> Date: Mon, 20 Jul 2020 11:39:26 +0100 Subject: [PATCH] [APM] Testing error rate API and restructuring folders (#72257) * adding error rate and restructuring tests * removing console log * removing console log * adding error rate and restructuring tests * fixing TS error * removing unnecessary files * removing trial tests --- .../apm_api_integration/basic/tests/index.ts | 36 +++++++++----- .../tests/{ => service_maps}/service_maps.ts | 2 +- .../services/{transactions => }/agent_name.ts | 2 +- .../basic/tests/{ => services}/annotations.ts | 2 +- .../{transactions => }/transaction_types.ts | 2 +- .../{ => settings}/agent_configuration.ts | 6 +-- .../basic/tests/{ => settings}/custom_link.ts | 4 +- .../top_traces.expectation.json | 0 .../basic/tests/traces/top_traces.ts | 2 +- .../tests/transaction_groups/error_rate.ts | 47 +++++++++++++++++++ .../expectation/error_rate.json | 42 +++++++++++++++++ .../expectation}/top_transaction_groups.json | 0 .../expectation}/transaction_charts.json | 0 .../top_transaction_groups.ts | 4 +- .../transaction_charts.ts | 4 +- .../apm_api_integration/trial/tests/index.ts | 12 +++-- .../tests/{ => service_maps}/service_maps.ts | 2 +- .../trial/tests/{ => services}/annotations.ts | 2 +- .../tests/{ => services}/rum_services.ts | 2 +- 19 files changed, 138 insertions(+), 33 deletions(-) rename x-pack/test/apm_api_integration/basic/tests/{ => service_maps}/service_maps.ts (93%) rename x-pack/test/apm_api_integration/basic/tests/services/{transactions => }/agent_name.ts (94%) rename x-pack/test/apm_api_integration/basic/tests/{ => services}/annotations.ts (95%) rename x-pack/test/apm_api_integration/basic/tests/services/{transactions => }/transaction_types.ts (94%) rename x-pack/test/apm_api_integration/basic/tests/{ => settings}/agent_configuration.ts (98%) rename x-pack/test/apm_api_integration/basic/tests/{ => settings}/custom_link.ts (96%) rename x-pack/test/apm_api_integration/basic/tests/traces/{ => expectation}/top_traces.expectation.json (100%) create mode 100644 x-pack/test/apm_api_integration/basic/tests/transaction_groups/error_rate.ts create mode 100644 x-pack/test/apm_api_integration/basic/tests/transaction_groups/expectation/error_rate.json rename x-pack/test/apm_api_integration/basic/tests/{services/transactions/expectations => transaction_groups/expectation}/top_transaction_groups.json (100%) rename x-pack/test/apm_api_integration/basic/tests/{services/transactions/expectations => transaction_groups/expectation}/transaction_charts.json (100%) rename x-pack/test/apm_api_integration/basic/tests/{services/transactions => transaction_groups}/top_transaction_groups.ts (93%) rename x-pack/test/apm_api_integration/basic/tests/{services/transactions => transaction_groups}/transaction_charts.ts (91%) rename x-pack/test/apm_api_integration/trial/tests/{ => service_maps}/service_maps.ts (99%) rename x-pack/test/apm_api_integration/trial/tests/{ => services}/annotations.ts (99%) rename x-pack/test/apm_api_integration/trial/tests/{ => services}/rum_services.ts (95%) diff --git a/x-pack/test/apm_api_integration/basic/tests/index.ts b/x-pack/test/apm_api_integration/basic/tests/index.ts index 3658208e38d00..873aa478ad080 100644 --- a/x-pack/test/apm_api_integration/basic/tests/index.ts +++ b/x-pack/test/apm_api_integration/basic/tests/index.ts @@ -9,22 +9,32 @@ export default function apmApiIntegrationTests({ loadTestFile }: FtrProviderCont describe('APM specs (basic)', function () { this.tags('ciGroup1'); - loadTestFile(require.resolve('./annotations')); loadTestFile(require.resolve('./feature_controls')); - loadTestFile(require.resolve('./agent_configuration')); - loadTestFile(require.resolve('./custom_link')); - loadTestFile(require.resolve('./service_maps')); - // traces - loadTestFile(require.resolve('./traces/top_traces')); + describe('Service Maps', function () { + loadTestFile(require.resolve('./service_maps/service_maps')); + }); - // services - loadTestFile(require.resolve('./services/top_services')); + describe('Services', function () { + loadTestFile(require.resolve('./services/annotations')); + loadTestFile(require.resolve('./services/top_services')); + loadTestFile(require.resolve('./services/agent_name')); + loadTestFile(require.resolve('./services/transaction_types')); + }); - // services/transaction - loadTestFile(require.resolve('./services/transactions/top_transaction_groups')); - loadTestFile(require.resolve('./services/transactions/transaction_charts')); - loadTestFile(require.resolve('./services/transactions/agent_name')); - loadTestFile(require.resolve('./services/transactions/transaction_types')); + describe('Settings', function () { + loadTestFile(require.resolve('./settings/custom_link')); + loadTestFile(require.resolve('./settings/agent_configuration')); + }); + + describe('Traces', function () { + loadTestFile(require.resolve('./traces/top_traces')); + }); + + describe('Transaction Group', function () { + loadTestFile(require.resolve('./transaction_groups/top_transaction_groups')); + loadTestFile(require.resolve('./transaction_groups/transaction_charts')); + loadTestFile(require.resolve('./transaction_groups/error_rate')); + }); }); } diff --git a/x-pack/test/apm_api_integration/basic/tests/service_maps.ts b/x-pack/test/apm_api_integration/basic/tests/service_maps/service_maps.ts similarity index 93% rename from x-pack/test/apm_api_integration/basic/tests/service_maps.ts rename to x-pack/test/apm_api_integration/basic/tests/service_maps/service_maps.ts index 45972aaf529af..b0e503eb7d1eb 100644 --- a/x-pack/test/apm_api_integration/basic/tests/service_maps.ts +++ b/x-pack/test/apm_api_integration/basic/tests/service_maps/service_maps.ts @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; export default function serviceMapsApiTests({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test/apm_api_integration/basic/tests/services/transactions/agent_name.ts b/x-pack/test/apm_api_integration/basic/tests/services/agent_name.ts similarity index 94% rename from x-pack/test/apm_api_integration/basic/tests/services/transactions/agent_name.ts rename to x-pack/test/apm_api_integration/basic/tests/services/agent_name.ts index a9aeaf813aa5c..5be5e43b359f5 100644 --- a/x-pack/test/apm_api_integration/basic/tests/services/transactions/agent_name.ts +++ b/x-pack/test/apm_api_integration/basic/tests/services/agent_name.ts @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; +import { FtrProviderContext } from '../../../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test/apm_api_integration/basic/tests/annotations.ts b/x-pack/test/apm_api_integration/basic/tests/services/annotations.ts similarity index 95% rename from x-pack/test/apm_api_integration/basic/tests/annotations.ts rename to x-pack/test/apm_api_integration/basic/tests/services/annotations.ts index e0659fe195f93..3136dcef2e985 100644 --- a/x-pack/test/apm_api_integration/basic/tests/annotations.ts +++ b/x-pack/test/apm_api_integration/basic/tests/services/annotations.ts @@ -6,7 +6,7 @@ import expect from '@kbn/expect'; import { JsonObject } from 'src/plugins/kibana_utils/common'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; export default function annotationApiTests({ getService }: FtrProviderContext) { const supertestWrite = getService('supertestAsApmAnnotationsWriteUser'); diff --git a/x-pack/test/apm_api_integration/basic/tests/services/transactions/transaction_types.ts b/x-pack/test/apm_api_integration/basic/tests/services/transaction_types.ts similarity index 94% rename from x-pack/test/apm_api_integration/basic/tests/services/transactions/transaction_types.ts rename to x-pack/test/apm_api_integration/basic/tests/services/transaction_types.ts index 56844dfcedda1..3e8f320ad6b24 100644 --- a/x-pack/test/apm_api_integration/basic/tests/services/transactions/transaction_types.ts +++ b/x-pack/test/apm_api_integration/basic/tests/services/transaction_types.ts @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; +import { FtrProviderContext } from '../../../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test/apm_api_integration/basic/tests/agent_configuration.ts b/x-pack/test/apm_api_integration/basic/tests/settings/agent_configuration.ts similarity index 98% rename from x-pack/test/apm_api_integration/basic/tests/agent_configuration.ts rename to x-pack/test/apm_api_integration/basic/tests/settings/agent_configuration.ts index 1c8097760bc04..283540201b9b5 100644 --- a/x-pack/test/apm_api_integration/basic/tests/agent_configuration.ts +++ b/x-pack/test/apm_api_integration/basic/tests/settings/agent_configuration.ts @@ -6,9 +6,9 @@ import expect from '@kbn/expect'; import { omit, orderBy } from 'lodash'; -import { AgentConfigurationIntake } from '../../../../plugins/apm/common/agent_configuration/configuration_types'; -import { AgentConfigSearchParams } from '../../../../plugins/apm/server/routes/settings/agent_configuration'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; +import { AgentConfigurationIntake } from '../../../../../plugins/apm/common/agent_configuration/configuration_types'; +import { AgentConfigSearchParams } from '../../../../../plugins/apm/server/routes/settings/agent_configuration'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; export default function agentConfigurationTests({ getService }: FtrProviderContext) { const supertestRead = getService('supertestAsApmReadUser'); diff --git a/x-pack/test/apm_api_integration/basic/tests/custom_link.ts b/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts similarity index 96% rename from x-pack/test/apm_api_integration/basic/tests/custom_link.ts rename to x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts index ec93d2b3a3b41..9465708db2fba 100644 --- a/x-pack/test/apm_api_integration/basic/tests/custom_link.ts +++ b/x-pack/test/apm_api_integration/basic/tests/settings/custom_link.ts @@ -5,8 +5,8 @@ */ 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 { CustomLink } from '../../../../../plugins/apm/common/custom_link/custom_link_types'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; export default function customLinksTests({ getService }: FtrProviderContext) { const supertestRead = getService('supertestAsApmReadUser'); diff --git a/x-pack/test/apm_api_integration/basic/tests/traces/top_traces.expectation.json b/x-pack/test/apm_api_integration/basic/tests/traces/expectation/top_traces.expectation.json similarity index 100% rename from x-pack/test/apm_api_integration/basic/tests/traces/top_traces.expectation.json rename to x-pack/test/apm_api_integration/basic/tests/traces/expectation/top_traces.expectation.json diff --git a/x-pack/test/apm_api_integration/basic/tests/traces/top_traces.ts b/x-pack/test/apm_api_integration/basic/tests/traces/top_traces.ts index aef208b6fc06b..e96cb20a68fda 100644 --- a/x-pack/test/apm_api_integration/basic/tests/traces/top_traces.ts +++ b/x-pack/test/apm_api_integration/basic/tests/traces/top_traces.ts @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; -import expectTopTraces from './top_traces.expectation.json'; +import expectTopTraces from './expectation/top_traces.expectation.json'; export default function ApiTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test/apm_api_integration/basic/tests/transaction_groups/error_rate.ts b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/error_rate.ts new file mode 100644 index 0000000000000..2c22cbbcce780 --- /dev/null +++ b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/error_rate.ts @@ -0,0 +1,47 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; +import expectedErrorRate from './expectation/error_rate.json'; + +export default function ApiTest({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + const esArchiver = getService('esArchiver'); + + // url parameters + const start = encodeURIComponent('2020-06-29T06:45:00.000Z'); + const end = encodeURIComponent('2020-06-29T06:49:00.000Z'); + const uiFilters = encodeURIComponent(JSON.stringify({})); + + describe('Error rate', () => { + describe('when data is not loaded', () => { + it('handles the empty state', async () => { + const response = await supertest.get( + `/api/apm/services/opbeans-node/transaction_groups/error_rate?start=${start}&end=${end}&uiFilters=${uiFilters}` + ); + expect(response.status).to.be(200); + expect(response.body).to.eql({ + noHits: true, + erroneousTransactionsRate: [], + average: null, + }); + }); + }); + describe('when data is loaded', () => { + before(() => esArchiver.load('8.0.0')); + after(() => esArchiver.unload('8.0.0')); + + it('returns the transaction error rate', async () => { + const response = await supertest.get( + `/api/apm/services/opbeans-node/transaction_groups/error_rate?start=${start}&end=${end}&uiFilters=${uiFilters}` + ); + + expect(response.status).to.be(200); + expect(response.body).to.eql(expectedErrorRate); + }); + }); + }); +} diff --git a/x-pack/test/apm_api_integration/basic/tests/transaction_groups/expectation/error_rate.json b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/expectation/error_rate.json new file mode 100644 index 0000000000000..9ff45ebdbb21b --- /dev/null +++ b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/expectation/error_rate.json @@ -0,0 +1,42 @@ +{ + "noHits":false, + "erroneousTransactionsRate":[ + { + "x":1593413100000, + "y":null + }, + { + "x":1593413130000, + "y":null + }, + { + "x":1593413160000, + "y":null + }, + { + "x":1593413190000, + "y":null + }, + { + "x":1593413220000, + "y":null + }, + { + "x":1593413250000, + "y":0 + }, + { + "x":1593413280000, + "y":0.14102564102564102 + }, + { + "x":1593413310000, + "y":0.14634146341463414 + }, + { + "x":1593413340000, + "y":null + } + ], + "average":0.09578903481342504 +} \ No newline at end of file diff --git a/x-pack/test/apm_api_integration/basic/tests/services/transactions/expectations/top_transaction_groups.json b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/expectation/top_transaction_groups.json similarity index 100% rename from x-pack/test/apm_api_integration/basic/tests/services/transactions/expectations/top_transaction_groups.json rename to x-pack/test/apm_api_integration/basic/tests/transaction_groups/expectation/top_transaction_groups.json diff --git a/x-pack/test/apm_api_integration/basic/tests/services/transactions/expectations/transaction_charts.json b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/expectation/transaction_charts.json similarity index 100% rename from x-pack/test/apm_api_integration/basic/tests/services/transactions/expectations/transaction_charts.json rename to x-pack/test/apm_api_integration/basic/tests/transaction_groups/expectation/transaction_charts.json diff --git a/x-pack/test/apm_api_integration/basic/tests/services/transactions/top_transaction_groups.ts b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/top_transaction_groups.ts similarity index 93% rename from x-pack/test/apm_api_integration/basic/tests/services/transactions/top_transaction_groups.ts rename to x-pack/test/apm_api_integration/basic/tests/transaction_groups/top_transaction_groups.ts index bf8d3f6a56e6a..43b2ad5414c7a 100644 --- a/x-pack/test/apm_api_integration/basic/tests/services/transactions/top_transaction_groups.ts +++ b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/top_transaction_groups.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; -import expectedTransactionGroups from './expectations/top_transaction_groups.json'; +import { FtrProviderContext } from '../../../../common/ftr_provider_context'; +import expectedTransactionGroups from './expectation/top_transaction_groups.json'; export default function ApiTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test/apm_api_integration/basic/tests/services/transactions/transaction_charts.ts b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/transaction_charts.ts similarity index 91% rename from x-pack/test/apm_api_integration/basic/tests/services/transactions/transaction_charts.ts rename to x-pack/test/apm_api_integration/basic/tests/transaction_groups/transaction_charts.ts index 7178498863787..68a7499a2389c 100644 --- a/x-pack/test/apm_api_integration/basic/tests/services/transactions/transaction_charts.ts +++ b/x-pack/test/apm_api_integration/basic/tests/transaction_groups/transaction_charts.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; -import expectedTransactionCharts from './expectations/transaction_charts.json'; +import { FtrProviderContext } from '../../../../common/ftr_provider_context'; +import expectedTransactionCharts from './expectation/transaction_charts.json'; export default function ApiTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test/apm_api_integration/trial/tests/index.ts b/x-pack/test/apm_api_integration/trial/tests/index.ts index 37328badcb794..fb942f755a063 100644 --- a/x-pack/test/apm_api_integration/trial/tests/index.ts +++ b/x-pack/test/apm_api_integration/trial/tests/index.ts @@ -9,8 +9,14 @@ import { FtrProviderContext } from '../../../api_integration/ftr_provider_contex export default function observabilityApiIntegrationTests({ loadTestFile }: FtrProviderContext) { describe('APM specs (trial)', function () { this.tags('ciGroup1'); - loadTestFile(require.resolve('./annotations')); - loadTestFile(require.resolve('./service_maps')); - loadTestFile(require.resolve('./rum_services')); + + describe('Services', function () { + loadTestFile(require.resolve('./services/annotations')); + loadTestFile(require.resolve('./services/rum_services.ts')); + }); + + describe('Service Maps', function () { + loadTestFile(require.resolve('./service_maps/service_maps')); + }); }); } diff --git a/x-pack/test/apm_api_integration/trial/tests/service_maps.ts b/x-pack/test/apm_api_integration/trial/tests/service_maps/service_maps.ts similarity index 99% rename from x-pack/test/apm_api_integration/trial/tests/service_maps.ts rename to x-pack/test/apm_api_integration/trial/tests/service_maps/service_maps.ts index 0b370f6a30a8b..4002e8cff5bad 100644 --- a/x-pack/test/apm_api_integration/trial/tests/service_maps.ts +++ b/x-pack/test/apm_api_integration/trial/tests/service_maps/service_maps.ts @@ -6,7 +6,7 @@ import querystring from 'querystring'; import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; export default function serviceMapsApiTests({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test/apm_api_integration/trial/tests/annotations.ts b/x-pack/test/apm_api_integration/trial/tests/services/annotations.ts similarity index 99% rename from x-pack/test/apm_api_integration/trial/tests/annotations.ts rename to x-pack/test/apm_api_integration/trial/tests/services/annotations.ts index 662879c495230..c2ddc10c5f1d2 100644 --- a/x-pack/test/apm_api_integration/trial/tests/annotations.ts +++ b/x-pack/test/apm_api_integration/trial/tests/services/annotations.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { merge, cloneDeep, isPlainObject } from 'lodash'; import { JsonObject } from 'src/plugins/kibana_utils/common'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; const DEFAULT_INDEX_NAME = 'observability-annotations'; diff --git a/x-pack/test/apm_api_integration/trial/tests/rum_services.ts b/x-pack/test/apm_api_integration/trial/tests/services/rum_services.ts similarity index 95% rename from x-pack/test/apm_api_integration/trial/tests/rum_services.ts rename to x-pack/test/apm_api_integration/trial/tests/services/rum_services.ts index 5505387de54a7..78171a65a11fd 100644 --- a/x-pack/test/apm_api_integration/trial/tests/rum_services.ts +++ b/x-pack/test/apm_api_integration/trial/tests/services/rum_services.ts @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; export default function rumServicesApiTests({ getService }: FtrProviderContext) { const supertest = getService('supertest');