From 90664021a1f116d744b5f5f2bf2c524d31dffd78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv?= Date: Mon, 23 Dec 2019 17:42:01 +0100 Subject: [PATCH 1/4] [APM] Add log statements for flaky test --- .../create_or_update_configuration.ts | 9 +++++- .../routes/settings/agent_configuration.ts | 9 ++++++ .../apis/apm/feature_controls.ts | 32 ++++++++++++++----- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_or_update_configuration.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_or_update_configuration.ts index 5a67f78de6f65..6ce9c0c70399a 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_or_update_configuration.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_or_update_configuration.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +/* eslint-disable no-console */ + import hash from 'object-hash'; import { Setup } from '../../helpers/setup_request'; import { AgentConfiguration } from './configuration_types'; @@ -44,5 +46,10 @@ export async function createOrUpdateConfiguration({ params.id = configurationId; } - return internalClient.index(params); + // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + console.log(`Creating agent configuration`); + const res = await internalClient.index(params); + // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + console.log(`Success creating agent configuration`); + return res; } diff --git a/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts b/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts index a670911079040..45f06f60a76e6 100644 --- a/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts +++ b/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +/* eslint-disable no-console */ + import * as t from 'io-ts'; import Boom from 'boom'; import { setupRequest } from '../../lib/helpers/setup_request'; @@ -161,6 +163,9 @@ export const agentConfigurationSearchRoute = createRoute(core => ({ }) }, handler: async ({ context, request }) => { + // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + // TODO: Remove console.log before 8.0 to avoid releasing to end users + console.log('Hitting: /api/apm/settings/agent-configuration/search'); const setup = await setupRequest(context, request); const { body } = context.params; const config = await searchConfigurations({ @@ -170,6 +175,10 @@ export const agentConfigurationSearchRoute = createRoute(core => ({ }); if (!config) { + // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + console.log( + `Config was not found for ${body.service.name}/${body.service.environment}` + ); context.logger.info( `Config was not found for ${body.service.name}/${body.service.environment}` ); diff --git a/x-pack/test/api_integration/apis/apm/feature_controls.ts b/x-pack/test/api_integration/apis/apm/feature_controls.ts index 839d4ff420a76..d2a66374fd2ff 100644 --- a/x-pack/test/api_integration/apis/apm/feature_controls.ts +++ b/x-pack/test/api_integration/apis/apm/feature_controls.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +/* eslint-disable no-console */ + import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; @@ -142,7 +144,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) }, ]; - const elasticsearchRole = { + const elasticsearchPrivileges = { indices: [ { names: ['apm-*'], privileges: ['read', 'view_index_metadata'] }, { names: ['.apm-agent-configuration'], privileges: ['read', 'write', 'view_index_metadata'] }, @@ -205,8 +207,13 @@ export default function featureControlsTests({ getService }: FtrProviderContext) spaceId?: string; }) { for (const endpoint of endpoints) { - log.debug(`hitting ${endpoint.req.url}`); + // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + console.log(`Requesting: ${endpoint.req.url}`); + log.info(`Requesting: ${endpoint.req.url}`); const result = await executeAsUser(endpoint.req, username, password, spaceId); + console.log(`Responded: ${endpoint.req.url}`); + log.info(`Responded: ${endpoint.req.url}`); + try { if (expectation === 'forbidden') { endpoint.expectForbidden(result); @@ -214,6 +221,10 @@ export default function featureControlsTests({ getService }: FtrProviderContext) endpoint.expectResponse(result); } } catch (e) { + // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + console.log(`${endpoint.req.url} failed`); + log.warning(`${endpoint.req.url} failed`); + const { statusCode, body, req } = result.response; throw new Error( `Endpoint: ${req.method} ${req.path} @@ -229,7 +240,9 @@ export default function featureControlsTests({ getService }: FtrProviderContext) describe('apm feature controls', () => { let res: any; before(async () => { - log.debug('creating agent configuration'); + // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + console.log(`Creating agent configuration`); + log.info('Creating agent configuration'); res = await executeAsAdmin({ method: 'post', url: '/api/apm/settings/agent-configuration/new', @@ -238,10 +251,13 @@ export default function featureControlsTests({ getService }: FtrProviderContext) settings: { transaction_sample_rate: 0.5 }, }, }); + // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + console.log(`Agent configuration created`); + log.info('Agent configuration created'); }); after(async () => { - log.debug('deleting agent configuration'); + log.info('deleting agent configuration'); const configurationId = res.body._id; await executeAsAdmin({ method: 'delete', @@ -255,7 +271,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) const password = `${username}-password`; try { await security.role.create(roleName, { - elasticsearch: elasticsearchRole, + elasticsearch: elasticsearchPrivileges, }); await security.user.create(username, { @@ -277,7 +293,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) const password = `${username}-password`; try { await security.role.create(roleName, { - elasticsearch: elasticsearchRole, + elasticsearch: elasticsearchPrivileges, kibana: [{ base: ['all'], spaces: ['*'] }], }); @@ -301,7 +317,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) const password = `${username}-password`; try { await security.role.create(roleName, { - elasticsearch: elasticsearchRole, + elasticsearch: elasticsearchPrivileges, kibana: [{ feature: { dashboard: ['all'] }, spaces: ['*'] }], }); @@ -339,7 +355,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) disabledFeatures: [], }); await security.role.create(roleName, { - elasticsearch: elasticsearchRole, + elasticsearch: elasticsearchPrivileges, kibana: [ { feature: { apm: ['read'] }, spaces: [space1Id] }, { feature: { dashboard: ['all'] }, spaces: [space2Id] }, From 9ab039dddd53d75a484b4d7e186fdf592f839f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv?= Date: Mon, 23 Dec 2019 21:21:32 +0100 Subject: [PATCH 2/4] Improve logging --- .../create_or_update_configuration.ts | 9 +---- .../routes/settings/agent_configuration.ts | 34 ++++++++++++------- .../apis/apm/feature_controls.ts | 15 ++------ 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_or_update_configuration.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_or_update_configuration.ts index 6ce9c0c70399a..5a67f78de6f65 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_or_update_configuration.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_or_update_configuration.ts @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -/* eslint-disable no-console */ - import hash from 'object-hash'; import { Setup } from '../../helpers/setup_request'; import { AgentConfiguration } from './configuration_types'; @@ -46,10 +44,5 @@ export async function createOrUpdateConfiguration({ params.id = configurationId; } - // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) - console.log(`Creating agent configuration`); - const res = await internalClient.index(params); - // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) - console.log(`Success creating agent configuration`); - return res; + return internalClient.index(params); } diff --git a/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts b/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts index 45f06f60a76e6..3afb95d16b0f5 100644 --- a/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts +++ b/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -/* eslint-disable no-console */ - import * as t from 'io-ts'; import Boom from 'boom'; import { setupRequest } from '../../lib/helpers/setup_request'; @@ -119,10 +117,19 @@ export const createAgentConfigurationRoute = createRoute(() => ({ }, handler: async ({ context, request }) => { const setup = await setupRequest(context, request); - return await createOrUpdateConfiguration({ - configuration: context.params.body, + const configuration = context.params.body; + + // TODO: Remove logger. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + context.logger.info( + `Hitting: /api/apm/settings/agent-configuration/new with ${configuration}` + ); + const res = await createOrUpdateConfiguration({ + configuration, setup }); + context.logger.info(`Created agent configuration`); + + return res; } })); @@ -163,11 +170,14 @@ export const agentConfigurationSearchRoute = createRoute(core => ({ }) }, handler: async ({ context, request }) => { - // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) - // TODO: Remove console.log before 8.0 to avoid releasing to end users - console.log('Hitting: /api/apm/settings/agent-configuration/search'); - const setup = await setupRequest(context, request); const { body } = context.params; + + // TODO: Remove logger. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) + context.logger.info( + `Hitting: /api/apm/settings/agent-configuration/search for ${body.service.name}/${body.service.environment}` + ); + + const setup = await setupRequest(context, request); const config = await searchConfigurations({ serviceName: body.service.name, environment: body.service.environment, @@ -175,16 +185,16 @@ export const agentConfigurationSearchRoute = createRoute(core => ({ }); if (!config) { - // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) - console.log( - `Config was not found for ${body.service.name}/${body.service.environment}` - ); context.logger.info( `Config was not found for ${body.service.name}/${body.service.environment}` ); throw new Boom('Not found', { statusCode: 404 }); } + context.logger.info( + `Config was found for ${body.service.name}/${body.service.environment}` + ); + // update `applied_by_agent` field if etags match if (body.etag === config._source.etag && !config._source.applied_by_agent) { markAppliedByAgent({ id: config._id, body: config._source, setup }); diff --git a/x-pack/test/api_integration/apis/apm/feature_controls.ts b/x-pack/test/api_integration/apis/apm/feature_controls.ts index d2a66374fd2ff..7d2206e014c4d 100644 --- a/x-pack/test/api_integration/apis/apm/feature_controls.ts +++ b/x-pack/test/api_integration/apis/apm/feature_controls.ts @@ -207,12 +207,9 @@ export default function featureControlsTests({ getService }: FtrProviderContext) spaceId?: string; }) { for (const endpoint of endpoints) { - // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) - console.log(`Requesting: ${endpoint.req.url}`); - log.info(`Requesting: ${endpoint.req.url}`); + console.log(`Requesting: ${endpoint.req.url} ${endpoint.req.body}`); const result = await executeAsUser(endpoint.req, username, password, spaceId); console.log(`Responded: ${endpoint.req.url}`); - log.info(`Responded: ${endpoint.req.url}`); try { if (expectation === 'forbidden') { @@ -221,9 +218,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) endpoint.expectResponse(result); } } catch (e) { - // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) - console.log(`${endpoint.req.url} failed`); - log.warning(`${endpoint.req.url} failed`); + console.warn(`Expectation for endpoint: "${endpoint.req.url}" failed`); const { statusCode, body, req } = result.response; throw new Error( @@ -240,9 +235,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) describe('apm feature controls', () => { let res: any; before(async () => { - // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) console.log(`Creating agent configuration`); - log.info('Creating agent configuration'); res = await executeAsAdmin({ method: 'post', url: '/api/apm/settings/agent-configuration/new', @@ -251,13 +244,11 @@ export default function featureControlsTests({ getService }: FtrProviderContext) settings: { transaction_sample_rate: 0.5 }, }, }); - // TODO: Remove console.log. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) console.log(`Agent configuration created`); - log.info('Agent configuration created'); }); after(async () => { - log.info('deleting agent configuration'); + console.log('deleting agent configuration'); const configurationId = res.body._id; await executeAsAdmin({ method: 'delete', From 4c5818eb889ccd836361c61c9de1f1126160c8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv?= Date: Mon, 23 Dec 2019 23:03:19 +0100 Subject: [PATCH 3/4] Improve logging --- .../plugins/apm/server/routes/settings/agent_configuration.ts | 2 +- x-pack/test/api_integration/apis/apm/feature_controls.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts b/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts index 3afb95d16b0f5..ddd6a27025131 100644 --- a/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts +++ b/x-pack/legacy/plugins/apm/server/routes/settings/agent_configuration.ts @@ -121,7 +121,7 @@ export const createAgentConfigurationRoute = createRoute(() => ({ // TODO: Remove logger. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764) context.logger.info( - `Hitting: /api/apm/settings/agent-configuration/new with ${configuration}` + `Hitting: /api/apm/settings/agent-configuration/new with ${configuration.service.name}/${configuration.service.environment}` ); const res = await createOrUpdateConfiguration({ configuration, diff --git a/x-pack/test/api_integration/apis/apm/feature_controls.ts b/x-pack/test/api_integration/apis/apm/feature_controls.ts index 7d2206e014c4d..b831e14b4d2bd 100644 --- a/x-pack/test/api_integration/apis/apm/feature_controls.ts +++ b/x-pack/test/api_integration/apis/apm/feature_controls.ts @@ -207,7 +207,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) spaceId?: string; }) { for (const endpoint of endpoints) { - console.log(`Requesting: ${endpoint.req.url} ${endpoint.req.body}`); + console.log(`Requesting: ${endpoint.req.url}. Expecting: ${expectation}`); const result = await executeAsUser(endpoint.req, username, password, spaceId); console.log(`Responded: ${endpoint.req.url}`); From 6b2c9868bf20b7c04fc4556272cf3678127f45ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv?= Date: Tue, 24 Dec 2019 11:05:56 +0100 Subject: [PATCH 4/4] Log full index on error --- .../api_integration/apis/apm/feature_controls.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/apm/feature_controls.ts b/x-pack/test/api_integration/apis/apm/feature_controls.ts index b831e14b4d2bd..ec2bbca23ddd2 100644 --- a/x-pack/test/api_integration/apis/apm/feature_controls.ts +++ b/x-pack/test/api_integration/apis/apm/feature_controls.ts @@ -15,6 +15,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) const security = getService('security'); const spaces = getService('spaces'); const log = getService('log'); + const es = getService('legacyEs'); const start = encodeURIComponent(new Date(Date.now() - 10000).toISOString()); const end = encodeURIComponent(new Date().toISOString()); @@ -37,6 +38,7 @@ export default function featureControlsTests({ getService }: FtrProviderContext) }; expectForbidden: (result: any) => void; expectResponse: (result: any) => void; + onExpectationFail?: () => Promise; } const endpoints: Endpoint[] = [ { @@ -141,6 +143,13 @@ export default function featureControlsTests({ getService }: FtrProviderContext) }, expectForbidden: expect404, expectResponse: expect200, + onExpectationFail: async () => { + const res = await es.search({ + index: '.apm-agent-configuration', + }); + + console.warn(JSON.stringify(res, null, 2)); + }, }, ]; @@ -218,7 +227,9 @@ export default function featureControlsTests({ getService }: FtrProviderContext) endpoint.expectResponse(result); } } catch (e) { - console.warn(`Expectation for endpoint: "${endpoint.req.url}" failed`); + if (endpoint.onExpectationFail) { + await endpoint.onExpectationFail(); + } const { statusCode, body, req } = result.response; throw new Error(