forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Migrate
/entities
to deployment agnostic test (elastic#199579)
## Summary Closes elastic#198968 Part of elastic#193245 This PR contains the changes to migrate `entities` test folder to Deployment-agnostic testing strategy. ### 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" ``` ## Checks - [ ] (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
- Loading branch information
1 parent
38b0cc4
commit 166d4e9
Showing
5 changed files
with
220 additions
and
196 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/entities/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,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('entities', () => { | ||
loadTestFile(require.resolve('./service_logs_error_rate_timeseries.spec.ts')); | ||
loadTestFile(require.resolve('./service_logs_rate_timeseries.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
180 changes: 180 additions & 0 deletions
180
.../deployment_agnostic/apis/observability/apm/entities/service_logs_rate_timeseries.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,180 @@ | ||
/* | ||
* 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 { log, timerange } from '@kbn/apm-synthtrace-client'; | ||
import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; | ||
import { APIClientRequestParamsOf } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; | ||
import { first, last } from 'lodash'; | ||
import { LogsSynthtraceEsClient } 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 serviceName = 'synth-go'; | ||
const start = new Date('2024-01-01T00:00:00.000Z').getTime(); | ||
const end = new Date('2024-01-01T00:15:00.000Z').getTime() - 1; | ||
|
||
const hostName = 'synth-host'; | ||
|
||
async function getLogsRateTimeseries( | ||
overrides?: RecursivePartial< | ||
APIClientRequestParamsOf<'GET /internal/apm/entities/services/{serviceName}/logs_rate_timeseries'>['params'] | ||
> | ||
) { | ||
const response = await apmApiClient.readUser({ | ||
endpoint: 'GET /internal/apm/entities/services/{serviceName}/logs_rate_timeseries', | ||
params: { | ||
path: { | ||
serviceName: 'synth-go', | ||
...overrides?.path, | ||
}, | ||
query: { | ||
start: new Date(start).toISOString(), | ||
end: new Date(end).toISOString(), | ||
environment: 'ENVIRONMENT_ALL', | ||
kuery: '', | ||
...overrides?.query, | ||
}, | ||
}, | ||
}); | ||
return response; | ||
} | ||
describe('logs rate timeseries', () => { | ||
describe('when data is not loaded', () => { | ||
it('handles empty state', async () => { | ||
const response = await getLogsRateTimeseries(); | ||
expect(response.status).to.be(200); | ||
expect(response.body.currentPeriod).to.empty(); | ||
}); | ||
}); | ||
|
||
describe('when data loaded', () => { | ||
let logSynthtrace: LogsSynthtraceEsClient; | ||
|
||
before(async () => { | ||
logSynthtrace = await synthtrace.createLogsSynthtraceEsClient(); | ||
}); | ||
|
||
after(async () => { | ||
await logSynthtrace.clean(); | ||
}); | ||
|
||
describe('Logs without log level field', () => { | ||
before(async () => { | ||
return logSynthtrace.index([ | ||
timerange(start, end) | ||
.interval('1m') | ||
.rate(1) | ||
.generator((timestamp) => | ||
log.create().message('This is a log message').timestamp(timestamp).defaults({ | ||
'log.file.path': '/my-service.log', | ||
'service.name': serviceName, | ||
'host.name': hostName, | ||
}) | ||
), | ||
]); | ||
}); | ||
after(async () => { | ||
await logSynthtrace.clean(); | ||
}); | ||
|
||
it('returns {} if log level is not available ', async () => { | ||
const response = await getLogsRateTimeseries(); | ||
expect(response.status).to.be(200); | ||
}); | ||
}); | ||
|
||
describe('Logs with log.level=error', () => { | ||
before(async () => { | ||
return logSynthtrace.index([ | ||
timerange(start, end) | ||
.interval('1m') | ||
.rate(1) | ||
.generator((timestamp) => | ||
log | ||
.create() | ||
.message('This is a log message') | ||
.logLevel('error') | ||
.timestamp(timestamp) | ||
.defaults({ | ||
'log.file.path': '/my-service.log', | ||
'service.name': serviceName, | ||
'host.name': hostName, | ||
'service.environment': 'test', | ||
}) | ||
), | ||
timerange(start, end) | ||
.interval('2m') | ||
.rate(1) | ||
.generator((timestamp) => | ||
log | ||
.create() | ||
.message('This is an error log message') | ||
.logLevel('error') | ||
.timestamp(timestamp) | ||
.defaults({ | ||
'log.file.path': '/my-service.log', | ||
'service.name': 'my-service', | ||
'host.name': hostName, | ||
'service.environment': 'production', | ||
}) | ||
), | ||
timerange(start, end) | ||
.interval('5m') | ||
.rate(1) | ||
.generator((timestamp) => | ||
log | ||
.create() | ||
.message('This is an info message') | ||
.logLevel('info') | ||
.timestamp(timestamp) | ||
.defaults({ | ||
'log.file.path': '/my-service.log', | ||
'service.name': 'my-service', | ||
'host.name': hostName, | ||
'service.environment': 'production', | ||
}) | ||
), | ||
]); | ||
}); | ||
after(async () => { | ||
await logSynthtrace.clean(); | ||
}); | ||
|
||
it('returns log rate timeseries', async () => { | ||
const response = await getLogsRateTimeseries(); | ||
expect(response.status).to.be(200); | ||
expect( | ||
response.body.currentPeriod[serviceName].every(({ y }) => y === 0.06666666666666667) | ||
).to.be(true); | ||
}); | ||
|
||
it('handles environment filter', async () => { | ||
const response = await getLogsRateTimeseries({ query: { environment: 'foo' } }); | ||
expect(response.status).to.be(200); | ||
expect(response.body.currentPeriod).to.empty(); | ||
}); | ||
|
||
describe('when my-service is selected', () => { | ||
it('returns some data', async () => { | ||
const response = await getLogsRateTimeseries({ | ||
path: { serviceName: 'my-service' }, | ||
}); | ||
|
||
expect(response.status).to.be(200); | ||
expect(first(response.body.currentPeriod?.['my-service'])?.y).to.be( | ||
0.18181818181818182 | ||
); | ||
expect(last(response.body.currentPeriod?.['my-service'])?.y).to.be(0.09090909090909091); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
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.