-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add topology applications (#1975)
Co-authored-by: Tal Borenstein <[email protected]>
- Loading branch information
Showing
56 changed files
with
3,178 additions
and
610 deletions.
There are no files selected for viewing
This file contains 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,3 @@ | ||
--- | ||
openapi: post /topology/applications | ||
--- |
This file contains 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,3 @@ | ||
--- | ||
openapi: delete /topology/applications/{application_id} | ||
--- |
This file contains 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,3 @@ | ||
--- | ||
openapi: get /topology/applications | ||
--- |
This file contains 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,3 @@ | ||
--- | ||
openapi: put /topology/applications/{application_id} | ||
--- |
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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,65 @@ | ||
import { getApiURL } from "../../../utils/apiUrl"; | ||
import { fetcher } from "../../../utils/fetcher"; | ||
import { Session } from "next-auth"; | ||
import { TopologyApplication, TopologyService } from "../model/models"; | ||
|
||
const isNullOrUndefined = (value: unknown): value is null | undefined => | ||
value === null || value === undefined; | ||
|
||
export function buildTopologyUrl({ | ||
providerId, | ||
service, | ||
environment, | ||
}: { | ||
providerId?: string; | ||
service?: string; | ||
environment?: string; | ||
}) { | ||
const apiUrl = getApiURL(); | ||
|
||
const baseUrl = `${apiUrl}/topology`; | ||
|
||
if ( | ||
!isNullOrUndefined(providerId) && | ||
!isNullOrUndefined(service) && | ||
!isNullOrUndefined(environment) | ||
) { | ||
const params = new URLSearchParams({ | ||
provider_id: providerId, | ||
service_id: service, | ||
environment: environment, | ||
}); | ||
return `${baseUrl}?${params.toString()}`; | ||
} | ||
|
||
return baseUrl; | ||
} | ||
|
||
export async function getApplications(session: Session | null) { | ||
if (!session) { | ||
return null; | ||
} | ||
const apiUrl = `${getApiURL()}/topology/applications`; | ||
return (await fetcher(apiUrl, session.accessToken)) as Promise< | ||
TopologyApplication[] | ||
>; | ||
} | ||
|
||
export function getTopology( | ||
session: Session | null, | ||
{ | ||
providerId, | ||
service, | ||
environment, | ||
}: { | ||
providerId?: string; | ||
service?: string; | ||
environment?: string; | ||
} | ||
) { | ||
if (!session) { | ||
return null; | ||
} | ||
const url = buildTopologyUrl({ providerId, service, environment }); | ||
return fetcher(url, session.accessToken) as Promise<TopologyService[]>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,30 +1,24 @@ | ||
"use client"; | ||
import { Subtitle, TextInput, Title } from "@tremor/react"; | ||
|
||
import { useState } from "react"; | ||
import { ServiceSearchContext } from "./service-search-context"; | ||
|
||
export default function Layout({ children }: { children: any }) { | ||
const [serviceInput, setServiceInput] = useState<string>(""); | ||
const [serviceQuery, setServiceQuery] = useState<string>(""); | ||
const [selectedServiceId, setSelectedServiceId] = useState<string | null>( | ||
null | ||
); | ||
|
||
return ( | ||
<main className="p-4 md:p-10 mx-auto max-w-full h-full"> | ||
<div className="flex w-full justify-between"> | ||
<div> | ||
<Title>Service Topology</Title> | ||
<Subtitle> | ||
Data describing the topology of components in your environment. | ||
</Subtitle> | ||
</div> | ||
<TextInput | ||
placeholder="Search for a service" | ||
value={serviceInput} | ||
onValueChange={setServiceInput} | ||
className="w-64 mt-2" | ||
/> | ||
</div> | ||
<ServiceSearchContext.Provider value={serviceInput}> | ||
{children} | ||
</ServiceSearchContext.Provider> | ||
</main> | ||
<ServiceSearchContext.Provider | ||
value={{ | ||
serviceQuery, | ||
setServiceQuery, | ||
selectedServiceId, | ||
setSelectedServiceId, | ||
}} | ||
> | ||
{children} | ||
</ServiceSearchContext.Provider> | ||
); | ||
} |
This file contains 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,51 @@ | ||
"use client"; | ||
|
||
import React, { createContext, useContext, useEffect, useState } from "react"; | ||
import { useWebsocket } from "@/utils/hooks/usePusher"; | ||
import { toast } from "react-toastify"; | ||
|
||
interface TopologyUpdate { | ||
providerType: string; | ||
providerId: string; | ||
} | ||
|
||
const TopologyPollingContext = createContext<number>(0); | ||
|
||
// Using this provider to avoid polling on every render | ||
export const TopologyPollingContextProvider: React.FC<{ | ||
children: React.ReactNode; | ||
}> = ({ children }) => { | ||
const [pollTopology, setPollTopology] = useState(0); | ||
const { bind, unbind } = useWebsocket(); | ||
|
||
useEffect(() => { | ||
const handleIncoming = (data: TopologyUpdate) => { | ||
toast.success( | ||
`Topology pulled from ${data.providerId} (${data.providerType})`, | ||
{ position: "top-right" } | ||
); | ||
setPollTopology((prev) => prev + 1); | ||
}; | ||
|
||
bind("topology-update", handleIncoming); | ||
return () => { | ||
unbind("topology-update", handleIncoming); | ||
}; | ||
}, [bind, unbind]); | ||
|
||
return ( | ||
<TopologyPollingContext.Provider value={pollTopology}> | ||
{children} | ||
</TopologyPollingContext.Provider> | ||
); | ||
}; | ||
|
||
export function useTopologyPollingContext() { | ||
const context = useContext(TopologyPollingContext); | ||
if (context === undefined) { | ||
throw new Error( | ||
"useTopologyContext must be used within a TopologyContextProvider" | ||
); | ||
} | ||
return context; | ||
} |
This file contains 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,12 @@ | ||
export type { | ||
TopologyService, | ||
TopologyServiceMinimal, | ||
TopologyApplication, | ||
TopologyApplicationMinimal, | ||
TopologyNode, | ||
ServiceNodeType, | ||
TopologyServiceDependency, | ||
} from "./models"; | ||
|
||
export { useTopology } from "./useTopology"; | ||
export { useTopologyApplications } from "./useTopologyApplications"; |
Oops, something went wrong.