Skip to content

Commit

Permalink
feat(frontend): add sources number of instances (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
blumamir authored Jul 2, 2024
1 parent 6822e74 commit 98dd8ba
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
25 changes: 14 additions & 11 deletions frontend/endpoints/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type InstrumentedApplicationDetails struct {
// this object contains only part of the source fields. It is used to display the sources in the frontend
type ThinSource struct {
SourceID
IaDetails *InstrumentedApplicationDetails `json:"instrumented_application_details"`
NumberOfRunningInstances int `json:"number_of_running_instances"`
IaDetails *InstrumentedApplicationDetails `json:"instrumented_application_details"`
}

type SourceID struct {
Expand Down Expand Up @@ -88,7 +89,8 @@ func GetSources(c *gin.Context, odigosns string) {
if item.nsItem.InstrumentationEffective {
id := SourceID{Namespace: item.namespace, Kind: string(item.nsItem.Kind), Name: item.nsItem.Name}
effectiveInstrumentedSources[id] = ThinSource{
SourceID: id,
NumberOfRunningInstances: item.nsItem.Instances,
SourceID: id,
}
}
}
Expand Down Expand Up @@ -119,7 +121,7 @@ func GetSource(c *gin.Context) {
name := c.Param("name")
k8sObjectName := workload.GetRuntimeObjectName(name, kind)

owner := getK8sObject(c, ns, kind, name)
owner, numberOfRunningInstances := getWorkloadObject(c, ns, kind, name)
if owner == nil {
c.JSON(500, gin.H{
"message": "could not find owner of instrumented application",
Expand All @@ -138,6 +140,7 @@ func GetSource(c *gin.Context) {
Kind: kind,
Name: name,
},
NumberOfRunningInstances: numberOfRunningInstances,
}

instrumentedApplication, err := kube.DefaultClient.OdigosClient.InstrumentedApplications(ns).Get(c, k8sObjectName, metav1.GetOptions{})
Expand Down Expand Up @@ -319,28 +322,28 @@ func addHealthyInstrumentationInstancesCondition(ctx context.Context, app *v1alp
return nil
}

func getK8sObject(c *gin.Context, ns string, kind string, name string) metav1.Object {
func getWorkloadObject(c *gin.Context, ns string, kind string, name string) (metav1.Object, int) {
switch kind {
case "Deployment":
deployment, err := kube.DefaultClient.AppsV1().Deployments(ns).Get(c, name, metav1.GetOptions{})
if err != nil {
return nil
return nil, 0
}
return deployment
return deployment, int(deployment.Status.AvailableReplicas)
case "StatefulSet":
statefulSet, err := kube.DefaultClient.AppsV1().StatefulSets(ns).Get(c, name, metav1.GetOptions{})
if err != nil {
return nil
return nil, 0
}
return statefulSet
return statefulSet, int(statefulSet.Status.ReadyReplicas)
case "DaemonSet":
daemonSet, err := kube.DefaultClient.AppsV1().DaemonSets(ns).Get(c, name, metav1.GetOptions{})
if err != nil {
return nil
return nil, 0
}
return daemonSet
return daemonSet, int(daemonSet.Status.NumberReady)
default:
return nil
return nil, 0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const IMAGE_STYLE: React.CSSProperties = {
};

export function ManageSourceHeader({ source }: { source: ManagedSource }) {
const mainLanguage = getMainContainerLanguage(
source?.instrumented_application_details?.languages || undefined
);
const mainLanguage = getMainContainerLanguage(source);
const imageUrl = LANGUAGES_LOGOS[mainLanguage];
return (
<ManageSourceHeaderWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ export function SourcesTableRow({
onSelectedCheckboxChange: (id: string) => void;
onRowClick: (source: ManagedSource) => void;
}) {
const workloadProgrammingLanguage = getMainContainerLanguage(
item?.instrumented_application_details?.languages || undefined
);
const workloadProgrammingLanguage = getMainContainerLanguage(item);

const containerName =
item?.instrumented_application_details?.languages?.[0].container_name || '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ export function EditSourceForm() {
name={currentSource?.name}
image_url={
LANGUAGES_LOGOS[
getMainContainerLanguage(
currentSource?.instrumented_application_details?.languages ||
undefined
)
getMainContainerLanguage(currentSource)
]
}
/>
Expand Down
1 change: 1 addition & 0 deletions frontend/webapp/types/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ManagedSource {
name: string;
namespace: string;
reported_name?: string;
number_of_running_instances: number;
instrumented_application_details: {
conditions: Array<Condition>;
languages: Array<{
Expand Down
25 changes: 18 additions & 7 deletions frontend/webapp/utils/constants/programming.languages.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ManagedSource } from "@/types/sources";

const BASE_URL = 'https://d1n7d4xz7fr8b4.cloudfront.net/';

// while odigos lists language per container, we want to aggregate one single language for the workload.
Expand All @@ -13,6 +15,7 @@ export enum WORKLOAD_PROGRAMMING_LANGUAGES {
UNKNOWN = 'unknown', // language detection completed but could not find a supported language
PROCESSING = 'processing', // language detection is not yet complotted, data is not available
NO_CONTAINERS = 'no containers', // language detection completed but no containers found or they are ignored
NO_RUNNING_PODS = 'no running pods', // no running pods are available for language detection
}

export const LANGUAGES_LOGOS: Record<WORKLOAD_PROGRAMMING_LANGUAGES, string> = {
Expand All @@ -25,6 +28,7 @@ export const LANGUAGES_LOGOS: Record<WORKLOAD_PROGRAMMING_LANGUAGES, string> = {
[WORKLOAD_PROGRAMMING_LANGUAGES.UNKNOWN]: `${BASE_URL}default.svg`, // TODO: good icon
[WORKLOAD_PROGRAMMING_LANGUAGES.PROCESSING]: `${BASE_URL}default.svg`, // TODO: good icon
[WORKLOAD_PROGRAMMING_LANGUAGES.NO_CONTAINERS]: `${BASE_URL}default.svg`, // TODO: good icon
[WORKLOAD_PROGRAMMING_LANGUAGES.NO_RUNNING_PODS]: `${BASE_URL}default.svg`, // TODO: good icon
};

export const LANGUAGES_COLORS: Record<WORKLOAD_PROGRAMMING_LANGUAGES, string> =
Expand All @@ -37,17 +41,24 @@ export const LANGUAGES_COLORS: Record<WORKLOAD_PROGRAMMING_LANGUAGES, string> =
[WORKLOAD_PROGRAMMING_LANGUAGES.MYSQL]: '#00758F',
[WORKLOAD_PROGRAMMING_LANGUAGES.UNKNOWN]: '#8b92a6',
[WORKLOAD_PROGRAMMING_LANGUAGES.PROCESSING]: '#3367d9',
[WORKLOAD_PROGRAMMING_LANGUAGES.NO_CONTAINERS]: '#000000',
[WORKLOAD_PROGRAMMING_LANGUAGES.NO_CONTAINERS]: '#111111',
[WORKLOAD_PROGRAMMING_LANGUAGES.NO_RUNNING_PODS]: '#666666',
};

export const getMainContainerLanguage = (
languages:
| Array<{
container_name: string;
language: string;
}>
| undefined
source: ManagedSource
): WORKLOAD_PROGRAMMING_LANGUAGES => {

const ia = source?.instrumented_application_details;
if(!ia) {
if(source?.number_of_running_instances > 0) {
return WORKLOAD_PROGRAMMING_LANGUAGES.PROCESSING;
} else {
return WORKLOAD_PROGRAMMING_LANGUAGES.NO_RUNNING_PODS;
}
}

const { languages } = ia;
if (!languages) {
return WORKLOAD_PROGRAMMING_LANGUAGES.PROCESSING;
}
Expand Down

0 comments on commit 98dd8ba

Please sign in to comment.