diff --git a/x-pack/plugins/infra/common/locators/helpers.ts b/x-pack/plugins/infra/common/locators/helpers.ts index 582499407bb40..d067ea15e7ebe 100644 --- a/x-pack/plugins/infra/common/locators/helpers.ts +++ b/x-pack/plugins/infra/common/locators/helpers.ts @@ -13,10 +13,8 @@ import { LogViewReference, ResolvedLogView, LogsLocatorParams, - NodeLogsLocatorParams, } from '@kbn/logs-shared-plugin/common'; import { flowRight } from 'lodash'; -import { findInventoryFields } from '@kbn/metrics-data-access-plugin/common'; import type { InfraClientCoreSetup } from '../../public/types'; import { MESSAGE_FIELD, TIMESTAMP_FIELD } from '../constants'; import type { TimeRange } from '../time'; @@ -33,15 +31,6 @@ interface LocationToDiscoverParams { logView?: LogViewReference; } -export const createNodeLogsQuery = (params: NodeLogsLocatorParams) => { - const { nodeType, nodeId, filter } = params; - - const nodeFilter = `${findInventoryFields(nodeType).id}: ${nodeId}`; - const query = filter ? `(${nodeFilter}) and (${filter})` : nodeFilter; - - return query; -}; - export const createSearchString = ({ time, timeRange, diff --git a/x-pack/plugins/infra/common/locators/node_logs_locator.ts b/x-pack/plugins/infra/common/locators/node_logs_locator.ts index c9ff9410e5822..d5bfe4d7ac936 100644 --- a/x-pack/plugins/infra/common/locators/node_logs_locator.ts +++ b/x-pack/plugins/infra/common/locators/node_logs_locator.ts @@ -6,7 +6,11 @@ */ import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public'; -import { INFRA_NODE_LOGS_LOCATOR_ID, NodeLogsLocatorParams } from '@kbn/logs-shared-plugin/common'; +import { + INFRA_NODE_LOGS_LOCATOR_ID, + NodeLogsLocatorParams, + createNodeLogsQuery, +} from '@kbn/logs-shared-plugin/common'; import type { InfraLogsLocatorDependencies } from './logs_locator'; export type InfraNodeLogsLocator = LocatorPublic; @@ -19,7 +23,7 @@ export class InfraNodeLogsLocatorDefinition implements LocatorDefinition { - const { createNodeLogsQuery, createSearchString } = await import('./helpers'); + const { createSearchString } = await import('./helpers'); const query = createNodeLogsQuery(params); diff --git a/x-pack/plugins/logs_shared/common/index.ts b/x-pack/plugins/logs_shared/common/index.ts index 39da6b1bb5f8f..f6b1e9ea27e43 100644 --- a/x-pack/plugins/logs_shared/common/index.ts +++ b/x-pack/plugins/logs_shared/common/index.ts @@ -69,3 +69,4 @@ export { getLogsLocatorsFromUrlService, } from './locators'; export type { LogsLocatorParams, NodeLogsLocatorParams, TraceLogsLocatorParams } from './locators'; +export { createNodeLogsQuery } from './locators/helpers'; diff --git a/x-pack/plugins/logs_shared/common/locators/helpers.ts b/x-pack/plugins/logs_shared/common/locators/helpers.ts index fa3ab132df78f..5f7b9ea589c30 100644 --- a/x-pack/plugins/logs_shared/common/locators/helpers.ts +++ b/x-pack/plugins/logs_shared/common/locators/helpers.ts @@ -6,25 +6,33 @@ */ import moment, { DurationInputObject } from 'moment'; +import { findInventoryFields } from '@kbn/metrics-data-access-plugin/common'; +import { LogsLocatorParams, NodeLogsLocatorParams, TraceLogsLocatorParams } from './types'; -export type NodeType = 'host' | 'pod' | 'container' | 'awsEC2' | 'awsS3' | 'awsSQS' | 'awsRDS'; +export const getLogsQuery = (params: LogsLocatorParams) => { + const { filter } = params; -const NodeTypeMapping: Record = { - host: 'host.name', - container: 'container.id', - pod: 'kubernetes.pod.uid', - awsEC2: 'awsEC2', - awsS3: 'awsS3', - awsSQS: 'awsSQS', - awsRDS: 'awsRDS', + return filter ? { language: 'kuery', query: filter } : undefined; }; -export const getNodeQuery = (type: NodeType, id: string) => { - return { language: 'kuery', query: `${NodeTypeMapping[type]}: ${id}` }; +export const createNodeLogsQuery = (params: NodeLogsLocatorParams) => { + const { nodeType, nodeId, filter } = params; + + const nodeFilter = `${findInventoryFields(nodeType).id}: ${nodeId}`; + return filter ? `(${nodeFilter}) and (${filter})` : nodeFilter; +}; + +export const getNodeQuery = (params: NodeLogsLocatorParams) => { + return { language: 'kuery', query: createNodeLogsQuery(params) }; }; -export const getTraceQuery = (traceId: string) => { - return { language: 'kuery', query: `trace.id:"${traceId}" OR (not trace.id:* AND "${traceId}")` }; +export const getTraceQuery = (params: TraceLogsLocatorParams) => { + const { traceId, filter } = params; + + const traceFilter = `trace.id:"${traceId}" OR (not trace.id:* AND "${traceId}")`; + const query = filter ? `(${traceFilter}) and (${filter})` : traceFilter; + + return { language: 'kuery', query }; }; const defaultTimeRangeFromPositionOffset: DurationInputObject = { hours: 1 }; diff --git a/x-pack/plugins/logs_shared/common/locators/logs_locator.ts b/x-pack/plugins/logs_shared/common/locators/logs_locator.ts index 3a6e2cfb1a754..2ebb343e10bbc 100644 --- a/x-pack/plugins/logs_shared/common/locators/logs_locator.ts +++ b/x-pack/plugins/logs_shared/common/locators/logs_locator.ts @@ -11,7 +11,7 @@ import { LocatorClient } from '@kbn/share-plugin/common/url_service'; import { INFRA_LOGS_LOCATOR_ID } from './infra'; import { LogsLocatorParams } from './types'; -import { getTimeRangeEndFromTime, getTimeRangeStartFromTime } from './helpers'; +import { getLogsQuery, getTimeRangeEndFromTime, getTimeRangeStartFromTime } from './helpers'; export const LOGS_LOCATOR_ID = 'LOGS_LOCATOR'; @@ -30,6 +30,7 @@ export class LogsLocatorDefinition implements LocatorDefinition(ALL_DATASETS_LOCATOR_ID)!; const { time } = params; return allDatasetsLocator.getLocation({ + query: getLogsQuery(params), ...(time ? { timeRange: { diff --git a/x-pack/plugins/logs_shared/common/locators/node_logs_locator.ts b/x-pack/plugins/logs_shared/common/locators/node_logs_locator.ts index b1cd7270fb902..e5288630334b8 100644 --- a/x-pack/plugins/logs_shared/common/locators/node_logs_locator.ts +++ b/x-pack/plugins/logs_shared/common/locators/node_logs_locator.ts @@ -33,9 +33,9 @@ export class NodeLogsLocatorDefinition implements LocatorDefinition(ALL_DATASETS_LOCATOR_ID)!; - const { nodeId, nodeType, time } = params; + const { time } = params; return allDatasetsLocator.getLocation({ - query: getNodeQuery(nodeType, nodeId), + query: getNodeQuery(params), ...(time ? { timeRange: { diff --git a/x-pack/plugins/logs_shared/common/locators/trace_logs_locator.ts b/x-pack/plugins/logs_shared/common/locators/trace_logs_locator.ts index 82cf1ccb5d89d..a62155aaaf4d1 100644 --- a/x-pack/plugins/logs_shared/common/locators/trace_logs_locator.ts +++ b/x-pack/plugins/logs_shared/common/locators/trace_logs_locator.ts @@ -21,20 +21,19 @@ export class TraceLogsLocatorDefinition implements LocatorDefinition { - const { traceId, time } = params; - const infraLogsLocator = this.locators.get(INFRA_LOGS_LOCATOR_ID); if (infraLogsLocator) { return infraLogsLocator.getLocation({ ...params, - filter: getTraceQuery(traceId).query, + filter: getTraceQuery(params).query, }); } + const { time } = params; const allDatasetsLocator = this.locators.get(ALL_DATASETS_LOCATOR_ID)!; return allDatasetsLocator.getLocation({ - query: getTraceQuery(traceId), + query: getTraceQuery(params), ...(time ? { timeRange: { diff --git a/x-pack/plugins/logs_shared/kibana.jsonc b/x-pack/plugins/logs_shared/kibana.jsonc index fc8dcf0e64d96..5f4ecf5fa178c 100644 --- a/x-pack/plugins/logs_shared/kibana.jsonc +++ b/x-pack/plugins/logs_shared/kibana.jsonc @@ -14,7 +14,8 @@ "usageCollection", "observabilityShared", "observabilityAIAssistant", - "share" + "share", + "metricsDataAccess" ], "requiredBundles": ["kibanaUtils", "kibanaReact"], "extraPublicDirs": ["common"] diff --git a/x-pack/plugins/logs_shared/tsconfig.json b/x-pack/plugins/logs_shared/tsconfig.json index 8d06a68a70873..2ff0ca9b7f242 100644 --- a/x-pack/plugins/logs_shared/tsconfig.json +++ b/x-pack/plugins/logs_shared/tsconfig.json @@ -28,6 +28,7 @@ "@kbn/ui-actions-plugin", "@kbn/observability-ai-assistant-plugin", "@kbn/deeplinks-observability", - "@kbn/share-plugin" + "@kbn/share-plugin", + "@kbn/metrics-data-access-plugin" ] }