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

[Backport 2.12] Fix jaeger spans key names for filtering #1457

Open
wants to merge 1 commit into
base: 2.12
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions common/types/trace_analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export type SpanField =
| 'SPAN_ID'
| 'PARENT_SPAN_ID'
| 'SERVICE'
| 'OPERATION'
| 'DURATION'
| 'START_TIME'
| 'END_TIME'
| 'ERRORS';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import React, { useState } from 'react';
interface FlyoutListItemProps {
title: React.ReactNode;
description: React.ReactNode;
addSpanFilter: () => void;
addSpanFilter?: () => void;
}

export function FlyoutListItem(props: FlyoutListItemProps) {
Expand All @@ -27,12 +27,15 @@ export function FlyoutListItem(props: FlyoutListItemProps) {
props.description !== '-' ? (
<EuiFlexGroup gutterSize="none">
<EuiFlexItem>
<EuiText size="s" style={{ wordBreak: 'break-all', wordWrap: 'break-word', whiteSpace: 'pre-line' }}>
<EuiText
size="s"
style={{ wordBreak: 'break-all', wordWrap: 'break-word', whiteSpace: 'pre-line' }}
>
<b>{props.description}</b>
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
{hover && (
{hover && props.addSpanFilter && (
<EuiToolTip position="top" content="Filter spans on this value">
<EuiButtonIcon
aria-label="span-flyout-filter-icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,71 @@
import React, { useEffect, useState } from 'react';
import { HttpSetup } from '../../../../../../../src/core/public';
import { TRACE_ANALYTICS_DATE_FORMAT } from '../../../../../common/constants/trace_analytics';
import { SpanField } from '../../../../../common/types/trace_analytics';
import { TraceAnalyticsMode } from '../../home';
import { handleSpansFlyoutRequest } from '../../requests/traces_request_handler';
import { microToMilliSec, nanoToMilliSec } from '../common/helper_functions';
import { FlyoutListItem } from './flyout_list_item';

const MODE_TO_FIELDS: Record<TraceAnalyticsMode, Record<SpanField, string | undefined>> = {
data_prepper: {
SPAN_ID: 'spanId',
PARENT_SPAN_ID: 'parentSpanId',
SERVICE: 'serviceName',
OPERATION: 'name',
DURATION: 'durationInNanos',
START_TIME: 'startTime',
END_TIME: 'endTime',
ERRORS: 'status.code',
},
jaeger: {
SPAN_ID: 'spanID',
PARENT_SPAN_ID: undefined,
SERVICE: 'process.serviceName',
OPERATION: 'operationName',
DURATION: 'duration',
START_TIME: 'startTime',
END_TIME: undefined,
ERRORS: 'tag.error',
},
};

const getSpanFieldKey = (mode: TraceAnalyticsMode, field: SpanField) => MODE_TO_FIELDS[mode][field];

const getSpanValue = (span: object, mode: TraceAnalyticsMode, field: SpanField) => {
const fieldKey = getSpanFieldKey(mode, field);
if (fieldKey === undefined) return undefined;
return _.get(span, fieldKey);
};

export function SpanDetailFlyout(props: {
http: HttpSetup;
spanId: string;
isFlyoutVisible: boolean;
closeFlyout: () => void;
addSpanFilter: (field: string, value: any) => void;

Check warning on line 67 in public/components/trace_analytics/components/traces/span_detail_flyout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
mode: TraceAnalyticsMode;
}) {
const { mode } = props;
const [span, setSpan] = useState<any>({});

Check warning on line 71 in public/components/trace_analytics/components/traces/span_detail_flyout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

useEffect(() => {
handleSpansFlyoutRequest(props.http, props.spanId, setSpan, mode);
}, [props.spanId]);

Check warning on line 75 in public/components/trace_analytics/components/traces/span_detail_flyout.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'mode' and 'props.http'. Either include them or remove the dependency array

const getListItem = (field: string, title: React.ReactNode, description: React.ReactNode) => {
const getListItem = (
fieldKey: string | undefined,
title: React.ReactNode,
description: React.ReactNode
) => {
return (
<FlyoutListItem
title={title}
description={description}
key={`list-item-${title}`}
addSpanFilter={() => props.addSpanFilter(field, span[field])}
addSpanFilter={
fieldKey ? () => props.addSpanFilter(fieldKey, _.get(span, fieldKey)) : undefined
}
/>
);
};
Expand All @@ -65,27 +103,27 @@
if (!span || _.isEmpty(span)) return '-';
const overviewList = [
getListItem(
'spanId',
getSpanFieldKey(mode, 'SPAN_ID'),
'Span ID',
(mode === 'data_prepper' ? span.spanId : span.spanID) ? (
getSpanValue(span, mode, 'SPAN_ID') ? (
<EuiFlexGroup gutterSize="xs" style={{ marginTop: -4, marginBottom: -4 }}>
<EuiFlexItem grow={false}>
<EuiCopy textToCopy={mode === 'data_prepper' ? span.spanId : span.spanID}>
<EuiCopy textToCopy={getSpanValue(span, mode, 'SPAN_ID')}>
{(copy) => (
<EuiButtonIcon aria-label="copy-button" onClick={copy} iconType="copyClipboard" />
)}
</EuiCopy>
</EuiFlexItem>
<EuiFlexItem>{mode === 'data_prepper' ? span.spanId : span.spanID}</EuiFlexItem>
<EuiFlexItem>{getSpanValue(span, mode, 'SPAN_ID')}</EuiFlexItem>
</EuiFlexGroup>
) : (
'-'
)
),
getListItem(
'parentSpanId',
getSpanFieldKey(mode, 'PARENT_SPAN_ID'),
'Parent span ID',
(mode === 'data_prepper' ? span.parentSpanId : span.references.length) ? (
getSpanValue(span, mode, 'PARENT_SPAN_ID') ? (
<EuiFlexGroup gutterSize="xs" style={{ marginTop: -4, marginBottom: -4 }}>
<EuiFlexItem grow={false}>
<EuiCopy
Expand All @@ -105,17 +143,17 @@
)
),
getListItem(
'serviceName',
getSpanFieldKey(mode, 'SERVICE'),
'Service',
(mode === 'data_prepper' ? span.serviceName : span.process.serviceName) || '-'
getSpanValue(span, mode, 'SERVICE') || '-'
),
getListItem(
'name',
getSpanFieldKey(mode, 'OPERATION'),
'Operation',
(mode === 'data_prepper' ? span.name : span.operationName) || '-'
getSpanValue(span, mode, 'OPERATION') || '-'
),
getListItem(
'durationInNanos',
getSpanFieldKey(mode, 'DURATION'),
'Duration',
`${
mode === 'data_prepper'
Expand All @@ -124,7 +162,7 @@
} ms`
),
getListItem(
'startTime',
getSpanFieldKey(mode, 'START_TIME'),
'Start time',
mode === 'data_prepper'
? moment(span.startTime).format(TRACE_ANALYTICS_DATE_FORMAT)
Expand All @@ -133,7 +171,7 @@
)
),
getListItem(
'endTime',
getSpanFieldKey(mode, 'END_TIME'),
'End time',
mode === 'data_prepper'
? moment(span.endTime).format(TRACE_ANALYTICS_DATE_FORMAT)
Expand All @@ -142,9 +180,9 @@
)
),
getListItem(
'status.code',
getSpanFieldKey(mode, 'ERRORS'),
'Errors',
(mode === 'data_prepper' ? span['status.code'] === 2 : span.tag.error) ? (
(mode === 'data_prepper' ? span['status.code'] === 2 : span.tag?.error) ? (
<EuiText color="danger" size="s" style={{ fontWeight: 700 }}>
Yes
</EuiText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable no-console */

import { BarOrientation } from '../../../../common/constants/shared';
import _ from 'lodash';
import moment from 'moment';
import { v1 as uuid } from 'uuid';
import { BarOrientation } from '../../../../common/constants/shared';
import { HttpSetup } from '../../../../../../src/core/public';
import { TRACE_ANALYTICS_DATE_FORMAT } from '../../../../common/constants/trace_analytics';
import { microToMilliSec, nanoToMilliSec } from '../components/common/helper_functions';
Expand All @@ -25,20 +24,20 @@
import { handleDslRequest } from './request_handler';
import { TraceAnalyticsMode } from '../home';

export const handleValidTraceIds = (http: HttpSetup, DSL: any, mode: TraceAnalyticsMode) => {

Check warning on line 27 in public/components/trace_analytics/requests/traces_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return handleDslRequest(http, {}, getValidTraceIdsQuery(DSL), mode)
.then((response) => response.aggregations.traces.buckets.map((bucket: any) => bucket.key))

Check warning on line 29 in public/components/trace_analytics/requests/traces_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
.catch((error) => console.error(error));
};

export const handleTracesRequest = async (
http: HttpSetup,
DSL: any,

Check warning on line 35 in public/components/trace_analytics/requests/traces_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
timeFilterDSL: any,

Check warning on line 36 in public/components/trace_analytics/requests/traces_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
items: any,

Check warning on line 37 in public/components/trace_analytics/requests/traces_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
setItems: (items: any) => void,

Check warning on line 38 in public/components/trace_analytics/requests/traces_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
mode: TraceAnalyticsMode,
sort?: any,
sort?: any

Check warning on line 40 in public/components/trace_analytics/requests/traces_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
) => {
const binarySearch = (arr: number[], target: number) => {
if (!arr) return Number.NaN;
Expand Down Expand Up @@ -73,7 +72,7 @@
.then((response) => {
return Promise.all(
response.aggregations.traces.buckets.map((bucket: any) => {
if (mode === 'data_prepper') {
if (mode === 'data_prepper') {
return {
trace_id: bucket.key,
trace_group: bucket.trace_group.buckets[0]?.key,
Expand All @@ -86,15 +85,14 @@
),
actions: '#',
};
}
return {
trace_id: bucket.key,
latency: bucket.latency.value,
last_updated: moment(bucket.last_updated.value).format(TRACE_ANALYTICS_DATE_FORMAT),
error_count: bucket.error_count.doc_count,
actions: '#',
};

}
return {
trace_id: bucket.key,
latency: bucket.latency.value,
last_updated: moment(bucket.last_updated.value).format(TRACE_ANALYTICS_DATE_FORMAT),
error_count: bucket.error_count.doc_count,
actions: '#',
};
})
);
})
Expand All @@ -109,7 +107,7 @@
http: HttpSetup,
fields: {},
setFields: (fields: any) => void,
mode: TraceAnalyticsMode,
mode: TraceAnalyticsMode
) => {
handleDslRequest(http, null, getTracesQuery(mode, traceId), mode)
.then(async (response) => {
Expand Down Expand Up @@ -138,7 +136,7 @@
http: HttpSetup,
setServiceBreakdownData: (serviceBreakdownData: any) => void,
setColorMap: (colorMap: any) => void,
mode: TraceAnalyticsMode,
mode: TraceAnalyticsMode
) => {
const colors = [
'#7492e7',
Expand Down Expand Up @@ -201,7 +199,7 @@
setSpanDetailData: (spanDetailData: any) => void,
colorMap: any,
spanFiltersDSL: any,
mode: TraceAnalyticsMode,
mode: TraceAnalyticsMode
) => {
handleDslRequest(http, spanFiltersDSL, getSpanDetailQuery(mode, traceId), mode)
.then((response) => hitsToSpanDetailData(response.hits.hits, colorMap, mode))
Expand All @@ -213,7 +211,7 @@
http: HttpSetup,
spanId: string,
setItems: (items: any) => void,
mode: TraceAnalyticsMode,
mode: TraceAnalyticsMode
) => {
handleDslRequest(http, null, getSpanFlyoutQuery(mode, spanId), mode)
.then((response) => {
Expand All @@ -230,15 +228,35 @@
};
if (hits.length === 0) return data;

const minStartTime = mode === 'jaeger' ? microToMilliSec(hits[hits.length - 1].sort[0]) : nanoToMilliSec(hits[hits.length - 1].sort[0]);
const minStartTime =
mode === 'jaeger'
? microToMilliSec(hits[hits.length - 1].sort[0])
: nanoToMilliSec(hits[hits.length - 1].sort[0]);
let maxEndTime = 0;

hits.forEach((hit: any) => {
const startTime = mode === 'jaeger' ? microToMilliSec(hit.sort[0]) - minStartTime : nanoToMilliSec(hit.sort[0]) - minStartTime;
const duration = mode === 'jaeger' ? _.round(microToMilliSec(hit._source.duration), 2) : _.round(nanoToMilliSec(hit._source.durationInNanos), 2);;
const serviceName = mode === 'jaeger'? _.get(hit, ['_source', 'process'])['serviceName'] : _.get(hit, ['_source', 'serviceName']);
const name = mode === 'jaeger' ? _.get(hit, '_source.operationName') : _.get(hit, '_source.name');
const error = mode === 'jaeger' ? (hit._source['tag']['error'] === true ? ' \u26a0 Error' : '') : (hit._source['status.code'] === 2 ? ' \u26a0 Error' : '');
const startTime =
mode === 'jaeger'
? microToMilliSec(hit.sort[0]) - minStartTime
: nanoToMilliSec(hit.sort[0]) - minStartTime;
const duration =
mode === 'jaeger'
? _.round(microToMilliSec(hit._source.duration), 2)
: _.round(nanoToMilliSec(hit._source.durationInNanos), 2);
const serviceName =
mode === 'jaeger'
? _.get(hit, ['_source', 'process']).serviceName
: _.get(hit, ['_source', 'serviceName']);
const name =
mode === 'jaeger' ? _.get(hit, '_source.operationName') : _.get(hit, '_source.name');
const error =
mode === 'jaeger'
? hit._source.tag?.['error'] === true
? ' \u26a0 Error'
: ''
: hit._source['status.code'] === 2
? ' \u26a0 Error'
: '';
const uniqueLabel = `${serviceName} <br>${name} ` + uuid();
maxEndTime = Math.max(maxEndTime, startTime + duration);

Expand Down Expand Up @@ -292,7 +310,7 @@
http: HttpSetup,
payloadData: any,
setPayloadData: (payloadData: any) => void,
mode: TraceAnalyticsMode,
mode: TraceAnalyticsMode
) => {
handleDslRequest(http, null, getPayloadQuery(mode, traceId), mode)
.then((response) => setPayloadData(JSON.stringify(response.hits.hits, null, 2)))
Expand All @@ -305,7 +323,7 @@
setTotal: (total: number) => void,
spanSearchParams: SpanSearchParams,
DSL: any,
mode: TraceAnalyticsMode,
mode: TraceAnalyticsMode
) => {
handleDslRequest(http, DSL, getSpansQuery(spanSearchParams), mode)
.then((response) => {
Expand Down
Loading