Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes order of source string, adds support for pods wildcard source #93

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"react-day-picker": "^8.10.1",
"react-dom": "^18.3.1",
"react-hot-toast": "^2.4.1",
"react-router-dom": "^6.23.0",
"react-timeago": "^7.2.0",
"react-virtualized-auto-sizer": "^1.0.24",
"react-window": "^1.8.10",
Expand Down Expand Up @@ -69,6 +68,7 @@
"history": "^5.3.0",
"jsdom": "^24.0.0",
"postcss": "^8.4.38",
"react-router-dom": "^6.23.1",
"rollup-plugin-visualizer": "^5.12.0",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
Expand Down
38 changes: 19 additions & 19 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 53 additions & 39 deletions frontend/src/lib/console/logging-resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export type Node = ExtractQueryType<typeof fragments.CONSOLE_NODES_LIST_ITEM_FRA
export type Workload = ExtractQueryType<typeof fragments.CONSOLE_LOGGING_RESOURCES_GENERIC_OBJECT_FRAGMENT>;
export type Pod = ExtractQueryType<typeof fragments.CONSOLE_LOGGING_RESOURCES_POD_FRAGMENT>;

type LoadWorkloadProps = {
namespace: string;
name: string;
sourcePath: string;
};

class WorkloadResponse {
loading: boolean = false;

Expand Down Expand Up @@ -182,16 +188,13 @@ const LoadPodsForLabels = ({
* Fetch a CronJob workload and associated streams
*/

const LoadCronJobWorkload = ({ sourcePath }: { sourcePath: string }) => {
const parts = sourcePath.split('/');
const [namespace, name] = [parts[1], parts[2]];

const LoadCronJobWorkload = ({ namespace, name, sourcePath }: LoadWorkloadProps) => {
const { loading, error, data } = useGetQueryWithSubscription({
query: ops.CONSOLE_LOGGING_RESOURCES_CRONJOB_GET,
subscription: ops.CONSOLE_LOGGING_RESOURCES_CRONJOB_WATCH,
queryDataKey: 'batchV1CronJobsGet',
subscriptionDataKey: 'batchV1CronJobsWatch',
skip: parts.length < 2,
skip: (!namespace || !name),
variables: { namespace, name },
});

Expand Down Expand Up @@ -234,14 +237,11 @@ const LoadCronJobWorkload = ({ sourcePath }: { sourcePath: string }) => {
* Fetch a DaemonSet workload and associated streams
*/

const LoadDaemonSetWorkload = ({ sourcePath }: { sourcePath: string }) => {
const parts = sourcePath.split('/');
const [namespace, name] = [parts[1], parts[2]];

const LoadDaemonSetWorkload = ({ namespace, name, sourcePath }: LoadWorkloadProps) => {
const { loading, error, data } = useGetQueryWithSubscription({
query: ops.CONSOLE_LOGGING_RESOURCES_DAEMONSET_GET,
subscription: ops.CONSOLE_LOGGING_RESOURCES_DAEMONSET_WATCH,
skip: parts.length < 2,
skip: (!namespace || !name),
variables: { namespace, name },
queryDataKey: 'appsV1DaemonSetsGet',
subscriptionDataKey: 'appsV1DaemonSetsWatch',
Expand All @@ -268,14 +268,11 @@ const LoadDaemonSetWorkload = ({ sourcePath }: { sourcePath: string }) => {
* Fetch a Deployment workload and associated streams
*/

const LoadDeploymentWorkload = ({ sourcePath }: { sourcePath: string }) => {
const parts = sourcePath.split('/');
const [namespace, name] = [parts[1], parts[2]];

const LoadDeploymentWorkload = ({ namespace, name, sourcePath }: LoadWorkloadProps) => {
const { loading, error, data } = useGetQueryWithSubscription({
query: ops.CONSOLE_LOGGING_RESOURCES_DEPLOYMENT_GET,
subscription: ops.CONSOLE_LOGGING_RESOURCES_DEPLOYMENT_WATCH,
skip: parts.length < 2,
skip: (!namespace || !name),
variables: { namespace, name },
queryDataKey: 'appsV1DeploymentsGet',
subscriptionDataKey: 'appsV1DeploymentsWatch',
Expand All @@ -302,14 +299,11 @@ const LoadDeploymentWorkload = ({ sourcePath }: { sourcePath: string }) => {
* Fetch a Job workload and associated streams
*/

const LoadJobWorkload = ({ sourcePath }: { sourcePath: string }) => {
const parts = sourcePath.split('/');
const [namespace, name] = [parts[1], parts[2]];

const LoadJobWorkload = ({ namespace, name, sourcePath }: LoadWorkloadProps) => {
const { loading, error, data } = useGetQueryWithSubscription({
query: ops.CONSOLE_LOGGING_RESOURCES_JOB_GET,
subscription: ops.CONSOLE_LOGGING_RESOURCES_JOB_WATCH,
skip: parts.length < 2,
skip: (!namespace || !name),
variables: { namespace, name },
queryDataKey: 'batchV1JobsGet',
subscriptionDataKey: 'batchV1JobsWatch',
Expand All @@ -336,14 +330,11 @@ const LoadJobWorkload = ({ sourcePath }: { sourcePath: string }) => {
* Fetch a Pod workload and associated streams
*/

const LoadPodWorkload = ({ sourcePath }: { sourcePath: string }) => {
const parts = sourcePath.split('/');
const [namespace, name] = [parts[1], parts[2]];

const LoadPodWorkload = ({ namespace, name, sourcePath }: LoadWorkloadProps) => {
const { loading, error, data } = useGetQueryWithSubscription({
query: ops.CONSOLE_LOGGING_RESOURCES_POD_GET,
subscription: ops.CONSOLE_LOGGING_RESOURCES_POD_WATCH,
skip: parts.length < 3,
skip: (!namespace || !name),
variables: { namespace, name },
queryDataKey: 'coreV1PodsGet',
subscriptionDataKey: 'coreV1PodsWatch',
Expand All @@ -370,14 +361,11 @@ const LoadPodWorkload = ({ sourcePath }: { sourcePath: string }) => {
* Fetch a ReplicaSet workload and associated streams
*/

const LoadReplicaSetWorkload = ({ sourcePath }: { sourcePath: string }) => {
const parts = sourcePath.split('/');
const [namespace, name] = [parts[1], parts[2]];

const LoadReplicaSetWorkload = ({ namespace, name, sourcePath }: LoadWorkloadProps) => {
const { loading, error, data } = useGetQueryWithSubscription({
query: ops.CONSOLE_LOGGING_RESOURCES_REPLICASET_GET,
subscription: ops.CONSOLE_LOGGING_RESOURCES_REPLICASET_WATCH,
skip: parts.length < 2,
skip: (!namespace || !name),
variables: { namespace, name },
queryDataKey: 'appsV1ReplicaSetsGet',
subscriptionDataKey: 'appsV1ReplicaSetsWatch',
Expand All @@ -404,14 +392,11 @@ const LoadReplicaSetWorkload = ({ sourcePath }: { sourcePath: string }) => {
* Fetch a StatefulSet workload and associated streams
*/

const LoadStatefulSetWorkload = ({ sourcePath }: { sourcePath: string }) => {
const parts = sourcePath.split('/');
const [namespace, name] = [parts[1], parts[2]];

const LoadStatefulSetWorkload = ({ namespace, name, sourcePath }: LoadWorkloadProps) => {
const { loading, error, data } = useGetQueryWithSubscription({
query: ops.CONSOLE_LOGGING_RESOURCES_STATEFULSET_GET,
subscription: ops.CONSOLE_LOGGING_RESOURCES_STATEFULSET_WATCH,
skip: parts.length < 2,
skip: (!namespace || !name),
variables: { namespace, name },
queryDataKey: 'appsV1StatefulSetsGet',
subscriptionDataKey: 'appsV1StatefulSetsWatch',
Expand All @@ -434,6 +419,32 @@ const LoadStatefulSetWorkload = ({ sourcePath }: { sourcePath: string }) => {
);
};

/**
* Fetch all pods and associated streams for a given namespace
*/

const LoadPodWorkloadWildcard = ({ namespace, sourcePath }: { namespace: string; sourcePath: string; }) => {
const { loading, error, data } = useListQueryWithSubscription({
query: ops.CONSOLE_LOGGING_RESOURCES_PODS_LIST_FETCH,
subscription: ops.CONSOLE_LOGGING_RESOURCES_PODS_LIST_WATCH,
skip: !namespace,
variables: { namespace },
queryDataKey: 'coreV1PodsList',
subscriptionDataKey: 'coreV1PodsWatch',
});

const [sourceToPodListResponseMap, setSourceToPodListResponseMap] = useRecoilState(sourceToPodListResponseMapState);

useEffect(() => {
const items = data?.coreV1PodsList?.items;
const newMap = new Map(sourceToPodListResponseMap);
newMap.set(sourcePath, { loading, error, items });
setSourceToPodListResponseMap(newMap);
}, [loading, error, data]);

return null;
};

/**
* Source deletion handler component
*/
Expand Down Expand Up @@ -490,10 +501,13 @@ export const LoggingResourcesProvider = ({ sourcePaths, children }: LoggingResou
<RecoilRoot>
<SourceDeletionHandler sourcePaths={sourcePathsSorted} />
{sourcePathsSorted.map((path) => {
const parts = path.split('/');
if (!(parts[0] in resourceLoaders)) throw new Error(`not implemented: ${parts[0]}`);
const Component = resourceLoaders[parts[0] as WorkloadType];
return <Component key={path} sourcePath={path} />;
const [namespace, workloadType, workloadName] = path.split('/');
if (workloadType === WorkloadType.PODS && workloadName === '*') {
return <LoadPodWorkloadWildcard key={path} namespace={namespace} sourcePath={path} />;
}
if (!(workloadType in resourceLoaders)) throw new Error(`not implemented: ${workloadType}`);
const Component = resourceLoaders[workloadType as WorkloadType];
return <Component key={path} namespace={namespace} name={workloadName} sourcePath={path} />;
})}
{children}
</RecoilRoot>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/lib/graphql/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading