diff --git a/packages/kbn-apm-synthtrace/src/scenarios/helpers/logs_mock_data.ts b/packages/kbn-apm-synthtrace/src/scenarios/helpers/logs_mock_data.ts index 5a6e1251bd897..e974528f16a80 100644 --- a/packages/kbn-apm-synthtrace/src/scenarios/helpers/logs_mock_data.ts +++ b/packages/kbn-apm-synthtrace/src/scenarios/helpers/logs_mock_data.ts @@ -8,6 +8,7 @@ */ import { generateShortId } from '@kbn/apm-synthtrace-client'; +import { ELASTIC_AGENT_NAMES } from '@kbn/elastic-agent-utils'; import { faker } from '@faker-js/faker'; import { randomInt } from 'crypto'; import moment from 'moment'; @@ -65,6 +66,8 @@ export const getGeoCoordinate = (index?: number) => getAtIndexOrRandom(GEO_COORD export const getCloudProvider = (index?: number) => getAtIndexOrRandom(CLOUD_PROVIDERS, index); export const getCloudRegion = (index?: number) => getAtIndexOrRandom(CLOUD_REGION, index); export const getServiceName = (index?: number) => getAtIndexOrRandom(SERVICE_NAMES, index); +export const getAgentName = (index?: number) => getAtIndexOrRandom(ELASTIC_AGENT_NAMES, index); + export const getJavaLog = () => `${moment().format('YYYY-MM-DD HH:mm:ss,SSS')} ${getAtIndexOrRandom( LOG_LEVELS diff --git a/packages/kbn-apm-synthtrace/src/scenarios/simple_logs.ts b/packages/kbn-apm-synthtrace/src/scenarios/simple_logs.ts index 9373560f26329..3c1fdc5131395 100644 --- a/packages/kbn-apm-synthtrace/src/scenarios/simple_logs.ts +++ b/packages/kbn-apm-synthtrace/src/scenarios/simple_logs.ts @@ -19,6 +19,7 @@ import { getCluster, getCloudProvider, getCloudRegion, + getAgentName, } from './helpers/logs_mock_data'; import { parseLogsScenarioOpts } from './helpers/logs_scenario_opts_parser'; @@ -44,7 +45,7 @@ const scenario: Scenario = async (runOptions) => { const commonLongEntryFields: LogDocument = { 'trace.id': generateShortId(), - 'agent.name': 'nodejs', + 'agent.name': getAgentName(), 'orchestrator.cluster.name': clusterName, 'orchestrator.cluster.id': clusterId, 'orchestrator.namespace': namespace, @@ -82,7 +83,6 @@ const scenario: Scenario = async (runOptions) => { .fill(0) .map(() => { const { - serviceName, logMessage: { level, message }, commonLongEntryFields, } = constructLogsCommonData(); @@ -91,7 +91,6 @@ const scenario: Scenario = async (runOptions) => { .create({ isLogsDb }) .message(message.replace('', generateShortId())) .logLevel(level) - .service(serviceName) .setGeoLocation(getGeoCoordinate()) .setHostIp(getIpAddress()) .defaults(commonLongEntryFields) diff --git a/packages/kbn-apm-synthtrace/tsconfig.json b/packages/kbn-apm-synthtrace/tsconfig.json index e5ca7beabd45c..d0f5c5801597a 100644 --- a/packages/kbn-apm-synthtrace/tsconfig.json +++ b/packages/kbn-apm-synthtrace/tsconfig.json @@ -9,6 +9,7 @@ "@kbn/datemath", "@kbn/apm-synthtrace-client", "@kbn/dev-utils", + "@kbn/elastic-agent-utils", ], "exclude": [ "target/**/*", diff --git a/src/plugins/discover/common/data_types/logs/constants.ts b/src/plugins/discover/common/data_types/logs/constants.ts index 060fa38c0027b..18259dcc56b28 100644 --- a/src/plugins/discover/common/data_types/logs/constants.ts +++ b/src/plugins/discover/common/data_types/logs/constants.ts @@ -66,3 +66,5 @@ export const DEFAULT_ALLOWED_DATA_VIEWS = ['logs', 'auditbeat', 'filebeat', 'win export const DEFAULT_ALLOWED_LOGS_DATA_VIEWS = ['logs', 'auditbeat', 'filebeat', 'winlogbeat']; export const LOG_LEVEL_FIELDS = ['log.level', 'log_level']; +export const SERVICE_NAME_FIELDS = ['service.name', 'service_name']; +export const AGENT_NAME_FIELD = 'agent.name'; diff --git a/src/plugins/discover/public/components/data_types/logs/service_name_cell.test.tsx b/src/plugins/discover/public/components/data_types/logs/service_name_cell.test.tsx new file mode 100644 index 0000000000000..8cf45be4f09e5 --- /dev/null +++ b/src/plugins/discover/public/components/data_types/logs/service_name_cell.test.tsx @@ -0,0 +1,61 @@ +/* + * 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 { buildDataTableRecord, DataTableRecord } from '@kbn/discover-utils'; +import { dataViewMock } from '@kbn/discover-utils/src/__mocks__'; +import { fieldFormatsMock } from '@kbn/field-formats-plugin/common/mocks'; +import { render, screen } from '@testing-library/react'; +import React from 'react'; +import { getServiceNameCell } from './service_name_cell'; + +const renderCell = (serviceNameField: string, record: DataTableRecord) => { + const ServiceNameCell = getServiceNameCell(serviceNameField); + render( + {}} + closePopover={() => {}} + /> + ); +}; + +describe('getServiceNameCell', () => { + it('renders icon if agent name is recognized', () => { + const record = buildDataTableRecord( + { fields: { 'service.name': 'test-service', 'agent.name': 'nodejs' } }, + dataViewMock + ); + renderCell('service.name', record); + expect(screen.getByTestId('serviceNameCell-nodejs')).toBeInTheDocument(); + }); + + it('renders default icon with unknwon test subject if agent name is missing', () => { + const record = buildDataTableRecord( + { fields: { 'service.name': 'test-service' } }, + dataViewMock + ); + renderCell('service.name', record); + expect(screen.getByTestId('serviceNameCell-unknown')).toBeInTheDocument(); + }); + + it('does not render if service name is missing', () => { + const record = buildDataTableRecord({ fields: { 'agent.name': 'nodejs' } }, dataViewMock); + renderCell('service.name', record); + expect(screen.queryByTestId('serviceNameCell-nodejs')).not.toBeInTheDocument(); + expect(screen.queryByTestId('serviceNameCell-unknown')).not.toBeInTheDocument(); + }); +}); diff --git a/src/plugins/discover/public/components/data_types/logs/service_name_cell.tsx b/src/plugins/discover/public/components/data_types/logs/service_name_cell.tsx new file mode 100644 index 0000000000000..e70c3dae4c2af --- /dev/null +++ b/src/plugins/discover/public/components/data_types/logs/service_name_cell.tsx @@ -0,0 +1,45 @@ +/* + * 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 { EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui'; +import type { AgentName } from '@kbn/elastic-agent-utils'; +import { dynamic } from '@kbn/shared-ux-utility'; +import type { DataGridCellValueElementProps } from '@kbn/unified-data-table'; +import React from 'react'; +import { getFieldValue } from '@kbn/discover-utils'; +import { AGENT_NAME_FIELD } from '../../../../common/data_types/logs/constants'; + +const dataTestSubj = 'serviceNameCell'; +const AgentIcon = dynamic(() => import('@kbn/custom-icons/src/components/agent_icon')); + +export const getServiceNameCell = + (serviceNameField: string) => (props: DataGridCellValueElementProps) => { + const serviceNameValue = getFieldValue(props.row, serviceNameField); + const agentName = getFieldValue(props.row, AGENT_NAME_FIELD) as AgentName; + + if (!serviceNameValue) { + return -; + } + + return ( + + + + + + + {serviceNameValue} + + ); + }; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx index 49950368300bf..69a2009f0a4af 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx @@ -7,9 +7,13 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { LOG_LEVEL_FIELDS } from '../../../../../../common/data_types/logs/constants'; +import { + LOG_LEVEL_FIELDS, + SERVICE_NAME_FIELDS, +} from '../../../../../../common/data_types/logs/constants'; import { getLogLevelBadgeCell } from '../../../../../components/data_types/logs/log_level_badge_cell'; -import type { DataSourceProfileProvider } from '../../../../profiles'; +import { getServiceNameCell } from '../../../../../components/data_types/logs/service_name_cell'; +import { DataSourceProfileProvider } from '../../../../profiles'; export const getCellRenderers: DataSourceProfileProvider['profile']['getCellRenderers'] = (prev) => () => ({ @@ -22,4 +26,12 @@ export const getCellRenderers: DataSourceProfileProvider['profile']['getCellRend }), {} ), + ...SERVICE_NAME_FIELDS.reduce( + (acc, field) => ({ + ...acc, + [field]: getServiceNameCell(field), + [`${field}.keyword`]: getServiceNameCell(`${field}.keyword`), + }), + {} + ), }); diff --git a/test/functional/apps/discover/context_awareness/extensions/_get_cell_renderers.ts b/test/functional/apps/discover/context_awareness/extensions/_get_cell_renderers.ts index b82bc9241b392..a1e884a82cb4f 100644 --- a/test/functional/apps/discover/context_awareness/extensions/_get_cell_renderers.ts +++ b/test/functional/apps/discover/context_awareness/extensions/_get_cell_renderers.ts @@ -37,135 +37,245 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); describe('ES|QL mode', () => { - it('should render log.level badge cell', async () => { - const state = kbnRison.encode({ - dataSource: { type: 'esql' }, - query: { - esql: 'from my-example-logs,logstash* | sort @timestamp desc | where `log.level` is not null', - }, + describe('Log Level Badge Cell', () => { + it('should render log.level badge cell', async () => { + const state = kbnRison.encode({ + dataSource: { type: 'esql' }, + query: { + esql: 'from my-example-logs,logstash* | sort @timestamp desc | where `log.level` is not null', + }, + }); + await common.navigateToActualUrl('discover', `?_a=${state}`, { + ensureCurrentUrl: false, + }); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await unifiedFieldList.clickFieldListItemAdd('log.level'); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + + const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); + const logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); + expect(await logLevelBadge.getVisibleText()).to.be('debug'); + expect(await logLevelBadge.getComputedStyle('background-color')).to.be( + 'rgba(190, 207, 227, 1)' + ); }); - await common.navigateToActualUrl('discover', `?_a=${state}`, { - ensureCurrentUrl: false, + + it("should not render log.level badge cell if it's not a logs data source", async () => { + const state = kbnRison.encode({ + dataSource: { type: 'esql' }, + query: { + esql: 'from my-example* | sort @timestamp desc | where `log.level` is not null', + }, + }); + await common.navigateToActualUrl('discover', `?_a=${state}`, { + ensureCurrentUrl: false, + }); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await unifiedFieldList.clickFieldListItemAdd('log.level'); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + + await retry.try(async () => { + const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); + expect(await firstCell.getVisibleText()).to.be('debug'); + await testSubjects.missingOrFail('*logLevelBadgeCell-'); + }); }); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - await unifiedFieldList.clickFieldListItemAdd('log.level'); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - - const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); - const logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); - expect(await logLevelBadge.getVisibleText()).to.be('debug'); - expect(await logLevelBadge.getComputedStyle('background-color')).to.be( - 'rgba(190, 207, 227, 1)' - ); }); + describe('Service Name Cell', () => { + it('should render service.name cell', async () => { + const state = kbnRison.encode({ + dataSource: { type: 'esql' }, + query: { + esql: 'from my-example-logs,logstash* | sort @timestamp desc | where `service.name` is not null', + }, + }); + await common.navigateToActualUrl('discover', `?_a=${state}`, { + ensureCurrentUrl: false, + }); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await unifiedFieldList.clickFieldListItemAdd('service.name'); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); - it("should not render log.level badge cell if it's not a logs data source", async () => { - const state = kbnRison.encode({ - dataSource: { type: 'esql' }, - query: { - esql: 'from my-example* | sort @timestamp desc | where `log.level` is not null', - }, - }); - await common.navigateToActualUrl('discover', `?_a=${state}`, { - ensureCurrentUrl: false, + const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); + const lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 0); + const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java'); + const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown'); + expect(await firstServiceNameCell.getVisibleText()).to.be('product'); + expect(await lastServiceNameCell.getVisibleText()).to.be('accounting'); }); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - await unifiedFieldList.clickFieldListItemAdd('log.level'); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - await retry.try(async () => { - const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); - expect(await firstCell.getVisibleText()).to.be('debug'); - await testSubjects.missingOrFail('*logLevelBadgeCell-'); + it("should not render service.name cell if it's not a logs data source", async () => { + const state = kbnRison.encode({ + dataSource: { type: 'esql' }, + query: { + esql: 'from my-example* | sort @timestamp desc | where `service.name` is not null', + }, + }); + await common.navigateToActualUrl('discover', `?_a=${state}`, { + ensureCurrentUrl: false, + }); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await unifiedFieldList.clickFieldListItemAdd('service.name'); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + + await retry.try(async () => { + const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); + expect(await firstCell.getVisibleText()).to.be('product'); + await testSubjects.missingOrFail('*serviceNameCell*'); + }); }); }); }); describe('data view mode', () => { - it('should render log.level badge cell', async () => { - await common.navigateToActualUrl('discover', undefined, { - ensureCurrentUrl: false, - }); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - await dataViews.switchToAndValidate('my-example-logs,logstash*'); - await queryBar.setQuery('log.level:*'); - await queryBar.submitQuery(); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - await unifiedFieldList.clickFieldListItemAdd('log.level'); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - - let firstCell: WebElementWrapper; - let logLevelBadge: WebElementWrapper; - - await retry.try(async () => { - firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); - logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); - expect(await logLevelBadge.getVisibleText()).to.be('debug'); - expect(await logLevelBadge.getComputedStyle('background-color')).to.be( - 'rgba(190, 207, 227, 1)' - ); + describe('Log Level Badge Cell', () => { + it('should render log.level badge cell', async () => { + await common.navigateToActualUrl('discover', undefined, { + ensureCurrentUrl: false, + }); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await dataViews.switchToAndValidate('my-example-logs,logstash*'); + await queryBar.setQuery('log.level:*'); + await queryBar.submitQuery(); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await unifiedFieldList.clickFieldListItemAdd('log.level'); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + + let firstCell: WebElementWrapper; + let logLevelBadge: WebElementWrapper; + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); + expect(await logLevelBadge.getVisibleText()).to.be('debug'); + expect(await logLevelBadge.getComputedStyle('background-color')).to.be( + 'rgba(190, 207, 227, 1)' + ); + }); + + // check Surrounding docs page + await dataGrid.clickRowToggle(); + const [, surroundingActionEl] = await dataGrid.getRowActions(); + await surroundingActionEl.click(); + await header.waitUntilLoadingHasFinished(); + await browser.refresh(); + await header.waitUntilLoadingHasFinished(); + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); + expect(await logLevelBadge.getVisibleText()).to.be('debug'); + expect(await logLevelBadge.getComputedStyle('background-color')).to.be( + 'rgba(190, 207, 227, 1)' + ); + }); }); - // check Surrounding docs page - await dataGrid.clickRowToggle(); - const [, surroundingActionEl] = await dataGrid.getRowActions(); - await surroundingActionEl.click(); - await header.waitUntilLoadingHasFinished(); - await browser.refresh(); - await header.waitUntilLoadingHasFinished(); - - await retry.try(async () => { - firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); - logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); - expect(await logLevelBadge.getVisibleText()).to.be('debug'); - expect(await logLevelBadge.getComputedStyle('background-color')).to.be( - 'rgba(190, 207, 227, 1)' - ); + it("should not render log.level badge cell if it's not a logs data source", async () => { + await common.navigateToActualUrl('discover', undefined, { + ensureCurrentUrl: false, + }); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await dataViews.switchToAndValidate('my-example-*'); + await queryBar.setQuery('log.level:*'); + await queryBar.submitQuery(); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await unifiedFieldList.clickFieldListItemAdd('log.level'); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + + let firstCell: WebElementWrapper; + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + expect(await firstCell.getVisibleText()).to.be('debug'); + await testSubjects.missingOrFail('*logLevelBadgeCell-'); + }); + + // check Surrounding docs page + await dataGrid.clickRowToggle(); + const [, surroundingActionEl] = await dataGrid.getRowActions(); + await surroundingActionEl.click(); + await header.waitUntilLoadingHasFinished(); + await browser.refresh(); + await header.waitUntilLoadingHasFinished(); + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(1, 1); + expect(await firstCell.getVisibleText()).to.be('debug'); + await testSubjects.missingOrFail('*logLevelBadgeCell-'); + }); }); }); - it("should not render log.level badge cell if it's not a logs data source", async () => { - await common.navigateToActualUrl('discover', undefined, { - ensureCurrentUrl: false, - }); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - await dataViews.switchToAndValidate('my-example-*'); - await queryBar.setQuery('log.level:*'); - await queryBar.submitQuery(); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - await unifiedFieldList.clickFieldListItemAdd('log.level'); - await header.waitUntilLoadingHasFinished(); - await discover.waitUntilSearchingHasFinished(); - - let firstCell: WebElementWrapper; - - await retry.try(async () => { - firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); - expect(await firstCell.getVisibleText()).to.be('debug'); - await testSubjects.missingOrFail('*logLevelBadgeCell-'); + describe('Service Name Cell', () => { + it('should render service.name cell', async () => { + await common.navigateToActualUrl('discover', undefined, { + ensureCurrentUrl: false, + }); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await dataViews.switchToAndValidate('my-example-logs,logstash*'); + await queryBar.setQuery('service.name:*'); + await queryBar.submitQuery(); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await unifiedFieldList.clickFieldListItemAdd('service.name'); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + + let firstCell: WebElementWrapper; + let lastCell: WebElementWrapper; + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 1); + const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java'); + const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown'); + expect(await firstServiceNameCell.getVisibleText()).to.be('product'); + expect(await lastServiceNameCell.getVisibleText()).to.be('accounting'); + }); }); - // check Surrounding docs page - await dataGrid.clickRowToggle(); - const [, surroundingActionEl] = await dataGrid.getRowActions(); - await surroundingActionEl.click(); - await header.waitUntilLoadingHasFinished(); - await browser.refresh(); - await header.waitUntilLoadingHasFinished(); - - await retry.try(async () => { - firstCell = await dataGrid.getCellElementExcludingControlColumns(1, 1); - expect(await firstCell.getVisibleText()).to.be('debug'); - await testSubjects.missingOrFail('*logLevelBadgeCell-'); + it("should not render service.name cell if it's not a logs data source", async () => { + await common.navigateToActualUrl('discover', undefined, { + ensureCurrentUrl: false, + }); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await dataViews.switchToAndValidate('my-example-*'); + await queryBar.setQuery('service.name:*'); + await queryBar.submitQuery(); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + await unifiedFieldList.clickFieldListItemAdd('service.name'); + await header.waitUntilLoadingHasFinished(); + await discover.waitUntilSearchingHasFinished(); + + let firstCell: WebElementWrapper; + let lastCell: WebElementWrapper; + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 1); + + expect(await firstCell.getVisibleText()).to.be('product'); + expect(await lastCell.getVisibleText()).to.be('accounting'); + await testSubjects.missingOrFail('*serviceNameCell*'); + }); }); }); }); diff --git a/test/functional/fixtures/es_archiver/discover/context_awareness/data.json.gz b/test/functional/fixtures/es_archiver/discover/context_awareness/data.json.gz index cd1f670958d7d..62eb2e67a32d3 100644 Binary files a/test/functional/fixtures/es_archiver/discover/context_awareness/data.json.gz and b/test/functional/fixtures/es_archiver/discover/context_awareness/data.json.gz differ diff --git a/test/functional/fixtures/es_archiver/discover/context_awareness/mappings.json b/test/functional/fixtures/es_archiver/discover/context_awareness/mappings.json index ef7a7edf29e00..9fd9e964f8959 100644 --- a/test/functional/fixtures/es_archiver/discover/context_awareness/mappings.json +++ b/test/functional/fixtures/es_archiver/discover/context_awareness/mappings.json @@ -9,6 +9,22 @@ "@timestamp": { "type": "date" }, + "agent": { + "properties": { + "name": { + "fields": { + "text": { + "type": "match_only_text" + } + }, + "type": "keyword" + }, + "version": { + "ignore_above": 1024, + "type": "keyword" + } + } + }, "data_stream": { "properties": { "type": { @@ -26,6 +42,18 @@ }, "message": { "type": "match_only_text" + }, + "service": { + "properties": { + "name": { + "fields": { + "text": { + "type": "match_only_text" + } + }, + "type": "keyword" + } + } } } }, @@ -49,6 +77,22 @@ "@timestamp": { "type": "date" }, + "agent": { + "properties": { + "name": { + "fields": { + "text": { + "type": "match_only_text" + } + }, + "type": "keyword" + }, + "version": { + "ignore_above": 1024, + "type": "keyword" + } + } + }, "data_stream": { "properties": { "type": { @@ -63,6 +107,18 @@ "type": "long" } } + }, + "service": { + "properties": { + "name": { + "fields": { + "text": { + "type": "match_only_text" + } + }, + "type": "keyword" + } + } } } }, diff --git a/x-pack/test_serverless/functional/test_suites/common/discover/context_awareness/extensions/_get_cell_renderers.ts b/x-pack/test_serverless/functional/test_suites/common/discover/context_awareness/extensions/_get_cell_renderers.ts index e25c833c80441..3816f61e83f05 100644 --- a/x-pack/test_serverless/functional/test_suites/common/discover/context_awareness/extensions/_get_cell_renderers.ts +++ b/x-pack/test_serverless/functional/test_suites/common/discover/context_awareness/extensions/_get_cell_renderers.ts @@ -37,135 +37,244 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); describe('ES|QL mode', () => { - it('should render log.level badge cell', async () => { - const state = kbnRison.encode({ - dataSource: { type: 'esql' }, - query: { - esql: 'from my-example-logs,logstash* | sort @timestamp desc | where `log.level` is not null', - }, + describe('Log Level Badge Cell', () => { + it('should render log.level badge cell', async () => { + const state = kbnRison.encode({ + dataSource: { type: 'esql' }, + query: { + esql: 'from my-example-logs,logstash* | sort @timestamp desc | where `log.level` is not null', + }, + }); + await PageObjects.common.navigateToActualUrl('discover', `?_a=${state}`, { + ensureCurrentUrl: false, + }); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.unifiedFieldList.clickFieldListItemAdd('log.level'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + + const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); + const logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); + expect(await logLevelBadge.getVisibleText()).to.be('debug'); + expect(await logLevelBadge.getComputedStyle('background-color')).to.be( + 'rgba(190, 207, 227, 1)' + ); }); - await PageObjects.common.navigateToActualUrl('discover', `?_a=${state}`, { - ensureCurrentUrl: false, + + it("should not render log.level badge cell if it's not a logs data source", async () => { + const state = kbnRison.encode({ + dataSource: { type: 'esql' }, + query: { + esql: 'from my-example* | sort @timestamp desc | where `log.level` is not null', + }, + }); + await PageObjects.common.navigateToActualUrl('discover', `?_a=${state}`, { + ensureCurrentUrl: false, + }); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.unifiedFieldList.clickFieldListItemAdd('log.level'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + + await retry.try(async () => { + const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); + expect(await firstCell.getVisibleText()).to.be('debug'); + await testSubjects.missingOrFail('*logLevelBadgeCell-'); + }); }); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - await PageObjects.unifiedFieldList.clickFieldListItemAdd('log.level'); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - - const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); - const logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); - expect(await logLevelBadge.getVisibleText()).to.be('debug'); - expect(await logLevelBadge.getComputedStyle('background-color')).to.be( - 'rgba(190, 207, 227, 1)' - ); }); + describe('Service Name Cell', () => { + it('should render service.name cell', async () => { + const state = kbnRison.encode({ + dataSource: { type: 'esql' }, + query: { + esql: 'from my-example-logs,logstash* | sort @timestamp desc | where `service.name` is not null', + }, + }); + await PageObjects.common.navigateToActualUrl('discover', `?_a=${state}`, { + ensureCurrentUrl: false, + }); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.unifiedFieldList.clickFieldListItemAdd('service.name'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); - it("should not render log.level badge cell if it's not a logs data source", async () => { - const state = kbnRison.encode({ - dataSource: { type: 'esql' }, - query: { - esql: 'from my-example* | sort @timestamp desc | where `log.level` is not null', - }, - }); - await PageObjects.common.navigateToActualUrl('discover', `?_a=${state}`, { - ensureCurrentUrl: false, + const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); + const lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 0); + const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java'); + const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown'); + expect(await firstServiceNameCell.getVisibleText()).to.be('product'); + expect(await lastServiceNameCell.getVisibleText()).to.be('accounting'); }); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - await PageObjects.unifiedFieldList.clickFieldListItemAdd('log.level'); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - await retry.try(async () => { - const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); - expect(await firstCell.getVisibleText()).to.be('debug'); - await testSubjects.missingOrFail('*logLevelBadgeCell-'); + it("should not render service.name cell if it's not a logs data source", async () => { + const state = kbnRison.encode({ + dataSource: { type: 'esql' }, + query: { + esql: 'from my-example* | sort @timestamp desc | where `service.name` is not null', + }, + }); + await PageObjects.common.navigateToActualUrl('discover', `?_a=${state}`, { + ensureCurrentUrl: false, + }); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.unifiedFieldList.clickFieldListItemAdd('service.name'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + + await retry.try(async () => { + const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); + expect(await firstCell.getVisibleText()).to.be('product'); + await testSubjects.missingOrFail('*serviceNameCell*'); + }); }); }); }); describe('data view mode', () => { - it('should render log.level badge cell', async () => { - await PageObjects.common.navigateToActualUrl('discover', undefined, { - ensureCurrentUrl: false, - }); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - await dataViews.switchToAndValidate('my-example-logs,logstash*'); - await queryBar.setQuery('log.level:*'); - await queryBar.submitQuery(); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - await PageObjects.unifiedFieldList.clickFieldListItemAdd('log.level'); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - - let firstCell: WebElementWrapper; - let logLevelBadge: WebElementWrapper; - - await retry.try(async () => { - firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); - logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); - expect(await logLevelBadge.getVisibleText()).to.be('debug'); - expect(await logLevelBadge.getComputedStyle('background-color')).to.be( - 'rgba(190, 207, 227, 1)' - ); + describe('Log Level Badge Cell', () => { + it('should render log.level badge cell', async () => { + await PageObjects.common.navigateToActualUrl('discover', undefined, { + ensureCurrentUrl: false, + }); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await dataViews.switchToAndValidate('my-example-logs,logstash*'); + await queryBar.setQuery('log.level:*'); + await queryBar.submitQuery(); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.unifiedFieldList.clickFieldListItemAdd('log.level'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + + let firstCell: WebElementWrapper; + let logLevelBadge: WebElementWrapper; + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); + expect(await logLevelBadge.getVisibleText()).to.be('debug'); + expect(await logLevelBadge.getComputedStyle('background-color')).to.be( + 'rgba(190, 207, 227, 1)' + ); + }); + + // check Surrounding docs page + await dataGrid.clickRowToggle(); + const [, surroundingActionEl] = await dataGrid.getRowActions(); + await surroundingActionEl.click(); + await PageObjects.header.waitUntilLoadingHasFinished(); + await browser.refresh(); + await PageObjects.header.waitUntilLoadingHasFinished(); + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); + expect(await logLevelBadge.getVisibleText()).to.be('debug'); + expect(await logLevelBadge.getComputedStyle('background-color')).to.be( + 'rgba(190, 207, 227, 1)' + ); + }); }); - // check Surrounding docs page - await dataGrid.clickRowToggle(); - const [, surroundingActionEl] = await dataGrid.getRowActions(); - await surroundingActionEl.click(); - await PageObjects.header.waitUntilLoadingHasFinished(); - await browser.refresh(); - await PageObjects.header.waitUntilLoadingHasFinished(); - - await retry.try(async () => { - firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); - logLevelBadge = await firstCell.findByTestSubject('*logLevelBadgeCell-'); - expect(await logLevelBadge.getVisibleText()).to.be('debug'); - expect(await logLevelBadge.getComputedStyle('background-color')).to.be( - 'rgba(190, 207, 227, 1)' - ); + it("should not render log.level badge cell if it's not a logs data source", async () => { + await PageObjects.common.navigateToActualUrl('discover', undefined, { + ensureCurrentUrl: false, + }); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await dataViews.switchToAndValidate('my-example-*'); + await queryBar.setQuery('log.level:*'); + await queryBar.submitQuery(); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.unifiedFieldList.clickFieldListItemAdd('log.level'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + + let firstCell: WebElementWrapper; + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + expect(await firstCell.getVisibleText()).to.be('debug'); + await testSubjects.missingOrFail('*logLevelBadgeCell-'); + }); + + // check Surrounding docs page + await dataGrid.clickRowToggle(); + const [, surroundingActionEl] = await dataGrid.getRowActions(); + await surroundingActionEl.click(); + await PageObjects.header.waitUntilLoadingHasFinished(); + await browser.refresh(); + await PageObjects.header.waitUntilLoadingHasFinished(); + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(1, 1); + expect(await firstCell.getVisibleText()).to.be('debug'); + await testSubjects.missingOrFail('*logLevelBadgeCell-'); + }); }); }); + describe('Service Name Cell', () => { + it('should render service.name cell', async () => { + await PageObjects.common.navigateToActualUrl('discover', undefined, { + ensureCurrentUrl: false, + }); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await dataViews.switchToAndValidate('my-example-logs,logstash*'); + await queryBar.setQuery('service.name:*'); + await queryBar.submitQuery(); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.unifiedFieldList.clickFieldListItemAdd('service.name'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); - it("should not render log.level badge cell if it's not a logs data source", async () => { - await PageObjects.common.navigateToActualUrl('discover', undefined, { - ensureCurrentUrl: false, - }); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - await dataViews.switchToAndValidate('my-example-*'); - await queryBar.setQuery('log.level:*'); - await queryBar.submitQuery(); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - await PageObjects.unifiedFieldList.clickFieldListItemAdd('log.level'); - await PageObjects.header.waitUntilLoadingHasFinished(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - - let firstCell: WebElementWrapper; - - await retry.try(async () => { - firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); - expect(await firstCell.getVisibleText()).to.be('debug'); - await testSubjects.missingOrFail('*logLevelBadgeCell-'); + let firstCell: WebElementWrapper; + let lastCell: WebElementWrapper; + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 1); + const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java'); + const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown'); + expect(await firstServiceNameCell.getVisibleText()).to.be('product'); + expect(await lastServiceNameCell.getVisibleText()).to.be('accounting'); + }); }); - // check Surrounding docs page - await dataGrid.clickRowToggle(); - const [, surroundingActionEl] = await dataGrid.getRowActions(); - await surroundingActionEl.click(); - await PageObjects.header.waitUntilLoadingHasFinished(); - await browser.refresh(); - await PageObjects.header.waitUntilLoadingHasFinished(); - - await retry.try(async () => { - firstCell = await dataGrid.getCellElementExcludingControlColumns(1, 1); - expect(await firstCell.getVisibleText()).to.be('debug'); - await testSubjects.missingOrFail('*logLevelBadgeCell-'); + it("should not render service.name cell if it's not a logs data source", async () => { + await PageObjects.common.navigateToActualUrl('discover', undefined, { + ensureCurrentUrl: false, + }); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await dataViews.switchToAndValidate('my-example-*'); + await queryBar.setQuery('service.name:*'); + await queryBar.submitQuery(); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.unifiedFieldList.clickFieldListItemAdd('service.name'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + + let firstCell: WebElementWrapper; + let lastCell: WebElementWrapper; + + await retry.try(async () => { + firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); + lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 1); + + expect(await firstCell.getVisibleText()).to.be('product'); + expect(await lastCell.getVisibleText()).to.be('accounting'); + await testSubjects.missingOrFail('*serviceNameCell*'); + }); }); }); });