Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ interface CellActionsPopoverProps {
}) => ReactElement;
}

const infraRoutes = {
overview: {
href: 'metrics/entity/Kubernetes/Overview?dashboardId=kubernetes-f4dc26db-1b53-4ea2-a78b-1bfab8ea267c',
label: 'Kubernetes Overview',
},
};

export function CellActionsPopover({
onFilter,
property,
Expand All @@ -81,6 +88,11 @@ export function CellActionsPopover({
'data-test-subj': `dataTableCellActionsPopover_${property}`,
};

const infraProps =
property in infraRoutes
? infraRoutes[property as keyof typeof infraRoutes]
: infraRoutes.overview;

return (
<EuiPopover
button={renderPopoverTrigger({ popoverTriggerProps })}
Expand All @@ -92,6 +104,7 @@ export function CellActionsPopover({
<EuiFlexGroup
gutterSize="none"
responsive={false}
justifyContent="spaceBetween"
data-test-subj="dataTableCellActionPopoverTitle"
>
<EuiFlexItem style={{ maxWidth: '200px' }}>
Expand Down Expand Up @@ -147,6 +160,11 @@ export function CellActionsPopover({
</EuiFlexGroup>
</EuiPopoverFooter>
) : null}
<EuiPopoverFooter>
<EuiButtonEmpty href={infraProps.href} size="s" iconType="dashboardApp">
Go to {infraProps.label} dashboard
</EuiButtonEmpty>
</EuiPopoverFooter>
<EuiPopoverFooter>
<EuiCopy textToCopy={value}>
{(copy) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
TRACE_FIELDS,
getLogDocumentOverview,
getMessageFieldWithFallbacks,
METRIC_FIELDS,
} from '@kbn/discover-utils';
import { getAvailableResourceFields, getAvailableTraceFields } from '@kbn/discover-utils/src';
import { Resource } from './resource';
Expand All @@ -42,9 +43,38 @@ export interface SummaryColumnFactoryDeps {
share?: SharePluginStart;
}

export type SummaryColumnProps = DataGridCellValueElementProps & { isTracesSummary?: boolean };
export type SummaryColumnProps = DataGridCellValueElementProps & { isTracesSummary?: boolean } & {
isMetricsSummary?: boolean;
};
export type AllSummaryColumnProps = SummaryColumnProps & SummaryColumnFactoryDeps;

const getResourceFields = ({
isTracesDoc,
isMetricsDoc,
}: {
isTracesDoc?: boolean;
isMetricsDoc?: boolean;
}) => {
if (isTracesDoc) {
return {
fields: TRACE_FIELDS,
getAvailableFields: getAvailableTraceFields,
};
}

if (isMetricsDoc) {
return {
fields: METRIC_FIELDS,
getAvailableFields: getAvailableResourceFields,
};
}

return {
fields: RESOURCE_FIELDS,
getAvailableFields: getAvailableResourceFields,
};
};

export const SummaryColumn = (props: AllSummaryColumnProps) => {
const { isDetails } = props;

Expand All @@ -66,35 +96,30 @@ const SummaryCell = ({
rowHeight: maybeNullishRowHeight,
...props
}: AllSummaryColumnProps) => {
const { dataView, onFilter, row, share, core, isTracesSummary, fieldFormats } = props;
const { dataView, onFilter, row, share, core, isTracesSummary, isMetricsSummary, fieldFormats } =
props;

const density = maybeNullishDensity ?? DataGridDensity.COMPACT;
const isCompressed = density === DataGridDensity.COMPACT;

const rowHeight = maybeNullishRowHeight ?? DEFAULT_ROW_COUNT;
const isSingleLine = rowHeight === SINGLE_ROW_COUNT;

const resourceFields = createResourceFields(
isTracesSummary && isTraceDocument(row)
? {
row,
fields: TRACE_FIELDS,
getAvailableFields: getAvailableTraceFields,
dataView,
core,
share,
fieldFormats,
}
: {
row,
fields: RESOURCE_FIELDS,
getAvailableFields: getAvailableResourceFields,
dataView,
core,
share,
fieldFormats,
}
);
const specificFields = getResourceFields({
isTracesDoc: isTracesSummary && isTraceDocument(row),
isMetricsDoc: isMetricsSummary,
});

const resourceFields = createResourceFields({
row,
dataView,
core,
share,
fieldFormats,
...specificFields,
});

console.log('SummaryCell', resourceFields, 'resourceFields');
const shouldRenderResource = resourceFields.length > 0;

return isSingleLine ? (
Expand Down Expand Up @@ -125,32 +150,31 @@ const SummaryCell = ({
};

export const SummaryCellPopover = (props: AllSummaryColumnProps) => {
const { row, dataView, fieldFormats, onFilter, closePopover, share, core, isTracesSummary } =
props;
const {
row,
dataView,
fieldFormats,
onFilter,
closePopover,
share,
core,
isTracesSummary,
isMetricsSummary,
} = props;

const isTraceDoc = isTracesSummary && isTraceDocument(row);

const resourceFields = createResourceFields(
isTraceDoc
? {
row,
fields: TRACE_FIELDS,
getAvailableFields: getAvailableTraceFields,
dataView,
core,
share,
fieldFormats,
}
: {
row,
fields: RESOURCE_FIELDS,
getAvailableFields: getAvailableResourceFields,
dataView,
core,
share,
fieldFormats,
}
);
const specificFields = getResourceFields({
isTracesDoc: isTraceDoc,
isMetricsDoc: isMetricsSummary,
});
const resourceFields = createResourceFields({
row,
dataView,
core,
share,
fieldFormats,
...specificFields,
});
const shouldRenderResource = resourceFields.length > 0;

const documentOverview = getLogDocumentOverview(row, { dataView, fieldFormats });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const getResourceBadgeComponent = (
core: CoreStart,
share?: SharePluginStart
): React.ComponentType<FieldBadgeWithActionsProps> => {
console.log('getResourceBadgeComponent', name, 'name');
switch (name) {
case EVENT_OUTCOME_FIELD:
return EventOutcomeBadge;
Expand Down
8 changes: 7 additions & 1 deletion src/platform/packages/shared/kbn-discover-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export {
convertValueToString,
createLogsContextService,
createTracesContextService,
createMetricsContextService,
createApmErrorsContextService,
createDegradedDocsControl,
createStacktraceControl,
Expand Down Expand Up @@ -62,7 +63,12 @@ export {
LogLevelBadge,
} from './src';

export type { LogsContextService, TracesContextService, ApmErrorsContextService } from './src';
export type {
LogsContextService,
TracesContextService,
ApmErrorsContextService,
MetricsContextService,
} from './src';

export * from './src/types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
export * from './logs';
export * from './traces';
export * from './apm';
export * from './metrics';
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ export const RESOURCE_FIELDS = [
fieldConstants.ORCHESTRATOR_CLUSTER_ID_FIELD,
fieldConstants.CONTAINER_ID_FIELD,
fieldConstants.AGENT_NAME_FIELD,
'kubernetes.container.name',
] as const;
export const METRIC_FIELDS = [
'kubernetes.container.name',
'k8s.container.name',
'kubernetes.pod.name',
'k8s.pod.name',
];
export const TRACE_FIELDS = [
fieldConstants.SERVICE_NAME_FIELD,
fieldConstants.EVENT_OUTCOME_FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const AVAILABLE_RESOURCE_FIELDS: Array<Array<keyof ResourceFields>> = [

export const getAvailableResourceFields = (resourceDoc: ResourceFields) =>
AVAILABLE_RESOURCE_FIELDS.reduce((acc, fields) => {
console.log('getAvailableResourceFields', fields, resourceDoc);
const field = fields.find((fieldName) => resourceDoc[fieldName]);
if (field) {
acc.push(field);
Expand Down
Original file line number Diff line number Diff line change
@@ -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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './metrics_context_service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { ApmSourceAccessPluginStart } from '@kbn/apm-sources-access-plugin/public';
import { createRegExpPatternFrom, testPatternAgainstAllowedList } from '@kbn/data-view-utils';
import { containsIndexPattern } from '../../utils';

export interface MetricsContextService {
getAllMetricsIndexPattern(): string;
isMetricsIndexPattern(indexPattern: unknown): boolean;
containsMetricsIndexPattern(indexPattern: unknown): boolean;
}

export interface MetricsContextServiceDeps {
apmSourcesAccess?: ApmSourceAccessPluginStart;
}

export const DEFAULT_ALLOWED_METRICS_BASE_PATTERNS = ['metrics', 'metricbeat'];

export const DEFAULT_ALLOWED_METRICS_BASE_PATTERNS_REGEXP = createRegExpPatternFrom(
DEFAULT_ALLOWED_METRICS_BASE_PATTERNS,
'data'
);

export const createMetricsContextService = async ({
apmSourcesAccess,
}: MetricsContextServiceDeps): Promise<MetricsContextService> => {
if (!apmSourcesAccess) {
return defaultMetricsContextService;
}

try {
const indices = await apmSourcesAccess.getApmIndices();

if (!indices) {
return defaultMetricsContextService;
}

const { transaction, span } = indices;
const allIndices = getAllIndices(transaction, span);
const uniqueIndices = Array.from(new Set(allIndices));

const metrics = uniqueIndices.join();
const allowedDataSources = [createRegExpPatternFrom(uniqueIndices, 'data')];

return getMetricsContextService(metrics, allowedDataSources);
} catch (error) {
return defaultMetricsContextService;
}
};

function getAllIndices(transaction: string, span: string) {
return [transaction, span]
.flatMap((index) => index.split(','))
.concat(DEFAULT_ALLOWED_METRICS_BASE_PATTERNS);
}

export const getMetricsContextService = (metrics: string, allowedDataSources: RegExp[]) => ({
getAllMetricsIndexPattern: () => metrics,
isMetricsIndexPattern: testPatternAgainstAllowedList(allowedDataSources),
containsMetricsIndexPattern: containsIndexPattern(allowedDataSources),
});

const defaultMetricsContextService = getMetricsContextService(
DEFAULT_ALLOWED_METRICS_BASE_PATTERNS.join(),
[DEFAULT_ALLOWED_METRICS_BASE_PATTERNS_REGEXP]
);
1 change: 1 addition & 0 deletions src/platform/plugins/shared/discover/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export const TABS_STATE_URL_KEY = '_t';
* Product feature IDs
*/
export const TRACES_PRODUCT_FEATURE_ID = 'discover:traces';
export const METRICS_PRODUCT_FEATURE_ID = 'discover:metrics';
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import { getShouldShowFieldHandler } from '@kbn/discover-utils';
import type { DataView } from '@kbn/data-views-plugin/common';
import type {
AllSummaryColumnProps,
SummaryColumnProps,
} from '@kbn/discover-contextual-components';
import { LazySummaryColumn } from '@kbn/discover-contextual-components';
import type { CellRenderersExtensionParams } from '../../../context_awareness';
import { useDiscoverServices } from '../../../hooks/use_discover_services';

export type SummaryColumnGetterDeps = CellRenderersExtensionParams;

const SummaryColumn = (props: Omit<AllSummaryColumnProps, 'core' | 'share'>) => {
const { share, core } = useDiscoverServices();
return <LazySummaryColumn {...props} share={share} core={core} />;
};

export const getMetricsSummaryColumn = (params: SummaryColumnGetterDeps) => {
const { actions, dataView, density, rowHeight } = params;
const shouldShowFieldHandler = createGetShouldShowFieldHandler(dataView);

return (props: Omit<SummaryColumnProps, 'core' | 'share'>) => (
<SummaryColumn
{...props}
isMetricsSummary
density={density}
onFilter={actions.addFilter}
rowHeight={rowHeight}
shouldShowFieldHandler={shouldShowFieldHandler}
/>
);
};

const createGetShouldShowFieldHandler = (dataView: DataView) => {
const dataViewFields = dataView.fields.getAll().map((fld) => fld.name);
return getShouldShowFieldHandler(dataViewFields, dataView, true);
};
Loading
Loading