Skip to content

Commit

Permalink
Merge branch 'release-v1.0.2' into features/console
Browse files Browse the repository at this point in the history
Signed-off-by: Bikash <[email protected]>
  • Loading branch information
tulsiojha authored Feb 14, 2024
2 parents ed7e7d6 + cecf0b9 commit 3680f38
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 29 deletions.
12 changes: 12 additions & 0 deletions lib/client/components/logger/dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const logsMockData = [
'nnQhCA0QTSuukrRA',
'0dlRACNaaPWkx3hBmZNksKoR',
'9BLDLfyAHeCTjoUgLshkJ9eWpqfUkLEf',
'TaJLEEhzWZvd6wt74fWe9oH9G7rhuzRO0ZZDFH49',
'o2Znr1VqxwlnFcyOe8S78z1HXrwIUcrnGdpXoEj2smsD6d',
'5EIOShSO5vqfRojDxuRzdr0S5ILjQ65TuMEm7o6Q75maqJqKCnAj9L',
'wfS7vAAvVY5BGhku2HE9Xnc7tF8wjH913u0i0f2JbOvXuvibfsFtbYnzC9ghk',
'eBfcNEUnIcTDceQGc3jAoZdOno977hMQ5Hfd8LNrrnm9ZVnZpQyMl5Hf3FbTqthhIMdvzs',
'jInteYIHeEBT7ZMKnNUbACPPs7YAUdnzegotEOzWkexdT1reZbzASBkb0LCx4k048gj2kUznyRvea45',
'SQpMBRSCEvC2EWIq2eQ21ljhQkx7hi3t9WNgMpLI0vuaeaUTTcIDXYPqorSJUiGmvQ9R1uQ0x9O0z0fVCNvGYehoaAEYp',
];
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ import Anser from 'anser';
import classNames from 'classnames';
import Fuse from 'fuse.js';
import hljs from 'highlight.js';
import React, { ReactNode, memo, useEffect, useRef, useState } from 'react';
import React, {
ReactNode,
createContext,
memo,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { ViewportList } from 'react-viewport-list';
import { dayjs } from '~/components/molecule/dayjs';
import {
Expand All @@ -14,9 +23,38 @@ import {
} from '~/root/lib/client/helpers/search-filter';
import useClass from '~/root/lib/client/hooks/use-class';
import { useSocketLogs } from '~/root/lib/client/helpers/socket/useSockLogs';
import { generatePlainColor } from '../color-generator';
import Pulsable from '../pulsable';
import { logsMockData } from '../../dummy/data';
import { generatePlainColor } from '~/root/lib/utils/color-generator';

import ReactPulsable from 'react-pulsable';
import { ChildrenProps } from '~/components/types';
import { logsMockData } from './dummy';

const pulsableContext = createContext(false);

export const usePulsableLoading = () => {
return useContext(pulsableContext);
};

const Pulsable = ({
children,
isLoading,
}: ChildrenProps & { isLoading: boolean }) => {
return (
<pulsableContext.Provider value={useMemo(() => isLoading, [isLoading])}>
<ReactPulsable
config={{
bgColors: {
light: 'rgba(161, 161, 170, 0.2)',
medium: 'rgba(161, 161, 170, 0.3)',
},
}}
isLoading={isLoading}
>
{children}
</ReactPulsable>
</pulsableContext.Provider>
);
};

export type ILog = {
podName: string;
Expand Down Expand Up @@ -694,7 +732,7 @@ const LogComp = ({
</div>
<div className="flex flex-col items-center justify-center flex-1">
<div className="headingMd">
No logs produced in the last 3 hours.
(only last 3 hours logs) fetching logs...
</div>
</div>
</div>
Expand Down
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
23 changes: 21 additions & 2 deletions lib/client/helpers/socket/useSockLogs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useEffect, useState } from 'react';
import { useSubscribe } from './context';
import { dayjs } from '~/components/molecule/dayjs';
import { ISocketResp, useSubscribe } from './context';
import { ILog } from '../../components/logger';

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

export const useSocketLogs = ({ account, cluster, trackingId }: IuseLog) => {
const [logs, setLogs] = useState<ISocketResp<ILog>[]>([]);
const { responses, subscribed, errors } = useSubscribe(
{
for: 'logs',
Expand All @@ -33,8 +36,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
File renamed without changes.
2 changes: 1 addition & 1 deletion src/apps/console/components/console-avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Avatar } from '~/components/atoms/avatar';
import { titleCase } from '~/components/utils';
import generateColor from './color-generator';
import generateColor from '~/root/lib/utils/color-generator';

const ConsoleAvatar = ({
name,
Expand Down
13 changes: 0 additions & 13 deletions src/apps/console/dummy/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,16 +720,3 @@ export const dummyData = {
},
],
};

export const logsMockData = [
'nnQhCA0QTSuukrRA',
'0dlRACNaaPWkx3hBmZNksKoR',
'9BLDLfyAHeCTjoUgLshkJ9eWpqfUkLEf',
'TaJLEEhzWZvd6wt74fWe9oH9G7rhuzRO0ZZDFH49',
'o2Znr1VqxwlnFcyOe8S78z1HXrwIUcrnGdpXoEj2smsD6d',
'5EIOShSO5vqfRojDxuRzdr0S5ILjQ65TuMEm7o6Q75maqJqKCnAj9L',
'wfS7vAAvVY5BGhku2HE9Xnc7tF8wjH913u0i0f2JbOvXuvibfsFtbYnzC9ghk',
'eBfcNEUnIcTDceQGc3jAoZdOno977hMQ5Hfd8LNrrnm9ZVnZpQyMl5Hf3FbTqthhIMdvzs',
'jInteYIHeEBT7ZMKnNUbACPPs7YAUdnzegotEOzWkexdT1reZbzASBkb0LCx4k048gj2kUznyRvea45',
'SQpMBRSCEvC2EWIq2eQ21ljhQkx7hi3t9WNgMpLI0vuaeaUTTcIDXYPqorSJUiGmvQ9R1uQ0x9O0z0fVCNvGYehoaAEYp',
];
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { useState } from 'react';
import { dayjs } from '~/components/molecule/dayjs';
import { parseValue } from '~/console/page-components/util';
import { ApexOptions } from 'apexcharts';
import LogComp from '~/console/components/logger';
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';
import LogComp from '~/root/lib/client/components/logger';

const LogsAndMetrics = () => {
const { app, project, account } = useOutletContext<IAppContext>();
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { Link, useOutletContext } from '@remix-run/react';
import { IStatus, listRender } from '~/console/components/commons';
import { listStatus } from '~/console/components/sync-status';
import AnimateHide from '~/components/atoms/animate-hide';
import LogComp from '~/console/components/logger';
import { ISetState } from '~/console/page-components/app-states';
import { Button } from '~/components/atoms/button';
import { dayjs } from '~/components/molecule/dayjs';
Expand All @@ -39,6 +38,7 @@ import {
findNodePlanWithSpec,
} from './nodepool-utils';
import { IAccountContext } from '../../../_layout';
import LogComp from '~/root/lib/client/components/logger';

const RESOURCE_NAME = 'nodepool';
type BaseType = ExtractNodeType<INodepools>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
parseUpdateOrCreatedBy,
parseUpdateOrCreatedOn,
} from '~/console/server/r-utils/common';
import LogComp from '~/console/components/logger';
import { renderCloudProvider } from '~/console/utils/commons';
import { CommonTabs } from '~/console/components/common-navbar-tabs';
import { DetailItem } from '~/console/components/commons';
import { INodepool } from '~/console/server/gql/queries/nodepool-queries';
import { IAccountContext } from '../../../_layout';
import LogComp from '~/root/lib/client/components/logger';

const ClusterTabs = () => {
const { account, cluster } = useParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import Chart from '~/console/components/charts/charts-client';
import { useState } from 'react';
import { dayjs } from '~/components/molecule/dayjs';
import { ApexOptions } from 'apexcharts';
import LogComp from '~/console/components/logger';
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 { IClusterContext } from '../../_layout';
import LogComp from '~/root/lib/client/components/logger';

const LogsAndMetrics = () => {
const { cluster, account } = useOutletContext<IClusterContext>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { useOutletContext } from '@remix-run/react';
import { IBuildRuns } from '~/console/server/gql/queries/build-run-queries';
import AnimateHide from '~/components/atoms/animate-hide';
import LogComp from '~/console/components/logger';
import { Button } from '~/components/atoms/button';
import {
CheckCircleFill,
Expand All @@ -27,6 +26,7 @@ import {
} from '@jengaicons/react';
import dayjs from 'dayjs';
import { IAccountContext } from '../../../_layout';
import LogComp from '~/root/lib/client/components/logger';

const RESOURCE_NAME = 'build run';
type BaseType = ExtractNodeType<IBuildRuns>;
Expand Down

0 comments on commit 3680f38

Please sign in to comment.