-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[APM] Migrate service tests to deployment agnostic #199812
Changes from all commits
d527ffe
f064d73
cb3f6ba
8a44e4c
8daa3fa
3b7a444
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import { apm, timerange } from '@kbn/apm-synthtrace-client'; | |
import expect from '@kbn/expect'; | ||
import { omit } from 'lodash'; | ||
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; | ||
import type { RoleCredentials, SupertestWithRoleScopeType } from '../../../../services'; | ||
import type { RoleCredentials } from '../../../../services'; | ||
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; | ||
import { | ||
fetchServiceInventoryAlertCounts, | ||
|
@@ -24,7 +24,6 @@ import { | |
} from './helpers/alerting_helper'; | ||
|
||
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
const roleScopedSupertest = getService('roleScopedSupertest'); | ||
const apmApiClient = getService('apmApi'); | ||
const synthtrace = getService('synthtrace'); | ||
const alertingApi = getService('alertingApi'); | ||
|
@@ -43,18 +42,9 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon | |
|
||
describe('transaction duration alert', () => { | ||
let apmSynthtraceEsClient: ApmSynthtraceEsClient; | ||
let supertestViewerWithCookieCredentials: SupertestWithRoleScopeType; | ||
let roleAuthc: RoleCredentials; | ||
|
||
before(async () => { | ||
supertestViewerWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not used |
||
'viewer', | ||
{ | ||
withInternalHeaders: true, | ||
useCookieHeader: true, | ||
} | ||
); | ||
|
||
roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('admin'); | ||
|
||
const opbeansJava = apm | ||
|
@@ -86,7 +76,6 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon | |
|
||
after(async () => { | ||
await apmSynthtraceEsClient.clean(); | ||
await supertestViewerWithCookieCredentials.destroy(); | ||
await samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { apm, timerange } from '@kbn/apm-synthtrace-client'; | |
import expect from '@kbn/expect'; | ||
import { omit } from 'lodash'; | ||
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; | ||
import type { RoleCredentials, SupertestWithRoleScopeType } from '../../../../services'; | ||
import type { RoleCredentials } from '../../../../services'; | ||
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; | ||
import { | ||
fetchServiceInventoryAlertCounts, | ||
|
@@ -23,26 +23,16 @@ import { | |
} from './helpers/alerting_helper'; | ||
|
||
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
const roleScopedSupertest = getService('roleScopedSupertest'); | ||
const apmApiClient = getService('apmApi'); | ||
const synthtrace = getService('synthtrace'); | ||
const alertingApi = getService('alertingApi'); | ||
const samlAuth = getService('samlAuth'); | ||
|
||
describe('transaction error rate alert', () => { | ||
let apmSynthtraceEsClient: ApmSynthtraceEsClient; | ||
let supertestViewerWithCookieCredentials: SupertestWithRoleScopeType; | ||
let roleAuthc: RoleCredentials; | ||
|
||
before(async () => { | ||
supertestViewerWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not used |
||
'viewer', | ||
{ | ||
withInternalHeaders: true, | ||
useCookieHeader: true, | ||
} | ||
); | ||
|
||
roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('admin'); | ||
|
||
const opbeansJava = apm | ||
|
@@ -84,7 +74,6 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon | |
|
||
after(async () => { | ||
await apmSynthtraceEsClient.clean(); | ||
await supertestViewerWithCookieCredentials.destroy(); | ||
await samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,24 +7,20 @@ | |
|
||
type ArchiveName = | ||
| '8.0.0' | ||
| 'apm_8.0.0' | ||
| 'apm_mappings_only_8.0.0' | ||
| 'infra_metrics_and_apm' | ||
| 'metrics_8.0.0' | ||
| 'ml_8.0.0' | ||
| 'observability_overview' | ||
| 'rum_8.0.0' | ||
| 'rum_test_data'; | ||
|
||
export const ARCHIVER_ROUTES: { [key in ArchiveName]: string } = { | ||
'8.0.0': 'x-pack/test/apm_api_integration/common/fixtures/es_archiver/8.0.0', | ||
'apm_8.0.0': 'x-pack/test/apm_api_integration/common/fixtures/es_archiver/apm_8.0.0', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not supported on serverless |
||
'apm_mappings_only_8.0.0': | ||
'x-pack/test/apm_api_integration/common/fixtures/es_archiver/apm_mappings_only_8.0.0', | ||
infra_metrics_and_apm: | ||
'x-pack/test/apm_api_integration/common/fixtures/es_archiver/infra_metrics_and_apm', | ||
'metrics_8.0.0': 'x-pack/test/apm_api_integration/common/fixtures/es_archiver/metrics_8.0.0', | ||
'ml_8.0.0': 'x-pack/test/apm_api_integration/common/fixtures/es_archiver/ml_8.0.0', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not supported on serverless There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the future, we could create our deployment-agnostic archives to only have supported features/configurations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should actually go for synthtrace instead. Archives are prone to these kinds of problems. |
||
observability_overview: | ||
'x-pack/test/apm_api_integration/common/fixtures/es_archiver/observability_overview', | ||
'rum_8.0.0': 'x-pack/test/apm_api_integration/common/fixtures/es_archiver/rum_8.0.0', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import expect from '@kbn/expect'; | ||
import { ApmDocumentType } from '@kbn/apm-plugin/common/document_type'; | ||
import { RollupInterval } from '@kbn/apm-plugin/common/rollup'; | ||
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
const apmApiClient = getService('apmApi'); | ||
|
||
const start = '2021-10-01T00:00:00.000Z'; | ||
const end = '2021-10-01T01:00:00.000Z'; | ||
|
||
const serviceNames = ['opbeans-java', 'opbeans-go']; | ||
|
||
describe('Services detailed statistics', () => { | ||
describe('Services detailed statistics when data is not loaded', () => { | ||
it('handles the empty state', async () => { | ||
const response = await apmApiClient.readUser({ | ||
endpoint: `POST /internal/apm/services/detailed_statistics`, | ||
params: { | ||
query: { | ||
start, | ||
end, | ||
environment: 'ENVIRONMENT_ALL', | ||
kuery: '', | ||
offset: '1d', | ||
probability: 1, | ||
documentType: ApmDocumentType.TransactionMetric, | ||
rollupInterval: RollupInterval.OneMinute, | ||
bucketSizeInSeconds: 60, | ||
}, | ||
body: { | ||
serviceNames: JSON.stringify(serviceNames), | ||
}, | ||
}, | ||
}); | ||
|
||
expect(response.status).to.be(200); | ||
expect(response.body.currentPeriod).to.be.empty(); | ||
expect(response.body.previousPeriod).to.be.empty(); | ||
}); | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { APIReturnType } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; | ||
|
||
import { RoleCredentials } from '@kbn/ftr-common-functional-services'; | ||
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
export default function annotationApiTests({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
const apmApiClient = getService('apmApi'); | ||
const es = getService('es'); | ||
const samlAuth = getService('samlAuth'); | ||
|
||
const dates = [ | ||
new Date('2021-02-01T00:00:00.000Z'), | ||
new Date('2021-02-01T01:00:00.000Z'), | ||
new Date('2021-02-01T02:00:00.000Z'), | ||
new Date('2021-02-01T03:00:00.000Z'), | ||
]; | ||
|
||
const indexName = 'apm-8.0.0-transaction'; | ||
|
||
describe('Derived deployment annotations', () => { | ||
describe('when there are multiple service versions', () => { | ||
let roleAuthc: RoleCredentials; | ||
let response: APIReturnType<'GET /api/apm/services/{serviceName}/annotation/search 2023-10-31'>; | ||
|
||
before(async () => { | ||
roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('viewer'); | ||
const indexExists = await es.indices.exists({ index: indexName }); | ||
if (indexExists) { | ||
await es.indices.delete({ | ||
index: indexName, | ||
}); | ||
} | ||
|
||
await es.indices.create({ | ||
index: indexName, | ||
body: { | ||
mappings: { | ||
properties: { | ||
service: { | ||
properties: { | ||
name: { | ||
type: 'keyword', | ||
}, | ||
version: { | ||
type: 'keyword', | ||
}, | ||
environment: { | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
transaction: { | ||
properties: { | ||
type: { | ||
type: 'keyword', | ||
}, | ||
duration: { | ||
type: 'long', | ||
}, | ||
}, | ||
}, | ||
processor: { | ||
properties: { | ||
event: { | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const docs = dates.flatMap((date, index) => { | ||
const baseAnnotation = { | ||
transaction: { | ||
type: 'request', | ||
duration: 1000000, | ||
}, | ||
|
||
service: { | ||
name: 'opbeans-java', | ||
environment: 'production', | ||
version: index + 1, | ||
}, | ||
processor: { | ||
event: 'transaction', | ||
}, | ||
}; | ||
return [ | ||
{ | ||
...baseAnnotation, | ||
'@timestamp': date.toISOString(), | ||
}, | ||
{ | ||
...baseAnnotation, | ||
'@timestamp': new Date(date.getTime() + 30000), | ||
}, | ||
{ | ||
...baseAnnotation, | ||
'@timestamp': new Date(date.getTime() + 60000), | ||
}, | ||
]; | ||
}); | ||
|
||
await es.bulk({ | ||
index: indexName, | ||
body: docs.flatMap((doc) => [{ index: {} }, doc]), | ||
refresh: true, | ||
}); | ||
|
||
response = ( | ||
await apmApiClient.readUser({ | ||
endpoint: 'GET /api/apm/services/{serviceName}/annotation/search 2023-10-31', | ||
params: { | ||
path: { | ||
serviceName: 'opbeans-java', | ||
}, | ||
query: { | ||
start: dates[1].toISOString(), | ||
end: dates[2].toISOString(), | ||
environment: 'production', | ||
}, | ||
}, | ||
roleAuthc, | ||
}) | ||
).body; | ||
}); | ||
|
||
after(async () => { | ||
await es.indices.delete({ | ||
index: indexName, | ||
}); | ||
await samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc); | ||
}); | ||
|
||
it('annotations are displayed for the service versions in the given time range', async () => { | ||
expect(response.annotations.length).to.be(2); | ||
expect(response.annotations[0]['@timestamp']).to.be(dates[1].getTime()); | ||
expect(response.annotations[1]['@timestamp']).to.be(dates[2].getTime()); | ||
|
||
expectSnapshot(response.annotations[0]).toMatchInline(` | ||
Object { | ||
"@timestamp": 1612141200000, | ||
"id": "2", | ||
"text": "2", | ||
"type": "version", | ||
} | ||
`); | ||
}); | ||
|
||
it('annotations are not displayed for the service versions outside of the given time range', () => { | ||
expect( | ||
response.annotations.some((annotation) => { | ||
return ( | ||
annotation['@timestamp'] !== dates[0].getTime() && | ||
annotation['@timestamp'] !== dates[2].getTime() | ||
); | ||
}) | ||
); | ||
}); | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used