Skip to content

Commit

Permalink
fix: reduce the amount of unnecessary route edges
Browse files Browse the repository at this point in the history
  • Loading branch information
davemooreuws committed Dec 18, 2024
1 parent 7970f8f commit d466f7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pkg/dashboard/frontend/cypress/e2e/architecture.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ describe('Architecture Spec', () => {
it('should have correct routes drawer content', () => {
const expected = [
[
'edge-label-e-first-api-allmethodsget-services/my-test-service.ts',
'edge-label-e-first-api-services/my-test-service.ts',
'DELETE/all-methodsGET/all-methodsOPTIONS/all-methodsPATCH/all-methodsPOST/all-methodsPUT/all-methodsGET/header-testPOST/json-testGET/path-test/{name}GET/query-testGET/schedule-countGET/topic-count',
],
[
'edge-label-e-second-api-imagefrombucketget-services/my-test-service.ts',
'edge-label-e-second-api-services/my-test-service.ts',
'GET/content-type-binaryGET/content-type-cssGET/content-type-htmlGET/content-type-imageGET/content-type-xmlDELETE/image-from-bucketGET/image-from-bucketPUT/image-from-bucketPUT/very-nested-files',
],
[
'edge-label-e-my-secret-api-setbinarypost-services/my-test-secret.ts',
'edge-label-e-my-secret-api-services/my-test-secret.ts',
'GET/getPOST/setPOST/set-binary',
],
['edge-label-e-my-db-api-getget-services/my-test-db.ts', 'GET/get'],
['edge-label-e-my-db-api-services/my-test-db.ts', 'GET/get'],
]

expected.forEach(([edge, routes]) => {
Expand Down
16 changes: 13 additions & 3 deletions pkg/dashboard/frontend/src/lib/utils/generate-architecture-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,16 @@ export function generateArchitectureData(data: WebSocketResponse): {
resource: api,
icon: GlobeAltIcon,
address: apiAddress,
description: `${routes.length} ${
routes.length === 1 ? 'Route' : 'Routes'
description: `${allEndpoints.length} ${
allEndpoints.length === 1 ? 'Route' : 'Routes'
}`,
endpoints: allEndpoints,
})

const specEntries = (api.spec && api.spec.paths) || []

const uniqueMap = new Map<string, string>()

Object.entries(specEntries).forEach(([path, operations]) => {
AllHttpMethods.forEach((m) => {
const method = operations && (operations[m] as any)
Expand All @@ -242,12 +244,20 @@ export function generateArchitectureData(data: WebSocketResponse): {

const target = method['x-nitric-target']['name']

// we only need one api edge per service target
if (uniqueMap.has(target)) {
return
}

// mark the target as unique
uniqueMap.set(target, target)

const endpoints = allEndpoints.filter(
(endpoint) => endpoint.requestingService === target,
)

edges.push({
id: `e-${api.name}-${method.operationId}-${target}`,
id: `e-${api.name}-${target}`,
source: node.id,
target,
animated: true,
Expand Down

0 comments on commit d466f7d

Please sign in to comment.