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 @@ -120,8 +120,7 @@ describe('SummaryColumn', () => {
it('should render a badge indicating the count of additional resources', () => {
const record = getBaseRecord();
renderSummary(record);
expect(screen.queryByText('+2')).toBeInTheDocument();
expect(screen.queryByText('+3')).not.toBeInTheDocument();
expect(screen.queryByText('+1')).toBeInTheDocument();
});

it('should render all the available resources in row autofit/custom mode', () => {
Expand All @@ -139,14 +138,6 @@ describe('SummaryColumn', () => {
expect(
screen.queryByTestId(`dataTableCellActionsPopover_${constants.HOST_NAME_FIELD}`)
).toBeInTheDocument();
expect(
screen.queryByTestId(
`dataTableCellActionsPopover_${constants.ORCHESTRATOR_NAMESPACE_FIELD}`
)
).toBeInTheDocument();
expect(
screen.queryByTestId(`dataTableCellActionsPopover_${constants.CLOUD_INSTANCE_ID_FIELD}`)
).toBeInTheDocument();
expect(screen.queryByText('+2')).not.toBeInTheDocument();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,35 @@ export interface LogFlyoutDoc {
}

export interface ResourceFields {
'host.name'?: string;
'service.name'?: string;
'agent.name'?: string;
'kubernetes.container.name'?: string;
'k8s.container.name'?: string;
'container.name'?: string;
'kubernetes.node.name'?: string;
'k8s.node.name'?: string;
'host.name'?: string;
'orchestrator.cluster.name'?: string;
'k8s.cluster.name'?: string;
'kubernetes.namespace'?: string;
'k8s.namespace.name'?: string;
'kubernetes.pod.name'?: string;
'k8s.pod.name'?: string;
'kubernetes.deployment.name'?: string;
'k8s.deployment.name'?: string;
'kubernetes.replicaset.name'?: string;
'k8s.replicaset.name'?: string;
'kubernetes.statefulset.name'?: string;
'k8s.statefulset.name'?: string;
'kubernetes.daemonset.name'?: string;
'k8s.daemonset.name'?: string;
'kubernetes.job.name'?: string;
'k8s.job.name'?: string;
'kubernetes.cronjob.name'?: string;
'k8s.cronjob.name'?: string;
'agent.name'?: string;
'orchestrator.cluster.id'?: string;
'orchestrator.resource.id'?: string;
'orchestrator.namespace'?: string;
'container.name'?: string;
'container.id'?: string;
'cloud.instance.id'?: string;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 { getAvailableResourceFields } from './get_available_resource_fields';
import type { ResourceFields } from '../../..';

describe('getAvailableResourceFields', () => {
it('should return available fields', () => {
const fields = getAvailableResourceFields({
'service.name': 'yes',
'container.name': 'yes',
'host.name': 'yes',
'k8s.cluster.name': 'yes',
'k8s.namespace.name': 'yes',
'k8s.pod.name': 'yes',
'k8s.cronjob.name': 'yes',
});
expect(fields).toEqual([
'service.name',
'container.name',
'host.name',
'k8s.cluster.name',
'k8s.namespace.name',
'k8s.pod.name',
'k8s.cronjob.name',
]);
});

it('should ignore empty fields', () => {
const fields = getAvailableResourceFields({
'service.name': '',
});
expect(fields).toEqual([]);
});

it('should ignore unknown fields', () => {
const fields = getAvailableResourceFields({
unknown: 'no',
} as ResourceFields);
expect(fields).toEqual([]);
});

it('should return first available field from each group', () => {
const fields = getAvailableResourceFields({
'service.name': 'yes',
'container.name': 'no',
'kubernetes.container.name': 'yes', // higher priority than `container.name`
'host.name': 'no',
'kubernetes.node.name': 'yes', // higher priority than `host.name`
'k8s.cluster.name': 'no',
'orchestrator.cluster.name': 'yes', // higher priority than `k8s.cluster.name`
'k8s.namespace.name': 'no',
'kubernetes.namespace': 'yes', // higher priority than `k8s.namespace.name`
'k8s.pod.name': 'no',
'kubernetes.pod.name': 'yes', // higher priority than `k8s.pod.name`
'k8s.cronjob.name': 'no',
'kubernetes.deployment.name': 'yes', // higher priority than `k8s.cronjob.name`
});
expect(fields).toEqual([
'service.name',
'kubernetes.container.name',
'kubernetes.node.name',
'orchestrator.cluster.name',
'kubernetes.namespace',
'kubernetes.pod.name',
'kubernetes.deployment.name',
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,38 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ResourceFields } from '../../..';
import * as constants from '../constants';
import type { ResourceFields } from '../../..';

export const getAvailableResourceFields = (resourceDoc: ResourceFields) => {
const resourceFields: Array<keyof ResourceFields> = [
constants.SERVICE_NAME_FIELD,
constants.CONTAINER_NAME_FIELD,
constants.HOST_NAME_FIELD,
constants.ORCHESTRATOR_NAMESPACE_FIELD,
constants.CLOUD_INSTANCE_ID_FIELD,
];
// Use first available field from each group
const AVAILABLE_RESOURCE_FIELDS: Array<Array<keyof ResourceFields>> = [
['service.name'],
['kubernetes.container.name', 'k8s.container.name', 'container.name'],
['kubernetes.node.name', 'k8s.node.name', 'host.name'],
['orchestrator.cluster.name', 'k8s.cluster.name'],
['kubernetes.namespace', 'k8s.namespace.name'],
['kubernetes.pod.name', 'k8s.pod.name'],
// Only one of these will be present in a single doc
[
'kubernetes.deployment.name',
'k8s.deployment.name',
'kubernetes.replicaset.name',
'k8s.replicaset.name',
'kubernetes.statefulset.name',
'k8s.statefulset.name',
'kubernetes.daemonset.name',
'k8s.daemonset.name',
'kubernetes.job.name',
'k8s.job.name',
'kubernetes.cronjob.name',
'k8s.cronjob.name',
],
];

return resourceFields.filter((fieldName) => Boolean(resourceDoc[fieldName]));
};
export const getAvailableResourceFields = (resourceDoc: ResourceFields) =>
AVAILABLE_RESOURCE_FIELDS.reduce((acc, fields) => {
const field = fields.find((fieldName) => resourceDoc[fieldName]);
if (field) {
acc.push(field);
}
return acc;
}, []);
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('createApacheErrorLogsDataSourceProfileProvider', () => {
context: { category: DataSourceCategory.Logs },
});
expect(getDefaultAppState?.({ dataView: dataViewWithTimefieldMock })).toEqual({
breakdownField: 'log.level',
columns: [
{ name: 'timestamp', width: 212 },
{ name: 'log.level', width: 150 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('createAwsS3accessLogsDataSourceProfileProvider', () => {
context: { category: DataSourceCategory.Logs },
});
expect(getDefaultAppState?.({ dataView: dataViewWithTimefieldMock })).toEqual({
breakdownField: 'log.level',
columns: [
{ name: 'timestamp', width: 212 },
{ name: 'aws.s3.bucket.name', width: 200 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('createKubernetesContainerLogsDataSourceProfileProvider', () => {
context: { category: DataSourceCategory.Logs },
});
expect(getDefaultAppState?.({ dataView: dataViewWithTimefieldMock })).toEqual({
breakdownField: 'log.level',
columns: [
{ name: 'timestamp', width: 212 },
{ name: 'log.level', width: 150 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('createNginxAccessLogsDataSourceProfileProvider', () => {
context: { category: DataSourceCategory.Logs },
});
expect(getDefaultAppState?.({ dataView: dataViewWithTimefieldMock })).toEqual({
breakdownField: 'log.level',
columns: [
{ name: 'timestamp', width: 212 },
{ name: 'url.path', width: 150 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('createNginxErrorLogsDataSourceProfileProvider', () => {
context: { category: DataSourceCategory.Logs },
});
expect(getDefaultAppState?.({ dataView: dataViewWithTimefieldMock })).toEqual({
breakdownField: 'log.level',
columns: [
{ name: 'timestamp', width: 212 },
{ name: 'log.level', width: 150 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('createSystemLogsDataSourceProfileProvider', () => {
context: { category: DataSourceCategory.Logs },
});
expect(getDefaultAppState?.({ dataView: dataViewWithTimefieldMock })).toEqual({
breakdownField: 'log.level',
columns: [
{ name: 'timestamp', width: 212 },
{ name: 'log.level', width: 150 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('createWindowsLogsDataSourceProfileProvider', () => {
context: { category: DataSourceCategory.Logs },
});
expect(getDefaultAppState?.({ dataView: dataViewWithTimefieldMock })).toEqual({
breakdownField: 'log.level',
columns: [
{ name: 'timestamp', width: 212 },
{ name: 'log.level', width: 150 },
Expand Down