Skip to content

Commit

Permalink
🐛 Fixed issue with observability
Browse files Browse the repository at this point in the history
  • Loading branch information
abdheshnayak committed Feb 14, 2024
1 parent 1271f7c commit c0593b3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/client/helpers/socket/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { socketUrl } from '~/root/lib/configs/base-url.cjs';

type IFor = 'logs' | 'resource-update';

interface ISocketResp<T = any> {
export interface ISocketResp<T = any> {
type: 'response' | 'error' | 'info';
for: IFor;
message: string;
Expand Down
22 changes: 20 additions & 2 deletions lib/client/helpers/socket/useSockLogs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { useSubscribe } from './context';
import { dayjs } from '~/components/molecule/dayjs';
import { ISocketResp, useSubscribe } from './context';

interface IuseLog {
account: string;
Expand All @@ -8,6 +9,7 @@ interface IuseLog {
}

export const useSocketLogs = ({ account, cluster, trackingId }: IuseLog) => {
const [logs, setLogs] = useState<ISocketResp<IuseLog>[]>([]);
const { responses, subscribed, errors } = useSubscribe(
{
for: 'logs',
Expand All @@ -33,8 +35,24 @@ export const useSocketLogs = ({ account, cluster, trackingId }: IuseLog) => {
}
}, []);

useEffect(() => {
const sorted = responses.sort((a, b) => {
const resp = b.data.podName.localeCompare(a.data.podName);

if (resp === 0) {
return dayjs(a.data.timestamp).unix() - dayjs(b.data.timestamp).unix();
}

return resp;
});

if (JSON.stringify(sorted) !== JSON.stringify(logs)) {
setLogs(sorted);
}
}, [responses]);

return {
logs: responses,
logs,
errors,
isLoading,
subscribed,
Expand Down
2 changes: 2 additions & 0 deletions lib/configs/base-url.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const baseUrls = () => {
baseUrl: bUrl,
githubAppName: 'kloudlite-dev',
socketUrl: `wss://websocket.${bUrl}`,
observeUrl: `https://observe.${bUrl}`,
};
};

Expand All @@ -99,6 +100,7 @@ const defaultConfig = {
githubAppName: baseUrls().githubAppName,
socketUrl: baseUrls().socketUrl,
registryHost: baseUrls().registryHost,
observeUrl: baseUrls().observeUrl,
getServerEnv,
getClientEnv,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { parseName } from '~/console/server/r-utils/common';
import { Clock, ListNumbers } from '@jengaicons/react';
import { cn } from '~/components/utils';
import { useDataState } from '~/console/page-components/common-state';
import { observeUrl } from '~/root/lib/configs/base-url.cjs';
import { IAppContext } from '../_layout';

const LogsAndMetrics = () => {
Expand All @@ -31,7 +32,7 @@ const LogsAndMetrics = () => {
(async () => {
try {
const resp = await axios({
url: `https://observe.dev.kloudlite.io/observability/metrics/cpu?cluster_name=${project.clusterName}&tracking_id=${app.id}`,
url: `${observeUrl}/observability/metrics/cpu?cluster_name=${project.clusterName}&tracking_id=${app.id}`,
method: 'GET',
withCredentials: true,
});
Expand All @@ -44,7 +45,7 @@ const LogsAndMetrics = () => {
(async () => {
try {
const resp = await axios({
url: `https://observe.dev.kloudlite.io/observability/metrics/memory?cluster_name=${project.clusterName}&tracking_id=${app.id}`,
url: `${observeUrl}/observability/metrics/memory?cluster_name=${project.clusterName}&tracking_id=${app.id}`,
method: 'GET',
withCredentials: true,
});
Expand Down

0 comments on commit c0593b3

Please sign in to comment.