-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[APM] Migrate /service_maps to deployment agnostic test
#199984
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
Merged
rmyz
merged 8 commits into
elastic:main
from
rmyz:198983-apm-migrate-service_maps-tests
Nov 18, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6baacef
test: migrate service_maps to deployment agnostic test
rmyz aedf831
Merge branch 'main' into 198983-apm-migrate-service_maps-tests
rmyz 475d954
refactor: fix import
rmyz 687b168
Merge branch 'main' into 198983-apm-migrate-service_maps-tests
rmyz 2e23cb0
Merge branch 'main' into 198983-apm-migrate-service_maps-tests
rmyz 438c5e3
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine 313ca15
Merge branch 'main' into 198983-apm-migrate-service_maps-tests
rmyz c1ecba7
Merge branch 'main' into 198983-apm-migrate-service_maps-tests
rmyz 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 hidden or 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
15 changes: 15 additions & 0 deletions
15
x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_maps/index.ts
This file contains hidden or 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,15 @@ | ||
| /* | ||
| * 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_maps', () => { | ||
| loadTestFile(require.resolve('./service_maps.spec.ts')); | ||
| loadTestFile(require.resolve('./service_maps_kuery_filter.spec.ts')); | ||
| }); | ||
| } |
156 changes: 156 additions & 0 deletions
156
..._integration/deployment_agnostic/apis/observability/apm/service_maps/service_maps.spec.ts
This file contains hidden or 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,156 @@ | ||
| /* | ||
| * 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 type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; | ||
| import expect from 'expect'; | ||
| import { serviceMap, timerange } from '@kbn/apm-synthtrace-client'; | ||
| import { Readable } from 'node:stream'; | ||
| import type { SupertestReturnType } from '../../../../../../apm_api_integration/common/apm_api_supertest'; | ||
| import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
|
||
| type DependencyResponse = SupertestReturnType<'GET /internal/apm/service-map/dependency'>; | ||
| type ServiceNodeResponse = | ||
| SupertestReturnType<'GET /internal/apm/service-map/service/{serviceName}'>; | ||
|
|
||
| export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
| const apmApiClient = getService('apmApi'); | ||
| const synthtrace = getService('synthtrace'); | ||
|
|
||
| const start = new Date('2024-06-01T00:00:00.000Z').getTime(); | ||
| const end = new Date('2024-06-01T00:01:00.000Z').getTime(); | ||
|
|
||
| describe('APM Service maps', () => { | ||
| describe('without data', () => { | ||
| it('returns an empty list', async () => { | ||
| const response = await apmApiClient.readUser({ | ||
| endpoint: `GET /internal/apm/service-map`, | ||
| params: { | ||
| query: { | ||
| start: new Date(start).toISOString(), | ||
| end: new Date(end).toISOString(), | ||
| environment: 'ENVIRONMENT_ALL', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.body.elements.length).toBe(0); | ||
| }); | ||
|
|
||
| describe('/internal/apm/service-map/service/{serviceName} without data', () => { | ||
| let response: ServiceNodeResponse; | ||
| before(async () => { | ||
| response = await apmApiClient.readUser({ | ||
| endpoint: `GET /internal/apm/service-map/service/{serviceName}`, | ||
| params: { | ||
| path: { serviceName: 'opbeans-node' }, | ||
| query: { | ||
| start: new Date(start).toISOString(), | ||
| end: new Date(end).toISOString(), | ||
| environment: 'ENVIRONMENT_ALL', | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('retuns status code 200', () => { | ||
| expect(response.status).toBe(200); | ||
| }); | ||
|
|
||
| it('returns an object with nulls', async () => { | ||
| [ | ||
| response.body.currentPeriod?.failedTransactionsRate?.value, | ||
| response.body.currentPeriod?.memoryUsage?.value, | ||
| response.body.currentPeriod?.cpuUsage?.value, | ||
| response.body.currentPeriod?.transactionStats?.latency?.value, | ||
| response.body.currentPeriod?.transactionStats?.throughput?.value, | ||
| ].forEach((value) => { | ||
| expect(value).toEqual(null); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('/internal/apm/service-map/dependency', () => { | ||
| let response: DependencyResponse; | ||
| before(async () => { | ||
| response = await apmApiClient.readUser({ | ||
| endpoint: `GET /internal/apm/service-map/dependency`, | ||
| params: { | ||
| query: { | ||
| dependencyName: 'postgres', | ||
| start: new Date(start).toISOString(), | ||
| end: new Date(end).toISOString(), | ||
| environment: 'ENVIRONMENT_ALL', | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('retuns status code 200', () => { | ||
| expect(response.status).toBe(200); | ||
| }); | ||
|
|
||
| it('returns undefined values', () => { | ||
| expect(response.body.currentPeriod).toEqual({ transactionStats: {} }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with synthtrace data', () => { | ||
| let synthtraceEsClient: ApmSynthtraceEsClient; | ||
|
|
||
| before(async () => { | ||
| synthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); | ||
|
|
||
| const events = timerange(start, end) | ||
| .interval('10s') | ||
| .rate(3) | ||
| .generator( | ||
| serviceMap({ | ||
| services: [ | ||
| { 'frontend-rum': 'rum-js' }, | ||
| { 'frontend-node': 'nodejs' }, | ||
| { advertService: 'java' }, | ||
| ], | ||
| definePaths([rum, node, adv]) { | ||
| return [ | ||
| [ | ||
| [rum, 'fetchAd'], | ||
| [node, 'GET /nodejs/adTag'], | ||
| [adv, 'APIRestController#getAd'], | ||
| ['elasticsearch', 'GET ad-*/_search'], | ||
| ], | ||
| ]; | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| return synthtraceEsClient.index(Readable.from(Array.from(events))); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await synthtraceEsClient.clean(); | ||
| }); | ||
|
|
||
| it('returns service map elements', async () => { | ||
| const response = await apmApiClient.readUser({ | ||
| endpoint: 'GET /internal/apm/service-map', | ||
| params: { | ||
| query: { | ||
| start: new Date(start).toISOString(), | ||
| end: new Date(end).toISOString(), | ||
| environment: 'ENVIRONMENT_ALL', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.body.elements.length).toBeGreaterThan(0); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
137 changes: 137 additions & 0 deletions
137
...deployment_agnostic/apis/observability/apm/service_maps/service_maps_kuery_filter.spec.ts
This file contains hidden or 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,137 @@ | ||
| /* | ||
| * 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 { timerange, serviceMap } from '@kbn/apm-synthtrace-client'; | ||
| import { | ||
| APIClientRequestParamsOf, | ||
| APIReturnType, | ||
| } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; | ||
| import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; | ||
| import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; | ||
| import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
|
||
| export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
| const apmApiClient = getService('apmApi'); | ||
| const synthtrace = getService('synthtrace'); | ||
|
|
||
| const start = new Date('2023-01-01T00:00:00.000Z').getTime(); | ||
| const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; | ||
|
|
||
| async function callApi( | ||
| overrides?: RecursivePartial< | ||
| APIClientRequestParamsOf<'GET /internal/apm/service-map'>['params'] | ||
| > | ||
| ) { | ||
| return await apmApiClient.readUser({ | ||
| endpoint: 'GET /internal/apm/service-map', | ||
| params: { | ||
| query: { | ||
| start: new Date(start).toISOString(), | ||
| end: new Date(end).toISOString(), | ||
| environment: 'ENVIRONMENT_ALL', | ||
| kuery: '', | ||
| ...overrides?.query, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| describe('service map kuery filter', () => { | ||
| let apmSynthtraceEsClient: ApmSynthtraceEsClient; | ||
|
|
||
| before(async () => { | ||
| apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); | ||
|
|
||
| const events = timerange(start, end) | ||
| .interval('15m') | ||
| .rate(1) | ||
| .generator( | ||
| serviceMap({ | ||
| services: [ | ||
| { 'synthbeans-go': 'go' }, | ||
| { 'synthbeans-java': 'java' }, | ||
| { 'synthbeans-node': 'nodejs' }, | ||
| ], | ||
| definePaths([go, java, node]) { | ||
| return [ | ||
| [go, java], | ||
| [java, go, 'redis'], | ||
| [node, 'redis'], | ||
| { | ||
| path: [node, java, go, 'elasticsearch'], | ||
| transaction: (t) => t.defaults({ 'labels.name': 'node-java-go-es' }), | ||
| }, | ||
| [go, node, java], | ||
| ]; | ||
| }, | ||
| }) | ||
| ); | ||
| await apmSynthtraceEsClient.index(events); | ||
| }); | ||
|
|
||
| after(() => apmSynthtraceEsClient.clean()); | ||
|
|
||
| it('returns full service map when no kuery is defined', async () => { | ||
| const { status, body } = await callApi(); | ||
|
|
||
| expect(status).to.be(200); | ||
|
|
||
| const { nodes, edges } = partitionElements(body.elements); | ||
|
|
||
| expect(getIds(nodes)).to.eql([ | ||
| '>elasticsearch', | ||
| '>redis', | ||
| 'synthbeans-go', | ||
| 'synthbeans-java', | ||
| 'synthbeans-node', | ||
| ]); | ||
| expect(getIds(edges)).to.eql([ | ||
| 'synthbeans-go~>elasticsearch', | ||
| 'synthbeans-go~>redis', | ||
| 'synthbeans-go~synthbeans-java', | ||
| 'synthbeans-go~synthbeans-node', | ||
| 'synthbeans-java~synthbeans-go', | ||
| 'synthbeans-node~>redis', | ||
| 'synthbeans-node~synthbeans-java', | ||
| ]); | ||
| }); | ||
|
|
||
| it('returns only service nodes and connections filtered by given kuery', async () => { | ||
| const { status, body } = await callApi({ | ||
| query: { kuery: `labels.name: "node-java-go-es"` }, | ||
| }); | ||
|
|
||
| expect(status).to.be(200); | ||
|
|
||
| const { nodes, edges } = partitionElements(body.elements); | ||
|
|
||
| expect(getIds(nodes)).to.eql([ | ||
| '>elasticsearch', | ||
| 'synthbeans-go', | ||
| 'synthbeans-java', | ||
| 'synthbeans-node', | ||
| ]); | ||
| expect(getIds(edges)).to.eql([ | ||
| 'synthbeans-go~>elasticsearch', | ||
| 'synthbeans-java~synthbeans-go', | ||
| 'synthbeans-node~synthbeans-java', | ||
| ]); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| type ConnectionElements = APIReturnType<'GET /internal/apm/service-map'>['elements']; | ||
|
|
||
| function partitionElements(elements: ConnectionElements) { | ||
| const edges = elements.filter(({ data }) => 'source' in data && 'target' in data); | ||
| const nodes = elements.filter((element) => !edges.includes(element)); | ||
| return { edges, nodes }; | ||
| } | ||
|
|
||
| function getIds(elements: ConnectionElements) { | ||
| return elements.map(({ data }) => data.id).sort(); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.