mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 11:05:39 -04:00
[APM] Add data access plugin (#162367)
Closes https://github.com/elastic/kibana/issues/161906
Related to:
https://github.com/elastic/observability-dev/discussions/2787
(_internal_)
This add a new plugin `apm_data_access` that contains the APM query
targets (indices to query for APM data).
This plugin can be consumed by apm and any other plugin, making it
possible for other plugins to know about the configured APM query
targets.
## Example:
APM query targets can be specified in kibana[.dev].yml using
`xpack.apm.indices.{dataset}: some-index-*` for instances:
```yml
xpack.apm.indices.transaction: apm-*
```
See all config options on:
https://www.elastic.co/guide/en/kibana/current/apm-settings-kb.html#general-apm-settings-kb
Query targets can also be specified via the UI (and persisted in a saved
object) via the settings page: `/app/apm/settings/apm-indices`
**Retrieving the query targets**
Query targets can be retrieved from other plugins via `getApmIndices`:
```ts
const apmIndices = await plugins.apmDataAccess.setup.getApmIndices(savedObjects.client);
```
TODO:
- [x] Add SO client and fetch space aware index config (see
4d7f626da0/x-pack/plugins/apm/server/routes/settings/apm_indices/get_apm_indices.ts (L32-L44)
)
- [ ] Add simple APM client for querying apm data
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
90c1a4a95c
commit
7df1cee163
112 changed files with 755 additions and 582 deletions
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
|
@ -36,6 +36,7 @@ packages/analytics/shippers/elastic_v3/server @elastic/kibana-core
|
||||||
packages/analytics/shippers/fullstory @elastic/kibana-core
|
packages/analytics/shippers/fullstory @elastic/kibana-core
|
||||||
packages/analytics/shippers/gainsight @elastic/kibana-core
|
packages/analytics/shippers/gainsight @elastic/kibana-core
|
||||||
packages/kbn-apm-config-loader @elastic/kibana-core @vigneshshanmugam
|
packages/kbn-apm-config-loader @elastic/kibana-core @vigneshshanmugam
|
||||||
|
x-pack/plugins/apm_data_access @elastic/apm-ui
|
||||||
x-pack/plugins/apm @elastic/apm-ui
|
x-pack/plugins/apm @elastic/apm-ui
|
||||||
packages/kbn-apm-synthtrace @elastic/apm-ui
|
packages/kbn-apm-synthtrace @elastic/apm-ui
|
||||||
packages/kbn-apm-synthtrace-client @elastic/apm-ui
|
packages/kbn-apm-synthtrace-client @elastic/apm-ui
|
||||||
|
|
|
@ -434,6 +434,10 @@ The plugin exposes the static DefaultEditorController class to consume.
|
||||||
|This plugin provides access to App Monitoring features provided by Elastic. It allows you to monitor your software services and applications in real-time; visualize detailed performance information on your services, identify and analyze errors, and monitor host-level and APM agent-specific metrics like JVM and Go runtime metrics.
|
|This plugin provides access to App Monitoring features provided by Elastic. It allows you to monitor your software services and applications in real-time; visualize detailed performance information on your services, identify and analyze errors, and monitor host-level and APM agent-specific metrics like JVM and Go runtime metrics.
|
||||||
|
|
||||||
|
|
||||||
|
|{kib-repo}blob/{branch}/x-pack/plugins/apm_data_access[apmDataAccess]
|
||||||
|
|WARNING: Missing README.
|
||||||
|
|
||||||
|
|
||||||
|{kib-repo}blob/{branch}/x-pack/plugins/asset_manager/README.md[assetManager]
|
|{kib-repo}blob/{branch}/x-pack/plugins/asset_manager/README.md[assetManager]
|
||||||
|This plugin provides access to the asset data stored in assets-* indices, primarily
|
|This plugin provides access to the asset data stored in assets-* indices, primarily
|
||||||
for inventory and topology purposes.
|
for inventory and topology purposes.
|
||||||
|
|
|
@ -152,6 +152,7 @@
|
||||||
"@kbn/analytics-shippers-fullstory": "link:packages/analytics/shippers/fullstory",
|
"@kbn/analytics-shippers-fullstory": "link:packages/analytics/shippers/fullstory",
|
||||||
"@kbn/analytics-shippers-gainsight": "link:packages/analytics/shippers/gainsight",
|
"@kbn/analytics-shippers-gainsight": "link:packages/analytics/shippers/gainsight",
|
||||||
"@kbn/apm-config-loader": "link:packages/kbn-apm-config-loader",
|
"@kbn/apm-config-loader": "link:packages/kbn-apm-config-loader",
|
||||||
|
"@kbn/apm-data-access-plugin": "link:x-pack/plugins/apm_data_access",
|
||||||
"@kbn/apm-plugin": "link:x-pack/plugins/apm",
|
"@kbn/apm-plugin": "link:x-pack/plugins/apm",
|
||||||
"@kbn/apm-utils": "link:packages/kbn-apm-utils",
|
"@kbn/apm-utils": "link:packages/kbn-apm-utils",
|
||||||
"@kbn/app-link-test-plugin": "link:test/plugin_functional/plugins/app_link_test",
|
"@kbn/app-link-test-plugin": "link:test/plugin_functional/plugins/app_link_test",
|
||||||
|
|
|
@ -66,6 +66,8 @@
|
||||||
"@kbn/analytics-shippers-gainsight/*": ["packages/analytics/shippers/gainsight/*"],
|
"@kbn/analytics-shippers-gainsight/*": ["packages/analytics/shippers/gainsight/*"],
|
||||||
"@kbn/apm-config-loader": ["packages/kbn-apm-config-loader"],
|
"@kbn/apm-config-loader": ["packages/kbn-apm-config-loader"],
|
||||||
"@kbn/apm-config-loader/*": ["packages/kbn-apm-config-loader/*"],
|
"@kbn/apm-config-loader/*": ["packages/kbn-apm-config-loader/*"],
|
||||||
|
"@kbn/apm-data-access-plugin": ["x-pack/plugins/apm_data_access"],
|
||||||
|
"@kbn/apm-data-access-plugin/*": ["x-pack/plugins/apm_data_access/*"],
|
||||||
"@kbn/apm-plugin": ["x-pack/plugins/apm"],
|
"@kbn/apm-plugin": ["x-pack/plugins/apm"],
|
||||||
"@kbn/apm-plugin/*": ["x-pack/plugins/apm/*"],
|
"@kbn/apm-plugin/*": ["x-pack/plugins/apm/*"],
|
||||||
"@kbn/apm-synthtrace": ["packages/kbn-apm-synthtrace"],
|
"@kbn/apm-synthtrace": ["packages/kbn-apm-synthtrace"],
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"xpack.stackAlerts": "plugins/stack_alerts",
|
"xpack.stackAlerts": "plugins/stack_alerts",
|
||||||
"xpack.stackConnectors": "plugins/stack_connectors",
|
"xpack.stackConnectors": "plugins/stack_connectors",
|
||||||
"xpack.apm": "plugins/apm",
|
"xpack.apm": "plugins/apm",
|
||||||
|
"xpack.apmDataAccess": "plugins/apm_data_access",
|
||||||
"xpack.banners": "plugins/banners",
|
"xpack.banners": "plugins/banners",
|
||||||
"xpack.canvas": "plugins/canvas",
|
"xpack.canvas": "plugins/canvas",
|
||||||
"xpack.cases": "plugins/cases",
|
"xpack.cases": "plugins/cases",
|
||||||
|
|
|
@ -5,13 +5,6 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// the types have to match the names of the saved object mappings
|
|
||||||
// in /x-pack/plugins/apm/mappings.json
|
|
||||||
|
|
||||||
// APM index settings
|
|
||||||
export const APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE = 'apm-indices';
|
|
||||||
export const APM_INDEX_SETTINGS_SAVED_OBJECT_ID = 'apm-indices';
|
|
||||||
|
|
||||||
// APM telemetry
|
// APM telemetry
|
||||||
export const APM_TELEMETRY_SAVED_OBJECT_TYPE = 'apm-telemetry';
|
export const APM_TELEMETRY_SAVED_OBJECT_TYPE = 'apm-telemetry';
|
||||||
export const APM_TELEMETRY_SAVED_OBJECT_ID = 'apm-telemetry';
|
export const APM_TELEMETRY_SAVED_OBJECT_ID = 'apm-telemetry';
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"configPath": ["xpack", "apm"],
|
"configPath": ["xpack", "apm"],
|
||||||
"requiredPlugins": [
|
"requiredPlugins": [
|
||||||
|
"apmDataAccess",
|
||||||
"data",
|
"data",
|
||||||
"dashboard",
|
"dashboard",
|
||||||
"controls",
|
"controls",
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
import { Client } from '@elastic/elasticsearch';
|
import { Client } from '@elastic/elasticsearch';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import axios, { AxiosInstance } from 'axios';
|
import axios, { AxiosInstance } from 'axios';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { APIReturnType } from '../../public/services/rest/create_call_apm_api';
|
import { APIReturnType } from '../../public/services/rest/create_call_apm_api';
|
||||||
import { getDiagnosticsBundle } from '../../server/routes/diagnostics/get_diagnostics_bundle';
|
import { getDiagnosticsBundle } from '../../server/routes/diagnostics/get_diagnostics_bundle';
|
||||||
import { ApmIndicesConfig } from '../../server/routes/settings/apm_indices/get_apm_indices';
|
|
||||||
|
|
||||||
type DiagnosticsBundle = APIReturnType<'GET /internal/apm/diagnostics'>;
|
type DiagnosticsBundle = APIReturnType<'GET /internal/apm/diagnostics'>;
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ async function getApmIndices(kibanaClient: AxiosInstance) {
|
||||||
savedValue ?? defaultValue,
|
savedValue ?? defaultValue,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
) as ApmIndicesConfig;
|
) as APMIndices;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFleetPackageInfo(kibanaClient: AxiosInstance) {
|
async function getFleetPackageInfo(kibanaClient: AxiosInstance) {
|
||||||
|
|
|
@ -10,8 +10,8 @@ import { kibanaPackageJson } from '@kbn/repo-info';
|
||||||
import { GetDeprecationsContext } from '@kbn/core/server';
|
import { GetDeprecationsContext } from '@kbn/core/server';
|
||||||
import { CloudSetup } from '@kbn/cloud-plugin/server';
|
import { CloudSetup } from '@kbn/cloud-plugin/server';
|
||||||
import { getDeprecations } from '.';
|
import { getDeprecations } from '.';
|
||||||
import { APMRouteHandlerResources } from '..';
|
|
||||||
import { AgentPolicy } from '@kbn/fleet-plugin/common';
|
import { AgentPolicy } from '@kbn/fleet-plugin/common';
|
||||||
|
import { APMRouteHandlerResources } from '../routes/apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
const deprecationContext = {
|
const deprecationContext = {
|
||||||
esClient: {},
|
esClient: {},
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
getCloudAgentPolicy,
|
getCloudAgentPolicy,
|
||||||
getApmPackagePolicy,
|
getApmPackagePolicy,
|
||||||
} from '../routes/fleet/get_cloud_apm_package_policy';
|
} from '../routes/fleet/get_cloud_apm_package_policy';
|
||||||
import { APMRouteHandlerResources } from '..';
|
import { APMRouteHandlerResources } from '../routes/apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
export function getDeprecations({
|
export function getDeprecations({
|
||||||
cloudSetup,
|
cloudSetup,
|
||||||
|
|
|
@ -12,11 +12,11 @@ import {
|
||||||
LicensingPluginSetup,
|
LicensingPluginSetup,
|
||||||
LicensingApiRequestHandlerContext,
|
LicensingApiRequestHandlerContext,
|
||||||
} from '@kbn/licensing-plugin/server';
|
} from '@kbn/licensing-plugin/server';
|
||||||
|
import { APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE } from '@kbn/apm-data-access-plugin/server/saved_objects/apm_indices';
|
||||||
import {
|
import {
|
||||||
ApmRuleType,
|
ApmRuleType,
|
||||||
APM_SERVER_FEATURE_ID,
|
APM_SERVER_FEATURE_ID,
|
||||||
} from '../common/rules/apm_rule_types';
|
} from '../common/rules/apm_rule_types';
|
||||||
import { APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE } from '../common/apm_saved_object_constants';
|
|
||||||
|
|
||||||
export const APM_FEATURE = {
|
export const APM_FEATURE = {
|
||||||
id: APM_SERVER_FEATURE_ID,
|
id: APM_SERVER_FEATURE_ID,
|
||||||
|
|
|
@ -56,13 +56,6 @@ const configSchema = schema.object({
|
||||||
enabled: schema.boolean({ defaultValue: false }),
|
enabled: schema.boolean({ defaultValue: false }),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
indices: schema.object({
|
|
||||||
transaction: schema.string({ defaultValue: 'traces-apm*,apm-*' }),
|
|
||||||
span: schema.string({ defaultValue: 'traces-apm*,apm-*' }),
|
|
||||||
error: schema.string({ defaultValue: 'logs-apm*,apm-*' }),
|
|
||||||
metric: schema.string({ defaultValue: 'metrics-apm*,apm-*' }),
|
|
||||||
onboarding: schema.string({ defaultValue: 'apm-*' }),
|
|
||||||
}),
|
|
||||||
forceSyntheticSource: schema.boolean({ defaultValue: false }),
|
forceSyntheticSource: schema.boolean({ defaultValue: false }),
|
||||||
latestAgentVersionsUrl: schema.string({
|
latestAgentVersionsUrl: schema.string({
|
||||||
defaultValue: 'https://apm-agent-versions.elastic.co/versions.json',
|
defaultValue: 'https://apm-agent-versions.elastic.co/versions.json',
|
||||||
|
@ -109,35 +102,12 @@ export const config: PluginConfigDescriptor<APMConfig> = {
|
||||||
deprecateFromRoot,
|
deprecateFromRoot,
|
||||||
unusedFromRoot,
|
unusedFromRoot,
|
||||||
}) => [
|
}) => [
|
||||||
unused('indices.sourcemap', { level: 'warning' }),
|
|
||||||
unused('ui.transactionGroupBucketSize', {
|
unused('ui.transactionGroupBucketSize', {
|
||||||
level: 'warning',
|
level: 'warning',
|
||||||
}),
|
}),
|
||||||
rename('autocreateApmIndexPattern', 'autoCreateApmDataView', {
|
rename('autocreateApmIndexPattern', 'autoCreateApmDataView', {
|
||||||
level: 'warning',
|
level: 'warning',
|
||||||
}),
|
}),
|
||||||
renameFromRoot(
|
|
||||||
'apm_oss.transactionIndices',
|
|
||||||
'xpack.apm.indices.transaction',
|
|
||||||
{ level: 'warning' }
|
|
||||||
),
|
|
||||||
renameFromRoot('apm_oss.spanIndices', 'xpack.apm.indices.span', {
|
|
||||||
level: 'warning',
|
|
||||||
}),
|
|
||||||
renameFromRoot('apm_oss.errorIndices', 'xpack.apm.indices.error', {
|
|
||||||
level: 'warning',
|
|
||||||
}),
|
|
||||||
renameFromRoot('apm_oss.metricsIndices', 'xpack.apm.indices.metric', {
|
|
||||||
level: 'warning',
|
|
||||||
}),
|
|
||||||
renameFromRoot('apm_oss.sourcemapIndices', 'xpack.apm.indices.sourcemap', {
|
|
||||||
level: 'warning',
|
|
||||||
}),
|
|
||||||
renameFromRoot(
|
|
||||||
'apm_oss.onboardingIndices',
|
|
||||||
'xpack.apm.indices.onboarding',
|
|
||||||
{ level: 'warning' }
|
|
||||||
),
|
|
||||||
deprecateFromRoot('apm_oss.enabled', '8.0.0', { level: 'warning' }),
|
deprecateFromRoot('apm_oss.enabled', '8.0.0', { level: 'warning' }),
|
||||||
unusedFromRoot('apm_oss.fleetMode', { level: 'warning' }),
|
unusedFromRoot('apm_oss.fleetMode', { level: 'warning' }),
|
||||||
unusedFromRoot('apm_oss.indexPattern', { level: 'warning' }),
|
unusedFromRoot('apm_oss.indexPattern', { level: 'warning' }),
|
||||||
|
@ -165,7 +135,6 @@ export const config: PluginConfigDescriptor<APMConfig> = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type APMConfig = TypeOf<typeof configSchema>;
|
export type APMConfig = TypeOf<typeof configSchema>;
|
||||||
export type ApmIndicesConfigName = keyof APMConfig['indices'];
|
|
||||||
|
|
||||||
export const plugin = (initContext: PluginInitializerContext) =>
|
export const plugin = (initContext: PluginInitializerContext) =>
|
||||||
new APMPlugin(initContext);
|
new APMPlugin(initContext);
|
||||||
|
@ -177,4 +146,3 @@ export type {
|
||||||
APMServerRouteRepository,
|
APMServerRouteRepository,
|
||||||
APIEndpoint,
|
APIEndpoint,
|
||||||
} from './routes/apm_routes/get_global_apm_server_route_repository';
|
} from './routes/apm_routes/get_global_apm_server_route_repository';
|
||||||
export type { APMRouteHandlerResources } from './routes/typings';
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import moment from 'moment';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { ProcessorEvent } from '@kbn/observability-plugin/common';
|
import { ProcessorEvent } from '@kbn/observability-plugin/common';
|
||||||
import { waitForIndexStatus } from '@kbn/core-saved-objects-migration-server-internal';
|
import { waitForIndexStatus } from '@kbn/core-saved-objects-migration-server-internal';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { ML_ERRORS } from '../../../common/anomaly_detection';
|
import { ML_ERRORS } from '../../../common/anomaly_detection';
|
||||||
import { METRICSET_NAME, PROCESSOR_EVENT } from '../../../common/es_fields/apm';
|
import { METRICSET_NAME, PROCESSOR_EVENT } from '../../../common/es_fields/apm';
|
||||||
import { Environment } from '../../../common/environment_rt';
|
import { Environment } from '../../../common/environment_rt';
|
||||||
|
@ -20,7 +21,6 @@ import { withApmSpan } from '../../utils/with_apm_span';
|
||||||
import { MlClient } from '../helpers/get_ml_client';
|
import { MlClient } from '../helpers/get_ml_client';
|
||||||
import { APM_ML_JOB_GROUP, ML_MODULE_ID_APM_TRANSACTION } from './constants';
|
import { APM_ML_JOB_GROUP, ML_MODULE_ID_APM_TRANSACTION } from './constants';
|
||||||
import { getAnomalyDetectionJobs } from './get_anomaly_detection_jobs';
|
import { getAnomalyDetectionJobs } from './get_anomaly_detection_jobs';
|
||||||
import { ApmIndicesConfig } from '../../routes/settings/apm_indices/get_apm_indices';
|
|
||||||
|
|
||||||
const DEFAULT_TIMEOUT = '60s';
|
const DEFAULT_TIMEOUT = '60s';
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export async function createAnomalyDetectionJobs({
|
||||||
}: {
|
}: {
|
||||||
mlClient?: MlClient;
|
mlClient?: MlClient;
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
indices: ApmIndicesConfig;
|
indices: APMIndices;
|
||||||
environments: Environment[];
|
environments: Environment[];
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
}) {
|
}) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';
|
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';
|
||||||
import { ApmIndicesConfig } from '../../../routes/settings/apm_indices/get_apm_indices';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { tasks } from './tasks';
|
import { tasks } from './tasks';
|
||||||
import {
|
import {
|
||||||
SERVICE_NAME,
|
SERVICE_NAME,
|
||||||
|
@ -19,7 +19,7 @@ describe('data telemetry collection tasks', () => {
|
||||||
metric: 'apm-8.0.0-metric',
|
metric: 'apm-8.0.0-metric',
|
||||||
span: 'apm-8.0.0-span',
|
span: 'apm-8.0.0-span',
|
||||||
transaction: 'apm-8.0.0-transaction',
|
transaction: 'apm-8.0.0-transaction',
|
||||||
} as ApmIndicesConfig;
|
} as APMIndices;
|
||||||
|
|
||||||
describe('environments', () => {
|
describe('environments', () => {
|
||||||
const task = tasks.find((t) => t.name === 'environments');
|
const task = tasks.find((t) => t.name === 'environments');
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { ProcessorEvent } from '@kbn/observability-plugin/common';
|
||||||
import { createHash } from 'crypto';
|
import { createHash } from 'crypto';
|
||||||
import { flatten, merge, pickBy, sortBy, sum, uniq } from 'lodash';
|
import { flatten, merge, pickBy, sortBy, sum, uniq } from 'lodash';
|
||||||
import { SavedObjectsClient } from '@kbn/core/server';
|
import { SavedObjectsClient } from '@kbn/core/server';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { AGENT_NAMES, RUM_AGENT_NAMES } from '../../../../common/agent_name';
|
import { AGENT_NAMES, RUM_AGENT_NAMES } from '../../../../common/agent_name';
|
||||||
import {
|
import {
|
||||||
AGENT_ACTIVATION_METHOD,
|
AGENT_ACTIVATION_METHOD,
|
||||||
|
@ -56,10 +57,7 @@ import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent';
|
||||||
import { Span } from '../../../../typings/es_schemas/ui/span';
|
import { Span } from '../../../../typings/es_schemas/ui/span';
|
||||||
import { Transaction } from '../../../../typings/es_schemas/ui/transaction';
|
import { Transaction } from '../../../../typings/es_schemas/ui/transaction';
|
||||||
import { APMTelemetry, APMPerService, APMDataTelemetry } from '../types';
|
import { APMTelemetry, APMPerService, APMDataTelemetry } from '../types';
|
||||||
import {
|
import { APM_AGENT_CONFIGURATION_INDEX } from '../../../routes/settings/apm_indices/apm_system_index_constants';
|
||||||
ApmIndicesConfig,
|
|
||||||
APM_AGENT_CONFIGURATION_INDEX,
|
|
||||||
} from '../../../routes/settings/apm_indices/get_apm_indices';
|
|
||||||
import { TelemetryClient } from '../telemetry_client';
|
import { TelemetryClient } from '../telemetry_client';
|
||||||
|
|
||||||
type ISavedObjectsClient = Pick<SavedObjectsClient, 'find'>;
|
type ISavedObjectsClient = Pick<SavedObjectsClient, 'find'>;
|
||||||
|
@ -76,7 +74,7 @@ interface TelemetryTask {
|
||||||
|
|
||||||
export interface TelemetryTaskExecutorParams {
|
export interface TelemetryTaskExecutorParams {
|
||||||
telemetryClient: TelemetryClient;
|
telemetryClient: TelemetryClient;
|
||||||
indices: ApmIndicesConfig;
|
indices: APMIndices;
|
||||||
savedObjectsClient: ISavedObjectsClient;
|
savedObjectsClient: ISavedObjectsClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
|
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
|
||||||
import { CoreSetup, Logger, SavedObjectsErrorHelpers } from '@kbn/core/server';
|
import {
|
||||||
|
CoreSetup,
|
||||||
|
Logger,
|
||||||
|
SavedObjectsClientContract,
|
||||||
|
SavedObjectsErrorHelpers,
|
||||||
|
} from '@kbn/core/server';
|
||||||
import {
|
import {
|
||||||
TaskManagerSetupContract,
|
TaskManagerSetupContract,
|
||||||
TaskManagerStartContract,
|
TaskManagerStartContract,
|
||||||
} from '@kbn/task-manager-plugin/server';
|
} from '@kbn/task-manager-plugin/server';
|
||||||
import { APMConfig } from '../..';
|
import { APMDataAccessConfig } from '@kbn/apm-data-access-plugin/server';
|
||||||
import {
|
import {
|
||||||
APM_TELEMETRY_SAVED_OBJECT_ID,
|
APM_TELEMETRY_SAVED_OBJECT_ID,
|
||||||
APM_TELEMETRY_SAVED_OBJECT_TYPE,
|
APM_TELEMETRY_SAVED_OBJECT_TYPE,
|
||||||
|
@ -20,14 +25,13 @@ import { getInternalSavedObjectsClient } from '../helpers/get_internal_saved_obj
|
||||||
import { collectDataTelemetry } from './collect_data_telemetry';
|
import { collectDataTelemetry } from './collect_data_telemetry';
|
||||||
import { APMUsage } from './types';
|
import { APMUsage } from './types';
|
||||||
import { apmSchema } from './schema';
|
import { apmSchema } from './schema';
|
||||||
import { getApmIndices } from '../../routes/settings/apm_indices/get_apm_indices';
|
|
||||||
import { getTelemetryClient } from './telemetry_client';
|
import { getTelemetryClient } from './telemetry_client';
|
||||||
|
|
||||||
export const APM_TELEMETRY_TASK_NAME = 'apm-telemetry-task';
|
export const APM_TELEMETRY_TASK_NAME = 'apm-telemetry-task';
|
||||||
|
|
||||||
export async function createApmTelemetry({
|
export async function createApmTelemetry({
|
||||||
core,
|
core,
|
||||||
config,
|
getApmIndices,
|
||||||
usageCollector,
|
usageCollector,
|
||||||
taskManager,
|
taskManager,
|
||||||
logger,
|
logger,
|
||||||
|
@ -35,7 +39,9 @@ export async function createApmTelemetry({
|
||||||
isProd,
|
isProd,
|
||||||
}: {
|
}: {
|
||||||
core: CoreSetup;
|
core: CoreSetup;
|
||||||
config: APMConfig;
|
getApmIndices: (
|
||||||
|
soClient: SavedObjectsClientContract
|
||||||
|
) => Promise<APMDataAccessConfig['indices']>;
|
||||||
usageCollector: UsageCollectionSetup;
|
usageCollector: UsageCollectionSetup;
|
||||||
taskManager: TaskManagerSetupContract;
|
taskManager: TaskManagerSetupContract;
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
|
@ -56,14 +62,14 @@ export async function createApmTelemetry({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const telemetryClient = await getTelemetryClient({ core });
|
||||||
const [coreStart] = await core.getStartServices();
|
const [coreStart] = await core.getStartServices();
|
||||||
const savedObjectsClient = await getInternalSavedObjectsClient(coreStart);
|
const savedObjectsClient = await getInternalSavedObjectsClient(coreStart);
|
||||||
const indices = await getApmIndices({ config, savedObjectsClient });
|
const apmIndices = await getApmIndices(savedObjectsClient);
|
||||||
const telemetryClient = await getTelemetryClient({ core });
|
|
||||||
|
|
||||||
const collectAndStore = async () => {
|
const collectAndStore = async () => {
|
||||||
const dataTelemetry = await collectDataTelemetry({
|
const dataTelemetry = await collectDataTelemetry({
|
||||||
indices,
|
indices: apmIndices,
|
||||||
telemetryClient,
|
telemetryClient,
|
||||||
logger,
|
logger,
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { APMEventESSearchRequest } from '.';
|
import { APMEventESSearchRequest } from '.';
|
||||||
import { ApmIndicesConfig } from '../../../../routes/settings/apm_indices/get_apm_indices';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { getRequestBase } from './get_request_base';
|
import { getRequestBase } from './get_request_base';
|
||||||
|
|
||||||
describe('getRequestBase', () => {
|
describe('getRequestBase', () => {
|
||||||
|
@ -26,7 +26,7 @@ describe('getRequestBase', () => {
|
||||||
error: 'my-apm-*-error-*',
|
error: 'my-apm-*-error-*',
|
||||||
span: 'my-apm-*-span-*',
|
span: 'my-apm-*-span-*',
|
||||||
onboarding: 'my-apm-*-onboarding-*',
|
onboarding: 'my-apm-*-onboarding-*',
|
||||||
} as ApmIndicesConfig;
|
} as APMIndices;
|
||||||
|
|
||||||
res = getRequestBase({ ...request, indices });
|
res = getRequestBase({ ...request, indices });
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ESFilter } from '@kbn/es-types';
|
import type { ESFilter } from '@kbn/es-types';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { ProcessorEvent } from '@kbn/observability-plugin/common';
|
import { ProcessorEvent } from '@kbn/observability-plugin/common';
|
||||||
import { uniq } from 'lodash';
|
import { uniq } from 'lodash';
|
||||||
import { ApmDataSource } from '../../../../../common/data_source';
|
import { ApmDataSource } from '../../../../../common/data_source';
|
||||||
import {} from '../../../../../common/document_type';
|
import {} from '../../../../../common/document_type';
|
||||||
import { PROCESSOR_EVENT } from '../../../../../common/es_fields/apm';
|
import { PROCESSOR_EVENT } from '../../../../../common/es_fields/apm';
|
||||||
import { ApmIndicesConfig } from '../../../../routes/settings/apm_indices/get_apm_indices';
|
|
||||||
import {
|
import {
|
||||||
getConfigForDocumentType,
|
getConfigForDocumentType,
|
||||||
getProcessorEventForDocumentType,
|
getProcessorEventForDocumentType,
|
||||||
|
@ -26,7 +26,7 @@ const processorEventIndexMap = {
|
||||||
|
|
||||||
export function processorEventsToIndex(
|
export function processorEventsToIndex(
|
||||||
events: ProcessorEvent[],
|
events: ProcessorEvent[],
|
||||||
indices: ApmIndicesConfig
|
indices: APMIndices
|
||||||
) {
|
) {
|
||||||
return uniq(
|
return uniq(
|
||||||
events.flatMap((event) =>
|
events.flatMap((event) =>
|
||||||
|
@ -37,7 +37,7 @@ export function processorEventsToIndex(
|
||||||
|
|
||||||
export function getRequestBase(options: {
|
export function getRequestBase(options: {
|
||||||
apm: { events: ProcessorEvent[] } | { sources: ApmDataSource[] };
|
apm: { events: ProcessorEvent[] } | { sources: ApmDataSource[] };
|
||||||
indices: ApmIndicesConfig;
|
indices: APMIndices;
|
||||||
}) {
|
}) {
|
||||||
const events =
|
const events =
|
||||||
'events' in options.apm
|
'events' in options.apm
|
||||||
|
|
|
@ -20,12 +20,12 @@ import { ProcessorEvent } from '@kbn/observability-plugin/common';
|
||||||
import { unwrapEsResponse } from '@kbn/observability-plugin/server';
|
import { unwrapEsResponse } from '@kbn/observability-plugin/server';
|
||||||
import { compact, omit } from 'lodash';
|
import { compact, omit } from 'lodash';
|
||||||
import { ValuesType } from 'utility-types';
|
import { ValuesType } from 'utility-types';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { ApmDataSource } from '../../../../../common/data_source';
|
import { ApmDataSource } from '../../../../../common/data_source';
|
||||||
import { APMError } from '../../../../../typings/es_schemas/ui/apm_error';
|
import { APMError } from '../../../../../typings/es_schemas/ui/apm_error';
|
||||||
import { Metric } from '../../../../../typings/es_schemas/ui/metric';
|
import { Metric } from '../../../../../typings/es_schemas/ui/metric';
|
||||||
import { Span } from '../../../../../typings/es_schemas/ui/span';
|
import { Span } from '../../../../../typings/es_schemas/ui/span';
|
||||||
import { Transaction } from '../../../../../typings/es_schemas/ui/transaction';
|
import { Transaction } from '../../../../../typings/es_schemas/ui/transaction';
|
||||||
import { ApmIndicesConfig } from '../../../../routes/settings/apm_indices/get_apm_indices';
|
|
||||||
import { withApmSpan } from '../../../../utils/with_apm_span';
|
import { withApmSpan } from '../../../../utils/with_apm_span';
|
||||||
import {
|
import {
|
||||||
callAsyncWithDebug,
|
callAsyncWithDebug,
|
||||||
|
@ -87,7 +87,7 @@ export interface APMEventClientConfig {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
debug: boolean;
|
debug: boolean;
|
||||||
request: KibanaRequest;
|
request: KibanaRequest;
|
||||||
indices: ApmIndicesConfig;
|
indices: APMIndices;
|
||||||
options: {
|
options: {
|
||||||
includeFrozen: boolean;
|
includeFrozen: boolean;
|
||||||
forceSyntheticSource: boolean;
|
forceSyntheticSource: boolean;
|
||||||
|
@ -98,7 +98,7 @@ export class APMEventClient {
|
||||||
private readonly esClient: ElasticsearchClient;
|
private readonly esClient: ElasticsearchClient;
|
||||||
private readonly debug: boolean;
|
private readonly debug: boolean;
|
||||||
private readonly request: KibanaRequest;
|
private readonly request: KibanaRequest;
|
||||||
public readonly indices: ApmIndicesConfig;
|
public readonly indices: APMIndices;
|
||||||
private readonly includeFrozen: boolean;
|
private readonly includeFrozen: boolean;
|
||||||
private readonly forceSyntheticSource: boolean;
|
private readonly forceSyntheticSource: boolean;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||||
import { APMRouteHandlerResources } from '../../../../routes/typings';
|
import { APMRouteHandlerResources } from '../../../../routes/apm_routes/register_apm_server_routes';
|
||||||
import { getInfraMetricIndices } from '../../get_infra_metric_indices';
|
import { getInfraMetricIndices } from '../../get_infra_metric_indices';
|
||||||
|
|
||||||
type InfraMetricsSearchParams = Omit<ESSearchRequest, 'index'> & {
|
type InfraMetricsSearchParams = Omit<ESSearchRequest, 'index'> & {
|
||||||
|
|
|
@ -8,17 +8,15 @@
|
||||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||||
import { unwrapEsResponse } from '@kbn/observability-plugin/server';
|
import { unwrapEsResponse } from '@kbn/observability-plugin/server';
|
||||||
import type { ESSearchResponse, ESSearchRequest } from '@kbn/es-types';
|
import type { ESSearchResponse, ESSearchRequest } from '@kbn/es-types';
|
||||||
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { APMConfig } from '../../../..';
|
import { APMRouteHandlerResources } from '../../../../routes/apm_routes/register_apm_server_routes';
|
||||||
import { APMRouteHandlerResources } from '../../../../routes/typings';
|
|
||||||
import {
|
import {
|
||||||
callAsyncWithDebug,
|
callAsyncWithDebug,
|
||||||
getDebugBody,
|
getDebugBody,
|
||||||
getDebugTitle,
|
getDebugTitle,
|
||||||
} from '../call_async_with_debug';
|
} from '../call_async_with_debug';
|
||||||
import { cancelEsRequestOnAbort } from '../cancel_es_request_on_abort';
|
import { cancelEsRequestOnAbort } from '../cancel_es_request_on_abort';
|
||||||
import { getApmIndices } from '../../../../routes/settings/apm_indices/get_apm_indices';
|
|
||||||
|
|
||||||
export type APMIndexDocumentParams<T> = estypes.IndexRequest<T>;
|
export type APMIndexDocumentParams<T> = estypes.IndexRequest<T>;
|
||||||
|
|
||||||
|
@ -28,39 +26,35 @@ export type APMInternalESClient = Awaited<
|
||||||
|
|
||||||
export async function createInternalESClientWithContext({
|
export async function createInternalESClientWithContext({
|
||||||
debug,
|
debug,
|
||||||
config,
|
apmIndices,
|
||||||
request,
|
request,
|
||||||
context,
|
context,
|
||||||
}: {
|
}: {
|
||||||
debug: boolean;
|
debug: boolean;
|
||||||
config: APMConfig;
|
apmIndices: APMIndices;
|
||||||
request: APMRouteHandlerResources['request'];
|
request: APMRouteHandlerResources['request'];
|
||||||
context: APMRouteHandlerResources['context'];
|
context: APMRouteHandlerResources['context'];
|
||||||
}) {
|
}) {
|
||||||
const coreContext = await context.core;
|
const coreContext = await context.core;
|
||||||
const { asInternalUser } = coreContext.elasticsearch.client;
|
const { asInternalUser } = coreContext.elasticsearch.client;
|
||||||
const savedObjectsClient = coreContext.savedObjects.client;
|
|
||||||
|
|
||||||
return createInternalESClient({
|
return createInternalESClient({
|
||||||
debug,
|
debug,
|
||||||
config,
|
apmIndices,
|
||||||
request,
|
request,
|
||||||
savedObjectsClient,
|
|
||||||
elasticsearchClient: asInternalUser,
|
elasticsearchClient: asInternalUser,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createInternalESClient({
|
export async function createInternalESClient({
|
||||||
debug,
|
debug,
|
||||||
config,
|
apmIndices,
|
||||||
request,
|
request,
|
||||||
savedObjectsClient,
|
|
||||||
elasticsearchClient,
|
elasticsearchClient,
|
||||||
}: {
|
}: {
|
||||||
debug: boolean;
|
debug: boolean;
|
||||||
config: APMConfig;
|
apmIndices: APMIndices;
|
||||||
request?: APMRouteHandlerResources['request'];
|
request?: APMRouteHandlerResources['request'];
|
||||||
savedObjectsClient: SavedObjectsClientContract;
|
|
||||||
elasticsearchClient: ElasticsearchClient;
|
elasticsearchClient: ElasticsearchClient;
|
||||||
}) {
|
}) {
|
||||||
function callEs<T extends { body: any }>(
|
function callEs<T extends { body: any }>(
|
||||||
|
@ -98,7 +92,7 @@ export async function createInternalESClient({
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
apmIndices: await getApmIndices({ savedObjectsClient, config }),
|
apmIndices,
|
||||||
search: async <
|
search: async <
|
||||||
TDocument = unknown,
|
TDocument = unknown,
|
||||||
TSearchRequest extends ESSearchRequest = ESSearchRequest
|
TSearchRequest extends ESSearchRequest = ESSearchRequest
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||||
import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common';
|
import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common';
|
||||||
import { APMRouteHandlerResources } from '../../routes/typings';
|
import { APMRouteHandlerResources } from '../../routes/apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
export type ApmAlertsClient = Awaited<ReturnType<typeof getApmAlertsClient>>;
|
export type ApmAlertsClient = Awaited<ReturnType<typeof getApmAlertsClient>>;
|
||||||
|
|
||||||
|
|
|
@ -6,24 +6,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { UI_SETTINGS } from '@kbn/data-plugin/common';
|
import { UI_SETTINGS } from '@kbn/data-plugin/common';
|
||||||
import { APMRouteHandlerResources } from '../../routes/typings';
|
|
||||||
import { getApmIndices } from '../../routes/settings/apm_indices/get_apm_indices';
|
|
||||||
import { APMEventClient } from './create_es_client/create_apm_event_client';
|
import { APMEventClient } from './create_es_client/create_apm_event_client';
|
||||||
import { withApmSpan } from '../../utils/with_apm_span';
|
import { withApmSpan } from '../../utils/with_apm_span';
|
||||||
|
import { APMRouteHandlerResources } from '../../routes/apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
export async function getApmEventClient({
|
export async function getApmEventClient({
|
||||||
context,
|
context,
|
||||||
params,
|
params,
|
||||||
config,
|
config,
|
||||||
|
getApmIndices,
|
||||||
request,
|
request,
|
||||||
}: APMRouteHandlerResources): Promise<APMEventClient> {
|
}: APMRouteHandlerResources): Promise<APMEventClient> {
|
||||||
return withApmSpan('get_apm_event_client', async () => {
|
return withApmSpan('get_apm_event_client', async () => {
|
||||||
const coreContext = await context.core;
|
const coreContext = await context.core;
|
||||||
const [indices, includeFrozen] = await Promise.all([
|
const [indices, includeFrozen] = await Promise.all([
|
||||||
getApmIndices({
|
getApmIndices(),
|
||||||
savedObjectsClient: coreContext.savedObjects.client,
|
|
||||||
config,
|
|
||||||
}),
|
|
||||||
withApmSpan('get_ui_settings', () =>
|
withApmSpan('get_ui_settings', () =>
|
||||||
coreContext.uiSettings.client.get<boolean>(
|
coreContext.uiSettings.client.get<boolean>(
|
||||||
UI_SETTINGS.SEARCH_INCLUDE_FROZEN
|
UI_SETTINGS.SEARCH_INCLUDE_FROZEN
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { SavedObjectsClientContract } from '@kbn/core/server';
|
import { SavedObjectsClientContract } from '@kbn/core/server';
|
||||||
import { APMRouteHandlerResources } from '../../routes/typings';
|
import { APMRouteHandlerResources } from '../../routes/apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
export async function getInfraMetricIndices({
|
export async function getInfraMetricIndices({
|
||||||
infraPlugin,
|
infraPlugin,
|
||||||
|
|
|
@ -7,10 +7,6 @@
|
||||||
|
|
||||||
import { CoreStart } from '@kbn/core/server';
|
import { CoreStart } from '@kbn/core/server';
|
||||||
|
|
||||||
export type InternalSavedObjectsClient = Awaited<
|
|
||||||
ReturnType<typeof getInternalSavedObjectsClient>
|
|
||||||
>;
|
|
||||||
|
|
||||||
export async function getInternalSavedObjectsClient(coreStart: CoreStart) {
|
export async function getInternalSavedObjectsClient(coreStart: CoreStart) {
|
||||||
return coreStart.savedObjects.createInternalRepository();
|
return coreStart.savedObjects.createInternalRepository();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
MlModules,
|
MlModules,
|
||||||
} from '@kbn/ml-plugin/server';
|
} from '@kbn/ml-plugin/server';
|
||||||
import { isActivePlatinumLicense } from '../../../common/license_check';
|
import { isActivePlatinumLicense } from '../../../common/license_check';
|
||||||
import { APMRouteHandlerResources } from '../../routes/typings';
|
import { APMRouteHandlerResources } from '../../routes/apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
export interface MlClient {
|
export interface MlClient {
|
||||||
mlSystem: MlMlSystem;
|
mlSystem: MlMlSystem;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import { KibanaRequest } from '@kbn/core/server';
|
import { KibanaRequest } from '@kbn/core/server';
|
||||||
import seedrandom from 'seedrandom';
|
import seedrandom from 'seedrandom';
|
||||||
import { APMRouteHandlerResources } from '../../..';
|
import { APMRouteHandlerResources } from '../../../routes/apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
export async function getRandomSampler({
|
export async function getRandomSampler({
|
||||||
security,
|
security,
|
||||||
|
|
|
@ -5,18 +5,15 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { firstValueFrom } from 'rxjs';
|
|
||||||
import {
|
import {
|
||||||
CoreSetup,
|
CoreSetup,
|
||||||
CoreStart,
|
CoreStart,
|
||||||
KibanaRequest,
|
|
||||||
Logger,
|
Logger,
|
||||||
Plugin,
|
Plugin,
|
||||||
PluginInitializerContext,
|
PluginInitializerContext,
|
||||||
} from '@kbn/core/server';
|
} from '@kbn/core/server';
|
||||||
import { isEmpty, mapValues } from 'lodash';
|
import { isEmpty, mapValues } from 'lodash';
|
||||||
import { Dataset } from '@kbn/rule-registry-plugin/server';
|
import { Dataset } from '@kbn/rule-registry-plugin/server';
|
||||||
import { UI_SETTINGS } from '@kbn/data-plugin/common';
|
|
||||||
import { mappingFromFieldMap } from '@kbn/alerting-plugin/common';
|
import { mappingFromFieldMap } from '@kbn/alerting-plugin/common';
|
||||||
import { alertsLocatorID } from '@kbn/observability-plugin/common';
|
import { alertsLocatorID } from '@kbn/observability-plugin/common';
|
||||||
import { APMConfig, APM_SERVER_FEATURE_ID } from '.';
|
import { APMConfig, APM_SERVER_FEATURE_ID } from '.';
|
||||||
|
@ -28,30 +25,25 @@ import {
|
||||||
} from './routes/alerts/register_apm_rule_types';
|
} from './routes/alerts/register_apm_rule_types';
|
||||||
import { registerFleetPolicyCallbacks } from './routes/fleet/register_fleet_policy_callbacks';
|
import { registerFleetPolicyCallbacks } from './routes/fleet/register_fleet_policy_callbacks';
|
||||||
import { createApmTelemetry } from './lib/apm_telemetry';
|
import { createApmTelemetry } from './lib/apm_telemetry';
|
||||||
import { APMEventClient } from './lib/helpers/create_es_client/create_apm_event_client';
|
|
||||||
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
|
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
|
||||||
import { createApmAgentConfigurationIndex } from './routes/settings/agent_configuration/create_agent_config_index';
|
import { createApmAgentConfigurationIndex } from './routes/settings/agent_configuration/create_agent_config_index';
|
||||||
import { getApmIndices } from './routes/settings/apm_indices/get_apm_indices';
|
|
||||||
import { createApmCustomLinkIndex } from './routes/settings/custom_link/create_custom_link_index';
|
import { createApmCustomLinkIndex } from './routes/settings/custom_link/create_custom_link_index';
|
||||||
import {
|
import {
|
||||||
apmIndices,
|
|
||||||
apmTelemetry,
|
apmTelemetry,
|
||||||
apmServerSettings,
|
apmServerSettings,
|
||||||
apmServiceGroups,
|
apmServiceGroups,
|
||||||
} from './saved_objects';
|
} from './saved_objects';
|
||||||
import type {
|
|
||||||
ApmPluginRequestHandlerContext,
|
|
||||||
APMRouteHandlerResources,
|
|
||||||
} from './routes/typings';
|
|
||||||
import {
|
import {
|
||||||
APMPluginSetup,
|
APMPluginSetup,
|
||||||
APMPluginSetupDependencies,
|
APMPluginSetupDependencies,
|
||||||
APMPluginStartDependencies,
|
APMPluginStartDependencies,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { registerRoutes } from './routes/apm_routes/register_apm_server_routes';
|
import {
|
||||||
|
APMRouteHandlerResources,
|
||||||
|
registerRoutes,
|
||||||
|
} from './routes/apm_routes/register_apm_server_routes';
|
||||||
import { getGlobalApmServerRouteRepository } from './routes/apm_routes/get_global_apm_server_route_repository';
|
import { getGlobalApmServerRouteRepository } from './routes/apm_routes/get_global_apm_server_route_repository';
|
||||||
import { tutorialProvider } from './tutorial';
|
import { tutorialProvider } from './tutorial';
|
||||||
import { migrateLegacyAPMIndicesToSpaceAware } from './saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware';
|
|
||||||
import { scheduleSourceMapMigration } from './routes/source_maps/schedule_source_map_migration';
|
import { scheduleSourceMapMigration } from './routes/source_maps/schedule_source_map_migration';
|
||||||
import { createApmSourceMapIndexTemplate } from './routes/source_maps/create_apm_source_map_index_template';
|
import { createApmSourceMapIndexTemplate } from './routes/source_maps/create_apm_source_map_index_template';
|
||||||
import { addApiKeysToEveryPackagePolicyIfMissing } from './routes/fleet/api_keys/add_api_keys_to_policies_if_missing';
|
import { addApiKeysToEveryPackagePolicyIfMissing } from './routes/fleet/api_keys/add_api_keys_to_policies_if_missing';
|
||||||
|
@ -80,7 +72,6 @@ export class APMPlugin
|
||||||
this.logger = this.initContext.logger.get();
|
this.logger = this.initContext.logger.get();
|
||||||
const config$ = this.initContext.config.create<APMConfig>();
|
const config$ = this.initContext.config.create<APMConfig>();
|
||||||
|
|
||||||
core.savedObjects.registerType(apmIndices);
|
|
||||||
core.savedObjects.registerType(apmTelemetry);
|
core.savedObjects.registerType(apmTelemetry);
|
||||||
core.savedObjects.registerType(apmServerSettings);
|
core.savedObjects.registerType(apmServerSettings);
|
||||||
core.savedObjects.registerType(apmServiceGroups);
|
core.savedObjects.registerType(apmServiceGroups);
|
||||||
|
@ -95,7 +86,7 @@ export class APMPlugin
|
||||||
) {
|
) {
|
||||||
createApmTelemetry({
|
createApmTelemetry({
|
||||||
core,
|
core,
|
||||||
config: currentConfig,
|
getApmIndices: plugins.apmDataAccess.getApmIndices,
|
||||||
usageCollector: plugins.usageCollection,
|
usageCollector: plugins.usageCollection,
|
||||||
taskManager: plugins.taskManager,
|
taskManager: plugins.taskManager,
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
|
@ -141,13 +132,12 @@ export class APMPlugin
|
||||||
};
|
};
|
||||||
}) as APMRouteHandlerResources['plugins'];
|
}) as APMRouteHandlerResources['plugins'];
|
||||||
|
|
||||||
const boundGetApmIndices = async () => {
|
const apmIndicesPromise = (async () => {
|
||||||
const coreStart = await getCoreStart();
|
const coreStart = await getCoreStart();
|
||||||
return getApmIndices({
|
const soClient = await getInternalSavedObjectsClient(coreStart);
|
||||||
savedObjectsClient: await getInternalSavedObjectsClient(coreStart),
|
const { getApmIndices } = plugins.apmDataAccess;
|
||||||
config: await firstValueFrom(config$),
|
return getApmIndices(soClient);
|
||||||
});
|
})();
|
||||||
};
|
|
||||||
|
|
||||||
// This if else block will go away in favour of removing Home Tutorial Integration
|
// This if else block will go away in favour of removing Home Tutorial Integration
|
||||||
// Ideally we will directly register a custom integration and pass the configs
|
// Ideally we will directly register a custom integration and pass the configs
|
||||||
|
@ -158,11 +148,11 @@ export class APMPlugin
|
||||||
apmTutorialCustomIntegration
|
apmTutorialCustomIntegration
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
boundGetApmIndices().then((indices) => {
|
apmIndicesPromise.then((apmIndices) => {
|
||||||
plugins.home?.tutorials.registerTutorial(
|
plugins.home?.tutorials.registerTutorial(
|
||||||
tutorialProvider({
|
tutorialProvider({
|
||||||
apmConfig: currentConfig,
|
apmConfig: currentConfig,
|
||||||
apmIndices: indices,
|
apmIndices,
|
||||||
cloud: plugins.cloud,
|
cloud: plugins.cloud,
|
||||||
isFleetPluginEnabled: !isEmpty(resourcePlugins.fleet),
|
isFleetPluginEnabled: !isEmpty(resourcePlugins.fleet),
|
||||||
})
|
})
|
||||||
|
@ -190,11 +180,14 @@ export class APMPlugin
|
||||||
kibanaVersion: this.initContext.env.packageInfo.version,
|
kibanaVersion: this.initContext.env.packageInfo.version,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { getApmIndices } = plugins.apmDataAccess;
|
||||||
|
|
||||||
if (plugins.alerting) {
|
if (plugins.alerting) {
|
||||||
registerApmRuleTypes({
|
registerApmRuleTypes({
|
||||||
|
getApmIndices,
|
||||||
alerting: plugins.alerting,
|
alerting: plugins.alerting,
|
||||||
basePath: core.http.basePath,
|
basePath: core.http.basePath,
|
||||||
config$,
|
apmConfig: currentConfig,
|
||||||
logger: this.logger!.get('rule'),
|
logger: this.logger!.get('rule'),
|
||||||
ml: plugins.ml,
|
ml: plugins.ml,
|
||||||
observability: plugins.observability,
|
observability: plugins.observability,
|
||||||
|
@ -207,7 +200,6 @@ export class APMPlugin
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
coreStartPromise: getCoreStart(),
|
coreStartPromise: getCoreStart(),
|
||||||
plugins: resourcePlugins,
|
plugins: resourcePlugins,
|
||||||
config: currentConfig,
|
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
this.logger?.error('Failed to register APM Fleet policy callbacks');
|
this.logger?.error('Failed to register APM Fleet policy callbacks');
|
||||||
this.logger?.error(e);
|
this.logger?.error(e);
|
||||||
|
@ -236,38 +228,7 @@ export class APMPlugin
|
||||||
this.logger?.error(e);
|
this.logger?.error(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return { config$ };
|
||||||
config$,
|
|
||||||
getApmIndices: boundGetApmIndices,
|
|
||||||
createApmEventClient: async ({
|
|
||||||
request,
|
|
||||||
context,
|
|
||||||
debug,
|
|
||||||
}: {
|
|
||||||
debug?: boolean;
|
|
||||||
request: KibanaRequest;
|
|
||||||
context: ApmPluginRequestHandlerContext;
|
|
||||||
}) => {
|
|
||||||
const coreContext = await context.core;
|
|
||||||
const [indices, includeFrozen] = await Promise.all([
|
|
||||||
boundGetApmIndices(),
|
|
||||||
coreContext.uiSettings.client.get(UI_SETTINGS.SEARCH_INCLUDE_FROZEN),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const esClient = coreContext.elasticsearch.client.asCurrentUser;
|
|
||||||
|
|
||||||
return new APMEventClient({
|
|
||||||
debug: debug ?? false,
|
|
||||||
esClient,
|
|
||||||
request,
|
|
||||||
indices,
|
|
||||||
options: {
|
|
||||||
includeFrozen,
|
|
||||||
forceSyntheticSource: currentConfig.forceSyntheticSource,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public start(core: CoreStart, plugins: APMPluginStartDependencies) {
|
public start(core: CoreStart, plugins: APMPluginStartDependencies) {
|
||||||
|
@ -295,14 +256,6 @@ export class APMPlugin
|
||||||
logger.error('Failed to create apm-source-map index template');
|
logger.error('Failed to create apm-source-map index template');
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: remove in 9.0
|
|
||||||
migrateLegacyAPMIndicesToSpaceAware({ coreStart: core, logger }).catch(
|
|
||||||
(e) => {
|
|
||||||
logger.error('Failed to run migration making APM indices space aware');
|
|
||||||
logger.error(e);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop() {}
|
public stop() {}
|
||||||
|
|
|
@ -7,8 +7,11 @@
|
||||||
|
|
||||||
import type { AlertsLocatorParams } from '@kbn/observability-plugin/common';
|
import type { AlertsLocatorParams } from '@kbn/observability-plugin/common';
|
||||||
import { LocatorPublic } from '@kbn/share-plugin/common';
|
import { LocatorPublic } from '@kbn/share-plugin/common';
|
||||||
import { Observable } from 'rxjs';
|
import {
|
||||||
import { IBasePath, Logger } from '@kbn/core/server';
|
IBasePath,
|
||||||
|
Logger,
|
||||||
|
SavedObjectsClientContract,
|
||||||
|
} from '@kbn/core/server';
|
||||||
import {
|
import {
|
||||||
PluginSetupContract as AlertingPluginSetupContract,
|
PluginSetupContract as AlertingPluginSetupContract,
|
||||||
type IRuleTypeAlerts,
|
type IRuleTypeAlerts,
|
||||||
|
@ -17,6 +20,7 @@ import { ObservabilityPluginSetup } from '@kbn/observability-plugin/server';
|
||||||
import { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
|
import { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
|
||||||
import { MlPluginSetup } from '@kbn/ml-plugin/server';
|
import { MlPluginSetup } from '@kbn/ml-plugin/server';
|
||||||
import { legacyExperimentalFieldMap } from '@kbn/alerts-as-data-utils';
|
import { legacyExperimentalFieldMap } from '@kbn/alerts-as-data-utils';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import {
|
import {
|
||||||
AGENT_NAME,
|
AGENT_NAME,
|
||||||
ERROR_GROUP_ID,
|
ERROR_GROUP_ID,
|
||||||
|
@ -91,7 +95,8 @@ export const ApmRuleTypeAlertDefinition: IRuleTypeAlerts = {
|
||||||
export interface RegisterRuleDependencies {
|
export interface RegisterRuleDependencies {
|
||||||
alerting: AlertingPluginSetupContract;
|
alerting: AlertingPluginSetupContract;
|
||||||
basePath: IBasePath;
|
basePath: IBasePath;
|
||||||
config$: Observable<APMConfig>;
|
getApmIndices: (soClient: SavedObjectsClientContract) => Promise<APMIndices>;
|
||||||
|
apmConfig: APMConfig;
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
ml?: MlPluginSetup;
|
ml?: MlPluginSetup;
|
||||||
observability: ObservabilityPluginSetup;
|
observability: ObservabilityPluginSetup;
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
import { firstValueFrom } from 'rxjs';
|
|
||||||
import {
|
import {
|
||||||
IScopedClusterClient,
|
IScopedClusterClient,
|
||||||
SavedObjectsClientContract,
|
SavedObjectsClientContract,
|
||||||
} from '@kbn/core/server';
|
} from '@kbn/core/server';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import {
|
import {
|
||||||
SERVICE_ENVIRONMENT,
|
SERVICE_ENVIRONMENT,
|
||||||
SERVICE_NAME,
|
SERVICE_NAME,
|
||||||
|
@ -20,20 +21,17 @@ import {
|
||||||
getServiceGroupFields,
|
getServiceGroupFields,
|
||||||
getServiceGroupFieldsAgg,
|
getServiceGroupFieldsAgg,
|
||||||
} from '../get_service_group_fields';
|
} from '../get_service_group_fields';
|
||||||
import { getApmIndices } from '../../../settings/apm_indices/get_apm_indices';
|
|
||||||
import { RegisterRuleDependencies } from '../../register_apm_rule_types';
|
|
||||||
|
|
||||||
export async function getServiceGroupFieldsForAnomaly({
|
export async function getServiceGroupFieldsForAnomaly({
|
||||||
config$,
|
apmIndices,
|
||||||
scopedClusterClient,
|
scopedClusterClient,
|
||||||
savedObjectsClient,
|
|
||||||
serviceName,
|
serviceName,
|
||||||
environment,
|
environment,
|
||||||
transactionType,
|
transactionType,
|
||||||
timestamp,
|
timestamp,
|
||||||
bucketSpan,
|
bucketSpan,
|
||||||
}: {
|
}: {
|
||||||
config$: RegisterRuleDependencies['config$'];
|
apmIndices: APMIndices;
|
||||||
scopedClusterClient: IScopedClusterClient;
|
scopedClusterClient: IScopedClusterClient;
|
||||||
savedObjectsClient: SavedObjectsClientContract;
|
savedObjectsClient: SavedObjectsClientContract;
|
||||||
serviceName: string;
|
serviceName: string;
|
||||||
|
@ -42,15 +40,8 @@ export async function getServiceGroupFieldsForAnomaly({
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
bucketSpan: number;
|
bucketSpan: number;
|
||||||
}) {
|
}) {
|
||||||
const config = await firstValueFrom(config$);
|
|
||||||
const indices = await getApmIndices({
|
|
||||||
config,
|
|
||||||
savedObjectsClient,
|
|
||||||
});
|
|
||||||
const { transaction: index } = indices;
|
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
index,
|
index: apmIndices.transaction,
|
||||||
body: {
|
body: {
|
||||||
size: 0,
|
size: 0,
|
||||||
track_total_hits: false,
|
track_total_hits: false,
|
||||||
|
|
|
@ -63,8 +63,8 @@ const ruleTypeConfig = RULE_TYPES_CONFIG[ApmRuleType.Anomaly];
|
||||||
export function registerAnomalyRuleType({
|
export function registerAnomalyRuleType({
|
||||||
alerting,
|
alerting,
|
||||||
alertsLocator,
|
alertsLocator,
|
||||||
|
getApmIndices,
|
||||||
basePath,
|
basePath,
|
||||||
config$,
|
|
||||||
logger,
|
logger,
|
||||||
ml,
|
ml,
|
||||||
ruleDataClient,
|
ruleDataClient,
|
||||||
|
@ -108,6 +108,8 @@ export function registerAnomalyRuleType({
|
||||||
scopedClusterClient,
|
scopedClusterClient,
|
||||||
} = services;
|
} = services;
|
||||||
|
|
||||||
|
const apmIndices = await getApmIndices(savedObjectsClient);
|
||||||
|
|
||||||
const ruleParams = params;
|
const ruleParams = params;
|
||||||
const request = {} as KibanaRequest;
|
const request = {} as KibanaRequest;
|
||||||
const { mlAnomalySearch } = ml.mlSystemProvider(
|
const { mlAnomalySearch } = ml.mlSystemProvider(
|
||||||
|
@ -256,7 +258,7 @@ export function registerAnomalyRuleType({
|
||||||
} = anomaly;
|
} = anomaly;
|
||||||
|
|
||||||
const eventSourceFields = await getServiceGroupFieldsForAnomaly({
|
const eventSourceFields = await getServiceGroupFieldsForAnomaly({
|
||||||
config$,
|
apmIndices,
|
||||||
scopedClusterClient,
|
scopedClusterClient,
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
serviceName,
|
serviceName,
|
||||||
|
|
|
@ -25,7 +25,6 @@ import {
|
||||||
} from '@kbn/observability-plugin/server';
|
} from '@kbn/observability-plugin/server';
|
||||||
import { addSpaceIdToPath } from '@kbn/spaces-plugin/common';
|
import { addSpaceIdToPath } from '@kbn/spaces-plugin/common';
|
||||||
import { asyncForEach } from '@kbn/std';
|
import { asyncForEach } from '@kbn/std';
|
||||||
import { firstValueFrom } from 'rxjs';
|
|
||||||
import { getEnvironmentEsField } from '../../../../../common/environment_filter_values';
|
import { getEnvironmentEsField } from '../../../../../common/environment_filter_values';
|
||||||
import {
|
import {
|
||||||
ERROR_GROUP_ID,
|
ERROR_GROUP_ID,
|
||||||
|
@ -42,7 +41,6 @@ import {
|
||||||
import { errorCountParamsSchema } from '../../../../../common/rules/schema';
|
import { errorCountParamsSchema } from '../../../../../common/rules/schema';
|
||||||
import { environmentQuery } from '../../../../../common/utils/environment_query';
|
import { environmentQuery } from '../../../../../common/utils/environment_query';
|
||||||
import { getAlertUrlErrorCount } from '../../../../../common/utils/formatters';
|
import { getAlertUrlErrorCount } from '../../../../../common/utils/formatters';
|
||||||
import { getApmIndices } from '../../../settings/apm_indices/get_apm_indices';
|
|
||||||
import { apmActionVariables } from '../../action_variables';
|
import { apmActionVariables } from '../../action_variables';
|
||||||
import { alertingEsClient } from '../../alerting_es_client';
|
import { alertingEsClient } from '../../alerting_es_client';
|
||||||
import {
|
import {
|
||||||
|
@ -63,7 +61,7 @@ export function registerErrorCountRuleType({
|
||||||
alerting,
|
alerting,
|
||||||
alertsLocator,
|
alertsLocator,
|
||||||
basePath,
|
basePath,
|
||||||
config$,
|
getApmIndices,
|
||||||
logger,
|
logger,
|
||||||
ruleDataClient,
|
ruleDataClient,
|
||||||
}: RegisterRuleDependencies) {
|
}: RegisterRuleDependencies) {
|
||||||
|
@ -108,8 +106,6 @@ export function registerErrorCountRuleType({
|
||||||
ruleParams.groupBy
|
ruleParams.groupBy
|
||||||
);
|
);
|
||||||
|
|
||||||
const config = await firstValueFrom(config$);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getAlertUuid,
|
getAlertUuid,
|
||||||
getAlertStartedDate,
|
getAlertStartedDate,
|
||||||
|
@ -117,10 +113,7 @@ export function registerErrorCountRuleType({
|
||||||
scopedClusterClient,
|
scopedClusterClient,
|
||||||
} = services;
|
} = services;
|
||||||
|
|
||||||
const indices = await getApmIndices({
|
const indices = await getApmIndices(savedObjectsClient);
|
||||||
config,
|
|
||||||
savedObjectsClient,
|
|
||||||
});
|
|
||||||
|
|
||||||
const termFilterQuery = !ruleParams.kqlFilter
|
const termFilterQuery = !ruleParams.kqlFilter
|
||||||
? [
|
? [
|
||||||
|
|
|
@ -26,7 +26,6 @@ import {
|
||||||
} from '@kbn/rule-data-utils';
|
} from '@kbn/rule-data-utils';
|
||||||
import { createLifecycleRuleTypeFactory } from '@kbn/rule-registry-plugin/server';
|
import { createLifecycleRuleTypeFactory } from '@kbn/rule-registry-plugin/server';
|
||||||
import { addSpaceIdToPath } from '@kbn/spaces-plugin/common';
|
import { addSpaceIdToPath } from '@kbn/spaces-plugin/common';
|
||||||
import { firstValueFrom } from 'rxjs';
|
|
||||||
import { getGroupByTerms } from '../utils/get_groupby_terms';
|
import { getGroupByTerms } from '../utils/get_groupby_terms';
|
||||||
import { SearchAggregatedTransactionSetting } from '../../../../../common/aggregated_transactions';
|
import { SearchAggregatedTransactionSetting } from '../../../../../common/aggregated_transactions';
|
||||||
import { getEnvironmentEsField } from '../../../../../common/environment_filter_values';
|
import { getEnvironmentEsField } from '../../../../../common/environment_filter_values';
|
||||||
|
@ -53,7 +52,6 @@ import {
|
||||||
getDocumentTypeFilterForTransactions,
|
getDocumentTypeFilterForTransactions,
|
||||||
getDurationFieldForTransactions,
|
getDurationFieldForTransactions,
|
||||||
} from '../../../../lib/helpers/transactions';
|
} from '../../../../lib/helpers/transactions';
|
||||||
import { getApmIndices } from '../../../settings/apm_indices/get_apm_indices';
|
|
||||||
import { apmActionVariables } from '../../action_variables';
|
import { apmActionVariables } from '../../action_variables';
|
||||||
import { alertingEsClient } from '../../alerting_es_client';
|
import { alertingEsClient } from '../../alerting_es_client';
|
||||||
import {
|
import {
|
||||||
|
@ -76,7 +74,8 @@ const ruleTypeConfig = RULE_TYPES_CONFIG[ApmRuleType.TransactionDuration];
|
||||||
export function registerTransactionDurationRuleType({
|
export function registerTransactionDurationRuleType({
|
||||||
alerting,
|
alerting,
|
||||||
ruleDataClient,
|
ruleDataClient,
|
||||||
config$,
|
getApmIndices,
|
||||||
|
apmConfig,
|
||||||
logger,
|
logger,
|
||||||
basePath,
|
basePath,
|
||||||
}: RegisterRuleDependencies) {
|
}: RegisterRuleDependencies) {
|
||||||
|
@ -114,21 +113,16 @@ export function registerTransactionDurationRuleType({
|
||||||
ruleParams.groupBy
|
ruleParams.groupBy
|
||||||
);
|
);
|
||||||
|
|
||||||
const config = await firstValueFrom(config$);
|
|
||||||
|
|
||||||
const { getAlertUuid, savedObjectsClient, scopedClusterClient } =
|
const { getAlertUuid, savedObjectsClient, scopedClusterClient } =
|
||||||
services;
|
services;
|
||||||
|
|
||||||
const indices = await getApmIndices({
|
const indices = await getApmIndices(savedObjectsClient);
|
||||||
config,
|
|
||||||
savedObjectsClient,
|
|
||||||
});
|
|
||||||
|
|
||||||
// only query transaction events when set to 'never',
|
// only query transaction events when set to 'never',
|
||||||
// to prevent (likely) unnecessary blocking request
|
// to prevent (likely) unnecessary blocking request
|
||||||
// in rule execution
|
// in rule execution
|
||||||
const searchAggregatedTransactions =
|
const searchAggregatedTransactions =
|
||||||
config.searchAggregatedTransactions !==
|
apmConfig.searchAggregatedTransactions !==
|
||||||
SearchAggregatedTransactionSetting.never;
|
SearchAggregatedTransactionSetting.never;
|
||||||
|
|
||||||
const index = searchAggregatedTransactions
|
const index = searchAggregatedTransactions
|
||||||
|
|
|
@ -26,7 +26,6 @@ import {
|
||||||
import { createLifecycleRuleTypeFactory } from '@kbn/rule-registry-plugin/server';
|
import { createLifecycleRuleTypeFactory } from '@kbn/rule-registry-plugin/server';
|
||||||
import { addSpaceIdToPath } from '@kbn/spaces-plugin/common';
|
import { addSpaceIdToPath } from '@kbn/spaces-plugin/common';
|
||||||
import { asyncForEach } from '@kbn/std';
|
import { asyncForEach } from '@kbn/std';
|
||||||
import { firstValueFrom } from 'rxjs';
|
|
||||||
import { SearchAggregatedTransactionSetting } from '../../../../../common/aggregated_transactions';
|
import { SearchAggregatedTransactionSetting } from '../../../../../common/aggregated_transactions';
|
||||||
import { getEnvironmentEsField } from '../../../../../common/environment_filter_values';
|
import { getEnvironmentEsField } from '../../../../../common/environment_filter_values';
|
||||||
import {
|
import {
|
||||||
|
@ -51,7 +50,6 @@ import {
|
||||||
getAlertUrlTransaction,
|
getAlertUrlTransaction,
|
||||||
} from '../../../../../common/utils/formatters';
|
} from '../../../../../common/utils/formatters';
|
||||||
import { getDocumentTypeFilterForTransactions } from '../../../../lib/helpers/transactions';
|
import { getDocumentTypeFilterForTransactions } from '../../../../lib/helpers/transactions';
|
||||||
import { getApmIndices } from '../../../settings/apm_indices/get_apm_indices';
|
|
||||||
import { apmActionVariables } from '../../action_variables';
|
import { apmActionVariables } from '../../action_variables';
|
||||||
import { alertingEsClient } from '../../alerting_es_client';
|
import { alertingEsClient } from '../../alerting_es_client';
|
||||||
import {
|
import {
|
||||||
|
@ -72,7 +70,8 @@ export function registerTransactionErrorRateRuleType({
|
||||||
alerting,
|
alerting,
|
||||||
alertsLocator,
|
alertsLocator,
|
||||||
basePath,
|
basePath,
|
||||||
config$,
|
getApmIndices,
|
||||||
|
apmConfig,
|
||||||
logger,
|
logger,
|
||||||
ruleDataClient,
|
ruleDataClient,
|
||||||
}: RegisterRuleDependencies) {
|
}: RegisterRuleDependencies) {
|
||||||
|
@ -117,8 +116,6 @@ export function registerTransactionErrorRateRuleType({
|
||||||
ruleParams.groupBy
|
ruleParams.groupBy
|
||||||
);
|
);
|
||||||
|
|
||||||
const config = await firstValueFrom(config$);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getAlertUuid,
|
getAlertUuid,
|
||||||
getAlertStartedDate,
|
getAlertStartedDate,
|
||||||
|
@ -126,16 +123,13 @@ export function registerTransactionErrorRateRuleType({
|
||||||
scopedClusterClient,
|
scopedClusterClient,
|
||||||
} = services;
|
} = services;
|
||||||
|
|
||||||
const indices = await getApmIndices({
|
const indices = await getApmIndices(savedObjectsClient);
|
||||||
config,
|
|
||||||
savedObjectsClient,
|
|
||||||
});
|
|
||||||
|
|
||||||
// only query transaction events when set to 'never',
|
// only query transaction events when set to 'never',
|
||||||
// to prevent (likely) unnecessary blocking request
|
// to prevent (likely) unnecessary blocking request
|
||||||
// in rule execution
|
// in rule execution
|
||||||
const searchAggregatedTransactions =
|
const searchAggregatedTransactions =
|
||||||
config.searchAggregatedTransactions !==
|
apmConfig.searchAggregatedTransactions !==
|
||||||
SearchAggregatedTransactionSetting.never;
|
SearchAggregatedTransactionSetting.never;
|
||||||
|
|
||||||
const index = searchAggregatedTransactions
|
const index = searchAggregatedTransactions
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { of } from 'rxjs';
|
|
||||||
import { IBasePath, Logger } from '@kbn/core/server';
|
import { IBasePath, Logger } from '@kbn/core/server';
|
||||||
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
|
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
|
||||||
import type { AlertsLocatorParams } from '@kbn/observability-plugin/common';
|
import type { AlertsLocatorParams } from '@kbn/observability-plugin/common';
|
||||||
|
@ -20,13 +19,6 @@ import { APMConfig, APM_SERVER_FEATURE_ID } from '../../..';
|
||||||
export const createRuleTypeMocks = () => {
|
export const createRuleTypeMocks = () => {
|
||||||
let alertExecutor: (...args: any[]) => Promise<any>;
|
let alertExecutor: (...args: any[]) => Promise<any>;
|
||||||
|
|
||||||
const mockedConfig$ = of({
|
|
||||||
indices: {
|
|
||||||
error: 'apm-*',
|
|
||||||
transaction: 'apm-*',
|
|
||||||
},
|
|
||||||
} as APMConfig);
|
|
||||||
|
|
||||||
const loggerMock = {
|
const loggerMock = {
|
||||||
debug: jest.fn(),
|
debug: jest.fn(),
|
||||||
warn: jest.fn(),
|
warn: jest.fn(),
|
||||||
|
@ -64,7 +56,14 @@ export const createRuleTypeMocks = () => {
|
||||||
publicBaseUrl: 'http://localhost:5601/eyr',
|
publicBaseUrl: 'http://localhost:5601/eyr',
|
||||||
serverBasePath: '/eyr',
|
serverBasePath: '/eyr',
|
||||||
} as IBasePath,
|
} as IBasePath,
|
||||||
config$: mockedConfig$,
|
apmConfig: { searchAggregatedTransactions: true } as any as APMConfig,
|
||||||
|
getApmIndices: async () => ({
|
||||||
|
error: 'apm-*',
|
||||||
|
transaction: 'apm-*',
|
||||||
|
span: 'apm-*',
|
||||||
|
metric: 'apm-*',
|
||||||
|
onboarding: 'apm-*',
|
||||||
|
}),
|
||||||
observability: {
|
observability: {
|
||||||
getAlertDetailsConfig: jest.fn().mockReturnValue({ apm: true }),
|
getAlertDetailsConfig: jest.fn().mockReturnValue({ apm: true }),
|
||||||
} as unknown as ObservabilityPluginSetup,
|
} as unknown as ObservabilityPluginSetup,
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
import { createServerRouteFactory } from '@kbn/server-route-repository';
|
import { createServerRouteFactory } from '@kbn/server-route-repository';
|
||||||
import { APMRouteCreateOptions, APMRouteHandlerResources } from '../typings';
|
import { APMRouteCreateOptions } from '../typings';
|
||||||
|
import { APMRouteHandlerResources } from './register_apm_server_routes';
|
||||||
|
|
||||||
export const createApmServerRoute = createServerRouteFactory<
|
export const createApmServerRoute = createServerRouteFactory<
|
||||||
APMRouteHandlerResources,
|
APMRouteHandlerResources,
|
||||||
|
|
|
@ -13,8 +13,11 @@ import {
|
||||||
import * as t from 'io-ts';
|
import * as t from 'io-ts';
|
||||||
import { CoreSetup, Logger } from '@kbn/core/server';
|
import { CoreSetup, Logger } from '@kbn/core/server';
|
||||||
import { APMConfig } from '../..';
|
import { APMConfig } from '../..';
|
||||||
import { APMRouteCreateOptions, APMRouteHandlerResources } from '../typings';
|
import { APMRouteCreateOptions } from '../typings';
|
||||||
import { registerRoutes } from './register_apm_server_routes';
|
import {
|
||||||
|
APMRouteHandlerResources,
|
||||||
|
registerRoutes,
|
||||||
|
} from './register_apm_server_routes';
|
||||||
import { NEVER } from 'rxjs';
|
import { NEVER } from 'rxjs';
|
||||||
|
|
||||||
type RegisterRouteDependencies = Parameters<typeof registerRoutes>[0];
|
type RegisterRouteDependencies = Parameters<typeof registerRoutes>[0];
|
||||||
|
@ -54,7 +57,18 @@ const getRegisterRouteDependencies = () => {
|
||||||
},
|
},
|
||||||
logger,
|
logger,
|
||||||
config: {} as APMConfig,
|
config: {} as APMConfig,
|
||||||
plugins: {},
|
plugins: {
|
||||||
|
apmDataAccess: {
|
||||||
|
setup: {
|
||||||
|
indices: {
|
||||||
|
errorIndices: 'apm-*',
|
||||||
|
metricsIndices: 'apm-*',
|
||||||
|
spanIndices: 'apm-*',
|
||||||
|
transactionIndices: 'apm-*',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
} as unknown as RegisterRouteDependencies,
|
} as unknown as RegisterRouteDependencies,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -208,9 +222,7 @@ describe('createApi', () => {
|
||||||
} = initApi([
|
} = initApi([
|
||||||
{
|
{
|
||||||
endpoint: 'GET /foo',
|
endpoint: 'GET /foo',
|
||||||
options: {
|
options: { tags: [] },
|
||||||
tags: [],
|
|
||||||
},
|
|
||||||
handler: handlerMock,
|
handler: handlerMock,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import Boom from '@hapi/boom';
|
import Boom from '@hapi/boom';
|
||||||
import * as t from 'io-ts';
|
import * as t from 'io-ts';
|
||||||
import {
|
import {
|
||||||
|
Logger,
|
||||||
KibanaRequest,
|
KibanaRequest,
|
||||||
KibanaResponseFactory,
|
KibanaResponseFactory,
|
||||||
RouteRegistrar,
|
RouteRegistrar,
|
||||||
|
@ -25,9 +26,17 @@ import { jsonRt, mergeRt } from '@kbn/io-ts-utils';
|
||||||
import { InspectResponse } from '@kbn/observability-plugin/typings/common';
|
import { InspectResponse } from '@kbn/observability-plugin/typings/common';
|
||||||
import apm from 'elastic-apm-node';
|
import apm from 'elastic-apm-node';
|
||||||
import { VersionedRouteRegistrar } from '@kbn/core-http-server';
|
import { VersionedRouteRegistrar } from '@kbn/core-http-server';
|
||||||
|
import { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
|
import { ApmFeatureFlags } from '../../../common/apm_feature_flags';
|
||||||
import { pickKeys } from '../../../common/utils/pick_keys';
|
import { pickKeys } from '../../../common/utils/pick_keys';
|
||||||
import { APMRouteHandlerResources, TelemetryUsageCounter } from '../typings';
|
import { APMCore, TelemetryUsageCounter } from '../typings';
|
||||||
import type { ApmPluginRequestHandlerContext } from '../typings';
|
import type { ApmPluginRequestHandlerContext } from '../typings';
|
||||||
|
import { APMConfig } from '../..';
|
||||||
|
import {
|
||||||
|
APMPluginSetupDependencies,
|
||||||
|
APMPluginStartDependencies,
|
||||||
|
} from '../../types';
|
||||||
|
|
||||||
const inspectRt = t.exact(
|
const inspectRt = t.exact(
|
||||||
t.partial({
|
t.partial({
|
||||||
|
@ -99,6 +108,14 @@ export function registerRoutes({
|
||||||
runtimeType
|
runtimeType
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getApmIndices = async () => {
|
||||||
|
const coreContext = await context.core;
|
||||||
|
const apmIndices = await plugins.apmDataAccess.setup.getApmIndices(
|
||||||
|
coreContext.savedObjects.client
|
||||||
|
);
|
||||||
|
return apmIndices;
|
||||||
|
};
|
||||||
|
|
||||||
const { aborted, data } = await Promise.race([
|
const { aborted, data } = await Promise.race([
|
||||||
handler({
|
handler({
|
||||||
request,
|
request,
|
||||||
|
@ -109,6 +126,7 @@ export function registerRoutes({
|
||||||
core,
|
core,
|
||||||
plugins,
|
plugins,
|
||||||
telemetryUsageCounter,
|
telemetryUsageCounter,
|
||||||
|
getApmIndices,
|
||||||
params: merge(
|
params: merge(
|
||||||
{
|
{
|
||||||
query: {
|
query: {
|
||||||
|
@ -231,3 +249,29 @@ export function registerRoutes({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Plugins = {
|
||||||
|
[key in keyof APMPluginSetupDependencies]: {
|
||||||
|
setup: Required<APMPluginSetupDependencies>[key];
|
||||||
|
start: () => Promise<Required<APMPluginStartDependencies>[key]>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface APMRouteHandlerResources {
|
||||||
|
request: KibanaRequest;
|
||||||
|
context: ApmPluginRequestHandlerContext;
|
||||||
|
params: {
|
||||||
|
query: {
|
||||||
|
_inspect: boolean;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config: APMConfig;
|
||||||
|
featureFlags: ApmFeatureFlags;
|
||||||
|
logger: Logger;
|
||||||
|
core: APMCore;
|
||||||
|
plugins: Plugins;
|
||||||
|
ruleDataClient: IRuleDataClient;
|
||||||
|
telemetryUsageCounter?: TelemetryUsageCounter;
|
||||||
|
kibanaVersion: string;
|
||||||
|
getApmIndices: () => Promise<APMIndices>;
|
||||||
|
}
|
||||||
|
|
|
@ -8,9 +8,10 @@
|
||||||
import { createStaticDataView } from './create_static_data_view';
|
import { createStaticDataView } from './create_static_data_view';
|
||||||
import * as HistoricalAgentData from '../historical_data/has_historical_agent_data';
|
import * as HistoricalAgentData from '../historical_data/has_historical_agent_data';
|
||||||
import { DataViewsService } from '@kbn/data-views-plugin/common';
|
import { DataViewsService } from '@kbn/data-views-plugin/common';
|
||||||
import { APMRouteHandlerResources, APMCore } from '../typings';
|
import { APMCore } from '../typings';
|
||||||
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
|
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
|
||||||
import { APMConfig } from '../..';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
|
import { APMRouteHandlerResources } from '../apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
function getMockedDataViewService(existingDataViewTitle: string) {
|
function getMockedDataViewService(existingDataViewTitle: string) {
|
||||||
return {
|
return {
|
||||||
|
@ -42,7 +43,7 @@ const apmEventClientMock = {
|
||||||
span: 'apm-*-span-*',
|
span: 'apm-*-span-*',
|
||||||
error: 'apm-*-error-*',
|
error: 'apm-*-error-*',
|
||||||
metric: 'apm-*-metrics-*',
|
metric: 'apm-*-metrics-*',
|
||||||
} as APMConfig['indices'],
|
} as APMIndices,
|
||||||
} as unknown as APMEventClient;
|
} as unknown as APMEventClient;
|
||||||
|
|
||||||
describe('createStaticDataView', () => {
|
describe('createStaticDataView', () => {
|
||||||
|
|
|
@ -17,9 +17,8 @@ import { APM_STATIC_DATA_VIEW_ID } from '../../../common/data_view_constants';
|
||||||
import { hasHistoricalAgentData } from '../historical_data/has_historical_agent_data';
|
import { hasHistoricalAgentData } from '../historical_data/has_historical_agent_data';
|
||||||
import { withApmSpan } from '../../utils/with_apm_span';
|
import { withApmSpan } from '../../utils/with_apm_span';
|
||||||
import { getApmDataViewTitle } from './get_apm_data_view_title';
|
import { getApmDataViewTitle } from './get_apm_data_view_title';
|
||||||
|
|
||||||
import { APMRouteHandlerResources } from '../typings';
|
|
||||||
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
|
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
|
||||||
|
import { APMRouteHandlerResources } from '../apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
export type CreateDataViewResponse = Promise<
|
export type CreateDataViewResponse = Promise<
|
||||||
| { created: boolean; dataView: DataView }
|
| { created: boolean; dataView: DataView }
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { getApmDataViewTitle } from './get_apm_data_view_title';
|
import { getApmDataViewTitle } from './get_apm_data_view_title';
|
||||||
|
|
||||||
describe('getApmDataViewTitle', () => {
|
describe('getApmDataViewTitle', () => {
|
||||||
|
@ -15,7 +15,7 @@ describe('getApmDataViewTitle', () => {
|
||||||
span: 'apm-*-span-*',
|
span: 'apm-*-span-*',
|
||||||
error: 'apm-*-error-*',
|
error: 'apm-*-error-*',
|
||||||
metric: 'apm-*-metrics-*',
|
metric: 'apm-*-metrics-*',
|
||||||
} as ApmIndicesConfig);
|
} as APMIndices);
|
||||||
expect(title).toBe(
|
expect(title).toBe(
|
||||||
'apm-*-transaction-*,apm-*-span-*,apm-*-error-*,apm-*-metrics-*'
|
'apm-*-transaction-*,apm-*-span-*,apm-*-error-*,apm-*-metrics-*'
|
||||||
);
|
);
|
||||||
|
@ -27,7 +27,7 @@ describe('getApmDataViewTitle', () => {
|
||||||
span: 'apm-*',
|
span: 'apm-*',
|
||||||
error: 'apm-*',
|
error: 'apm-*',
|
||||||
metric: 'apm-*',
|
metric: 'apm-*',
|
||||||
} as ApmIndicesConfig);
|
} as APMIndices);
|
||||||
expect(title).toBe('apm-*');
|
expect(title).toBe('apm-*');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { uniq } from 'lodash';
|
import { uniq } from 'lodash';
|
||||||
import { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
|
|
||||||
export function getApmDataViewTitle(apmIndicesConfig: ApmIndicesConfig) {
|
export function getApmDataViewTitle(apmIndices: APMIndices) {
|
||||||
return uniq([
|
return uniq([
|
||||||
apmIndicesConfig.transaction,
|
apmIndices.transaction,
|
||||||
apmIndicesConfig.span,
|
apmIndices.span,
|
||||||
apmIndicesConfig.error,
|
apmIndices.error,
|
||||||
apmIndicesConfig.metric,
|
apmIndices.metric,
|
||||||
]).join(',');
|
]).join(',');
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import {
|
||||||
} from './create_static_data_view';
|
} from './create_static_data_view';
|
||||||
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
|
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
|
||||||
import { getApmDataViewTitle } from './get_apm_data_view_title';
|
import { getApmDataViewTitle } from './get_apm_data_view_title';
|
||||||
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
|
|
||||||
import { getApmEventClient } from '../../lib/helpers/get_apm_event_client';
|
import { getApmEventClient } from '../../lib/helpers/get_apm_event_client';
|
||||||
|
|
||||||
const staticDataViewRoute = createApmServerRoute({
|
const staticDataViewRoute = createApmServerRoute({
|
||||||
|
@ -43,15 +42,8 @@ const staticDataViewRoute = createApmServerRoute({
|
||||||
const dataViewTitleRoute = createApmServerRoute({
|
const dataViewTitleRoute = createApmServerRoute({
|
||||||
endpoint: 'GET /internal/apm/data_view/title',
|
endpoint: 'GET /internal/apm/data_view/title',
|
||||||
options: { tags: ['access:apm'] },
|
options: { tags: ['access:apm'] },
|
||||||
handler: async ({
|
handler: async ({ getApmIndices }): Promise<{ apmDataViewTitle: string }> => {
|
||||||
context,
|
const apmIndicies = await getApmIndices();
|
||||||
config,
|
|
||||||
}): Promise<{ apmDataViewTitle: string }> => {
|
|
||||||
const coreContext = await context.core;
|
|
||||||
const apmIndicies = await getApmIndices({
|
|
||||||
savedObjectsClient: coreContext.savedObjects.client,
|
|
||||||
config,
|
|
||||||
});
|
|
||||||
const apmDataViewTitle = getApmDataViewTitle(apmIndicies);
|
const apmDataViewTitle = getApmDataViewTitle(apmIndicies);
|
||||||
|
|
||||||
return { apmDataViewTitle };
|
return { apmDataViewTitle };
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { kqlQuery, rangeQuery } from '@kbn/observability-plugin/server';
|
import { kqlQuery, rangeQuery } from '@kbn/observability-plugin/server';
|
||||||
import { merge } from 'lodash';
|
import { merge } from 'lodash';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import {
|
import {
|
||||||
PROCESSOR_EVENT,
|
PROCESSOR_EVENT,
|
||||||
METRICSET_NAME,
|
METRICSET_NAME,
|
||||||
|
@ -15,7 +16,6 @@ import {
|
||||||
TRANSACTION_DURATION_SUMMARY,
|
TRANSACTION_DURATION_SUMMARY,
|
||||||
INDEX,
|
INDEX,
|
||||||
} from '../../../../common/es_fields/apm';
|
} from '../../../../common/es_fields/apm';
|
||||||
import { ApmIndicesConfig } from '../../settings/apm_indices/get_apm_indices';
|
|
||||||
import { getTypedSearch, TypedSearch } from '../create_typed_es_client';
|
import { getTypedSearch, TypedSearch } from '../create_typed_es_client';
|
||||||
import { getApmIndexPatterns } from './get_indices';
|
import { getApmIndexPatterns } from './get_indices';
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ export async function getApmEvents({
|
||||||
kuery,
|
kuery,
|
||||||
}: {
|
}: {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
start: number;
|
start: number;
|
||||||
end: number;
|
end: number;
|
||||||
kuery?: string;
|
kuery?: string;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { ApmIndicesConfig } from '../../settings/apm_indices/get_apm_indices';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { getApmIndexPatterns } from './get_indices';
|
import { getApmIndexPatterns } from './get_indices';
|
||||||
|
|
||||||
export async function getDataStreams({
|
export async function getDataStreams({
|
||||||
|
@ -14,7 +14,7 @@ export async function getDataStreams({
|
||||||
apmIndices,
|
apmIndices,
|
||||||
}: {
|
}: {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
}) {
|
}) {
|
||||||
const apmIndexPatterns = getApmIndexPatterns([
|
const apmIndexPatterns = getApmIndexPatterns([
|
||||||
apmIndices.error,
|
apmIndices.error,
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
|
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
|
||||||
import { ApmIndicesConfig } from '../../settings/apm_indices/get_apm_indices';
|
|
||||||
import { getApmIndexPatterns } from './get_indices';
|
import { getApmIndexPatterns } from './get_indices';
|
||||||
|
|
||||||
export function getFieldCaps({
|
export function getFieldCaps({
|
||||||
|
@ -15,7 +15,7 @@ export function getFieldCaps({
|
||||||
apmIndices,
|
apmIndices,
|
||||||
}: {
|
}: {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
}) {
|
}) {
|
||||||
return esClient.fieldCaps({
|
return esClient.fieldCaps({
|
||||||
index: getApmIndexPatterns([apmIndices.metric, apmIndices.transaction]),
|
index: getApmIndexPatterns([apmIndices.metric, apmIndices.transaction]),
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { IndicesSimulateTemplateResponse } from '@elastic/elasticsearch/lib/api/types';
|
import { IndicesSimulateTemplateResponse } from '@elastic/elasticsearch/lib/api/types';
|
||||||
import { orderBy } from 'lodash';
|
import { orderBy } from 'lodash';
|
||||||
import { errors } from '@elastic/elasticsearch';
|
import { errors } from '@elastic/elasticsearch';
|
||||||
import { ApmIndicesConfig } from '../../settings/apm_indices/get_apm_indices';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { getApmIndexPatterns } from './get_indices';
|
import { getApmIndexPatterns } from './get_indices';
|
||||||
import { getIndexTemplate } from './get_index_template';
|
import { getIndexTemplate } from './get_index_template';
|
||||||
import { getApmIndexTemplateNames } from '../helpers/get_apm_index_template_names';
|
import { getApmIndexTemplateNames } from '../helpers/get_apm_index_template_names';
|
||||||
|
@ -19,7 +19,7 @@ export async function getIndexTemplatesByIndexPattern({
|
||||||
apmIndices,
|
apmIndices,
|
||||||
}: {
|
}: {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
}) {
|
}) {
|
||||||
const indexPatterns = getApmIndexPatterns([
|
const indexPatterns = getApmIndexPatterns([
|
||||||
apmIndices.error,
|
apmIndices.error,
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import { compact, uniq } from 'lodash';
|
import { compact, uniq } from 'lodash';
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { ApmIndicesConfig } from '../../settings/apm_indices/get_apm_indices';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
|
|
||||||
export function getApmIndexPatterns(indices: string[]) {
|
export function getApmIndexPatterns(indices: string[]) {
|
||||||
return uniq(indices.flatMap((index): string[] => index.split(',')));
|
return uniq(indices.flatMap((index): string[] => index.split(',')));
|
||||||
|
@ -18,7 +18,7 @@ export async function getIndicesAndIngestPipelines({
|
||||||
apmIndices,
|
apmIndices,
|
||||||
}: {
|
}: {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
}) {
|
}) {
|
||||||
const indices = await esClient.indices.get({
|
const indices = await esClient.indices.get({
|
||||||
index: getApmIndexPatterns([
|
index: getApmIndexPatterns([
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { ApmIndicesConfig } from '@kbn/observability-plugin/common/typings';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
|
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
|
||||||
import { getApmIndexTemplateNames } from '../helpers/get_apm_index_template_names';
|
import { getApmIndexTemplateNames } from '../helpers/get_apm_index_template_names';
|
||||||
import { getFieldCaps } from './get_field_caps';
|
import { getFieldCaps } from './get_field_caps';
|
||||||
|
@ -17,7 +17,7 @@ export async function getIndicesStates({
|
||||||
apmIndices,
|
apmIndices,
|
||||||
}: {
|
}: {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
}) {
|
}) {
|
||||||
const { indices, ingestPipelines } = await getIndicesAndIngestPipelines({
|
const { indices, ingestPipelines } = await getIndicesAndIngestPipelines({
|
||||||
esClient,
|
esClient,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { ApmIndicesConfig } from '@kbn/observability-plugin/common/typings';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { getApmIndexPatterns } from './get_indices';
|
import { getApmIndexPatterns } from './get_indices';
|
||||||
|
|
||||||
export async function getNonDataStreamIndices({
|
export async function getNonDataStreamIndices({
|
||||||
|
@ -14,7 +14,7 @@ export async function getNonDataStreamIndices({
|
||||||
apmIndices,
|
apmIndices,
|
||||||
}: {
|
}: {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
}) {
|
}) {
|
||||||
const apmIndexPatterns = getApmIndexPatterns([
|
const apmIndexPatterns = getApmIndexPatterns([
|
||||||
apmIndices.error,
|
apmIndices.error,
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { NOT_AVAILABLE_LABEL } from '../../../common/i18n';
|
import { NOT_AVAILABLE_LABEL } from '../../../common/i18n';
|
||||||
import { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices';
|
|
||||||
import { getDataStreams } from './bundle/get_data_streams';
|
import { getDataStreams } from './bundle/get_data_streams';
|
||||||
import { getNonDataStreamIndices } from './bundle/get_non_data_stream_indices';
|
import { getNonDataStreamIndices } from './bundle/get_non_data_stream_indices';
|
||||||
import { getElasticsearchVersion } from './get_elasticsearch_version';
|
import { getElasticsearchVersion } from './get_elasticsearch_version';
|
||||||
|
@ -30,7 +30,7 @@ export async function getDiagnosticsBundle({
|
||||||
kuery,
|
kuery,
|
||||||
}: {
|
}: {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
start: number | undefined;
|
start: number | undefined;
|
||||||
end: number | undefined;
|
end: number | undefined;
|
||||||
kuery: string | undefined;
|
kuery: string | undefined;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FleetUnauthorizedError } from '@kbn/fleet-plugin/server/errors';
|
import { FleetUnauthorizedError } from '@kbn/fleet-plugin/server/errors';
|
||||||
import { APMRouteHandlerResources } from '../typings';
|
import { APMRouteHandlerResources } from '../apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
export async function getFleetPackageInfo(resources: APMRouteHandlerResources) {
|
export async function getFleetPackageInfo(resources: APMRouteHandlerResources) {
|
||||||
const fleetPluginStart = await resources.plugins.fleet?.start();
|
const fleetPluginStart = await resources.plugins.fleet?.start();
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { ApmIndicesConfig } from '../../settings/apm_indices/get_apm_indices';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { getApmIndexPatterns } from '../bundle/get_indices';
|
import { getApmIndexPatterns } from '../bundle/get_indices';
|
||||||
|
|
||||||
export async function getDiagnosticsPrivileges({
|
export async function getDiagnosticsPrivileges({
|
||||||
|
@ -14,7 +14,7 @@ export async function getDiagnosticsPrivileges({
|
||||||
apmIndices,
|
apmIndices,
|
||||||
}: {
|
}: {
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
}) {
|
}) {
|
||||||
const indexPatterns = getApmIndexPatterns([
|
const indexPatterns = getApmIndexPatterns([
|
||||||
apmIndices.error,
|
apmIndices.error,
|
||||||
|
|
|
@ -13,13 +13,10 @@ import {
|
||||||
IngestGetPipelineResponse,
|
IngestGetPipelineResponse,
|
||||||
SecurityHasPrivilegesPrivileges,
|
SecurityHasPrivilegesPrivileges,
|
||||||
} from '@elastic/elasticsearch/lib/api/types';
|
} from '@elastic/elasticsearch/lib/api/types';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import * as t from 'io-ts';
|
import * as t from 'io-ts';
|
||||||
import { isoToEpochRt } from '@kbn/io-ts-utils';
|
import { isoToEpochRt } from '@kbn/io-ts-utils';
|
||||||
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
|
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
|
||||||
import {
|
|
||||||
ApmIndicesConfig,
|
|
||||||
getApmIndices,
|
|
||||||
} from '../settings/apm_indices/get_apm_indices';
|
|
||||||
import { ApmEvent } from './bundle/get_apm_events';
|
import { ApmEvent } from './bundle/get_apm_events';
|
||||||
import { getDiagnosticsBundle } from './get_diagnostics_bundle';
|
import { getDiagnosticsBundle } from './get_diagnostics_bundle';
|
||||||
import { getFleetPackageInfo } from './get_fleet_package_info';
|
import { getFleetPackageInfo } from './get_fleet_package_info';
|
||||||
|
@ -38,6 +35,49 @@ export interface IndiciesItem {
|
||||||
isValid: boolean;
|
isValid: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DiagnosticsBundle = Promise<{
|
||||||
|
esResponses: {
|
||||||
|
existingIndexTemplates: IndicesGetIndexTemplateIndexTemplateItem[];
|
||||||
|
fieldCaps: FieldCapsResponse;
|
||||||
|
indices: IndicesGetResponse;
|
||||||
|
ingestPipelines: IngestGetPipelineResponse;
|
||||||
|
};
|
||||||
|
diagnosticsPrivileges: {
|
||||||
|
index: Record<string, SecurityHasPrivilegesPrivileges>;
|
||||||
|
cluster: Record<string, boolean>;
|
||||||
|
hasAllClusterPrivileges: boolean;
|
||||||
|
hasAllIndexPrivileges: boolean;
|
||||||
|
hasAllPrivileges: boolean;
|
||||||
|
};
|
||||||
|
apmIndices: APMIndices;
|
||||||
|
apmIndexTemplates: Array<{
|
||||||
|
name: string;
|
||||||
|
isNonStandard: boolean;
|
||||||
|
exists: boolean;
|
||||||
|
}>;
|
||||||
|
fleetPackageInfo: {
|
||||||
|
isInstalled: boolean;
|
||||||
|
version?: string;
|
||||||
|
};
|
||||||
|
kibanaVersion: string;
|
||||||
|
elasticsearchVersion: string;
|
||||||
|
apmEvents: ApmEvent[];
|
||||||
|
invalidIndices: IndiciesItem[];
|
||||||
|
validIndices: IndiciesItem[];
|
||||||
|
dataStreams: IndicesDataStream[];
|
||||||
|
nonDataStreamIndices: string[];
|
||||||
|
indexTemplatesByIndexPattern: Array<{
|
||||||
|
indexPattern: string;
|
||||||
|
indexTemplates: Array<{
|
||||||
|
priority: number | undefined;
|
||||||
|
isNonStandard: boolean;
|
||||||
|
templateIndexPatterns: string[];
|
||||||
|
templateName: string;
|
||||||
|
}>;
|
||||||
|
}>;
|
||||||
|
params: { start: number; end: number; kuery?: string };
|
||||||
|
}>;
|
||||||
|
|
||||||
const getDiagnosticsRoute = createApmServerRoute({
|
const getDiagnosticsRoute = createApmServerRoute({
|
||||||
endpoint: 'GET /internal/apm/diagnostics',
|
endpoint: 'GET /internal/apm/diagnostics',
|
||||||
options: { tags: ['access:apm'] },
|
options: { tags: ['access:apm'] },
|
||||||
|
@ -64,7 +104,7 @@ const getDiagnosticsRoute = createApmServerRoute({
|
||||||
hasAllIndexPrivileges: boolean;
|
hasAllIndexPrivileges: boolean;
|
||||||
hasAllPrivileges: boolean;
|
hasAllPrivileges: boolean;
|
||||||
};
|
};
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
apmIndexTemplates: Array<{
|
apmIndexTemplates: Array<{
|
||||||
name: string;
|
name: string;
|
||||||
isNonStandard: boolean;
|
isNonStandard: boolean;
|
||||||
|
@ -94,11 +134,8 @@ const getDiagnosticsRoute = createApmServerRoute({
|
||||||
}> => {
|
}> => {
|
||||||
const { start, end, kuery } = resources.params.query;
|
const { start, end, kuery } = resources.params.query;
|
||||||
const coreContext = await resources.context.core;
|
const coreContext = await resources.context.core;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
const { asCurrentUser: esClient } = coreContext.elasticsearch.client;
|
const { asCurrentUser: esClient } = coreContext.elasticsearch.client;
|
||||||
const apmIndices = await getApmIndices({
|
|
||||||
savedObjectsClient: coreContext.savedObjects.client,
|
|
||||||
config: resources.config,
|
|
||||||
});
|
|
||||||
|
|
||||||
const bundle = await getDiagnosticsBundle({
|
const bundle = await getDiagnosticsBundle({
|
||||||
esClient,
|
esClient,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { CoreStart, Logger } from '@kbn/core/server';
|
||||||
import {
|
import {
|
||||||
APM_AGENT_CONFIGURATION_INDEX,
|
APM_AGENT_CONFIGURATION_INDEX,
|
||||||
APM_SOURCE_MAP_INDEX,
|
APM_SOURCE_MAP_INDEX,
|
||||||
} from '../../settings/apm_indices/get_apm_indices';
|
} from '../../settings/apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
const apiKeyMetadata = {
|
const apiKeyMetadata = {
|
||||||
application: 'apm',
|
application: 'apm',
|
||||||
|
|
|
@ -5,7 +5,11 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Logger, CoreStart } from '@kbn/core/server';
|
import {
|
||||||
|
Logger,
|
||||||
|
CoreStart,
|
||||||
|
SavedObjectsClientContract,
|
||||||
|
} from '@kbn/core/server';
|
||||||
import {
|
import {
|
||||||
FleetStartContract,
|
FleetStartContract,
|
||||||
PostPackagePolicyCreateCallback,
|
PostPackagePolicyCreateCallback,
|
||||||
|
@ -14,7 +18,7 @@ import {
|
||||||
PutPackagePolicyUpdateCallback,
|
PutPackagePolicyUpdateCallback,
|
||||||
} from '@kbn/fleet-plugin/server';
|
} from '@kbn/fleet-plugin/server';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { APMConfig, APMPlugin, APMRouteHandlerResources } from '../..';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { decoratePackagePolicyWithAgentConfigAndSourceMap } from './merge_package_policy_with_apm';
|
import { decoratePackagePolicyWithAgentConfigAndSourceMap } from './merge_package_policy_with_apm';
|
||||||
import { addApiKeysToPackagePolicyIfMissing } from './api_keys/add_api_keys_to_policies_if_missing';
|
import { addApiKeysToPackagePolicyIfMissing } from './api_keys/add_api_keys_to_policies_if_missing';
|
||||||
import {
|
import {
|
||||||
|
@ -23,33 +27,41 @@ import {
|
||||||
} from './get_package_policy_decorators';
|
} from './get_package_policy_decorators';
|
||||||
import { createInternalESClient } from '../../lib/helpers/create_es_client/create_internal_es_client';
|
import { createInternalESClient } from '../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { getInternalSavedObjectsClient } from '../../lib/helpers/get_internal_saved_objects_client';
|
import { getInternalSavedObjectsClient } from '../../lib/helpers/get_internal_saved_objects_client';
|
||||||
|
import { APMRouteHandlerResources } from '../apm_routes/register_apm_server_routes';
|
||||||
|
|
||||||
export async function registerFleetPolicyCallbacks({
|
export async function registerFleetPolicyCallbacks({
|
||||||
logger,
|
logger,
|
||||||
coreStartPromise,
|
coreStartPromise,
|
||||||
plugins,
|
plugins,
|
||||||
config,
|
|
||||||
}: {
|
}: {
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
coreStartPromise: Promise<CoreStart>;
|
coreStartPromise: Promise<CoreStart>;
|
||||||
plugins: APMRouteHandlerResources['plugins'];
|
plugins: APMRouteHandlerResources['plugins'];
|
||||||
config: NonNullable<APMPlugin['currentConfig']>;
|
|
||||||
}) {
|
}) {
|
||||||
if (!plugins.fleet) {
|
if (!plugins.fleet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fleetPluginStart = await plugins.fleet.start();
|
const fleetPluginStart = await plugins.fleet.start();
|
||||||
|
const { getApmIndices } = plugins.apmDataAccess.setup;
|
||||||
const coreStart = await coreStartPromise;
|
const coreStart = await coreStartPromise;
|
||||||
|
|
||||||
fleetPluginStart.registerExternalCallback(
|
fleetPluginStart.registerExternalCallback(
|
||||||
'packagePolicyUpdate',
|
'packagePolicyUpdate',
|
||||||
onPackagePolicyCreateOrUpdate({ fleetPluginStart, config, coreStart })
|
onPackagePolicyCreateOrUpdate({
|
||||||
|
fleetPluginStart,
|
||||||
|
getApmIndices,
|
||||||
|
coreStart,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
fleetPluginStart.registerExternalCallback(
|
fleetPluginStart.registerExternalCallback(
|
||||||
'packagePolicyCreate',
|
'packagePolicyCreate',
|
||||||
onPackagePolicyCreateOrUpdate({ fleetPluginStart, config, coreStart })
|
onPackagePolicyCreateOrUpdate({
|
||||||
|
fleetPluginStart,
|
||||||
|
getApmIndices,
|
||||||
|
coreStart,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
fleetPluginStart.registerExternalCallback(
|
fleetPluginStart.registerExternalCallback(
|
||||||
|
@ -143,11 +155,11 @@ function onPackagePolicyPostCreate({
|
||||||
*/
|
*/
|
||||||
function onPackagePolicyCreateOrUpdate({
|
function onPackagePolicyCreateOrUpdate({
|
||||||
fleetPluginStart,
|
fleetPluginStart,
|
||||||
config,
|
getApmIndices,
|
||||||
coreStart,
|
coreStart,
|
||||||
}: {
|
}: {
|
||||||
fleetPluginStart: FleetStartContract;
|
fleetPluginStart: FleetStartContract;
|
||||||
config: APMConfig;
|
getApmIndices: (soClient: SavedObjectsClientContract) => Promise<APMIndices>;
|
||||||
coreStart: CoreStart;
|
coreStart: CoreStart;
|
||||||
}): PutPackagePolicyUpdateCallback & PostPackagePolicyCreateCallback {
|
}): PutPackagePolicyUpdateCallback & PostPackagePolicyCreateCallback {
|
||||||
return async (packagePolicy) => {
|
return async (packagePolicy) => {
|
||||||
|
@ -157,10 +169,11 @@ function onPackagePolicyCreateOrUpdate({
|
||||||
|
|
||||||
const { asInternalUser } = coreStart.elasticsearch.client;
|
const { asInternalUser } = coreStart.elasticsearch.client;
|
||||||
const savedObjectsClient = await getInternalSavedObjectsClient(coreStart);
|
const savedObjectsClient = await getInternalSavedObjectsClient(coreStart);
|
||||||
|
const apmIndices = await getApmIndices(savedObjectsClient);
|
||||||
|
|
||||||
const internalESClient = await createInternalESClient({
|
const internalESClient = await createInternalESClient({
|
||||||
debug: false,
|
debug: false,
|
||||||
config,
|
apmIndices,
|
||||||
savedObjectsClient,
|
|
||||||
elasticsearchClient: asInternalUser,
|
elasticsearchClient: asInternalUser,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -153,11 +153,13 @@ const createCloudApmPackagePolicyRoute = createApmServerRoute({
|
||||||
coreStart,
|
coreStart,
|
||||||
fleetPluginStart,
|
fleetPluginStart,
|
||||||
securityPluginStart,
|
securityPluginStart,
|
||||||
|
apmIndices,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
(await context.core).savedObjects.client,
|
(await context.core).savedObjects.client,
|
||||||
resources.core.start(),
|
resources.core.start(),
|
||||||
plugins.fleet.start(),
|
plugins.fleet.start(),
|
||||||
plugins.security.start(),
|
plugins.security.start(),
|
||||||
|
resources.getApmIndices(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const esClient = coreStart.elasticsearch.client.asScoped(
|
const esClient = coreStart.elasticsearch.client.asScoped(
|
||||||
|
@ -174,7 +176,7 @@ const createCloudApmPackagePolicyRoute = createApmServerRoute({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: resources.params.query._inspect,
|
debug: resources.params.query._inspect,
|
||||||
config: resources.config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
|
|
||||||
const cloudApmPackagePolicy = await createCloudApmPackgePolicy({
|
const cloudApmPackagePolicy = await createCloudApmPackgePolicy({
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { PackagePolicy } from '@kbn/fleet-plugin/common';
|
import { PackagePolicy } from '@kbn/fleet-plugin/common';
|
||||||
import { APMRouteHandlerResources } from '../typings';
|
import { APMRouteHandlerResources } from '../apm_routes/register_apm_server_routes';
|
||||||
import { getApmPackagePolicies } from './get_apm_package_policies';
|
import { getApmPackagePolicies } from './get_apm_package_policies';
|
||||||
import {
|
import {
|
||||||
getApmPackagePolicy,
|
getApmPackagePolicy,
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ProcessorEvent } from '@kbn/observability-plugin/common';
|
import { ProcessorEvent } from '@kbn/observability-plugin/common';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
|
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
|
||||||
import { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices';
|
|
||||||
|
|
||||||
export interface HasDataResponse {
|
export interface HasDataResponse {
|
||||||
hasData: boolean;
|
hasData: boolean;
|
||||||
|
@ -24,7 +24,7 @@ export async function getHasData({
|
||||||
indices,
|
indices,
|
||||||
apmEventClient,
|
apmEventClient,
|
||||||
}: {
|
}: {
|
||||||
indices: ApmIndicesConfig;
|
indices: APMIndices;
|
||||||
apmEventClient: APMEventClient;
|
apmEventClient: APMEventClient;
|
||||||
}): Promise<HasDataResponse> {
|
}): Promise<HasDataResponse> {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
createOrUpdateIndex,
|
createOrUpdateIndex,
|
||||||
Mappings,
|
Mappings,
|
||||||
} from '@kbn/observability-plugin/server';
|
} from '@kbn/observability-plugin/server';
|
||||||
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export async function createApmAgentConfigurationIndex({
|
export async function createApmAgentConfigurationIndex({
|
||||||
client,
|
client,
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
APMIndexDocumentParams,
|
APMIndexDocumentParams,
|
||||||
APMInternalESClient,
|
APMInternalESClient,
|
||||||
} from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
} from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export function createOrUpdateConfiguration({
|
export function createOrUpdateConfiguration({
|
||||||
configurationId,
|
configurationId,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export async function deleteConfiguration({
|
export async function deleteConfiguration({
|
||||||
configurationId,
|
configurationId,
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {
|
||||||
SERVICE_NAME,
|
SERVICE_NAME,
|
||||||
} from '../../../../common/es_fields/apm';
|
} from '../../../../common/es_fields/apm';
|
||||||
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
import { convertConfigSettingsToString } from './convert_settings_to_string';
|
import { convertConfigSettingsToString } from './convert_settings_to_string';
|
||||||
import { getConfigsAppliedToAgentsThroughFleet } from './get_config_applied_to_agent_through_fleet';
|
import { getConfigsAppliedToAgentsThroughFleet } from './get_config_applied_to_agent_through_fleet';
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
} from '../../../../../common/es_fields/apm';
|
} from '../../../../../common/es_fields/apm';
|
||||||
import { ALL_OPTION_VALUE } from '../../../../../common/agent_configuration/all_option';
|
import { ALL_OPTION_VALUE } from '../../../../../common/agent_configuration/all_option';
|
||||||
import { APMInternalESClient } from '../../../../lib/helpers/create_es_client/create_internal_es_client';
|
import { APMInternalESClient } from '../../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_AGENT_CONFIGURATION_INDEX } from '../../apm_indices/get_apm_indices';
|
import { APM_AGENT_CONFIGURATION_INDEX } from '../../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export async function getExistingEnvironmentsForService({
|
export async function getExistingEnvironmentsForService({
|
||||||
serviceName,
|
serviceName,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { AgentConfiguration } from '../../../../common/agent_configuration/confi
|
||||||
import { convertConfigSettingsToString } from './convert_settings_to_string';
|
import { convertConfigSettingsToString } from './convert_settings_to_string';
|
||||||
import { getConfigsAppliedToAgentsThroughFleet } from './get_config_applied_to_agent_through_fleet';
|
import { getConfigsAppliedToAgentsThroughFleet } from './get_config_applied_to_agent_through_fleet';
|
||||||
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export async function listConfigurations(
|
export async function listConfigurations(
|
||||||
internalESClient: APMInternalESClient
|
internalESClient: APMInternalESClient
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import { AgentConfiguration } from '../../../../common/agent_configuration/configuration_types';
|
import { AgentConfiguration } from '../../../../common/agent_configuration/configuration_types';
|
||||||
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
// We're not wrapping this function with a span as it is not blocking the request
|
// We're not wrapping this function with a span as it is not blocking the request
|
||||||
export async function markAppliedByAgent({
|
export async function markAppliedByAgent({
|
||||||
|
|
|
@ -49,13 +49,14 @@ const agentConfigurationRoute = createApmServerRoute({
|
||||||
}> => {
|
}> => {
|
||||||
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
||||||
|
|
||||||
const { context, request, params, config } = resources;
|
const { context, request, params } = resources;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
const internalESClient = await createInternalESClientWithContext({
|
const internalESClient = await createInternalESClientWithContext({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: params.query._inspect,
|
debug: params.query._inspect,
|
||||||
config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
|
|
||||||
const configurations = await listConfigurations(internalESClient);
|
const configurations = await listConfigurations(internalESClient);
|
||||||
|
@ -74,15 +75,16 @@ const getSingleAgentConfigurationRoute = createApmServerRoute({
|
||||||
handler: async (resources): Promise<AgentConfiguration> => {
|
handler: async (resources): Promise<AgentConfiguration> => {
|
||||||
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
||||||
|
|
||||||
const { params, logger, context, request, config } = resources;
|
const { params, logger, context, request } = resources;
|
||||||
const { name, environment, _inspect } = params.query;
|
const { name, environment, _inspect } = params.query;
|
||||||
const service = { name, environment };
|
const service = { name, environment };
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
const internalESClient = await createInternalESClientWithContext({
|
const internalESClient = await createInternalESClientWithContext({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: _inspect,
|
debug: _inspect,
|
||||||
config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
const exactConfig = await findExactConfiguration({
|
const exactConfig = await findExactConfiguration({
|
||||||
service,
|
service,
|
||||||
|
@ -115,22 +117,16 @@ const deleteAgentConfigurationRoute = createApmServerRoute({
|
||||||
handler: async (resources): Promise<{ result: string }> => {
|
handler: async (resources): Promise<{ result: string }> => {
|
||||||
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
||||||
|
|
||||||
const {
|
const { params, logger, core, telemetryUsageCounter, context, request } =
|
||||||
params,
|
resources;
|
||||||
logger,
|
|
||||||
core,
|
|
||||||
telemetryUsageCounter,
|
|
||||||
context,
|
|
||||||
request,
|
|
||||||
config,
|
|
||||||
} = resources;
|
|
||||||
const { service } = params.body;
|
const { service } = params.body;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
const internalESClient = await createInternalESClientWithContext({
|
const internalESClient = await createInternalESClientWithContext({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: params.query._inspect,
|
debug: params.query._inspect,
|
||||||
config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
const exactConfig = await findExactConfiguration({
|
const exactConfig = await findExactConfiguration({
|
||||||
service,
|
service,
|
||||||
|
@ -181,22 +177,16 @@ const createOrUpdateAgentConfigurationRoute = createApmServerRoute({
|
||||||
]),
|
]),
|
||||||
handler: async (resources): Promise<void> => {
|
handler: async (resources): Promise<void> => {
|
||||||
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
||||||
const {
|
const { params, logger, core, telemetryUsageCounter, context, request } =
|
||||||
params,
|
resources;
|
||||||
logger,
|
|
||||||
core,
|
|
||||||
telemetryUsageCounter,
|
|
||||||
context,
|
|
||||||
request,
|
|
||||||
config,
|
|
||||||
} = resources;
|
|
||||||
const { body, query } = params;
|
const { body, query } = params;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
const internalESClient = await createInternalESClientWithContext({
|
const internalESClient = await createInternalESClientWithContext({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: params.query._inspect,
|
debug: params.query._inspect,
|
||||||
config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
|
|
||||||
// if the config already exists, it is fetched and updated
|
// if the config already exists, it is fetched and updated
|
||||||
|
@ -258,19 +248,20 @@ const agentConfigurationSearchRoute = createApmServerRoute({
|
||||||
): Promise<SearchHit<AgentConfiguration, undefined, undefined> | null> => {
|
): Promise<SearchHit<AgentConfiguration, undefined, undefined> | null> => {
|
||||||
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
||||||
|
|
||||||
const { params, logger, context, config, request } = resources;
|
const { params, logger, context, request } = resources;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
service,
|
service,
|
||||||
etag,
|
etag,
|
||||||
mark_as_applied_by_agent: markAsAppliedByAgent,
|
mark_as_applied_by_agent: markAsAppliedByAgent,
|
||||||
} = params.body;
|
} = params.body;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
const internalESClient = await createInternalESClientWithContext({
|
const internalESClient = await createInternalESClientWithContext({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: params.query._inspect,
|
debug: params.query._inspect,
|
||||||
config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
const configuration = await searchConfigurations({
|
const configuration = await searchConfigurations({
|
||||||
service,
|
service,
|
||||||
|
@ -332,12 +323,14 @@ const listAgentConfigurationEnvironmentsRoute = createApmServerRoute({
|
||||||
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
throwNotFoundIfAgentConfigNotAvailable(resources.featureFlags);
|
||||||
|
|
||||||
const { context, request, params, config } = resources;
|
const { context, request, params, config } = resources;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
const [internalESClient, apmEventClient] = await Promise.all([
|
const [internalESClient, apmEventClient] = await Promise.all([
|
||||||
createInternalESClientWithContext({
|
createInternalESClientWithContext({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: params.query._inspect,
|
debug: params.query._inspect,
|
||||||
config,
|
apmIndices,
|
||||||
}),
|
}),
|
||||||
getApmEventClient(resources),
|
getApmEventClient(resources),
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
import { AgentConfiguration } from '../../../../common/agent_configuration/configuration_types';
|
import { AgentConfiguration } from '../../../../common/agent_configuration/configuration_types';
|
||||||
import { convertConfigSettingsToString } from './convert_settings_to_string';
|
import { convertConfigSettingsToString } from './convert_settings_to_string';
|
||||||
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export async function searchConfigurations({
|
export async function searchConfigurations({
|
||||||
service,
|
service,
|
||||||
|
|
|
@ -21,7 +21,6 @@ import { updateToV3 } from './update_to_v3';
|
||||||
import { environmentStringRt } from '../../../../common/environment_rt';
|
import { environmentStringRt } from '../../../../common/environment_rt';
|
||||||
import { getMlJobsWithAPMGroup } from '../../../lib/anomaly_detection/get_ml_jobs_with_apm_group';
|
import { getMlJobsWithAPMGroup } from '../../../lib/anomaly_detection/get_ml_jobs_with_apm_group';
|
||||||
import { getApmEventClient } from '../../../lib/helpers/get_apm_event_client';
|
import { getApmEventClient } from '../../../lib/helpers/get_apm_event_client';
|
||||||
import { getApmIndices } from '../apm_indices/get_apm_indices';
|
|
||||||
import { ApmMlJob } from '../../../../common/anomaly_detection/apm_ml_job';
|
import { ApmMlJob } from '../../../../common/anomaly_detection/apm_ml_job';
|
||||||
// get ML anomaly detection jobs for each environment
|
// get ML anomaly detection jobs for each environment
|
||||||
const anomalyDetectionJobsRoute = createApmServerRoute({
|
const anomalyDetectionJobsRoute = createApmServerRoute({
|
||||||
|
@ -68,18 +67,14 @@ const createAnomalyDetectionJobsRoute = createApmServerRoute({
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
handler: async (resources): Promise<{ jobCreated: true }> => {
|
handler: async (resources): Promise<{ jobCreated: true }> => {
|
||||||
const { params, context, logger, config } = resources;
|
const { params, context, logger, getApmIndices } = resources;
|
||||||
const { environments } = params.body;
|
const { environments } = params.body;
|
||||||
const licensingContext = await context.licensing;
|
const licensingContext = await context.licensing;
|
||||||
const coreContext = await context.core;
|
|
||||||
const esClient = (await context.core).elasticsearch.client;
|
const esClient = (await context.core).elasticsearch.client;
|
||||||
|
|
||||||
const [mlClient, indices] = await Promise.all([
|
const [mlClient, indices] = await Promise.all([
|
||||||
getMlClient(resources),
|
getMlClient(resources),
|
||||||
getApmIndices({
|
getApmIndices(),
|
||||||
savedObjectsClient: coreContext.savedObjects.client,
|
|
||||||
config,
|
|
||||||
}),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!isActivePlatinumLicense(licensingContext.license)) {
|
if (!isActivePlatinumLicense(licensingContext.license)) {
|
||||||
|
@ -142,9 +137,9 @@ const anomalyDetectionUpdateToV3Route = createApmServerRoute({
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
handler: async (resources): Promise<{ update: boolean }> => {
|
handler: async (resources): Promise<{ update: boolean }> => {
|
||||||
const { config, context } = resources;
|
const { getApmIndices } = resources;
|
||||||
const coreContext = await context.core;
|
const [indices, mlClient, esClient] = await Promise.all([
|
||||||
const [mlClient, esClient, indices] = await Promise.all([
|
getApmIndices(),
|
||||||
getMlClient(resources),
|
getMlClient(resources),
|
||||||
resources.core
|
resources.core
|
||||||
.start()
|
.start()
|
||||||
|
@ -152,10 +147,6 @@ const anomalyDetectionUpdateToV3Route = createApmServerRoute({
|
||||||
(start): ElasticsearchClient =>
|
(start): ElasticsearchClient =>
|
||||||
start.elasticsearch.client.asInternalUser
|
start.elasticsearch.client.asInternalUser
|
||||||
),
|
),
|
||||||
getApmIndices({
|
|
||||||
config,
|
|
||||||
savedObjectsClient: coreContext.savedObjects.client,
|
|
||||||
}),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const { logger } = resources;
|
const { logger } = resources;
|
||||||
|
|
|
@ -9,11 +9,11 @@ import { uniq } from 'lodash';
|
||||||
import pLimit from 'p-limit';
|
import pLimit from 'p-limit';
|
||||||
import { ElasticsearchClient } from '@kbn/core/server';
|
import { ElasticsearchClient } from '@kbn/core/server';
|
||||||
import { JOB_STATE } from '@kbn/ml-plugin/common';
|
import { JOB_STATE } from '@kbn/ml-plugin/common';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { createAnomalyDetectionJobs } from '../../../lib/anomaly_detection/create_anomaly_detection_jobs';
|
import { createAnomalyDetectionJobs } from '../../../lib/anomaly_detection/create_anomaly_detection_jobs';
|
||||||
import { getAnomalyDetectionJobs } from '../../../lib/anomaly_detection/get_anomaly_detection_jobs';
|
import { getAnomalyDetectionJobs } from '../../../lib/anomaly_detection/get_anomaly_detection_jobs';
|
||||||
import { MlClient } from '../../../lib/helpers/get_ml_client';
|
import { MlClient } from '../../../lib/helpers/get_ml_client';
|
||||||
import { withApmSpan } from '../../../utils/with_apm_span';
|
import { withApmSpan } from '../../../utils/with_apm_span';
|
||||||
import { ApmIndicesConfig } from '../apm_indices/get_apm_indices';
|
|
||||||
|
|
||||||
export async function updateToV3({
|
export async function updateToV3({
|
||||||
logger,
|
logger,
|
||||||
|
@ -23,7 +23,7 @@ export async function updateToV3({
|
||||||
}: {
|
}: {
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
mlClient?: MlClient;
|
mlClient?: MlClient;
|
||||||
indices: ApmIndicesConfig;
|
indices: APMIndices;
|
||||||
esClient: ElasticsearchClient;
|
esClient: ElasticsearchClient;
|
||||||
}) {
|
}) {
|
||||||
const allJobs = await getAnomalyDetectionJobs(mlClient);
|
const allJobs = await getAnomalyDetectionJobs(mlClient);
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const APM_AGENT_CONFIGURATION_INDEX = '.apm-agent-configuration';
|
||||||
|
export const APM_CUSTOM_LINK_INDEX = '.apm-custom-link';
|
||||||
|
export const APM_SOURCE_MAP_INDEX = '.apm-source-map';
|
|
@ -5,71 +5,8 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { SavedObjectsClient } from '@kbn/core/server';
|
import { getApmIndicesSavedObject } from '@kbn/apm-data-access-plugin/server/saved_objects/apm_indices';
|
||||||
import {
|
import { APMRouteHandlerResources } from '../../apm_routes/register_apm_server_routes';
|
||||||
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
|
|
||||||
APM_INDEX_SETTINGS_SAVED_OBJECT_ID,
|
|
||||||
} from '../../../../common/apm_saved_object_constants';
|
|
||||||
import { APMConfig } from '../../..';
|
|
||||||
import { APMRouteHandlerResources } from '../../typings';
|
|
||||||
import { withApmSpan } from '../../../utils/with_apm_span';
|
|
||||||
import { APMIndices } from '../../../saved_objects/apm_indices';
|
|
||||||
|
|
||||||
export type ApmIndicesConfig = Readonly<{
|
|
||||||
error: string;
|
|
||||||
onboarding: string;
|
|
||||||
span: string;
|
|
||||||
transaction: string;
|
|
||||||
metric: string;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export const APM_AGENT_CONFIGURATION_INDEX = '.apm-agent-configuration';
|
|
||||||
export const APM_CUSTOM_LINK_INDEX = '.apm-custom-link';
|
|
||||||
export const APM_SOURCE_MAP_INDEX = '.apm-source-map';
|
|
||||||
|
|
||||||
type ISavedObjectsClient = Pick<SavedObjectsClient, 'get'>;
|
|
||||||
|
|
||||||
async function getApmIndicesSavedObject(
|
|
||||||
savedObjectsClient: ISavedObjectsClient
|
|
||||||
) {
|
|
||||||
const apmIndicesSavedObject = await withApmSpan(
|
|
||||||
'get_apm_indices_saved_object',
|
|
||||||
() =>
|
|
||||||
savedObjectsClient.get<Partial<APMIndices>>(
|
|
||||||
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
|
|
||||||
APM_INDEX_SETTINGS_SAVED_OBJECT_ID
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return apmIndicesSavedObject.attributes.apmIndices;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getApmIndicesConfig(config: APMConfig): ApmIndicesConfig {
|
|
||||||
return {
|
|
||||||
error: config.indices.error,
|
|
||||||
onboarding: config.indices.onboarding,
|
|
||||||
span: config.indices.span,
|
|
||||||
transaction: config.indices.transaction,
|
|
||||||
metric: config.indices.metric,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getApmIndices({
|
|
||||||
config,
|
|
||||||
savedObjectsClient,
|
|
||||||
}: {
|
|
||||||
config: APMConfig;
|
|
||||||
savedObjectsClient: ISavedObjectsClient;
|
|
||||||
}): Promise<ApmIndicesConfig> {
|
|
||||||
try {
|
|
||||||
const apmIndicesSavedObject = await getApmIndicesSavedObject(
|
|
||||||
savedObjectsClient
|
|
||||||
);
|
|
||||||
const apmIndicesConfig = getApmIndicesConfig(config);
|
|
||||||
return { ...apmIndicesConfig, ...apmIndicesSavedObject };
|
|
||||||
} catch (error) {
|
|
||||||
return getApmIndicesConfig(config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ApmIndexSettingsResponse = Array<{
|
export type ApmIndexSettingsResponse = Array<{
|
||||||
configurationName: 'transaction' | 'span' | 'error' | 'metric' | 'onboarding';
|
configurationName: 'transaction' | 'span' | 'error' | 'metric' | 'onboarding';
|
||||||
|
@ -77,35 +14,21 @@ export type ApmIndexSettingsResponse = Array<{
|
||||||
savedValue: string | undefined;
|
savedValue: string | undefined;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export async function getApmIndexSettings({
|
export async function getApmIndexSettings(
|
||||||
context,
|
resources: APMRouteHandlerResources
|
||||||
config,
|
): Promise<ApmIndexSettingsResponse> {
|
||||||
}: Pick<
|
const { apmIndicesFromConfigFile } = resources.plugins.apmDataAccess.setup;
|
||||||
APMRouteHandlerResources,
|
|
||||||
'context' | 'config'
|
|
||||||
>): Promise<ApmIndexSettingsResponse> {
|
|
||||||
let apmIndicesSavedObject: Awaited<
|
|
||||||
ReturnType<typeof getApmIndicesSavedObject>
|
|
||||||
>;
|
|
||||||
try {
|
|
||||||
const soClient = (await context.core).savedObjects.client;
|
|
||||||
apmIndicesSavedObject = await getApmIndicesSavedObject(soClient);
|
|
||||||
} catch (error: any) {
|
|
||||||
if (error.output && error.output.statusCode === 404) {
|
|
||||||
apmIndicesSavedObject = {};
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const apmIndicesConfig = getApmIndicesConfig(config);
|
|
||||||
|
|
||||||
const apmIndices = Object.keys(config.indices) as Array<
|
const soClient = (await resources.context.core).savedObjects.client;
|
||||||
keyof typeof config.indices
|
const apmIndicesSavedObject = await getApmIndicesSavedObject(soClient);
|
||||||
|
|
||||||
|
const apmIndicesKeys = Object.keys(apmIndicesFromConfigFile) as Array<
|
||||||
|
keyof typeof apmIndicesFromConfigFile
|
||||||
>;
|
>;
|
||||||
|
|
||||||
return apmIndices.map((configurationName) => ({
|
return apmIndicesKeys.map((configurationName) => ({
|
||||||
configurationName,
|
configurationName,
|
||||||
defaultValue: apmIndicesConfig[configurationName], // value defined in kibana[.dev].yml
|
defaultValue: apmIndicesFromConfigFile[configurationName], // value defined in kibana[.dev].yml
|
||||||
savedValue: apmIndicesSavedObject?.[configurationName], // value saved via Saved Objects service
|
savedValue: apmIndicesSavedObject?.[configurationName], // value saved via Saved Objects service
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,27 +7,24 @@
|
||||||
|
|
||||||
import * as t from 'io-ts';
|
import * as t from 'io-ts';
|
||||||
import { SavedObject } from '@kbn/core/server';
|
import { SavedObject } from '@kbn/core/server';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { createApmServerRoute } from '../../apm_routes/create_apm_server_route';
|
import { createApmServerRoute } from '../../apm_routes/create_apm_server_route';
|
||||||
import {
|
import {
|
||||||
getApmIndices,
|
|
||||||
getApmIndexSettings,
|
getApmIndexSettings,
|
||||||
ApmIndexSettingsResponse,
|
ApmIndexSettingsResponse,
|
||||||
ApmIndicesConfig,
|
|
||||||
} from './get_apm_indices';
|
} from './get_apm_indices';
|
||||||
import { saveApmIndices } from './save_apm_indices';
|
import { saveApmIndices } from './save_apm_indices';
|
||||||
import { APMConfig } from '../../..';
|
|
||||||
|
|
||||||
// get list of apm indices and values
|
// get list of apm indices and values
|
||||||
const apmIndexSettingsRoute = createApmServerRoute({
|
const apmIndexSettingsRoute = createApmServerRoute({
|
||||||
endpoint: 'GET /internal/apm/settings/apm-index-settings',
|
endpoint: 'GET /internal/apm/settings/apm-index-settings',
|
||||||
options: { tags: ['access:apm'] },
|
options: { tags: ['access:apm'] },
|
||||||
handler: async ({
|
handler: async (
|
||||||
config,
|
resources
|
||||||
context,
|
): Promise<{
|
||||||
}): Promise<{
|
|
||||||
apmIndexSettings: ApmIndexSettingsResponse;
|
apmIndexSettings: ApmIndexSettingsResponse;
|
||||||
}> => {
|
}> => {
|
||||||
const apmIndexSettings = await getApmIndexSettings({ config, context });
|
const apmIndexSettings = await getApmIndexSettings(resources);
|
||||||
return { apmIndexSettings };
|
return { apmIndexSettings };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -36,18 +33,13 @@ const apmIndexSettingsRoute = createApmServerRoute({
|
||||||
const apmIndicesRoute = createApmServerRoute({
|
const apmIndicesRoute = createApmServerRoute({
|
||||||
endpoint: 'GET /internal/apm/settings/apm-indices',
|
endpoint: 'GET /internal/apm/settings/apm-indices',
|
||||||
options: { tags: ['access:apm'] },
|
options: { tags: ['access:apm'] },
|
||||||
handler: async (resources): Promise<ApmIndicesConfig> => {
|
handler: async (resources): Promise<APMIndices> => {
|
||||||
const { context, config } = resources;
|
return await resources.getApmIndices();
|
||||||
const savedObjectsClient = (await context.core).savedObjects.client;
|
|
||||||
return await getApmIndices({
|
|
||||||
savedObjectsClient,
|
|
||||||
config,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
type SaveApmIndicesBodySchema = {
|
type SaveApmIndicesBodySchema = {
|
||||||
[Property in keyof APMConfig['indices']]: t.StringC;
|
[Property in keyof APMIndices]: t.StringC;
|
||||||
};
|
};
|
||||||
|
|
||||||
// save ui indices
|
// save ui indices
|
||||||
|
|
|
@ -6,20 +6,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { SavedObjectsClientContract } from '@kbn/core/server';
|
import { SavedObjectsClientContract } from '@kbn/core/server';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import {
|
import {
|
||||||
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
|
APMIndicesSavedObjectBody,
|
||||||
APM_INDEX_SETTINGS_SAVED_OBJECT_ID,
|
APM_INDEX_SETTINGS_SAVED_OBJECT_ID,
|
||||||
} from '../../../../common/apm_saved_object_constants';
|
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
|
||||||
import { APMIndices } from '../../../saved_objects/apm_indices';
|
} from '@kbn/apm-data-access-plugin/server/saved_objects/apm_indices';
|
||||||
import { withApmSpan } from '../../../utils/with_apm_span';
|
import { withApmSpan } from '../../../utils/with_apm_span';
|
||||||
import { ApmIndicesConfig } from './get_apm_indices';
|
|
||||||
|
|
||||||
export function saveApmIndices(
|
export function saveApmIndices(
|
||||||
savedObjectsClient: SavedObjectsClientContract,
|
savedObjectsClient: SavedObjectsClientContract,
|
||||||
apmIndices: Partial<ApmIndicesConfig>
|
apmIndices: Partial<APMIndices>
|
||||||
) {
|
) {
|
||||||
return withApmSpan('save_apm_indices', () =>
|
return withApmSpan('save_apm_indices', () =>
|
||||||
savedObjectsClient.create<APMIndices>(
|
savedObjectsClient.create<APMIndicesSavedObjectBody>(
|
||||||
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
|
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
|
||||||
{ apmIndices: removeEmpty(apmIndices), isSpaceAware: true },
|
{ apmIndices: removeEmpty(apmIndices), isSpaceAware: true },
|
||||||
{ id: APM_INDEX_SETTINGS_SAVED_OBJECT_ID, overwrite: true }
|
{ id: APM_INDEX_SETTINGS_SAVED_OBJECT_ID, overwrite: true }
|
||||||
|
@ -28,7 +28,7 @@ export function saveApmIndices(
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove empty/undefined values
|
// remove empty/undefined values
|
||||||
function removeEmpty(apmIndices: Partial<ApmIndicesConfig>) {
|
function removeEmpty(apmIndices: Partial<APMIndices>) {
|
||||||
return Object.entries(apmIndices)
|
return Object.entries(apmIndices)
|
||||||
.map(([key, value]) => [key, value?.trim()])
|
.map(([key, value]) => [key, value?.trim()])
|
||||||
.filter(([_, value]) => !!value)
|
.filter(([_, value]) => !!value)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
createOrUpdateIndex,
|
createOrUpdateIndex,
|
||||||
Mappings,
|
Mappings,
|
||||||
} from '@kbn/observability-plugin/server';
|
} from '@kbn/observability-plugin/server';
|
||||||
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export const createApmCustomLinkIndex = async ({
|
export const createApmCustomLinkIndex = async ({
|
||||||
client,
|
client,
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
APMIndexDocumentParams,
|
APMIndexDocumentParams,
|
||||||
APMInternalESClient,
|
APMInternalESClient,
|
||||||
} from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
} from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export function createOrUpdateCustomLink({
|
export function createOrUpdateCustomLink({
|
||||||
customLinkId,
|
customLinkId,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export function deleteCustomLink({
|
export function deleteCustomLink({
|
||||||
customLinkId,
|
customLinkId,
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
import { fromESFormat } from './helper';
|
import { fromESFormat } from './helper';
|
||||||
import { filterOptionsRt } from './custom_link_types';
|
import { filterOptionsRt } from './custom_link_types';
|
||||||
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
import { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/get_apm_indices';
|
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export async function listCustomLinks({
|
export async function listCustomLinks({
|
||||||
internalESClient,
|
internalESClient,
|
||||||
|
|
|
@ -50,8 +50,9 @@ const listCustomLinksRoute = createApmServerRoute({
|
||||||
): Promise<{
|
): Promise<{
|
||||||
customLinks: CustomLink[];
|
customLinks: CustomLink[];
|
||||||
}> => {
|
}> => {
|
||||||
const { context, params, request, config } = resources;
|
const { context, params, request } = resources;
|
||||||
const licensingContext = await context.licensing;
|
const licensingContext = await context.licensing;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
if (!isActiveGoldLicense(licensingContext.license)) {
|
if (!isActiveGoldLicense(licensingContext.license)) {
|
||||||
throw Boom.forbidden(INVALID_LICENSE);
|
throw Boom.forbidden(INVALID_LICENSE);
|
||||||
|
@ -63,7 +64,7 @@ const listCustomLinksRoute = createApmServerRoute({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: resources.params.query._inspect,
|
debug: resources.params.query._inspect,
|
||||||
config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
|
|
||||||
// picks only the items listed in FILTER_OPTIONS
|
// picks only the items listed in FILTER_OPTIONS
|
||||||
|
@ -83,8 +84,9 @@ const createCustomLinkRoute = createApmServerRoute({
|
||||||
}),
|
}),
|
||||||
options: { tags: ['access:apm', 'access:apm_write'] },
|
options: { tags: ['access:apm', 'access:apm_write'] },
|
||||||
handler: async (resources): Promise<void> => {
|
handler: async (resources): Promise<void> => {
|
||||||
const { context, params, request, config } = resources;
|
const { context, params, request } = resources;
|
||||||
const licensingContext = await context.licensing;
|
const licensingContext = await context.licensing;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
if (!isActiveGoldLicense(licensingContext.license)) {
|
if (!isActiveGoldLicense(licensingContext.license)) {
|
||||||
throw Boom.forbidden(INVALID_LICENSE);
|
throw Boom.forbidden(INVALID_LICENSE);
|
||||||
|
@ -94,7 +96,7 @@ const createCustomLinkRoute = createApmServerRoute({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: resources.params.query._inspect,
|
debug: resources.params.query._inspect,
|
||||||
config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
const customLink = params.body;
|
const customLink = params.body;
|
||||||
|
|
||||||
|
@ -119,8 +121,9 @@ const updateCustomLinkRoute = createApmServerRoute({
|
||||||
tags: ['access:apm', 'access:apm_write'],
|
tags: ['access:apm', 'access:apm_write'],
|
||||||
},
|
},
|
||||||
handler: async (resources): Promise<void> => {
|
handler: async (resources): Promise<void> => {
|
||||||
const { params, context, request, config } = resources;
|
const { params, context, request } = resources;
|
||||||
const licensingContext = await context.licensing;
|
const licensingContext = await context.licensing;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
if (!isActiveGoldLicense(licensingContext.license)) {
|
if (!isActiveGoldLicense(licensingContext.license)) {
|
||||||
throw Boom.forbidden(INVALID_LICENSE);
|
throw Boom.forbidden(INVALID_LICENSE);
|
||||||
|
@ -130,7 +133,7 @@ const updateCustomLinkRoute = createApmServerRoute({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: resources.params.query._inspect,
|
debug: resources.params.query._inspect,
|
||||||
config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { id } = params.path;
|
const { id } = params.path;
|
||||||
|
@ -155,8 +158,9 @@ const deleteCustomLinkRoute = createApmServerRoute({
|
||||||
tags: ['access:apm', 'access:apm_write'],
|
tags: ['access:apm', 'access:apm_write'],
|
||||||
},
|
},
|
||||||
handler: async (resources): Promise<{ result: string }> => {
|
handler: async (resources): Promise<{ result: string }> => {
|
||||||
const { context, params, request, config } = resources;
|
const { context, params, request } = resources;
|
||||||
const licensingContext = await context.licensing;
|
const licensingContext = await context.licensing;
|
||||||
|
const apmIndices = await resources.getApmIndices();
|
||||||
|
|
||||||
if (!isActiveGoldLicense(licensingContext.license)) {
|
if (!isActiveGoldLicense(licensingContext.license)) {
|
||||||
throw Boom.forbidden(INVALID_LICENSE);
|
throw Boom.forbidden(INVALID_LICENSE);
|
||||||
|
@ -166,7 +170,7 @@ const deleteCustomLinkRoute = createApmServerRoute({
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
debug: resources.params.query._inspect,
|
debug: resources.params.query._inspect,
|
||||||
config,
|
apmIndices,
|
||||||
});
|
});
|
||||||
const { id } = params.path;
|
const { id } = params.path;
|
||||||
const res = await deleteCustomLink({
|
const res = await deleteCustomLink({
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { Artifact } from '@kbn/fleet-plugin/server';
|
import { Artifact } from '@kbn/fleet-plugin/server';
|
||||||
import { getUnzippedArtifactBody } from '../fleet/source_maps';
|
import { getUnzippedArtifactBody } from '../fleet/source_maps';
|
||||||
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/get_apm_indices';
|
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
|
||||||
import { ApmSourceMap } from './create_apm_source_map_index_template';
|
import { ApmSourceMap } from './create_apm_source_map_index_template';
|
||||||
import { getEncodedSourceMapContent, getSourceMapId } from './sourcemap_utils';
|
import { getEncodedSourceMapContent, getSourceMapId } from './sourcemap_utils';
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { Logger } from '@kbn/core/server';
|
import { Logger } from '@kbn/core/server';
|
||||||
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/get_apm_indices';
|
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
|
||||||
import { ApmSourceMap } from './create_apm_source_map_index_template';
|
import { ApmSourceMap } from './create_apm_source_map_index_template';
|
||||||
import { SourceMap } from './route';
|
import { SourceMap } from './route';
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import { IndicesPutIndexTemplateRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
import { IndicesPutIndexTemplateRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||||
import { ElasticsearchClient, Logger } from '@kbn/core/server';
|
import { ElasticsearchClient, Logger } from '@kbn/core/server';
|
||||||
import { createOrUpdateIndexTemplate } from '@kbn/observability-plugin/server';
|
import { createOrUpdateIndexTemplate } from '@kbn/observability-plugin/server';
|
||||||
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/get_apm_indices';
|
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
const indexTemplate: IndicesPutIndexTemplateRequest = {
|
const indexTemplate: IndicesPutIndexTemplateRequest = {
|
||||||
name: 'apm-source-map',
|
name: 'apm-source-map',
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||||
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/get_apm_indices';
|
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
|
||||||
|
|
||||||
export async function deleteApmSourceMap({
|
export async function deleteApmSourceMap({
|
||||||
internalESClient,
|
internalESClient,
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { TaskManagerSetupContract } from '@kbn/task-manager-plugin/server';
|
||||||
import { CoreStart, Logger } from '@kbn/core/server';
|
import { CoreStart, Logger } from '@kbn/core/server';
|
||||||
import { getApmArtifactClient } from '../fleet/source_maps';
|
import { getApmArtifactClient } from '../fleet/source_maps';
|
||||||
import { bulkCreateApmSourceMaps } from './bulk_create_apm_source_maps';
|
import { bulkCreateApmSourceMaps } from './bulk_create_apm_source_maps';
|
||||||
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/get_apm_indices';
|
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
|
||||||
import { ApmSourceMap } from './create_apm_source_map_index_template';
|
import { ApmSourceMap } from './create_apm_source_map_index_template';
|
||||||
import { APMPluginStartDependencies } from '../../types';
|
import { APMPluginStartDependencies } from '../../types';
|
||||||
import { createApmSourceMapIndexTemplate } from './create_apm_source_map_index_template';
|
import { createApmSourceMapIndexTemplate } from './create_apm_source_map_index_template';
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { isCrossClusterSearch } from './is_cross_cluster_search';
|
import { isCrossClusterSearch } from './is_cross_cluster_search';
|
||||||
import { ApmIndicesConfig } from '@kbn/observability-plugin/common/typings';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
|
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
|
||||||
|
|
||||||
describe('isCrossClusterSearch', () => {
|
describe('isCrossClusterSearch', () => {
|
||||||
|
@ -17,7 +17,7 @@ describe('isCrossClusterSearch', () => {
|
||||||
span: 'traces-apm*',
|
span: 'traces-apm*',
|
||||||
metric: 'metrics-apm*',
|
metric: 'metrics-apm*',
|
||||||
error: 'logs-apm*',
|
error: 'logs-apm*',
|
||||||
} as ApmIndicesConfig,
|
} as APMIndices,
|
||||||
} as unknown as APMEventClient;
|
} as unknown as APMEventClient;
|
||||||
|
|
||||||
expect(isCrossClusterSearch(mockApmEventClient)).toBe(false);
|
expect(isCrossClusterSearch(mockApmEventClient)).toBe(false);
|
||||||
|
@ -30,7 +30,7 @@ describe('isCrossClusterSearch', () => {
|
||||||
span: 'traces-apm*,test-apm*',
|
span: 'traces-apm*,test-apm*',
|
||||||
metric: 'metrics-apm*,test-apm*',
|
metric: 'metrics-apm*,test-apm*',
|
||||||
error: 'logs-apm*,test-apm*',
|
error: 'logs-apm*,test-apm*',
|
||||||
} as ApmIndicesConfig,
|
} as APMIndices,
|
||||||
} as unknown as APMEventClient;
|
} as unknown as APMEventClient;
|
||||||
|
|
||||||
expect(isCrossClusterSearch(mockApmEventClient)).toBe(false);
|
expect(isCrossClusterSearch(mockApmEventClient)).toBe(false);
|
||||||
|
@ -44,7 +44,7 @@ describe('isCrossClusterSearch', () => {
|
||||||
metric: '',
|
metric: '',
|
||||||
error: '',
|
error: '',
|
||||||
onboarding: 'apm-*,remote_cluster:apm-*',
|
onboarding: 'apm-*,remote_cluster:apm-*',
|
||||||
} as ApmIndicesConfig,
|
} as APMIndices,
|
||||||
} as unknown as APMEventClient;
|
} as unknown as APMEventClient;
|
||||||
|
|
||||||
expect(isCrossClusterSearch(mockApmEventClient)).toBe(false);
|
expect(isCrossClusterSearch(mockApmEventClient)).toBe(false);
|
||||||
|
@ -57,7 +57,7 @@ describe('isCrossClusterSearch', () => {
|
||||||
span: '',
|
span: '',
|
||||||
metric: '',
|
metric: '',
|
||||||
error: '',
|
error: '',
|
||||||
} as ApmIndicesConfig,
|
} as APMIndices,
|
||||||
} as unknown as APMEventClient;
|
} as unknown as APMEventClient;
|
||||||
|
|
||||||
expect(isCrossClusterSearch(mockApmEventClient)).toBe(true);
|
expect(isCrossClusterSearch(mockApmEventClient)).toBe(true);
|
||||||
|
@ -70,7 +70,7 @@ describe('isCrossClusterSearch', () => {
|
||||||
span: 'traces-apm*,remote_cluster:traces-apm*',
|
span: 'traces-apm*,remote_cluster:traces-apm*',
|
||||||
metric: '',
|
metric: '',
|
||||||
error: '',
|
error: '',
|
||||||
} as ApmIndicesConfig,
|
} as APMIndices,
|
||||||
} as unknown as APMEventClient;
|
} as unknown as APMEventClient;
|
||||||
|
|
||||||
expect(isCrossClusterSearch(mockApmEventClient)).toBe(true);
|
expect(isCrossClusterSearch(mockApmEventClient)).toBe(true);
|
||||||
|
@ -83,7 +83,7 @@ describe('isCrossClusterSearch', () => {
|
||||||
span: '',
|
span: '',
|
||||||
metric: 'metrics-apm*,remote_cluster:metrics-apm*',
|
metric: 'metrics-apm*,remote_cluster:metrics-apm*',
|
||||||
error: '',
|
error: '',
|
||||||
} as ApmIndicesConfig,
|
} as APMIndices,
|
||||||
} as unknown as APMEventClient;
|
} as unknown as APMEventClient;
|
||||||
|
|
||||||
expect(isCrossClusterSearch(mockApmEventClient)).toBe(true);
|
expect(isCrossClusterSearch(mockApmEventClient)).toBe(true);
|
||||||
|
@ -96,7 +96,7 @@ describe('isCrossClusterSearch', () => {
|
||||||
span: '',
|
span: '',
|
||||||
metric: '',
|
metric: '',
|
||||||
error: 'logs-apm*,remote_cluster:logs-apm*',
|
error: 'logs-apm*,remote_cluster:logs-apm*',
|
||||||
} as ApmIndicesConfig,
|
} as APMIndices,
|
||||||
} as unknown as APMEventClient;
|
} as unknown as APMEventClient;
|
||||||
|
|
||||||
expect(isCrossClusterSearch(mockApmEventClient)).toBe(true);
|
expect(isCrossClusterSearch(mockApmEventClient)).toBe(true);
|
||||||
|
|
|
@ -8,22 +8,13 @@
|
||||||
import {
|
import {
|
||||||
CoreSetup,
|
CoreSetup,
|
||||||
CustomRequestHandlerContext,
|
CustomRequestHandlerContext,
|
||||||
Logger,
|
|
||||||
KibanaRequest,
|
|
||||||
CoreStart,
|
CoreStart,
|
||||||
RouteConfigOptions,
|
RouteConfigOptions,
|
||||||
} from '@kbn/core/server';
|
} from '@kbn/core/server';
|
||||||
import { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
|
|
||||||
import { AlertingApiRequestHandlerContext } from '@kbn/alerting-plugin/server';
|
import { AlertingApiRequestHandlerContext } from '@kbn/alerting-plugin/server';
|
||||||
import type { RacApiRequestHandlerContext } from '@kbn/rule-registry-plugin/server';
|
import type { RacApiRequestHandlerContext } from '@kbn/rule-registry-plugin/server';
|
||||||
import { LicensingApiRequestHandlerContext } from '@kbn/licensing-plugin/server';
|
import { LicensingApiRequestHandlerContext } from '@kbn/licensing-plugin/server';
|
||||||
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
|
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
|
||||||
import { APMConfig } from '..';
|
|
||||||
import {
|
|
||||||
APMPluginSetupDependencies,
|
|
||||||
APMPluginStartDependencies,
|
|
||||||
} from '../types';
|
|
||||||
import { ApmFeatureFlags } from '../../common/apm_feature_flags';
|
|
||||||
|
|
||||||
export type ApmPluginRequestHandlerContext = CustomRequestHandlerContext<{
|
export type ApmPluginRequestHandlerContext = CustomRequestHandlerContext<{
|
||||||
licensing: LicensingApiRequestHandlerContext;
|
licensing: LicensingApiRequestHandlerContext;
|
||||||
|
@ -54,26 +45,3 @@ export interface APMCore {
|
||||||
setup: CoreSetup;
|
setup: CoreSetup;
|
||||||
start: () => Promise<CoreStart>;
|
start: () => Promise<CoreStart>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface APMRouteHandlerResources {
|
|
||||||
request: KibanaRequest;
|
|
||||||
context: ApmPluginRequestHandlerContext;
|
|
||||||
params: {
|
|
||||||
query: {
|
|
||||||
_inspect: boolean;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
config: APMConfig;
|
|
||||||
featureFlags: ApmFeatureFlags;
|
|
||||||
logger: Logger;
|
|
||||||
core: APMCore;
|
|
||||||
plugins: {
|
|
||||||
[key in keyof APMPluginSetupDependencies]: {
|
|
||||||
setup: Required<APMPluginSetupDependencies>[key];
|
|
||||||
start: () => Promise<Required<APMPluginStartDependencies>[key]>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
ruleDataClient: IRuleDataClient;
|
|
||||||
telemetryUsageCounter?: TelemetryUsageCounter;
|
|
||||||
kibanaVersion: string;
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { apmIndices } from './apm_indices';
|
|
||||||
export { apmTelemetry } from './apm_telemetry';
|
export { apmTelemetry } from './apm_telemetry';
|
||||||
export { apmServerSettings } from './apm_server_settings';
|
export { apmServerSettings } from './apm_server_settings';
|
||||||
export { apmServiceGroups } from './apm_service_groups';
|
export { apmServiceGroups } from './apm_service_groups';
|
||||||
|
|
|
@ -11,8 +11,8 @@ import {
|
||||||
TutorialSchema,
|
TutorialSchema,
|
||||||
InstructionSetSchema,
|
InstructionSetSchema,
|
||||||
} from '@kbn/home-plugin/server';
|
} from '@kbn/home-plugin/server';
|
||||||
|
|
||||||
import { CloudSetup } from '@kbn/cloud-plugin/server';
|
import { CloudSetup } from '@kbn/cloud-plugin/server';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import {
|
import {
|
||||||
createNodeAgentInstructions,
|
createNodeAgentInstructions,
|
||||||
createDjangoAgentInstructions,
|
createDjangoAgentInstructions,
|
||||||
|
@ -26,16 +26,15 @@ import {
|
||||||
createPhpAgentInstructions,
|
createPhpAgentInstructions,
|
||||||
createOpenTelemetryAgentInstructions,
|
createOpenTelemetryAgentInstructions,
|
||||||
} from '../../../common/tutorial/instructions/apm_agent_instructions';
|
} from '../../../common/tutorial/instructions/apm_agent_instructions';
|
||||||
import { APMConfig } from '../..';
|
|
||||||
import { getOnPremApmServerInstructionSet } from './on_prem_apm_server_instruction_set';
|
import { getOnPremApmServerInstructionSet } from './on_prem_apm_server_instruction_set';
|
||||||
|
|
||||||
export function createElasticCloudInstructions({
|
export function createElasticCloudInstructions({
|
||||||
cloudSetup,
|
cloudSetup,
|
||||||
apmConfig,
|
apmIndices,
|
||||||
isFleetPluginEnabled,
|
isFleetPluginEnabled,
|
||||||
}: {
|
}: {
|
||||||
cloudSetup?: CloudSetup;
|
cloudSetup?: CloudSetup;
|
||||||
apmConfig: APMConfig;
|
apmIndices: APMIndices;
|
||||||
isFleetPluginEnabled: boolean;
|
isFleetPluginEnabled: boolean;
|
||||||
}): TutorialSchema['elasticCloud'] {
|
}): TutorialSchema['elasticCloud'] {
|
||||||
const apmServerUrl = cloudSetup?.apm.url;
|
const apmServerUrl = cloudSetup?.apm.url;
|
||||||
|
@ -46,7 +45,7 @@ export function createElasticCloudInstructions({
|
||||||
}
|
}
|
||||||
|
|
||||||
instructionSets.push(
|
instructionSets.push(
|
||||||
getOnPremApmServerInstructionSet({ apmConfig, isFleetPluginEnabled })
|
getOnPremApmServerInstructionSet({ apmIndices, isFleetPluginEnabled })
|
||||||
);
|
);
|
||||||
instructionSets.push(getApmAgentInstructionSet(cloudSetup));
|
instructionSets.push(getApmAgentInstructionSet(cloudSetup));
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
INSTRUCTION_VARIANT,
|
INSTRUCTION_VARIANT,
|
||||||
InstructionsSchema,
|
InstructionsSchema,
|
||||||
} from '@kbn/home-plugin/server';
|
} from '@kbn/home-plugin/server';
|
||||||
import { APMConfig } from '../..';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import {
|
import {
|
||||||
createDjangoAgentInstructions,
|
createDjangoAgentInstructions,
|
||||||
createDotNetAgentInstructions,
|
createDotNetAgentInstructions,
|
||||||
|
@ -27,15 +27,18 @@ import {
|
||||||
import { getOnPremApmServerInstructionSet } from './on_prem_apm_server_instruction_set';
|
import { getOnPremApmServerInstructionSet } from './on_prem_apm_server_instruction_set';
|
||||||
|
|
||||||
export function onPremInstructions({
|
export function onPremInstructions({
|
||||||
apmConfig,
|
apmIndices,
|
||||||
isFleetPluginEnabled,
|
isFleetPluginEnabled,
|
||||||
}: {
|
}: {
|
||||||
apmConfig: APMConfig;
|
apmIndices: APMIndices;
|
||||||
isFleetPluginEnabled: boolean;
|
isFleetPluginEnabled: boolean;
|
||||||
}): InstructionsSchema {
|
}): InstructionsSchema {
|
||||||
return {
|
return {
|
||||||
instructionSets: [
|
instructionSets: [
|
||||||
getOnPremApmServerInstructionSet({ apmConfig, isFleetPluginEnabled }),
|
getOnPremApmServerInstructionSet({
|
||||||
|
apmIndices,
|
||||||
|
isFleetPluginEnabled,
|
||||||
|
}),
|
||||||
{
|
{
|
||||||
title: i18n.translate('xpack.apm.tutorial.apmAgents.title', {
|
title: i18n.translate('xpack.apm.tutorial.apmAgents.title', {
|
||||||
defaultMessage: 'APM Agents',
|
defaultMessage: 'APM Agents',
|
||||||
|
@ -121,9 +124,9 @@ export function onPremInstructions({
|
||||||
),
|
),
|
||||||
esHitsCheck: {
|
esHitsCheck: {
|
||||||
index: [
|
index: [
|
||||||
apmConfig.indices.error,
|
apmIndices.error,
|
||||||
apmConfig.indices.transaction,
|
apmIndices.transaction,
|
||||||
apmConfig.indices.metric,
|
apmIndices.metric,
|
||||||
],
|
],
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
bool: {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
InstructionsSchema,
|
InstructionsSchema,
|
||||||
INSTRUCTION_VARIANT,
|
INSTRUCTION_VARIANT,
|
||||||
} from '@kbn/home-plugin/server';
|
} from '@kbn/home-plugin/server';
|
||||||
import { APMConfig } from '../..';
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import {
|
import {
|
||||||
createDownloadServerDeb,
|
createDownloadServerDeb,
|
||||||
createDownloadServerOsx,
|
createDownloadServerOsx,
|
||||||
|
@ -29,10 +29,10 @@ const START_SERVER_UNIX_SYSV = createStartServerUnixSysv();
|
||||||
const START_SERVER_UNIX_BINARI = createStartServerUnixBinari();
|
const START_SERVER_UNIX_BINARI = createStartServerUnixBinari();
|
||||||
|
|
||||||
export function getOnPremApmServerInstructionSet({
|
export function getOnPremApmServerInstructionSet({
|
||||||
apmConfig,
|
apmIndices,
|
||||||
isFleetPluginEnabled,
|
isFleetPluginEnabled,
|
||||||
}: {
|
}: {
|
||||||
apmConfig: APMConfig;
|
apmIndices: APMIndices;
|
||||||
isFleetPluginEnabled: boolean;
|
isFleetPluginEnabled: boolean;
|
||||||
}): InstructionsSchema['instructionSets'][0] {
|
}): InstructionsSchema['instructionSets'][0] {
|
||||||
return {
|
return {
|
||||||
|
@ -132,7 +132,7 @@ export function getOnPremApmServerInstructionSet({
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
esHitsCheck: {
|
esHitsCheck: {
|
||||||
index: apmConfig.indices.onboarding,
|
index: apmIndices.onboarding,
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
bool: {
|
||||||
filter: [{ term: { 'processor.event': 'onboarding' } }],
|
filter: [{ term: { 'processor.event': 'onboarding' } }],
|
||||||
|
|
|
@ -12,8 +12,8 @@ import {
|
||||||
TutorialSchema,
|
TutorialSchema,
|
||||||
} from '@kbn/home-plugin/server';
|
} from '@kbn/home-plugin/server';
|
||||||
import { CloudSetup } from '@kbn/cloud-plugin/server';
|
import { CloudSetup } from '@kbn/cloud-plugin/server';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { APMConfig } from '..';
|
import { APMConfig } from '..';
|
||||||
import { ApmIndicesConfig } from '../routes/settings/apm_indices/get_apm_indices';
|
|
||||||
import { createElasticCloudInstructions } from './envs/elastic_cloud';
|
import { createElasticCloudInstructions } from './envs/elastic_cloud';
|
||||||
import { onPremInstructions } from './envs/on_prem';
|
import { onPremInstructions } from './envs/on_prem';
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ export const tutorialProvider =
|
||||||
isFleetPluginEnabled,
|
isFleetPluginEnabled,
|
||||||
}: {
|
}: {
|
||||||
apmConfig: APMConfig;
|
apmConfig: APMConfig;
|
||||||
apmIndices: ApmIndicesConfig;
|
apmIndices: APMIndices;
|
||||||
cloud?: CloudSetup;
|
cloud?: CloudSetup;
|
||||||
isFleetPluginEnabled: boolean;
|
isFleetPluginEnabled: boolean;
|
||||||
}) =>
|
}) =>
|
||||||
|
@ -90,9 +90,9 @@ It allows you to monitor the performance of thousands of applications in real ti
|
||||||
integrationBrowserCategories: ['observability', 'apm'],
|
integrationBrowserCategories: ['observability', 'apm'],
|
||||||
artifacts,
|
artifacts,
|
||||||
customStatusCheckName: 'apm_fleet_server_status_check',
|
customStatusCheckName: 'apm_fleet_server_status_check',
|
||||||
onPrem: onPremInstructions({ apmConfig, isFleetPluginEnabled }),
|
onPrem: onPremInstructions({ apmIndices, isFleetPluginEnabled }),
|
||||||
elasticCloud: createElasticCloudInstructions({
|
elasticCloud: createElasticCloudInstructions({
|
||||||
apmConfig,
|
apmIndices,
|
||||||
isFleetPluginEnabled,
|
isFleetPluginEnabled,
|
||||||
cloudSetup: cloud,
|
cloudSetup: cloud,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
import { SharePluginSetup } from '@kbn/share-plugin/server';
|
import { SharePluginSetup } from '@kbn/share-plugin/server';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { KibanaRequest } from '@kbn/core/server';
|
|
||||||
import {
|
import {
|
||||||
RuleRegistryPluginSetupContract,
|
RuleRegistryPluginSetupContract,
|
||||||
RuleRegistryPluginStartContract,
|
RuleRegistryPluginStartContract,
|
||||||
|
@ -16,6 +15,11 @@ import {
|
||||||
PluginSetup as DataPluginSetup,
|
PluginSetup as DataPluginSetup,
|
||||||
PluginStart as DataPluginStart,
|
PluginStart as DataPluginStart,
|
||||||
} from '@kbn/data-plugin/server';
|
} from '@kbn/data-plugin/server';
|
||||||
|
import {
|
||||||
|
ApmDataAccessPluginSetup,
|
||||||
|
ApmDataAccessPluginStart,
|
||||||
|
} from '@kbn/apm-data-access-plugin/server';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SpacesPluginSetup,
|
SpacesPluginSetup,
|
||||||
SpacesPluginStart,
|
SpacesPluginStart,
|
||||||
|
@ -58,22 +62,14 @@ import {
|
||||||
CustomIntegrationsPluginStart,
|
CustomIntegrationsPluginStart,
|
||||||
} from '@kbn/custom-integrations-plugin/server';
|
} from '@kbn/custom-integrations-plugin/server';
|
||||||
import { APMConfig } from '.';
|
import { APMConfig } from '.';
|
||||||
import { ApmIndicesConfig } from './routes/settings/apm_indices/get_apm_indices';
|
|
||||||
import { APMEventClient } from './lib/helpers/create_es_client/create_apm_event_client';
|
|
||||||
import { ApmPluginRequestHandlerContext } from './routes/typings';
|
|
||||||
|
|
||||||
export interface APMPluginSetup {
|
export interface APMPluginSetup {
|
||||||
config$: Observable<APMConfig>;
|
config$: Observable<APMConfig>;
|
||||||
getApmIndices: () => Promise<ApmIndicesConfig>;
|
|
||||||
createApmEventClient: (params: {
|
|
||||||
debug?: boolean;
|
|
||||||
request: KibanaRequest;
|
|
||||||
context: ApmPluginRequestHandlerContext;
|
|
||||||
}) => Promise<APMEventClient>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface APMPluginSetupDependencies {
|
export interface APMPluginSetupDependencies {
|
||||||
// required dependencies
|
// required dependencies
|
||||||
|
apmDataAccess: ApmDataAccessPluginSetup;
|
||||||
data: DataPluginSetup;
|
data: DataPluginSetup;
|
||||||
features: FeaturesPluginSetup;
|
features: FeaturesPluginSetup;
|
||||||
licensing: LicensingPluginSetup;
|
licensing: LicensingPluginSetup;
|
||||||
|
@ -98,6 +94,7 @@ export interface APMPluginSetupDependencies {
|
||||||
}
|
}
|
||||||
export interface APMPluginStartDependencies {
|
export interface APMPluginStartDependencies {
|
||||||
// required dependencies
|
// required dependencies
|
||||||
|
apmDataAccess: ApmDataAccessPluginStart;
|
||||||
data: DataPluginStart;
|
data: DataPluginStart;
|
||||||
features: FeaturesPluginStart;
|
features: FeaturesPluginStart;
|
||||||
licensing: LicensingPluginStart;
|
licensing: LicensingPluginStart;
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ESSearchRequest, ESSearchResponse } from '@kbn/es-types';
|
import type { ESSearchRequest, ESSearchResponse } from '@kbn/es-types';
|
||||||
|
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
|
||||||
import { APMConfig } from '..';
|
import { APMConfig } from '..';
|
||||||
import { APMEventClient } from '../lib/helpers/create_es_client/create_apm_event_client';
|
import { APMEventClient } from '../lib/helpers/create_es_client/create_apm_event_client';
|
||||||
import { APMInternalESClient } from '../lib/helpers/create_es_client/create_internal_es_client';
|
import { APMInternalESClient } from '../lib/helpers/create_es_client/create_internal_es_client';
|
||||||
import { ApmAlertsClient } from '../lib/helpers/get_apm_alerts_client';
|
import { ApmAlertsClient } from '../lib/helpers/get_apm_alerts_client';
|
||||||
import { ApmIndicesConfig } from '../routes/settings/apm_indices/get_apm_indices';
|
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
mockResponse?: (
|
mockResponse?: (
|
||||||
|
@ -30,7 +30,7 @@ export async function inspectSearchParams(
|
||||||
mockApmEventClient: APMEventClient;
|
mockApmEventClient: APMEventClient;
|
||||||
mockConfig: APMConfig;
|
mockConfig: APMConfig;
|
||||||
mockInternalESClient: APMInternalESClient;
|
mockInternalESClient: APMInternalESClient;
|
||||||
mockIndices: ApmIndicesConfig;
|
mockIndices: APMIndices;
|
||||||
mockApmAlertsClient: ApmAlertsClient;
|
mockApmAlertsClient: ApmAlertsClient;
|
||||||
}) => Promise<any>,
|
}) => Promise<any>,
|
||||||
options: Options = {}
|
options: Options = {}
|
||||||
|
@ -53,7 +53,7 @@ export async function inspectSearchParams(
|
||||||
let error;
|
let error;
|
||||||
const mockApmEventClient = { search: spy } as any;
|
const mockApmEventClient = { search: spy } as any;
|
||||||
const indices: {
|
const indices: {
|
||||||
[Property in keyof APMConfig['indices']]: string;
|
[Property in keyof APMIndices]: string;
|
||||||
} = {
|
} = {
|
||||||
error: 'myIndex',
|
error: 'myIndex',
|
||||||
onboarding: 'myIndex',
|
onboarding: 'myIndex',
|
||||||
|
@ -61,6 +61,7 @@ export async function inspectSearchParams(
|
||||||
transaction: 'myIndex',
|
transaction: 'myIndex',
|
||||||
metric: 'myIndex',
|
metric: 'myIndex',
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockConfig = new Proxy(
|
const mockConfig = new Proxy(
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
|
@ -73,8 +74,6 @@ export async function inspectSearchParams(
|
||||||
switch (key) {
|
switch (key) {
|
||||||
default:
|
default:
|
||||||
return 'myIndex';
|
return 'myIndex';
|
||||||
case 'indices':
|
|
||||||
return indices;
|
|
||||||
case 'ui':
|
case 'ui':
|
||||||
return {
|
return {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
|
@ -76,7 +76,6 @@
|
||||||
"@kbn/babel-register",
|
"@kbn/babel-register",
|
||||||
"@kbn/core-saved-objects-migration-server-internal",
|
"@kbn/core-saved-objects-migration-server-internal",
|
||||||
"@kbn/core-elasticsearch-server",
|
"@kbn/core-elasticsearch-server",
|
||||||
"@kbn/core-saved-objects-api-server",
|
|
||||||
"@kbn/safer-lodash-set",
|
"@kbn/safer-lodash-set",
|
||||||
"@kbn/shared-ux-router",
|
"@kbn/shared-ux-router",
|
||||||
"@kbn/alerts-as-data-utils",
|
"@kbn/alerts-as-data-utils",
|
||||||
|
@ -96,7 +95,8 @@
|
||||||
"@kbn/logs-shared-plugin",
|
"@kbn/logs-shared-plugin",
|
||||||
"@kbn/unified-field-list",
|
"@kbn/unified-field-list",
|
||||||
"@kbn/discover-plugin",
|
"@kbn/discover-plugin",
|
||||||
"@kbn/observability-ai-assistant-plugin"
|
"@kbn/observability-ai-assistant-plugin",
|
||||||
|
"@kbn/apm-data-access-plugin"
|
||||||
],
|
],
|
||||||
"exclude": ["target/**/*"]
|
"exclude": ["target/**/*"]
|
||||||
}
|
}
|
||||||
|
|
9
x-pack/plugins/apm_data_access/common/index.ts
Normal file
9
x-pack/plugins/apm_data_access/common/index.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const PLUGIN_ID = 'apmDataAccess';
|
||||||
|
export const PLUGIN_NAME = 'apmDataAccess';
|
14
x-pack/plugins/apm_data_access/jest.config.js
Normal file
14
x-pack/plugins/apm_data_access/jest.config.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test',
|
||||||
|
rootDir: path.resolve(__dirname, '../../..'),
|
||||||
|
roots: ['<rootDir>/x-pack/plugins/apm_data_access'],
|
||||||
|
};
|
14
x-pack/plugins/apm_data_access/kibana.jsonc
Normal file
14
x-pack/plugins/apm_data_access/kibana.jsonc
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"type": "plugin",
|
||||||
|
"id": "@kbn/apm-data-access-plugin",
|
||||||
|
"owner": "@elastic/apm-ui",
|
||||||
|
"plugin": {
|
||||||
|
"id": "apmDataAccess",
|
||||||
|
"server": true,
|
||||||
|
"browser": false,
|
||||||
|
"configPath": ["xpack", "apm_data_access"],
|
||||||
|
"requiredPlugins": ["data"],
|
||||||
|
"optionalPlugins": [],
|
||||||
|
"requiredBundles": []
|
||||||
|
}
|
||||||
|
}
|
80
x-pack/plugins/apm_data_access/server/index.ts
Normal file
80
x-pack/plugins/apm_data_access/server/index.ts
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* 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 { schema, TypeOf } from '@kbn/config-schema';
|
||||||
|
import { PluginConfigDescriptor, PluginInitializerContext } from '@kbn/core/server';
|
||||||
|
import { ApmDataAccessPlugin } from './plugin';
|
||||||
|
|
||||||
|
const configSchema = schema.object({
|
||||||
|
indices: schema.object({
|
||||||
|
transaction: schema.string({ defaultValue: 'traces-apm*,apm-*' }), // TODO: remove apm-* pattern in 9.0
|
||||||
|
span: schema.string({ defaultValue: 'traces-apm*,apm-*' }),
|
||||||
|
error: schema.string({ defaultValue: 'logs-apm*,apm-*' }),
|
||||||
|
metric: schema.string({ defaultValue: 'metrics-apm*,apm-*' }),
|
||||||
|
onboarding: schema.string({ defaultValue: 'apm-*' }), // Unused: to be deleted
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
// plugin config
|
||||||
|
export const config: PluginConfigDescriptor<APMDataAccessConfig> = {
|
||||||
|
deprecations: ({ renameFromRoot, unused, deprecate }) => [
|
||||||
|
// deprecations
|
||||||
|
unused('indices.sourcemap', { level: 'warning' }),
|
||||||
|
deprecate('indices.onboarding', 'a future version', {
|
||||||
|
level: 'warning',
|
||||||
|
message: `Configuring "xpack.apm.indices.onboarding" is deprecated and will be removed in a future version. Please remove this setting.`,
|
||||||
|
}),
|
||||||
|
|
||||||
|
// deprecations due to removal of apm_oss plugin
|
||||||
|
renameFromRoot('apm_oss.transactionIndices', 'xpack.apm.indices.transaction', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
renameFromRoot('apm_oss.spanIndices', 'xpack.apm.indices.span', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
renameFromRoot('apm_oss.errorIndices', 'xpack.apm.indices.error', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
renameFromRoot('apm_oss.metricsIndices', 'xpack.apm.indices.metric', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
renameFromRoot('apm_oss.onboardingIndices', 'xpack.apm.indices.onboarding', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
|
||||||
|
// rename from apm to apm_data_access plugin
|
||||||
|
renameFromRoot('xpack.apm.indices.transaction', 'xpack.apm_data_access.indices.transaction', {
|
||||||
|
level: 'warning',
|
||||||
|
silent: true,
|
||||||
|
}),
|
||||||
|
renameFromRoot('xpack.apm.indices.span', 'xpack.apm_data_access.indices.span', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
renameFromRoot('xpack.apm.indices.error', 'xpack.apm_data_access.indices.error', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
renameFromRoot('xpack.apm.indices.metric', 'xpack.apm_data_access.indices.metric', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
renameFromRoot('xpack.apm.indices.sourcemap', 'xpack.apm_data_access.indices.sourcemap', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
renameFromRoot('xpack.apm.indices.onboarding', 'xpack.apm_data_access.indices.onboarding', {
|
||||||
|
level: 'warning',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
|
||||||
|
schema: configSchema,
|
||||||
|
};
|
||||||
|
export type APMDataAccessConfig = TypeOf<typeof configSchema>;
|
||||||
|
export type APMIndices = APMDataAccessConfig['indices'];
|
||||||
|
|
||||||
|
export function plugin(initializerContext: PluginInitializerContext) {
|
||||||
|
return new ApmDataAccessPlugin(initializerContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { ApmDataAccessPluginSetup, ApmDataAccessPluginStart } from './types';
|
59
x-pack/plugins/apm_data_access/server/plugin.ts
Normal file
59
x-pack/plugins/apm_data_access/server/plugin.ts
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* 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 {
|
||||||
|
PluginInitializerContext,
|
||||||
|
CoreSetup,
|
||||||
|
CoreStart,
|
||||||
|
Plugin,
|
||||||
|
SavedObjectsClientContract,
|
||||||
|
} from '@kbn/core/server';
|
||||||
|
import { APMDataAccessConfig } from '.';
|
||||||
|
import { ApmDataAccessPluginSetup, ApmDataAccessPluginStart } from './types';
|
||||||
|
import { migrateLegacyAPMIndicesToSpaceAware } from './saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware';
|
||||||
|
import {
|
||||||
|
apmIndicesSavedObjectDefinition,
|
||||||
|
getApmIndicesSavedObject,
|
||||||
|
} from './saved_objects/apm_indices';
|
||||||
|
|
||||||
|
export class ApmDataAccessPlugin
|
||||||
|
implements Plugin<ApmDataAccessPluginSetup, ApmDataAccessPluginStart>
|
||||||
|
{
|
||||||
|
constructor(private readonly initContext: PluginInitializerContext) {
|
||||||
|
this.initContext = initContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setup(core: CoreSetup): ApmDataAccessPluginSetup {
|
||||||
|
// retrieve APM indices from config
|
||||||
|
const apmDataAccessConfig = this.initContext.config.get<APMDataAccessConfig>();
|
||||||
|
const apmIndicesFromConfigFile = apmDataAccessConfig.indices;
|
||||||
|
|
||||||
|
// register saved object
|
||||||
|
core.savedObjects.registerType(apmIndicesSavedObjectDefinition);
|
||||||
|
|
||||||
|
// expose
|
||||||
|
return {
|
||||||
|
apmIndicesFromConfigFile,
|
||||||
|
getApmIndices: async (savedObjectsClient: SavedObjectsClientContract) => {
|
||||||
|
const apmIndicesFromSavedObject = await getApmIndicesSavedObject(savedObjectsClient);
|
||||||
|
return { ...apmIndicesFromConfigFile, ...apmIndicesFromSavedObject };
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public start(core: CoreStart) {
|
||||||
|
const logger = this.initContext.logger.get();
|
||||||
|
// TODO: remove in 9.0
|
||||||
|
migrateLegacyAPMIndicesToSpaceAware({ coreStart: core, logger }).catch((e) => {
|
||||||
|
logger.error('Failed to run migration making APM indices space aware');
|
||||||
|
logger.error(e);
|
||||||
|
});
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
public stop() {}
|
||||||
|
}
|
|
@ -8,9 +8,14 @@
|
||||||
import { SavedObjectsType } from '@kbn/core/server';
|
import { SavedObjectsType } from '@kbn/core/server';
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { schema } from '@kbn/config-schema';
|
import { schema } from '@kbn/config-schema';
|
||||||
|
import { SavedObjectsErrorHelpers } from '@kbn/core/server';
|
||||||
|
import { SavedObjectsClientContract } from '@kbn/core/server';
|
||||||
import { updateApmOssIndexPaths } from './migrations/update_apm_oss_index_paths';
|
import { updateApmOssIndexPaths } from './migrations/update_apm_oss_index_paths';
|
||||||
|
|
||||||
export interface APMIndices {
|
export const APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE = 'apm-indices';
|
||||||
|
export const APM_INDEX_SETTINGS_SAVED_OBJECT_ID = 'apm-indices';
|
||||||
|
|
||||||
|
export interface APMIndicesSavedObjectBody {
|
||||||
apmIndices?: {
|
apmIndices?: {
|
||||||
error?: string;
|
error?: string;
|
||||||
onboarding?: string;
|
onboarding?: string;
|
||||||
|
@ -21,8 +26,8 @@ export interface APMIndices {
|
||||||
isSpaceAware?: boolean;
|
isSpaceAware?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const apmIndices: SavedObjectsType = {
|
export const apmIndicesSavedObjectDefinition: SavedObjectsType = {
|
||||||
name: 'apm-indices',
|
name: APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
namespaceType: 'single',
|
namespaceType: 'single',
|
||||||
mappings: {
|
mappings: {
|
||||||
|
@ -33,7 +38,7 @@ export const apmIndices: SavedObjectsType = {
|
||||||
importableAndExportable: true,
|
importableAndExportable: true,
|
||||||
icon: 'apmApp',
|
icon: 'apmApp',
|
||||||
getTitle: () =>
|
getTitle: () =>
|
||||||
i18n.translate('xpack.apm.apmSettings.index', {
|
i18n.translate('xpack.apmDataAccess.apmSettings.index', {
|
||||||
defaultMessage: 'APM Settings - Index',
|
defaultMessage: 'APM Settings - Index',
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@ -67,3 +72,20 @@ export const apmIndices: SavedObjectsType = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export async function getApmIndicesSavedObject(savedObjectsClient: SavedObjectsClientContract) {
|
||||||
|
try {
|
||||||
|
const apmIndicesSavedObject = await savedObjectsClient.get<Partial<APMIndicesSavedObjectBody>>(
|
||||||
|
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE,
|
||||||
|
APM_INDEX_SETTINGS_SAVED_OBJECT_ID
|
||||||
|
);
|
||||||
|
return apmIndicesSavedObject.attributes.apmIndices;
|
||||||
|
} catch (error) {
|
||||||
|
// swallow error if saved object does not exist
|
||||||
|
if (SavedObjectsErrorHelpers.isNotFoundError(error)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue