-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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_groups API tests to be deployment-agnostic #199988
Merged
iblancof
merged 3 commits into
elastic:main
from
iblancof:198982-apm-migrate-test-apm_api_integration-tests-service_groups-to-be-deployment-agnostic-api-tests
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 18 additions & 0 deletions
18
...k/test/api_integration/deployment_agnostic/apis/observability/apm/service_groups/index.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,18 @@ | ||
/* | ||
* 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 { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) { | ||
describe('service_groups', () => { | ||
loadTestFile(require.resolve('./save_service_group.spec.ts')); | ||
loadTestFile( | ||
require.resolve('./service_group_with_overflow/service_group_with_overflow.spec.ts') | ||
); | ||
loadTestFile(require.resolve('./service_group_count/service_group_count.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
74 changes: 74 additions & 0 deletions
74
...yment_agnostic/apis/observability/apm/service_groups/service_group_count/generate_data.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,74 @@ | ||
/* | ||
* 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 { apm, timerange } from '@kbn/apm-synthtrace-client'; | ||
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; | ||
|
||
export async function generateData({ | ||
apmSynthtraceEsClient, | ||
start, | ||
end, | ||
}: { | ||
apmSynthtraceEsClient: ApmSynthtraceEsClient; | ||
start: number; | ||
end: number; | ||
}) { | ||
const synthServices = [ | ||
apm | ||
.service({ name: 'synth-go', environment: 'testing', agentName: 'go' }) | ||
.instance('instance-1'), | ||
apm | ||
.service({ name: 'synth-java', environment: 'testing', agentName: 'java' }) | ||
.instance('instance-2'), | ||
apm | ||
.service({ name: 'opbeans-node', environment: 'testing', agentName: 'nodejs' }) | ||
.instance('instance-3'), | ||
]; | ||
|
||
await apmSynthtraceEsClient.index( | ||
synthServices.map((service) => | ||
timerange(start, end) | ||
.interval('5m') | ||
.rate(1) | ||
.generator((timestamp) => | ||
service | ||
.transaction({ | ||
transactionName: 'GET /api/product/list', | ||
transactionType: 'request', | ||
}) | ||
.duration(2000) | ||
.timestamp(timestamp) | ||
.children( | ||
service | ||
.span({ | ||
spanName: '/_search', | ||
spanType: 'db', | ||
spanSubtype: 'elasticsearch', | ||
}) | ||
.destination('elasticsearch') | ||
.duration(100) | ||
.success() | ||
.timestamp(timestamp), | ||
service | ||
.span({ | ||
spanName: '/_search', | ||
spanType: 'db', | ||
spanSubtype: 'elasticsearch', | ||
}) | ||
.destination('elasticsearch') | ||
.duration(300) | ||
.success() | ||
.timestamp(timestamp) | ||
) | ||
.errors( | ||
service.error({ message: 'error 1', type: 'foo' }).timestamp(timestamp), | ||
service.error({ message: 'error 2', type: 'foo' }).timestamp(timestamp), | ||
service.error({ message: 'error 3', type: 'bar' }).timestamp(timestamp) | ||
) | ||
) | ||
) | ||
); | ||
} |
63 changes: 63 additions & 0 deletions
63
...tic/apis/observability/apm/service_groups/service_group_count/service_group_count.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,63 @@ | ||
/* | ||
* 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 { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; | ||
import { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context'; | ||
import { | ||
createServiceGroupApi, | ||
deleteAllServiceGroups, | ||
getServiceGroupCounts, | ||
} from '../service_groups_api_methods'; | ||
import { generateData } from './generate_data'; | ||
|
||
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
const synthtrace = getService('synthtrace'); | ||
const apmApiClient = getService('apmApi'); | ||
const start = Date.now() - 24 * 60 * 60 * 1000; | ||
const end = Date.now(); | ||
|
||
describe('Service group counts', () => { | ||
let synthbeansServiceGroupId: string; | ||
let opbeansServiceGroupId: string; | ||
let apmSynthtraceEsClient: ApmSynthtraceEsClient; | ||
|
||
before(async () => { | ||
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); | ||
|
||
const [, { body: synthbeansServiceGroup }, { body: opbeansServiceGroup }] = await Promise.all( | ||
[ | ||
generateData({ start, end, apmSynthtraceEsClient }), | ||
createServiceGroupApi({ | ||
apmApiClient, | ||
groupName: 'synthbeans', | ||
kuery: 'service.name: synth*', | ||
}), | ||
createServiceGroupApi({ | ||
apmApiClient, | ||
groupName: 'opbeans', | ||
kuery: 'service.name: opbeans*', | ||
}), | ||
] | ||
); | ||
synthbeansServiceGroupId = synthbeansServiceGroup.id; | ||
opbeansServiceGroupId = opbeansServiceGroup.id; | ||
}); | ||
|
||
after(async () => { | ||
await deleteAllServiceGroups(apmApiClient); | ||
await apmSynthtraceEsClient.clean(); | ||
}); | ||
|
||
it('returns the correct number of services', async () => { | ||
const response = await getServiceGroupCounts(apmApiClient); | ||
expect(response.status).to.be(200); | ||
expect(Object.keys(response.body).length).to.be(2); | ||
expect(response.body[synthbeansServiceGroupId]).to.have.property('services', 2); | ||
expect(response.body[opbeansServiceGroupId]).to.have.property('services', 1); | ||
}); | ||
}); | ||
} |
File renamed without changes.
File renamed without changes.
104 changes: 104 additions & 0 deletions
104
...bility/apm/service_groups/service_group_with_overflow/service_group_with_overflow.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,104 @@ | ||
/* | ||
* 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 { ValuesType } from 'utility-types'; | ||
import { ENVIRONMENT_ALL } from '@kbn/apm-plugin/common/environment_filter_values'; | ||
import { ApmDocumentType } from '@kbn/apm-plugin/common/document_type'; | ||
import { RollupInterval } from '@kbn/apm-plugin/common/rollup'; | ||
import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; | ||
import { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context'; | ||
import { createServiceGroupApi, deleteAllServiceGroups } from '../service_groups_api_methods'; | ||
import { createServiceTransactionMetricsDocs } from './es_utils'; | ||
import { generateData } from './generate_data'; | ||
|
||
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
const apmApiClient = getService('apmApi'); | ||
const es = getService('es'); | ||
const synthtrace = getService('synthtrace'); | ||
|
||
describe('Display overflow bucket in Service Groups', () => { | ||
const indexName = 'metrics-apm.service_transaction.1m-default'; | ||
const start = '2023-06-21T06:50:15.910Z'; | ||
const end = '2023-06-21T06:59:15.910Z'; | ||
const startTime = new Date(start).getTime() + 1000; | ||
const OVERFLOW_SERVICE_NAME = '_other'; | ||
let serviceGroupId: string; | ||
let apmSynthtraceEsClient: ApmSynthtraceEsClient; | ||
|
||
after(async () => { | ||
await deleteAllServiceGroups(apmApiClient); | ||
await apmSynthtraceEsClient.clean(); | ||
}); | ||
|
||
before(async () => { | ||
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); | ||
|
||
await generateData({ start, end, apmSynthtraceEsClient }); | ||
|
||
const docs = [ | ||
createServiceTransactionMetricsDocs({ | ||
time: startTime, | ||
service: { | ||
name: OVERFLOW_SERVICE_NAME, | ||
}, | ||
overflowCount: 13, | ||
}), | ||
]; | ||
|
||
const bulkActions = docs.reduce( | ||
(prev, doc) => { | ||
return [...prev, { create: { _index: indexName } }, doc]; | ||
}, | ||
[] as Array< | ||
| { | ||
create: { | ||
_index: string; | ||
}; | ||
} | ||
| ValuesType<typeof docs> | ||
> | ||
); | ||
|
||
await es.bulk({ | ||
body: bulkActions, | ||
refresh: 'wait_for', | ||
}); | ||
|
||
const serviceGroup = { | ||
groupName: 'overflowGroup', | ||
kuery: 'service.name: synth-go or service.name: synth-java', | ||
}; | ||
const createResponse = await createServiceGroupApi({ apmApiClient, ...serviceGroup }); | ||
expect(createResponse.status).to.be(200); | ||
serviceGroupId = createResponse.body.id; | ||
}); | ||
|
||
it('get the overflow bucket even though its not added explicitly in the Service Group', async () => { | ||
const response = await apmApiClient.readUser({ | ||
endpoint: `GET /internal/apm/services`, | ||
params: { | ||
query: { | ||
start, | ||
end, | ||
environment: ENVIRONMENT_ALL.value, | ||
kuery: '', | ||
serviceGroup: serviceGroupId, | ||
probability: 1, | ||
documentType: ApmDocumentType.ServiceTransactionMetric, | ||
rollupInterval: RollupInterval.OneMinute, | ||
useDurationSummary: true, | ||
}, | ||
}, | ||
}); | ||
|
||
const overflowBucket = response.body.items.find( | ||
(service) => service.serviceName === OVERFLOW_SERVICE_NAME | ||
); | ||
expect(overflowBucket?.serviceName).to.equal(OVERFLOW_SERVICE_NAME); | ||
}); | ||
}); | ||
} |
66 changes: 66 additions & 0 deletions
66
...n/deployment_agnostic/apis/observability/apm/service_groups/service_groups_api_methods.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,66 @@ | ||
/* | ||
* 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 { ApmApiClient } from '../../../../services/apm_api'; | ||
|
||
export async function getServiceGroupsApi(apmApiClient: ApmApiClient) { | ||
return apmApiClient.writeUser({ | ||
endpoint: 'GET /internal/apm/service-groups', | ||
}); | ||
} | ||
|
||
export async function createServiceGroupApi({ | ||
apmApiClient, | ||
serviceGroupId, | ||
groupName, | ||
kuery, | ||
description, | ||
color, | ||
}: { | ||
apmApiClient: ApmApiClient; | ||
serviceGroupId?: string; | ||
groupName: string; | ||
kuery: string; | ||
description?: string; | ||
color?: string; | ||
}) { | ||
const response = await apmApiClient.writeUser({ | ||
endpoint: 'POST /internal/apm/service-group', | ||
params: { | ||
query: { | ||
serviceGroupId, | ||
}, | ||
body: { | ||
groupName, | ||
kuery, | ||
description, | ||
color, | ||
}, | ||
}, | ||
}); | ||
return response; | ||
} | ||
|
||
export async function getServiceGroupCounts(apmApiClient: ApmApiClient) { | ||
return apmApiClient.readUser({ | ||
endpoint: 'GET /internal/apm/service-group/counts', | ||
}); | ||
} | ||
|
||
export async function deleteAllServiceGroups(apmApiClient: ApmApiClient) { | ||
return await getServiceGroupsApi(apmApiClient).then((response) => { | ||
const promises = response.body.serviceGroups.map((item) => { | ||
if (item.id) { | ||
return apmApiClient.writeUser({ | ||
endpoint: 'DELETE /internal/apm/service-group', | ||
params: { query: { serviceGroupId: item.id } }, | ||
}); | ||
} | ||
}); | ||
return Promise.all(promises); | ||
}); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It can't be migrated because it uses the
.alert-*
index as stated in #193245 (comment).