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] Fix max bucket error in Dependencies pages (elastic#173083)
fixes: elastic#161239 ## Summary This PR changes how dependencies data is fetched. To mitigate the max bucket error risk, and, at the same time, keep the compatibility with the dependencies-related pages that consume the `get_connection_stats` query, it now paginates the composite aggregation, using smaller batches of 1k items per pagination. **10k dependencies** <img width="826" alt="image" src="https://github.com/elastic/kibana/assets/2767137/fb277dd9-0a09-48ef-9e3e-fc1d5a4445e8"> **500 dependencies per service** <img width="821" alt="image" src="https://github.com/elastic/kibana/assets/2767137/cf8be999-2fa6-44ee-8838-c255fdb9896d"> **Notes:** Fetching 1k on each iteration might make the page slower; The max bucket error might still happen depending on the date range or how services are instrumented. ### How to test 1. Run synthtrace ``` node scripts/synthtrace service_many_dependencies.ts --from=now-15m --to=now --clean ``` 2. Navigate to the Dependencies Inventory page 3. Navigate to a service overview and then to the dependency tab --------- Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
42272f9
commit 403a8d0
Showing
4 changed files
with
265 additions
and
61 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/kbn-apm-synthtrace/src/scenarios/service_many_dependencies.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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ApmFields, Instance } from '@kbn/apm-synthtrace-client'; | ||
import { service } from '@kbn/apm-synthtrace-client/src/lib/apm/service'; | ||
import { Scenario } from '../cli/scenario'; | ||
import { RunOptions } from '../cli/utils/parse_run_cli_flags'; | ||
import { getSynthtraceEnvironment } from '../lib/utils/get_synthtrace_environment'; | ||
import { withClient } from '../lib/utils/with_client'; | ||
|
||
const ENVIRONMENT = getSynthtraceEnvironment(__filename); | ||
const MAX_DEPENDENCIES = 10000; | ||
const MAX_DEPENDENCIES_PER_SERVICE = 500; | ||
const MAX_SERVICES = 20; | ||
|
||
const scenario: Scenario<ApmFields> = async (runOptions: RunOptions) => { | ||
return { | ||
generate: ({ range, clients: { apmEsClient } }) => { | ||
const javaInstances = Array.from({ length: MAX_SERVICES }).map((_, index) => | ||
service(`opbeans-java-${index}`, ENVIRONMENT, 'java').instance(`java-instance-${index}`) | ||
); | ||
|
||
const instanceDependencies = (instance: Instance, startIndex: number) => { | ||
const rate = range.ratePerMinute(60); | ||
|
||
return rate.generator((timestamp, index) => { | ||
const currentIndex = index % MAX_DEPENDENCIES_PER_SERVICE; | ||
const destination = (startIndex + currentIndex) % MAX_DEPENDENCIES; | ||
|
||
const span = instance | ||
.transaction({ transactionName: 'GET /java' }) | ||
.timestamp(timestamp) | ||
.duration(400) | ||
.success() | ||
.children( | ||
instance | ||
.span({ | ||
spanName: 'GET apm-*/_search', | ||
spanType: 'db', | ||
spanSubtype: 'elasticsearch', | ||
}) | ||
.destination(`elasticsearch/${destination}`) | ||
.timestamp(timestamp) | ||
.duration(200) | ||
.success() | ||
); | ||
|
||
return span; | ||
}); | ||
}; | ||
|
||
return withClient( | ||
apmEsClient, | ||
javaInstances.map((instance, index) => | ||
instanceDependencies(instance, (index * MAX_DEPENDENCIES_PER_SERVICE) % MAX_DEPENDENCIES) | ||
) | ||
); | ||
}, | ||
}; | ||
}; | ||
|
||
export default scenario; |
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
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/apm/ftr_e2e/cypress/e2e/dependencies/generate_many_dependencies.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,69 @@ | ||
/* | ||
* 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, Instance, timerange } from '@kbn/apm-synthtrace-client'; | ||
|
||
const MAX_DEPENDENCIES = 10000; | ||
const MAX_DEPENDENCIES_PER_SERVICE = 500; | ||
const MAX_SERVICES = 20; | ||
|
||
export function generateManyDependencies({ | ||
from, | ||
to, | ||
}: { | ||
from: number; | ||
to: number; | ||
}) { | ||
const instances = Array.from({ length: MAX_SERVICES }).map((_, index) => | ||
apm | ||
.service({ | ||
name: `synth-java-${index}`, | ||
environment: 'production', | ||
agentName: 'java', | ||
}) | ||
.instance(`java-instance-${index}`) | ||
); | ||
|
||
const instanceDependencies = (instance: Instance, startIndex: number) => { | ||
return Array.from( | ||
timerange(new Date(from), new Date(to)) | ||
.interval('1m') | ||
.rate(60) | ||
.generator((timestamp, index) => { | ||
const currentIndex = index % MAX_DEPENDENCIES_PER_SERVICE; | ||
const destination = (startIndex + currentIndex) % MAX_DEPENDENCIES; | ||
|
||
const span = instance | ||
.transaction({ transactionName: 'GET /java' }) | ||
.timestamp(timestamp) | ||
.duration(400) | ||
.success() | ||
.children( | ||
instance | ||
.span({ | ||
spanName: 'GET apm-*/_search', | ||
spanType: 'db', | ||
spanSubtype: 'elasticsearch', | ||
}) | ||
.destination(`elasticsearch/${destination}`) | ||
.timestamp(timestamp) | ||
.duration(200) | ||
.success() | ||
); | ||
|
||
return span; | ||
}) | ||
); | ||
}; | ||
|
||
return instances.flatMap((instance, index) => | ||
instanceDependencies( | ||
instance, | ||
(index * MAX_DEPENDENCIES_PER_SERVICE) % MAX_DEPENDENCIES | ||
) | ||
); | ||
} |
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