-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Add registry providers for APM data #244856
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
db9823e
Add registry providers for APM data
sorenlouv 11bb79d
Changes from node scripts/lint_ts_projects --fix
kibanamachine 2b18296
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine 15b4270
Add missing type
sorenlouv fad5b21
Merge branch 'data-registry-apm-types' of github.com:sorenlouv/kibana…
sorenlouv 56343b0
Add missing dep
sorenlouv 940580f
Merge branch 'main' into data-registry-apm-types
sorenlouv 259c2d4
Merge branch 'main' into data-registry-apm-types
sorenlouv 1224fce
Merge branch 'main' into data-registry-apm-types
sorenlouv a38a1d5
Merge branch 'main' into data-registry-apm-types
sorenlouv a819243
Merge branch 'main' into data-registry-apm-types
sorenlouv 96c61fb
Merge branch 'main' into data-registry-apm-types
sorenlouv 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
128 changes: 128 additions & 0 deletions
128
...solutions/observability/plugins/apm/server/observability_agent/register_data_providers.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,128 @@ | ||
| /* | ||
| * 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 { CoreSetup, Logger } from '@kbn/core/server'; | ||
| import { getRandomSampler } from '../lib/helpers/get_random_sampler'; | ||
| import { getApmServiceSummary } from '../routes/assistant_functions/get_apm_service_summary'; | ||
| import { getApmDownstreamDependencies } from '../routes/assistant_functions/get_apm_downstream_dependencies'; | ||
| import { getApmErrors } from '../routes/assistant_functions/get_observability_alert_details_context/get_apm_errors'; | ||
| import { | ||
| getExitSpanChangePoints, | ||
| getServiceChangePoints, | ||
| } from '../routes/assistant_functions/get_changepoints'; | ||
| import { buildApmToolResources } from '../agent_tools/utils/build_apm_tool_resources'; | ||
| import type { APMPluginSetupDependencies, APMPluginStartDependencies } from '../types'; | ||
|
|
||
| export function registerDataProviders({ | ||
| core, | ||
| plugins, | ||
| logger, | ||
| }: { | ||
| core: CoreSetup<APMPluginStartDependencies>; | ||
| plugins: APMPluginSetupDependencies; | ||
| logger: Logger; | ||
| }) { | ||
| const { observabilityAgent } = plugins; | ||
| if (!observabilityAgent) { | ||
| return; | ||
| } | ||
|
|
||
| observabilityAgent.registerDataProvider( | ||
| 'apmServiceSummary', | ||
| async ({ request, serviceName, serviceEnvironment, start, end, transactionType }) => { | ||
| const { apmEventClient, apmAlertsClient, mlClient, esClient } = await buildApmToolResources({ | ||
| core, | ||
| plugins, | ||
| request, | ||
| logger, | ||
| }); | ||
|
|
||
| return getApmServiceSummary({ | ||
| apmEventClient, | ||
| esClient: esClient.asCurrentUser, | ||
| apmAlertsClient, | ||
| mlClient, | ||
| logger, | ||
| arguments: { | ||
| 'service.name': serviceName, | ||
| 'service.environment': serviceEnvironment, | ||
| start, | ||
| end, | ||
| 'transaction.type': transactionType, | ||
| }, | ||
| }); | ||
| } | ||
| ); | ||
|
|
||
| observabilityAgent.registerDataProvider( | ||
| 'apmDownstreamDependencies', | ||
| async ({ request, serviceName, serviceEnvironment, start, end }) => { | ||
| const { apmEventClient } = await buildApmToolResources({ core, plugins, request, logger }); | ||
| const [coreStart] = await core.getStartServices(); | ||
| const randomSampler = await getRandomSampler({ coreStart, probability: 1, request }); | ||
|
|
||
| return getApmDownstreamDependencies({ | ||
| apmEventClient, | ||
| randomSampler, | ||
| arguments: { | ||
| serviceName, | ||
| serviceEnvironment, | ||
| start, | ||
| end, | ||
| }, | ||
| }); | ||
| } | ||
| ); | ||
|
|
||
| observabilityAgent.registerDataProvider( | ||
| 'apmErrors', | ||
| async ({ request, serviceName, serviceEnvironment, start, end }) => { | ||
| const { apmEventClient } = await buildApmToolResources({ core, plugins, request, logger }); | ||
| return getApmErrors({ apmEventClient, serviceName, serviceEnvironment, start, end }); | ||
| } | ||
| ); | ||
|
|
||
| observabilityAgent.registerDataProvider( | ||
| 'apmExitSpanChangePoints', | ||
| async ({ request, serviceName, serviceEnvironment, start, end }) => { | ||
| const { apmEventClient } = await buildApmToolResources({ core, plugins, request, logger }); | ||
|
|
||
| return getExitSpanChangePoints({ | ||
| apmEventClient, | ||
| serviceName, | ||
| serviceEnvironment, | ||
| start, | ||
| end, | ||
| }); | ||
| } | ||
| ); | ||
|
|
||
| observabilityAgent.registerDataProvider( | ||
| 'apmServiceChangePoints', | ||
| async ({ | ||
| request, | ||
| serviceName, | ||
| serviceEnvironment, | ||
| transactionType, | ||
| transactionName, | ||
| start, | ||
| end, | ||
| }) => { | ||
| const { apmEventClient } = await buildApmToolResources({ core, plugins, request, logger }); | ||
|
|
||
| return getServiceChangePoints({ | ||
| apmEventClient, | ||
| serviceName, | ||
| serviceEnvironment, | ||
| transactionType, | ||
| transactionName, | ||
| start, | ||
| end, | ||
| }); | ||
| } | ||
| ); | ||
| } | ||
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
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
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
55 changes: 0 additions & 55 deletions
55
x-pack/solutions/observability/plugins/observability_agent/server/data_registry.ts
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
...solutions/observability/plugins/observability_agent/server/data_registry/data_registry.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,42 @@ | ||
| /* | ||
| * 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 { Logger } from '@kbn/core/server'; | ||
| import type { ObservabilityAgentDataRegistryTypes } from './data_registry_types'; | ||
|
|
||
| export class ObservabilityAgentDataRegistry { | ||
| private readonly providers = new Map<string, (...args: any[]) => Promise<any>>(); | ||
|
|
||
| constructor(private readonly logger: Logger) {} | ||
|
|
||
| public registerDataProvider<K extends keyof ObservabilityAgentDataRegistryTypes>( | ||
| id: K, | ||
| provider: ObservabilityAgentDataRegistryTypes[K] | ||
| ): void { | ||
| if (this.providers.has(id)) { | ||
| this.logger.warn(`Overwriting data provider for key: ${id}`); | ||
| } else { | ||
| this.logger.debug(`Registered data provider for key: ${id}`); | ||
| } | ||
|
|
||
| this.providers.set(id, provider); | ||
| } | ||
|
|
||
| public async getData<K extends keyof ObservabilityAgentDataRegistryTypes>( | ||
| id: K, | ||
| params: Parameters<ObservabilityAgentDataRegistryTypes[K]>[0] | ||
| ): Promise<ReturnType<ObservabilityAgentDataRegistryTypes[K]> | undefined> { | ||
| const provider = this.providers.get(id) as ObservabilityAgentDataRegistryTypes[K] | undefined; | ||
|
|
||
| if (!provider) { | ||
| this.logger.error(`No data provider registered for key: ${id}`); | ||
| return; | ||
| } | ||
|
|
||
| return provider(params) as Promise<ReturnType<ObservabilityAgentDataRegistryTypes[K]>>; | ||
| } | ||
| } |
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.