-
Notifications
You must be signed in to change notification settings - Fork 2
Chatty API #555
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
Merged
Merged
Chatty API #555
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
212 changes: 212 additions & 0 deletions
212
...ts/Insights/common/insights/ExcessiveAPICallsInsight/ExcessiveAPICallsInsight.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| import { Meta, StoryObj } from "@storybook/react"; | ||
| import { ExcessiveAPICallsInsight } from "."; | ||
| import { InsightCategory, InsightScope, InsightType } from "../../../types"; | ||
|
|
||
| // More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction | ||
| const meta: Meta<typeof ExcessiveAPICallsInsight> = { | ||
| title: "Insights/common/insights/ExcessiveAPICallsInsight", | ||
| component: ExcessiveAPICallsInsight, | ||
| parameters: { | ||
| // More on how to position stories at: https://storybook.js.org/docs/react/configure/story-layout | ||
| layout: "fullscreen" | ||
| } | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| insight: { | ||
| id: "60b55792-8262-4c5d-9688-7cce7979ad6d", | ||
| firstDetected: "2023-12-05T17:25:47.010Z", | ||
| lastDetected: "2024-01-05T13:14:47.010Z", | ||
| criticality: 0.5, | ||
| firstCommitId: "b3f7b3f", | ||
| lastCommitId: "a1b2c3d", | ||
| deactivatedCommitId: null, | ||
| reopenCount: 0, | ||
| ticketLink: null, | ||
| impact: 0, | ||
| name: "HTTP Chatter", | ||
| type: InsightType.EndpointChattyApi, | ||
| category: InsightCategory.Performance, | ||
| specifity: 2, | ||
| importance: 3, | ||
| spans: [ | ||
| { | ||
| repeats: 29, | ||
| clientSpan: { | ||
| name: "HTTP GET mockapi.io", | ||
| displayName: "HTTP GET mockapi.io", | ||
| instrumentationLibrary: "io.opentelemetry.okhttp-3.0", | ||
| spanCodeObjectId: | ||
| "span:io.opentelemetry.okhttp-3.0$_$HTTP GET mockapi.io", | ||
| methodCodeObjectId: null, | ||
| kind: "Client", | ||
| codeObjectId: null | ||
| }, | ||
| traceId: "00E4D714D4FAD0A00F9D8A39C8A49E8A" | ||
| }, | ||
| { | ||
| repeats: 29, | ||
| clientSpan: { | ||
| name: "HTTP GET mockapi.io 2", | ||
| displayName: "HTTP GET mockapi.io 2", | ||
| instrumentationLibrary: "io.opentelemetry.okhttp-3.0", | ||
| spanCodeObjectId: | ||
| "span:io.opentelemetry.okhttp-3.0$_$HTTP GET mockapi.io 2", | ||
| methodCodeObjectId: null, | ||
| kind: "Client", | ||
| codeObjectId: null | ||
| }, | ||
| traceId: "00E4D714D4FAD0A00F9D8A39C8A49E8B" | ||
| }, | ||
| { | ||
| repeats: 29, | ||
| clientSpan: { | ||
| name: "HTTP GET mockapi.io 3", | ||
| displayName: "HTTP GET mockapi.io 3", | ||
| instrumentationLibrary: "io.opentelemetry.okhttp-3.0", | ||
| spanCodeObjectId: | ||
| "span:io.opentelemetry.okhttp-3.0$_$HTTP GET mockapi.io 3", | ||
| methodCodeObjectId: null, | ||
| kind: "Client", | ||
| codeObjectId: null | ||
| }, | ||
| traceId: "00E4D714D4FAD0A00F9D8A39C8A49E8C" | ||
| }, | ||
| { | ||
| repeats: 29, | ||
| clientSpan: { | ||
| name: "HTTP GET mockapi.io 4", | ||
| displayName: "HTTP GET mockapi.io 4", | ||
| instrumentationLibrary: "io.opentelemetry.okhttp-3.0", | ||
| spanCodeObjectId: | ||
| "span:io.opentelemetry.okhttp-3.0$_$HTTP GET mockapi.io 4", | ||
| methodCodeObjectId: null, | ||
| kind: "Client", | ||
| codeObjectId: null | ||
| }, | ||
| traceId: "00E4D714D4FAD0A00F9D8A39C8A49E8C" | ||
| } | ||
| ], | ||
| scope: InsightScope.EntrySpan, | ||
| endpointSpan: "HTTP POST /owners/{ownerId}/pets/new", | ||
| spanCodeObjectId: | ||
| "span:io.opentelemetry.tomcat-10.0$_$HTTP POST /owners/{ownerId}/pets/new", | ||
| route: "epHTTP:HTTP POST /owners/{ownerId}/pets/new", | ||
| serviceName: "spring-petclinic", | ||
| spanInfo: { | ||
| name: "HTTP POST /owners/{ownerId}/pets/new", | ||
| displayName: "HTTP POST /owners/{ownerId}/pets/new", | ||
| instrumentationLibrary: "io.opentelemetry.tomcat-10.0", | ||
| spanCodeObjectId: | ||
| "span:io.opentelemetry.tomcat-10.0$_$HTTP POST /owners/{ownerId}/pets/new", | ||
| methodCodeObjectId: | ||
| "method:org.springframework.samples.petclinic.owner.PetController$_$processCreationForm", | ||
| kind: "Server", | ||
| codeObjectId: | ||
| "org.springframework.samples.petclinic.owner.PetController$_$processCreationForm" | ||
| }, | ||
| shortDisplayInfo: { | ||
| title: "", | ||
| targetDisplayName: "", | ||
| subtitle: "", | ||
| description: "" | ||
| }, | ||
| codeObjectId: | ||
| "org.springframework.samples.petclinic.owner.PetController$_$processCreationForm", | ||
| decorators: [ | ||
| { | ||
| title: "Excessive HTTP Calls", | ||
| description: "Numerous Http calls to the same endpoint detected " | ||
| } | ||
| ], | ||
| environment: "BOB-LAPTOP[LOCAL]", | ||
| severity: 0.0, | ||
| isRecalculateEnabled: false, | ||
| prefixedCodeObjectId: | ||
| "method:org.springframework.samples.petclinic.owner.PetController$_$processCreationForm", | ||
| customStartTime: null, | ||
| actualStartTime: "2023-08-10T08:04:00Z" | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| export const EmptyTrace: Story = { | ||
| args: { | ||
| insight: { | ||
| id: "60b55792-8262-4c5d-9688-7cce7979ad6d", | ||
| firstDetected: "2023-12-05T17:25:47.010Z", | ||
| lastDetected: "2024-01-05T13:14:47.010Z", | ||
| criticality: 0.5, | ||
| firstCommitId: "b3f7b3f", | ||
| lastCommitId: "a1b2c3d", | ||
| deactivatedCommitId: null, | ||
| reopenCount: 0, | ||
| ticketLink: null, | ||
| impact: 0, | ||
| name: "HTTP Chatter", | ||
| type: InsightType.EndpointChattyApi, | ||
| category: InsightCategory.Performance, | ||
| specifity: 2, | ||
| importance: 3, | ||
| spans: [ | ||
| { | ||
| repeats: 29, | ||
| clientSpan: { | ||
| name: "HTTP GET mockapi.io", | ||
| displayName: "HTTP GET mockapi.io", | ||
| instrumentationLibrary: "io.opentelemetry.okhttp-3.0", | ||
| spanCodeObjectId: | ||
| "span:io.opentelemetry.okhttp-3.0$_$HTTP GET mockapi.io", | ||
| methodCodeObjectId: null, | ||
| kind: "Client", | ||
| codeObjectId: null | ||
| } | ||
| } | ||
| ], | ||
| scope: InsightScope.EntrySpan, | ||
| endpointSpan: "HTTP POST /owners/{ownerId}/pets/new", | ||
| spanCodeObjectId: | ||
| "span:io.opentelemetry.tomcat-10.0$_$HTTP POST /owners/{ownerId}/pets/new", | ||
| route: "epHTTP:HTTP POST /owners/{ownerId}/pets/new", | ||
| serviceName: "spring-petclinic", | ||
| spanInfo: { | ||
| name: "HTTP POST /owners/{ownerId}/pets/new", | ||
| displayName: "HTTP POST /owners/{ownerId}/pets/new", | ||
| instrumentationLibrary: "io.opentelemetry.tomcat-10.0", | ||
| spanCodeObjectId: | ||
| "span:io.opentelemetry.tomcat-10.0$_$HTTP POST /owners/{ownerId}/pets/new", | ||
| methodCodeObjectId: | ||
| "method:org.springframework.samples.petclinic.owner.PetController$_$processCreationForm", | ||
| kind: "Server", | ||
| codeObjectId: | ||
| "org.springframework.samples.petclinic.owner.PetController$_$processCreationForm" | ||
| }, | ||
| shortDisplayInfo: { | ||
| title: "", | ||
| targetDisplayName: "", | ||
| subtitle: "", | ||
| description: "" | ||
| }, | ||
| codeObjectId: | ||
| "org.springframework.samples.petclinic.owner.PetController$_$processCreationForm", | ||
| decorators: [ | ||
| { | ||
| title: "Excessive HTTP Calls", | ||
| description: "Numerous Http calls to the same endpoint detected " | ||
| } | ||
| ], | ||
| environment: "BOB-LAPTOP[LOCAL]", | ||
| severity: 0.0, | ||
| isRecalculateEnabled: false, | ||
| prefixedCodeObjectId: | ||
| "method:org.springframework.samples.petclinic.owner.PetController$_$processCreationForm", | ||
| customStartTime: null, | ||
| actualStartTime: "2023-08-10T08:04:00Z" | ||
| } | ||
| } | ||
| }; |
91 changes: 91 additions & 0 deletions
91
src/components/Insights/common/insights/ExcessiveAPICallsInsight/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { useContext } from "react"; | ||
| import { usePagination } from "../../../../../hooks/usePagination"; | ||
| import { ConfigContext } from "../../../../common/App/ConfigContext"; | ||
| import { TargetIcon } from "../../../../common/icons/12px/TargetIcon"; | ||
| import { Button } from "../../../../common/v3/Button"; | ||
| import { Pagination } from "../../../../common/v3/Pagination"; | ||
| import { InsightType, Trace } from "../../../types"; | ||
| import { InsightCard } from "../../InsightCard"; | ||
| import * as s from "./styles"; | ||
| import { ExcessiveAPICallsInsightProps } from "./types"; | ||
|
|
||
| const PAGE_SIZE = 3; | ||
|
|
||
| export const ExcessiveAPICallsInsight = ( | ||
| props: ExcessiveAPICallsInsightProps | ||
| ) => { | ||
| const config = useContext(ConfigContext); | ||
|
|
||
| const [pageItems, page, setPage] = usePagination( | ||
| props.insight.spans, | ||
| PAGE_SIZE, | ||
| props.insight.codeObjectId | ||
| ); | ||
|
|
||
| const handleLinkClick = (spanCodeObjectId: string) => { | ||
| props.onAssetLinkClick(spanCodeObjectId, props.insight.type); | ||
| }; | ||
|
|
||
| const handleTraceButtonClick = ( | ||
| trace: Trace, | ||
| insightType: InsightType, | ||
| spanCodeObjectId: string | ||
| ) => { | ||
| props.onTraceButtonClick(trace, insightType, spanCodeObjectId); | ||
| }; | ||
|
|
||
| return ( | ||
| <InsightCard | ||
| insight={props.insight} | ||
| content={ | ||
| <s.ContentContainer> | ||
| <s.Description> | ||
| Excessive API calls to specific endpoint found | ||
| </s.Description> | ||
| <s.List> | ||
| {pageItems.map((span) => { | ||
| const spanName = span.clientSpan.displayName; | ||
| const traceId = span.traceId; | ||
| const spanCodeObjectId = span.clientSpan.spanCodeObjectId; | ||
|
|
||
| return ( | ||
| <s.SpanListItem | ||
| key={spanCodeObjectId} | ||
| name={spanName} | ||
| onClick={() => handleLinkClick(spanCodeObjectId)} | ||
| buttons={[ | ||
| config.isJaegerEnabled && traceId && ( | ||
| <Button | ||
| key={spanCodeObjectId + "trace"} | ||
| icon={TargetIcon} | ||
| onClick={() => | ||
| handleTraceButtonClick( | ||
| { | ||
| name: spanName, | ||
| id: traceId | ||
| }, | ||
| props.insight.type, | ||
| spanCodeObjectId | ||
| ) | ||
| } | ||
| /> | ||
| ) | ||
| ]} | ||
| /> | ||
| ); | ||
| })} | ||
| <Pagination | ||
| itemsCount={props.insight.spans.length} | ||
| page={page} | ||
| pageSize={PAGE_SIZE} | ||
| onPageChange={setPage} | ||
| withDescription={true} | ||
| /> | ||
| </s.List> | ||
| </s.ContentContainer> | ||
| } | ||
| onRecalculate={props.onRecalculate} | ||
| onRefresh={props.onRefresh} | ||
| /> | ||
| ); | ||
| }; | ||
25 changes: 25 additions & 0 deletions
25
src/components/Insights/common/insights/ExcessiveAPICallsInsight/styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import styled from "styled-components"; | ||
| import { caption1RegularTypography } from "../../../../common/App/typographies"; | ||
| import { ListItem } from "../../InsightCard/ListItem"; | ||
|
|
||
| export const ContentContainer = styled.div` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 4px; | ||
| `; | ||
|
|
||
| export const List = styled.div` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 4px; | ||
| `; | ||
|
|
||
| export const Description = styled.div` | ||
| color: ${({ theme }) => theme.colors.v3.text.tertiary}; | ||
|
|
||
| ${caption1RegularTypography} | ||
| `; | ||
|
|
||
| export const SpanListItem = styled(ListItem)` | ||
| padding: 4px; | ||
| `; |
19 changes: 19 additions & 0 deletions
19
src/components/Insights/common/insights/ExcessiveAPICallsInsight/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { | ||
| ChattyApiEndpointInsight, | ||
| InsightProps, | ||
| InsightType, | ||
| Trace | ||
| } from "../../../types"; | ||
|
|
||
| export interface ExcessiveAPICallsInsightProps extends InsightProps { | ||
| insight: ChattyApiEndpointInsight; | ||
| onAssetLinkClick: ( | ||
| spanCodeObjectId: string, | ||
| insightType: InsightType | ||
| ) => void; | ||
| onTraceButtonClick: ( | ||
| trace: Trace, | ||
| insightType: InsightType, | ||
| spanCodeObjectId: string | ||
| ) => void; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.