-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Migrate service tests to deployment agnostic (#199812)
## Summary Closes #198988 Part of #193245 This PR contains the changes to migrate `service` test folder to Deployment-agnostic testing strategy. >[!NOTE] > `top_services.spec.ts` and `throughput.spec.ts` were partially migrated and `annotations.spec.ts` was not migrated ### How to test - Serverless ``` node scripts/functional_tests_server --config x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts node scripts/functional_test_runner --config x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts --grep="APM" ``` It's recommended to be run against [MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki) - Stateful ``` node scripts/functional_tests_server --config x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts node scripts/functional_test_runner --config x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts --grep="APM" ``` - [ ] ~(OPTIONAL, only if a test has been unskipped) Run flaky test suite~ - [x] local run for serverless - [x] local run for stateful - [x] MKI run for serverless --------- Co-authored-by: Sergi Romeu <[email protected]>
- Loading branch information
1 parent
671ff30
commit 2e9926d
Showing
33 changed files
with
1,634 additions
and
1,634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
49 changes: 49 additions & 0 deletions
49
...ent_agnostic/apis/observability/apm/services/archive_services_detailed_statistics.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
} |
172 changes: 172 additions & 0 deletions
172
...tegration/deployment_agnostic/apis/observability/apm/services/derived_annotations.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
}) | ||
); | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.