Skip to content

Commit

Permalink
[APM] Update ES archive used for API tests (elastic#85286)
Browse files Browse the repository at this point in the history
* [APM] Make sure jest script can be run from anywhere

* Update archive to 7.11
  • Loading branch information
dgieselaar committed Dec 9, 2020
1 parent 0b73dd7 commit 6b27a4f
Show file tree
Hide file tree
Showing 30 changed files with 10,780 additions and 64,956 deletions.
156 changes: 115 additions & 41 deletions x-pack/plugins/apm/scripts/create-functional-tests-archive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import { execSync } from 'child_process';
import moment from 'moment';
import path from 'path';
import fs from 'fs';
import { getEsClient } from '../shared/get_es_client';
import { parseIndexUrl } from '../shared/parse_index_url';

async function run() {
const archiveName = 'apm_8.0.0';

// include important APM data and ML data
const indices =
'apm-*-transaction,apm-*-span,apm-*-error,apm-*-metric,.ml-anomalies*,.ml-config';

const esUrl = argv['es-url'] as string | undefined;

if (!esUrl) {
Expand All @@ -30,52 +28,94 @@ async function run() {
const gte = moment().subtract(1, 'hour').toISOString();
const lt = moment(gte).add(30, 'minutes').toISOString();

// eslint-disable-next-line no-console
console.log(`Archiving from ${gte} to ${lt}...`);

// APM data uses '@timestamp' (ECS), ML data uses 'timestamp'

const rangeQueries = [
// include important APM data and ML data
const should = [
{
range: {
'@timestamp': {
gte,
lt,
},
index: 'apm-*-transaction,apm-*-span,apm-*-error,apm-*-metric',
bool: {
must_not: [
{
term: {
'service.name': 'elastic-co-frontend',
},
},
],
filter: [
{
terms: {
'processor.event': ['transaction', 'span', 'error', 'metric'],
},
},
{
range: {
'@timestamp': {
gte,
lt,
},
},
},
],
},
},
{
range: {
timestamp: {
gte,
lt,
},
index: '.ml-anomalies-shared',
bool: {
filter: [
{
term: {
_index: '.ml-anomalies-shared',
},
},
{
range: {
timestamp: {
gte,
lt,
},
},
},
],
},
},
{
index: '.ml-config',
bool: {
filter: [
{
term: {
_index: '.ml-config',
},
},
{
term: {
groups: 'apm',
},
},
],
},
},
{
index: '.kibana',
bool: {
filter: [
{
term: {
type: 'ml-job',
},
},
],
},
},
];

// some of the data is timeless/content
// eslint-disable-next-line no-console
console.log(`Archiving from ${gte} to ${lt}...`);

// APM data uses '@timestamp' (ECS), ML data uses 'timestamp'

const query = {
bool: {
should: [
...rangeQueries,
{
bool: {
must_not: [
{
exists: {
field: '@timestamp',
},
},
{
exists: {
field: 'timestamp',
},
},
],
},
},
],
should: should.map(({ bool }) => ({ bool })),
minimum_should_match: 1,
},
};
Expand All @@ -84,10 +124,44 @@ async function run() {
const commonDir = path.join(root, 'x-pack/test/apm_api_integration/common');
const archivesDir = path.join(commonDir, 'fixtures/es_archiver');

const options = parseIndexUrl(esUrl);

const client = getEsClient({
node: options.node,
});

const response = await client.search({
body: {
query,
aggs: {
index: {
terms: {
field: '_index',
size: 1000,
},
},
},
},
index: should.map(({ index }) => index),
});

// only store data for indices that actually have docs
// for performance reasons, by looking at the search
// profile
const indicesWithDocs =
response.body.aggregations?.index.buckets.map(
(bucket) => bucket.key as string
) ?? [];

// create the archive

execSync(
`node scripts/es_archiver save ${archiveName} ${indices} --dir=${archivesDir} --kibana-url=${kibanaUrl} --es-url=${esUrl} --query='${JSON.stringify(
`node scripts/es_archiver save ${archiveName} ${indicesWithDocs
.filter((index) => !index.startsWith('.kibana'))
.concat('.kibana')
.join(
','
)} --dir=${archivesDir} --kibana-url=${kibanaUrl} --es-url=${esUrl} --query='${JSON.stringify(
query
)}'`,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

it('returns significant terms', () => {
expectSnapshot(response.body?.significantTerms?.map((term) => term.fieldName))
expectSnapshot(response.body?.significantTerms?.map((term) => term.fieldName).sort())
.toMatchInline(`
Array [
"container.id",
"container.id",
"host.ip",
"host.ip",
"service.node.name",
"container.id",
"service.node.name",
"url.domain",
"url.domain",
"user_agent.name",
"user.id",
"host.ip",
"service.node.name",
"container.id",
"user.id",
"user_agent.name",
]
`);
});
Expand All @@ -82,7 +82,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
it('returns a distribution per term', () => {
// @ts-ignore
expectSnapshot(response.body?.significantTerms[0].distribution.length).toMatchInline(
`11`
`42`
);
});

Expand All @@ -93,7 +93,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

it('returns overall distribution', () => {
// @ts-ignore
expectSnapshot(response.body?.overall.distribution.length).toMatchInline(`11`);
expectSnapshot(response.body?.overall.distribution.length).toMatchInline(`42`);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export default function ApiTest({ getService }: FtrProviderContext) {
expect(response.body.serviceCount).to.be.greaterThan(0);
expect(response.body.transactionCoordinates.length).to.be.greaterThan(0);

expectSnapshot(response.body.serviceCount).toMatchInline(`8`);
expectSnapshot(response.body.serviceCount).toMatchInline(`9`);

expectSnapshot(response.body.transactionCoordinates.length).toMatchInline(`30`);
expectSnapshot(response.body.transactionCoordinates.length).toMatchInline(`31`);

expectSnapshot(
response.body.transactionCoordinates
Expand All @@ -58,24 +58,24 @@ export default function ApiTest({ getService }: FtrProviderContext) {
).toMatchInline(`
Array [
Object {
"x": "2020-09-29T14:30:00.000Z",
"y": 2.26666666666667,
"x": "2020-12-08T13:57:00.000Z",
"y": 0.166666666666667,
},
Object {
"x": "2020-09-29T14:31:00.000Z",
"y": 1.03333333333333,
"x": "2020-12-08T13:58:00.000Z",
"y": 5.23333333333333,
},
Object {
"x": "2020-09-29T14:32:00.000Z",
"y": 1.9,
"x": "2020-12-08T13:59:00.000Z",
"y": 4.4,
},
Object {
"x": "2020-09-29T14:33:00.000Z",
"y": 0.8,
"x": "2020-12-08T14:00:00.000Z",
"y": 5.73333333333333,
},
Object {
"x": "2020-09-29T14:34:00.000Z",
"y": 1.9,
"x": "2020-12-08T14:01:00.000Z",
"y": 4.33333333333333,
},
]
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expectSnapshot(response.body.error_groups.map((group: any) => group.name)).toMatchInline(`
Array [
"Could not write JSON: Null return value from advice does not match primitive return type for: public abstract double co.elastic.apm.opbeans.repositories.Numbers.getCost(); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Null return value from advice does not match primitive return type for: public abstract double co.elastic.apm.opbeans.repositories.Numbers.getCost() (through reference chain: co.elastic.apm.opbeans.repositories.Stats[\\"numbers\\"]->com.sun.proxy.$Proxy133[\\"cost\\"])",
"Could not write JSON: Null return value from advice does not match primitive return type for: public abstract double co.elastic.apm.opbeans.repositories.Numbers.getRevenue(); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Null return value from advice does not match primitive return type for: public abstract double co.elastic.apm.opbeans.repositories.Numbers.getRevenue() (through reference chain: co.elastic.apm.opbeans.repositories.Stats[\\"numbers\\"]->com.sun.proxy.$Proxy132[\\"revenue\\"])",
"java.io.IOException: Connection reset by peer",
"Connection reset by peer",
"Could not write JSON: Unable to find co.elastic.apm.opbeans.model.Customer with id 6617; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unable to find co.elastic.apm.opbeans.model.Customer with id 6617 (through reference chain: co.elastic.apm.opbeans.model.Customer_$$_jvst369_3[\\"email\\"])",
"java.io.IOException: Connection reset by peer",
"Could not write JSON: Unable to find co.elastic.apm.opbeans.model.Customer with id 7173; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unable to find co.elastic.apm.opbeans.model.Customer with id 7173 (through reference chain: co.elastic.apm.opbeans.model.Customer_$$_jvst101_3[\\"email\\"])",
"Request method 'POST' not supported",
]
`);

expectSnapshot(response.body.error_groups.map((group: any) => group.occurrences.value))
.toMatchInline(`
Array [
8,
5,
3,
2,
1,
1,
1,
]
`);

Expand All @@ -91,16 +91,16 @@ export default function ApiTest({ getService }: FtrProviderContext) {
.toMatchInline(`
Object {
"group_id": "051f95eabf120ebe2f8b0399fe3e54c5",
"last_seen": 1601391561523,
"name": "Could not write JSON: Null return value from advice does not match primitive return type for: public abstract double co.elastic.apm.opbeans.repositories.Numbers.getCost(); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Null return value from advice does not match primitive return type for: public abstract double co.elastic.apm.opbeans.repositories.Numbers.getCost() (through reference chain: co.elastic.apm.opbeans.repositories.Stats[\\"numbers\\"]->com.sun.proxy.$Proxy133[\\"cost\\"])",
"last_seen": 1607437366098,
"name": "Could not write JSON: Null return value from advice does not match primitive return type for: public abstract double co.elastic.apm.opbeans.repositories.Numbers.getRevenue(); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Null return value from advice does not match primitive return type for: public abstract double co.elastic.apm.opbeans.repositories.Numbers.getRevenue() (through reference chain: co.elastic.apm.opbeans.repositories.Stats[\\"numbers\\"]->com.sun.proxy.$Proxy132[\\"revenue\\"])",
"occurrences": Object {
"value": 8,
"value": 5,
},
}
`);

const visibleDataPoints = firstItem.occurrences.timeseries.filter(({ y }: any) => y > 0);
expectSnapshot(visibleDataPoints.length).toMatchInline(`7`);
expectSnapshot(visibleDataPoints.length).toMatchInline(`4`);
});

it('sorts items in the correct order', async () => {
Expand Down
Loading

0 comments on commit 6b27a4f

Please sign in to comment.