Skip to content

Commit

Permalink
[apm][infra] remove infra dependency from apm (#167531)
Browse files Browse the repository at this point in the history
## Summary

Closes #166834

Moves the following components out of infra plugin so we can remove the
apm->infra dependency
- `/infra/metrics_explorer` route
- (Host|Pod|Container)MetricsTable components
- InfraAppId
- InfraLocators

### Testing
We should focus the testing on the metrics_explorer route which is used
by 1. Tables in the Infrastructure section of apm and 2. Infrastructure
> Metrics explorer app. No functionality was added so these apps should
have the same existing behavior. Easiest way to get these views loaded
is by connecting kibana to an edge-oblt cluster, alternatively load
service and metrics with a data loader.

### Follow up
- (Host|Pod|Container)MetricsTable components are part of the
metricsDataAccess plugin contract but should be moved to stateless
package

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Jason Rhodes <[email protected]>
  • Loading branch information
3 people authored Nov 2, 2023
1 parent 99a0adf commit f1fa4b0
Show file tree
Hide file tree
Showing 382 changed files with 7,788 additions and 752 deletions.
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pageLoadAssetSize:
management: 46112
maps: 90000
mapsEms: 26072
metricsDataAccess: 60000
ml: 82187
monitoring: 80000
navigation: 37269
Expand Down
1 change: 1 addition & 0 deletions x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"xpack.logstash": ["plugins/logstash"],
"xpack.main": "legacy/plugins/xpack_main",
"xpack.maps": ["plugins/maps"],
"xpack.metricsData": "plugins/metrics_data_access",
"xpack.ml": [
"packages/ml/anomaly_utils",
"packages/ml/data_grid",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/apm/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"discover",
"fleet",
"fieldFormats",
"infra",
"home",
"ml",
"security",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/apm/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const renderApp = ({
plugins: pluginsSetup,
data: pluginsStart.data,
inspector: pluginsStart.inspector,
infra: pluginsStart.infra,
observability: pluginsStart.observability,
observabilityShared: pluginsStart.observabilityShared,
observabilityRuleTypeRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CoreStart } from '@kbn/core/public';
import { shallow } from 'enzyme';

const KibanaReactContext = createKibanaReactContext({
infra: {
metricsDataAccess: {
HostMetricsTable: () => 'Host metrics table',
ContainerMetricsTable: () => 'Container metrics table',
PodMetricsTable: () => 'Pods metrics table',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export function useTabs({
end: string;
}) {
const { services } = useKibana<ApmPluginStartDeps>();
const { infra } = services;
const HostMetricsTable = infra?.HostMetricsTable;
const ContainerMetricsTable = infra?.ContainerMetricsTable;
const PodMetricsTable = infra?.PodMetricsTable;
const { metricsDataAccess } = services;
const HostMetricsTable = metricsDataAccess?.HostMetricsTable;
const ContainerMetricsTable = metricsDataAccess?.ContainerMetricsTable;
const PodMetricsTable = metricsDataAccess?.PodMetricsTable;

const timerange = useMemo(
() => ({
Expand Down Expand Up @@ -91,23 +91,32 @@ export function useTabs({
<>
<EuiSpacer />
{ContainerMetricsTable &&
ContainerMetricsTable({ timerange, filterClauseDsl: containersFilter })}
ContainerMetricsTable({
timerange,
filterClauseDsl: containersFilter,
})}
</>
);

const podMetricsTable = (
<>
<EuiSpacer />
{PodMetricsTable &&
PodMetricsTable({ timerange, filterClauseDsl: podsFilter })}
PodMetricsTable({
timerange,
filterClauseDsl: podsFilter,
})}
</>
);

const hostMetricsTable = (
<>
<EuiSpacer />
{HostMetricsTable &&
HostMetricsTable({ timerange, filterClauseDsl: hostsFilter })}
HostMetricsTable({
timerange,
filterClauseDsl: hostsFilter,
})}
</>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {
AllDatasetsLocatorParams,
ALL_DATASETS_LOCATOR_ID,
} from '@kbn/deeplinks-observability/locators';
import {
NODE_LOGS_LOCATOR_ID,
NodeLogsLocatorParams,
} from '@kbn/logs-shared-plugin/common';
import { isJavaAgentName } from '../../../../../../common/agent_name';
import { SERVICE_NODE_NAME } from '../../../../../../common/es_fields/apm';
import { useApmPluginContext } from '../../../../../context/apm_plugin/use_apm_plugin_context';
Expand All @@ -44,7 +48,7 @@ export function InstanceActionsMenu({
kuery,
onClose,
}: Props) {
const { core, infra, share } = useApmPluginContext();
const { core, share } = useApmPluginContext();
const { data, status } = useInstanceDetailsFetcher({
serviceName,
serviceNodeName,
Expand All @@ -59,6 +63,8 @@ export function InstanceActionsMenu({
const allDatasetsLocator = share.url.locators.get<AllDatasetsLocatorParams>(
ALL_DATASETS_LOCATOR_ID
)!;
const nodeLogsLocator =
share.url.locators.get<NodeLogsLocatorParams>(NODE_LOGS_LOCATOR_ID)!;

if (isPending(status)) {
return (
Expand Down Expand Up @@ -97,8 +103,8 @@ export function InstanceActionsMenu({
basePath: core.http.basePath,
onFilterByInstanceClick: handleFilterByInstanceClick,
metricsHref,
infraLocators: infra?.locators,
allDatasetsLocator,
nodeLogsLocator,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import { i18n } from '@kbn/i18n';
import { IBasePath } from '@kbn/core/public';
import moment from 'moment';
import type { InfraLocators } from '@kbn/infra-plugin/common/locators';
import type { LocatorPublic } from '@kbn/share-plugin/public';
import { AllDatasetsLocatorParams } from '@kbn/deeplinks-observability/locators';
import { NodeLogsLocatorParams } from '@kbn/logs-shared-plugin/common';
import { getNodeLogsHref } from '../../../../shared/links/observability_logs_link';
import { APIReturnType } from '../../../../../services/rest/create_call_apm_api';
import { getInfraHref } from '../../../../shared/links/infra_link';
Expand Down Expand Up @@ -41,37 +41,36 @@ export function getMenuSections({
basePath,
onFilterByInstanceClick,
metricsHref,
infraLocators,
allDatasetsLocator,
nodeLogsLocator,
}: {
instanceDetails: InstaceDetails;
basePath: IBasePath;
onFilterByInstanceClick: () => void;
metricsHref: string;
infraLocators?: InfraLocators;
allDatasetsLocator: LocatorPublic<AllDatasetsLocatorParams>;
nodeLogsLocator: LocatorPublic<NodeLogsLocatorParams>;
}) {
const podId = instanceDetails.kubernetes?.pod?.uid;
const containerId = instanceDetails.container?.id;
const time = instanceDetails['@timestamp']
? new Date(instanceDetails['@timestamp']).valueOf()
: undefined;
const infraMetricsQuery = getInfraMetricsQuery(instanceDetails['@timestamp']);
const infraNodeLocator = infraLocators?.nodeLogsLocator;

const podLogsHref = getNodeLogsHref(
'pod',
podId!,
time,
allDatasetsLocator,
infraNodeLocator
nodeLogsLocator
);
const containerLogsHref = getNodeLogsHref(
'container',
containerId!,
time,
allDatasetsLocator,
infraNodeLocator
nodeLogsLocator
);

const podActions: Action[] = [
Expand All @@ -96,7 +95,7 @@ export function getMenuSections({
path: `/link-to/pod-detail/${podId}`,
query: infraMetricsQuery,
}),
condition: !!podId && !!infraLocators,
condition: !!podId,
},
];

Expand All @@ -122,7 +121,7 @@ export function getMenuSections({
path: `/link-to/container-detail/${containerId}`,
query: infraMetricsQuery,
}),
condition: !!containerId && !!infraLocators,
condition: !!containerId,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui';
import { IBasePath } from '@kbn/core/public';
import React from 'react';
import url from 'url';
import { InfraAppId } from '@kbn/infra-plugin/public';
import { InfraAppId } from '@kbn/observability-shared-plugin/public/infra';
import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
import { fromQuery } from './url_helpers';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import type {
NodeLogsLocator,
LogsLocator,
} from '@kbn/infra-plugin/common/locators';
LogsLocatorParams,
NodeLogsLocatorParams,
} from '@kbn/logs-shared-plugin/common';
import { AllDatasetsLocatorParams } from '@kbn/deeplinks-observability/locators';
import { LocatorPublic } from '@kbn/share-plugin/common';
import moment from 'moment';
Expand All @@ -27,7 +27,7 @@ export const getNodeLogsHref = (
id: string,
time: number | undefined,
allDatasetsLocator: LocatorPublic<AllDatasetsLocatorParams>,
infraNodeLocator?: NodeLogsLocator
infraNodeLocator?: LocatorPublic<NodeLogsLocatorParams>
): string => {
if (infraNodeLocator)
return infraNodeLocator?.getRedirectUrl({
Expand All @@ -53,7 +53,7 @@ export const getTraceLogsHref = (
traceId: string,
time: number | undefined,
allDatasetsLocator: LocatorPublic<AllDatasetsLocatorParams>,
infraLogsLocator?: LogsLocator
infraLogsLocator: LocatorPublic<LogsLocatorParams>
): string => {
const query = `trace.id:"${traceId}" OR (not trace.id:* AND "${traceId}")`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import { createMemoryHistory } from 'history';
import { IBasePath } from '@kbn/core/public';
import { LocatorPublic } from '@kbn/share-plugin/common';
import {
LogsLocatorParams,
NodeLogsLocatorParams,
} from '@kbn/logs-shared-plugin/common';
import { Transaction } from '../../../../typings/es_schemas/ui/transaction';
import { getSections } from './sections';
import {
Expand All @@ -24,12 +29,12 @@ const apmRouter = {
`some-basepath/app/apm${apmRouterBase.link(...args)}`,
} as ApmRouter;

const infraLocators = infraLocatorsMock;
const { allDatasetsLocator } = observabilityLogExplorerLocatorsMock;
const { nodeLogsLocator, logsLocator } = infraLocatorsMock;

const expectInfraLocatorsToBeCalled = () => {
expect(infraLocators.nodeLogsLocator.getRedirectUrl).toBeCalledTimes(3);
expect(infraLocators.logsLocator.getRedirectUrl).toBeCalledTimes(1);
expect(nodeLogsLocator.getRedirectUrl).toBeCalledTimes(3);
expect(logsLocator.getRedirectUrl).toBeCalledTimes(1);
};

describe('Transaction action menu', () => {
Expand Down Expand Up @@ -64,8 +69,10 @@ describe('Transaction action menu', () => {
basePath,
location,
apmRouter,
infraLocators,
allDatasetsLocator,
logsLocator: logsLocator as unknown as LocatorPublic<LogsLocatorParams>,
nodeLogsLocator:
nodeLogsLocator as unknown as LocatorPublic<NodeLogsLocatorParams>,
infraLinksAvailable: false,
rangeFrom: 'now-24h',
rangeTo: 'now',
Expand Down Expand Up @@ -130,7 +137,9 @@ describe('Transaction action menu', () => {
basePath,
location,
apmRouter,
infraLocators,
logsLocator: logsLocator as unknown as LocatorPublic<LogsLocatorParams>,
nodeLogsLocator:
nodeLogsLocator as unknown as LocatorPublic<NodeLogsLocatorParams>,
allDatasetsLocator,
infraLinksAvailable: true,
rangeFrom: 'now-24h',
Expand Down Expand Up @@ -215,7 +224,9 @@ describe('Transaction action menu', () => {
basePath,
location,
apmRouter,
infraLocators,
logsLocator: logsLocator as unknown as LocatorPublic<LogsLocatorParams>,
nodeLogsLocator:
nodeLogsLocator as unknown as LocatorPublic<NodeLogsLocatorParams>,
allDatasetsLocator,
infraLinksAvailable: true,
rangeFrom: 'now-24h',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { IBasePath } from '@kbn/core/public';
import { isEmpty, pickBy } from 'lodash';
import moment from 'moment';
import url from 'url';
import type { InfraLocators } from '@kbn/infra-plugin/common/locators';
import {
LogsLocatorParams,
NodeLogsLocatorParams,
} from '@kbn/logs-shared-plugin/common';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { AllDatasetsLocatorParams } from '@kbn/deeplinks-observability/locators';
import type { ProfilingLocators } from '@kbn/observability-shared-plugin/public';
Expand Down Expand Up @@ -44,32 +47,33 @@ export const getSections = ({
basePath,
location,
apmRouter,
infraLocators,
infraLinksAvailable,
profilingLocators,
rangeFrom,
rangeTo,
environment,
allDatasetsLocator,
logsLocator,
nodeLogsLocator,
}: {
transaction?: Transaction;
basePath: IBasePath;
location: Location;
apmRouter: ApmRouter;
infraLocators?: InfraLocators;
infraLinksAvailable: boolean;
profilingLocators?: ProfilingLocators;
rangeFrom: string;
rangeTo: string;
environment: Environment;
allDatasetsLocator: LocatorPublic<AllDatasetsLocatorParams>;
logsLocator: LocatorPublic<LogsLocatorParams>;
nodeLogsLocator: LocatorPublic<NodeLogsLocatorParams>;
}) => {
if (!transaction) return [];

const hostName = transaction.host?.hostname;
const podId = transaction.kubernetes?.pod?.uid;
const containerId = transaction.container?.id;
const { nodeLogsLocator, logsLocator } = infraLocators ?? {};

const time = Math.round(transaction.timestamp.us / 1000);
const infraMetricsQuery = getInfraMetricsQuery(transaction);
Expand Down
Loading

0 comments on commit f1fa4b0

Please sign in to comment.