From d1c901a33c9d9cfe2356499db3e3b20862461089 Mon Sep 17 00:00:00 2001 From: Kyrylo Shmidt Date: Mon, 4 Mar 2024 19:20:23 +0100 Subject: [PATCH 1/2] Handle nullable endpoint list --- .../Insights/BottleneckInsight/index.tsx | 4 ++- .../Insights/NPlusOneInsight/index.tsx | 4 ++- .../QueryOptimizationInsight/index.tsx | 3 +- .../Insights/ScalingIssueInsight/index.tsx | 13 +++++---- .../insights/ScalingIssueInsight/index.tsx | 28 +++++++++---------- .../SpanEndpointBottleneckInsight.stories.tsx | 12 ++++---- .../SpanEndpointBottleneckInsight/index.tsx | 18 ++++++------ .../insights/SpanNPlusOneInsight/index.tsx | 19 +++++-------- .../SpanQueryOptimizationInsight/index.tsx | 7 +++-- .../tickets/BottleneckInsightTicket/index.tsx | 5 ++-- .../tickets/NPlusOneInsightTicket/index.tsx | 6 ++-- .../BottleneckEndpoints.stories.tsx | 10 ++++--- .../common/BottleneckEndpoints/index.tsx | 2 +- .../NPlusOneAffectedEndpoints.stories.tsx | 10 ++++--- .../NPlusOneAffectedEndpoints/index.tsx | 2 +- .../QueryOptimizationEndpoints.stories.tsx | 10 ++++--- .../QueryOptimizationEndpoints/index.tsx | 2 +- .../ScalingIssueAffectedEndpoints/index.tsx | 4 +-- src/components/Insights/types.ts | 24 ++++++++-------- 19 files changed, 96 insertions(+), 87 deletions(-) diff --git a/src/components/Insights/BottleneckInsight/index.tsx b/src/components/Insights/BottleneckInsight/index.tsx index 34c8d41b3..dca3e6e1a 100644 --- a/src/components/Insights/BottleneckInsight/index.tsx +++ b/src/components/Insights/BottleneckInsight/index.tsx @@ -24,6 +24,8 @@ export const BottleneckInsight = (props: BottleneckInsightProps) => { props.onJiraTicketCreate(props.insight, undefined, event); }; + const slowEndpoints = props.insight.slowEndpoints || []; + return ( { content={ <> - {props.insight.slowEndpoints.map((endpoint, i) => { + {slowEndpoints.map((endpoint, i) => { const endpointName = `${ endpoint.endpointInfo.serviceName }:${trimEndpointScheme(endpoint.endpointInfo.route)}`; diff --git a/src/components/Insights/NPlusOneInsight/index.tsx b/src/components/Insights/NPlusOneInsight/index.tsx index d85fe011b..bb7fa678a 100644 --- a/src/components/Insights/NPlusOneInsight/index.tsx +++ b/src/components/Insights/NPlusOneInsight/index.tsx @@ -44,6 +44,8 @@ export const NPlusOneInsight = (props: NPlusOneInsightProps) => { const spanCodeObjectId = props.insight.clientSpanCodeObjectId || undefined; const traceId = props.insight.traceId; + const endpoints = props.insight.endpoints || []; + return ( { Affected endpoints: - {props.insight.endpoints.map((x) => { + {endpoints.map((x) => { const spanCodeObjectId = x.endpointInfo.entrySpanCodeObjectId; const route = trimEndpointScheme(x.endpointInfo.route); diff --git a/src/components/Insights/QueryOptimizationInsight/index.tsx b/src/components/Insights/QueryOptimizationInsight/index.tsx index 9b34c906b..f2a14505d 100644 --- a/src/components/Insights/QueryOptimizationInsight/index.tsx +++ b/src/components/Insights/QueryOptimizationInsight/index.tsx @@ -49,6 +49,7 @@ export const QueryOptimizationInsight = ( const spanCodeObjectId = props.insight.spanInfo?.spanCodeObjectId || undefined; const traceId = props.insight.traceId; + const endpoints = props.insight.endpoints || []; return ( Affected endpoints: - {props.insight.endpoints.map((x) => { + {endpoints.map((x) => { const spanCodeObjectId = x.endpointInfo.spanCodeObjectId; const route = trimEndpointScheme(x.endpointInfo.route); diff --git a/src/components/Insights/ScalingIssueInsight/index.tsx b/src/components/Insights/ScalingIssueInsight/index.tsx index 6e98ffda2..78f94f607 100644 --- a/src/components/Insights/ScalingIssueInsight/index.tsx +++ b/src/components/Insights/ScalingIssueInsight/index.tsx @@ -1,6 +1,7 @@ import { useContext } from "react"; import { InsightType } from "../../../types"; import { getDurationString } from "../../../utils/getDurationString"; +import { sendTrackingEvent } from "../../../utils/sendTrackingEvent"; import { trimEndpointScheme } from "../../../utils/trimEndpointScheme"; import { ConfigContext } from "../../common/App/ConfigContext"; import { Button } from "../../common/Button"; @@ -9,14 +10,12 @@ import { ChartIcon } from "../../common/icons/ChartIcon"; import { CrosshairIcon } from "../../common/icons/CrosshairIcon"; import { InsightCard } from "../InsightCard"; import { Criticality } from "../common/Criticality"; +import { JiraButton } from "../common/JiraButton"; import { Description, Link } from "../styles"; +import { trackingEvents } from "../tracking"; import { Trace } from "../types"; import * as s from "./styles"; import { ScalingIssueInsightProps } from "./types"; -import { JiraButton } from "../common/JiraButton"; -import { sendTrackingEvent } from "../../../utils/sendTrackingEvent"; -import { trackingEvents } from "../tracking"; -import { ButtonsContainer } from "./styles"; export const ScalingIssueInsight = (props: ScalingIssueInsightProps) => { const config = useContext(ConfigContext); @@ -55,6 +54,8 @@ export const ScalingIssueInsight = (props: ScalingIssueInsightProps) => { props.onJiraTicketCreate(props.insight, spanCodeObjectId, event); }; + const affectedEndpoints = props.insight.affectedEndpoints || []; + return ( { })} )} - {props.insight.affectedEndpoints.length > 0 && ( + {affectedEndpoints.length > 0 && ( Affected endpoints: - {props.insight.affectedEndpoints.map((endpoint) => { + {affectedEndpoints.map((endpoint) => { const endpointRoute = trimEndpointScheme(endpoint.route); return ( diff --git a/src/components/Insights/common/insights/ScalingIssueInsight/index.tsx b/src/components/Insights/common/insights/ScalingIssueInsight/index.tsx index 0d2c2eaeb..3119f6d44 100644 --- a/src/components/Insights/common/insights/ScalingIssueInsight/index.tsx +++ b/src/components/Insights/common/insights/ScalingIssueInsight/index.tsx @@ -20,8 +20,9 @@ import { ScalingIssueInsightProps } from "./types"; const PAGE_SIZE = 3; export const ScalingIssueInsight = (props: ScalingIssueInsightProps) => { const config = useContext(ConfigContext); + const affectedEndpoints = props.insight.affectedEndpoints || []; const [pageItems, page, setPage] = usePagination( - props.insight.affectedEndpoints, + affectedEndpoints, PAGE_SIZE, props.insight.codeObjectId ); @@ -120,22 +121,21 @@ export const ScalingIssueInsight = (props: ScalingIssueInsightProps) => { {renderRootCause(props.insight.rootCauseSpans)} - {props.insight.affectedEndpoints.length > 0 && ( + {affectedEndpoints.length > 0 && ( Affected endpoints: - {props.insight.affectedEndpoints.length > 0 && - pageItems.map((endpoint) => { - const endpointRoute = trimEndpointScheme(endpoint.route); - return ( - handleLinkClick(endpoint.spanCodeObjectId)} - name={endpointRoute} - /> - ); - })} + {pageItems.map((endpoint) => { + const endpointRoute = trimEndpointScheme(endpoint.route); + return ( + handleLinkClick(endpoint.spanCodeObjectId)} + name={endpointRoute} + /> + ); + })} ; +const mockedSlowEndpoints = mockedBottleneckInsight.slowEndpoints || []; + export const Default: Story = { args: { insight: { ...mockedBottleneckInsight, slowEndpoints: [ - ...mockedBottleneckInsight.slowEndpoints, + ...mockedSlowEndpoints, { - ...mockedBottleneckInsight.slowEndpoints[0], + ...mockedSlowEndpoints[0], requestPercentage: 100, endpointInfo: { - ...mockedBottleneckInsight.slowEndpoints[0].endpointInfo, - route: `${mockedBottleneckInsight.slowEndpoints[0].endpointInfo.route}1`, - spanCodeObjectId: `${mockedBottleneckInsight.slowEndpoints[0].endpointInfo.spanCodeObjectId}1` + ...mockedSlowEndpoints[0].endpointInfo, + route: `${mockedSlowEndpoints[0].endpointInfo.route}1`, + spanCodeObjectId: `${mockedSlowEndpoints[0].endpointInfo.spanCodeObjectId}1` } } ] diff --git a/src/components/Insights/common/insights/SpanEndpointBottleneckInsight/index.tsx b/src/components/Insights/common/insights/SpanEndpointBottleneckInsight/index.tsx index f9bd93a2c..63eed93d4 100644 --- a/src/components/Insights/common/insights/SpanEndpointBottleneckInsight/index.tsx +++ b/src/components/Insights/common/insights/SpanEndpointBottleneckInsight/index.tsx @@ -40,8 +40,9 @@ const renderOptions = ( export const SpanEndpointBottleneckInsight = ( props: SpanEndpointBottleneckInsightProps ) => { + const slowEndpoints = props.insight.slowEndpoints || []; const [selectedEndpoint, setSelectedEndpoint] = useState( - props.insight?.slowEndpoints.length ? props.insight.slowEndpoints[0] : null + slowEndpoints.length > 0 ? slowEndpoints[0] : null ); const handleSpanLinkClick = (spanCodeObjectId?: string) => { @@ -57,9 +58,7 @@ export const SpanEndpointBottleneckInsight = ( props.onJiraTicketCreate(props.insight, undefined, event); }; - const endpoints = props.insight.slowEndpoints; - - if (endpoints.length === 0) { + if (slowEndpoints.length === 0) { return null; } @@ -75,21 +74,20 @@ export const SpanEndpointBottleneckInsight = ( content={
- Affected Endpoints ({endpoints.length}) + + Affected Endpoints ({slowEndpoints.length}) +