Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[One Discover] Custom Service Name Cell #192381

Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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';
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-apm-synthtrace/src/scenarios/simple_logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getCluster,
getCloudProvider,
getCloudRegion,
getAgentName,
} from './helpers/logs_mock_data';
import { parseLogsScenarioOpts } from './helpers/logs_scenario_opts_parser';

Expand All @@ -44,7 +45,7 @@ const scenario: Scenario<LogDocument> = 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,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/discover/common/data_types/logs/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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, EuiText } from '@elastic/eui';
import type { CSSObject } from '@emotion/react';
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 { AGENT_NAME_FIELD } from '../../../../common/data_types/logs/constants';

const dataTestSubj = 'serviceNameBadgeCell';
const badgeCss: CSSObject = { marginTop: '-4px' };
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved Hide resolved

const AgentIcon = dynamic(() => import('@kbn/custom-icons/src/components/agent_icon'));

export const getServiceNameBadgeCell =
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved Hide resolved
(serviceNameField: string) => (props: DataGridCellValueElementProps) => {
const serviceNameValue = props.row.flattened[serviceNameField];
const agentNameValue = props.row.flattened[AGENT_NAME_FIELD];
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved Hide resolved

if (!agentNameValue) {
return (
<EuiText data-test-subj={`${dataTestSubj}-empty`} size="xs">
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved Hide resolved
{serviceNameValue}
</EuiText>
);
}

const agentName = (
Array.isArray(agentNameValue) ? agentNameValue[0] : agentNameValue
) as AgentName;

return (
<EuiFlexGroup gutterSize="xs" css={badgeCss} data-test-subj={dataTestSubj}>
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved Hide resolved
<EuiFlexItem grow={false}>
<AgentIcon agentName={agentName} size="m" />
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved Hide resolved
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="xs">{serviceNameValue}</EuiText>
</EuiFlexItem>
mohamedhamed-ahmed marked this conversation as resolved.
Show resolved Hide resolved
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { LOG_LEVEL_FIELDS } from '../../../../../common/data_types/logs/constants';
import { getServiceNameBadgeCell } from '../../../../components/data_types/logs/service_name_badge_cell';
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';

Expand All @@ -22,4 +26,12 @@ export const getCellRenderers: DataSourceProfileProvider['profile']['getCellRend
}),
{}
),
...SERVICE_NAME_FIELDS.reduce(
(acc, field) => ({
...acc,
[field]: getServiceNameBadgeCell(field),
[`${field}.keyword`]: getServiceNameBadgeCell(`${field}.keyword`),
}),
{}
),
});
Loading