-
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] switch get environment function to use terms_enum api (#150175)
Fixes #144544 ## Summary To get the list of Environments, aggregation was used on search api. With this change, list of environments will now be retrieved using the [Terms Enum API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-terms-enum.html#search-terms-enum) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
c3bab3e
commit 0648296
Showing
6 changed files
with
210 additions
and
20 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
67 changes: 67 additions & 0 deletions
67
x-pack/test/apm_api_integration/tests/environment/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,67 @@ | ||
/* | ||
* 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'; | ||
|
||
// Generate synthetic data for the environment test suite | ||
export async function generateData({ | ||
synthtraceEsClient, | ||
start, | ||
end, | ||
}: { | ||
synthtraceEsClient: ApmSynthtraceEsClient; | ||
start: number; | ||
end: number; | ||
}) { | ||
const environmentNames = ['production', 'development', 'staging']; | ||
const serviceNames = ['go', 'java', 'node']; | ||
|
||
const services = environmentNames.flatMap((environment) => { | ||
return serviceNames.flatMap((serviceName) => { | ||
return apm | ||
.service({ | ||
name: serviceName, | ||
environment, | ||
agentName: serviceName, | ||
}) | ||
.instance('instance-a'); | ||
}); | ||
}); | ||
|
||
const goServiceWithAdditionalEnvironment = apm | ||
.service({ | ||
name: 'go', | ||
environment: 'custom-go-environment', | ||
agentName: 'go', | ||
}) | ||
.instance('instance-a'); | ||
|
||
// Generate a transaction for each service | ||
const docs = timerange(start, end) | ||
.ratePerMinute(1) | ||
.generator((timestamp) => { | ||
const loopGeneratedDocs = services.flatMap((service) => { | ||
return service | ||
.transaction({ transactionName: 'GET /api/product/:id' }) | ||
.timestamp(timestamp) | ||
.duration(1000); | ||
}); | ||
|
||
const customDoc = goServiceWithAdditionalEnvironment | ||
.transaction({ | ||
transactionName: 'GET /api/go/memory', | ||
transactionType: 'custom-go-type', | ||
}) | ||
.timestamp(timestamp) | ||
.duration(1000); | ||
|
||
return [...loopGeneratedDocs, customDoc]; | ||
}); | ||
|
||
await synthtraceEsClient.index(docs); | ||
} |
94 changes: 94 additions & 0 deletions
94
x-pack/test/apm_api_integration/tests/environment/get_environment.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,94 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../common/ftr_provider_context'; | ||
import { generateData } from './generate_data'; | ||
|
||
const startNumber = new Date('2021-01-01T00:00:00.000Z').getTime(); | ||
const endNumber = new Date('2021-01-01T00:05:00.000Z').getTime() - 1; | ||
|
||
const start = new Date(startNumber).toISOString(); | ||
const end = new Date(endNumber).toISOString(); | ||
|
||
export default function environmentsAPITests({ getService }: FtrProviderContext) { | ||
const registry = getService('registry'); | ||
const apmApiClient = getService('apmApiClient'); | ||
const synthtraceEsClient = getService('synthtraceEsClient'); | ||
|
||
registry.when('environments when data is loaded', { config: 'basic', archives: [] }, async () => { | ||
before(async () => { | ||
await generateData({ | ||
synthtraceEsClient, | ||
start: startNumber, | ||
end: endNumber, | ||
}); | ||
}); | ||
|
||
after(() => synthtraceEsClient.clean()); | ||
|
||
describe('get environments', () => { | ||
describe('when service name is not specified', () => { | ||
it('returns all environments', async () => { | ||
const { body } = await apmApiClient.readUser({ | ||
endpoint: 'GET /internal/apm/environments', | ||
params: { | ||
query: { start, end }, | ||
}, | ||
}); | ||
expect(body.environments.length).to.be.equal(4); | ||
expectSnapshot(body.environments).toMatchInline(` | ||
Array [ | ||
"development", | ||
"production", | ||
"staging", | ||
"custom-go-environment", | ||
] | ||
`); | ||
}); | ||
}); | ||
|
||
describe('when service name is specified', () => { | ||
it('returns service specific environments for go', async () => { | ||
const { body } = await apmApiClient.readUser({ | ||
endpoint: 'GET /internal/apm/environments', | ||
params: { | ||
query: { start, end, serviceName: 'go' }, | ||
}, | ||
}); | ||
|
||
expect(body.environments.length).to.be.equal(4); | ||
expectSnapshot(body.environments).toMatchInline(` | ||
Array [ | ||
"custom-go-environment", | ||
"development", | ||
"production", | ||
"staging", | ||
] | ||
`); | ||
}); | ||
|
||
it('returns service specific environments for java', async () => { | ||
const { body } = await apmApiClient.readUser({ | ||
endpoint: 'GET /internal/apm/environments', | ||
params: { | ||
query: { start, end, serviceName: 'java' }, | ||
}, | ||
}); | ||
|
||
expect(body.environments.length).to.be.equal(3); | ||
expectSnapshot(body.environments).toMatchInline(` | ||
Array [ | ||
"development", | ||
"production", | ||
"staging", | ||
] | ||
`); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |