Skip to content

Commit

Permalink
[Infra UI] Fix Open in Logs links in Infra and APM when in Serverle…
Browse files Browse the repository at this point in the history
…ss (elastic#172137)

Fixes elastic#171082

## Summary

The PR wraps the
[LogsLocator](https://github.com/elastic/kibana/blob/f59ac2916d02d643310dd44a8f80b7a9cc61f608/x-pack/plugins/infra/common/locators/logs_locator.ts#L18C27-L18C27)
and
[NodeLogsLocator](https://github.com/elastic/kibana/blob/f59ac2916d02d643310dd44a8f80b7a9cc61f608/x-pack/plugins/infra/common/locators/node_logs_locator.ts#L16)
of **infra** plugin inside corresponding locators in **logs_shared**
plugin while including the fallback logic to navigate to Logs Explorer
when Steam UI isn't available.

Previously, it was assumed that Steam UI will always be available as
long as Infra UI is available, but **infra** plugin introduced a new
feature flag `logsUIEnabled` which when `false` won't enable the
`/stream/` route in Serverless.

The added locators in **logs_shared** will now check whether locators
redirecting to `/steam/` are available, otherwise they'll redirect to
Logs Explorer, thus the new locators are abstracting this decision in
their definition. This abstraction was already being done in **apm**
plugin, which has also been refactored to use the newly added
**logs_shared** locators.

Links in Serverless:


https://github.com/elastic/kibana/assets/2748376/16e5747a-546e-44b3-87e3-95428945cf63
  • Loading branch information
awahab07 authored and delanni committed Jan 11, 2024
1 parent a5bcc42 commit 8c14f93
Show file tree
Hide file tree
Showing 33 changed files with 441 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import {
AllDatasetsLocatorParams,
ALL_DATASETS_LOCATOR_ID,
} from '@kbn/deeplinks-observability/locators';
import {
NODE_LOGS_LOCATOR_ID,
NodeLogsLocatorParams,
} from '@kbn/logs-shared-plugin/common';
import { getLogsLocatorsFromUrlService } 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 Down Expand Up @@ -63,8 +60,7 @@ 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)!;
const { nodeLogsLocator } = getLogsLocatorsFromUrlService(share.url);

if (isPending(status)) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import { i18n } from '@kbn/i18n';
import { IBasePath } from '@kbn/core/public';
import moment from 'moment';
import type { LocatorPublic } from '@kbn/share-plugin/public';
import { AllDatasetsLocatorParams } from '@kbn/deeplinks-observability/locators';
import type { LocatorPublic } from '@kbn/share-plugin/public';
import { NodeLogsLocatorParams } from '@kbn/logs-shared-plugin/common';
import { getNodeLogsHref } from '../../../../shared/links/observability_logs_link';
import { findInventoryFields } from '@kbn/metrics-data-access-plugin/common';
import { APIReturnType } from '../../../../../services/rest/create_call_apm_api';
import { getInfraHref } from '../../../../shared/links/infra_link';
import {
Expand Down Expand Up @@ -58,20 +58,17 @@ export function getMenuSections({
: undefined;
const infraMetricsQuery = getInfraMetricsQuery(instanceDetails['@timestamp']);

const podLogsHref = getNodeLogsHref(
'pod',
podId!,
const podLogsHref = nodeLogsLocator.getRedirectUrl({
nodeField: findInventoryFields('pod').id,
nodeId: podId!,
time,
allDatasetsLocator,
nodeLogsLocator
);
const containerLogsHref = getNodeLogsHref(
'container',
containerId!,
});

const containerLogsHref = nodeLogsLocator.getRedirectUrl({
nodeField: findInventoryFields('container').id,
nodeId: containerId!,
time,
allDatasetsLocator,
nodeLogsLocator
);
});

const podActions: Action[] = [
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@

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 {
apmRouter as apmRouterBase,
ApmRouter,
} from '../../routing/apm_route_config';
import {
infraLocatorsMock,
logsLocatorsMock,
observabilityLogExplorerLocatorsMock,
} from '../../../context/apm_plugin/mock_apm_plugin_context';

Expand All @@ -30,11 +25,11 @@ const apmRouter = {
} as ApmRouter;

const { allDatasetsLocator } = observabilityLogExplorerLocatorsMock;
const { nodeLogsLocator, logsLocator } = infraLocatorsMock;
const { nodeLogsLocator, traceLogsLocator } = logsLocatorsMock;

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

describe('Transaction action menu', () => {
Expand Down Expand Up @@ -70,9 +65,7 @@ describe('Transaction action menu', () => {
location,
apmRouter,
allDatasetsLocator,
logsLocator: logsLocator as unknown as LocatorPublic<LogsLocatorParams>,
nodeLogsLocator:
nodeLogsLocator as unknown as LocatorPublic<NodeLogsLocatorParams>,
logsLocators: logsLocatorsMock,
infraLinksAvailable: false,
rangeFrom: 'now-24h',
rangeTo: 'now',
Expand Down Expand Up @@ -121,7 +114,7 @@ describe('Transaction action menu', () => {
},
],
]);
expectInfraLocatorsToBeCalled();
expectLogsLocatorsToBeCalled();
});

it('shows pod and required sections only', () => {
Expand All @@ -138,10 +131,8 @@ describe('Transaction action menu', () => {
basePath,
location,
apmRouter,
logsLocator: logsLocator as unknown as LocatorPublic<LogsLocatorParams>,
nodeLogsLocator:
nodeLogsLocator as unknown as LocatorPublic<NodeLogsLocatorParams>,
allDatasetsLocator,
logsLocators: logsLocatorsMock,
infraLinksAvailable: true,
rangeFrom: 'now-24h',
rangeTo: 'now',
Expand Down Expand Up @@ -209,7 +200,7 @@ describe('Transaction action menu', () => {
},
],
]);
expectInfraLocatorsToBeCalled();
expectLogsLocatorsToBeCalled();
});

it('shows host and required sections only', () => {
Expand All @@ -226,10 +217,8 @@ describe('Transaction action menu', () => {
basePath,
location,
apmRouter,
logsLocator: logsLocator as unknown as LocatorPublic<LogsLocatorParams>,
nodeLogsLocator:
nodeLogsLocator as unknown as LocatorPublic<NodeLogsLocatorParams>,
allDatasetsLocator,
logsLocators: logsLocatorsMock,
infraLinksAvailable: true,
rangeFrom: 'now-24h',
rangeTo: 'now',
Expand Down Expand Up @@ -296,6 +285,6 @@ describe('Transaction action menu', () => {
},
],
]);
expectInfraLocatorsToBeCalled();
expectLogsLocatorsToBeCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import { IBasePath } from '@kbn/core/public';
import { isEmpty, pickBy } from 'lodash';
import moment from 'moment';
import url from 'url';
import {
LogsLocatorParams,
NodeLogsLocatorParams,
} from '@kbn/logs-shared-plugin/common';
import type { getLogsLocatorsFromUrlService } from '@kbn/logs-shared-plugin/common';
import { findInventoryFields } from '@kbn/metrics-data-access-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 All @@ -27,10 +25,6 @@ import { fromQuery } from '../links/url_helpers';
import { SectionRecord, getNonEmptySections, Action } from './sections_helper';
import { HOST_NAME, TRACE_ID } from '../../../../common/es_fields/apm';
import { ApmRouter } from '../../routing/apm_route_config';
import {
getNodeLogsHref,
getTraceLogsHref,
} from '../links/observability_logs_link';

function getInfraMetricsQuery(transaction: Transaction) {
const timestamp = new Date(transaction['@timestamp']).getTime();
Expand All @@ -53,8 +47,7 @@ export const getSections = ({
rangeTo,
environment,
allDatasetsLocator,
logsLocator,
nodeLogsLocator,
logsLocators,
dataViewId,
}: {
transaction?: Transaction;
Expand All @@ -67,8 +60,7 @@ export const getSections = ({
rangeTo: string;
environment: Environment;
allDatasetsLocator: LocatorPublic<AllDatasetsLocatorParams>;
logsLocator: LocatorPublic<LogsLocatorParams>;
nodeLogsLocator: LocatorPublic<NodeLogsLocatorParams>;
logsLocators: ReturnType<typeof getLogsLocatorsFromUrlService>;
dataViewId?: string;
}) => {
if (!transaction) return [];
Expand All @@ -95,33 +87,26 @@ export const getSections = ({
});

// Logs hrefs
const podLogsHref = getNodeLogsHref(
'pod',
podId!,
const podLogsHref = logsLocators.nodeLogsLocator.getRedirectUrl({
nodeField: findInventoryFields('pod').id,
nodeId: podId!,
time,
allDatasetsLocator,
nodeLogsLocator
);
const containerLogsHref = getNodeLogsHref(
'container',
containerId!,
});
const containerLogsHref = logsLocators.nodeLogsLocator.getRedirectUrl({
nodeField: findInventoryFields('container').id,
nodeId: containerId!,
time,
allDatasetsLocator,
nodeLogsLocator
);
const hostLogsHref = getNodeLogsHref(
'host',
hostName!,
});
const hostLogsHref = logsLocators.nodeLogsLocator.getRedirectUrl({
nodeField: findInventoryFields('host').id,
nodeId: hostName!,
time,
allDatasetsLocator,
nodeLogsLocator
);
const traceLogsHref = getTraceLogsHref(
transaction.trace.id!,
});

const traceLogsHref = logsLocators.traceLogsLocator.getRedirectUrl({
traceId: transaction.trace.id!,
time,
allDatasetsLocator,
logsLocator
);
});

const podActions: Action[] = [
{
Expand Down
Loading

0 comments on commit 8c14f93

Please sign in to comment.