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

[GEN-1729]: add "describe source" to UI #1982

Merged
merged 11 commits into from
Dec 15, 2024
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
1 change: 1 addition & 0 deletions frontend/webapp/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Kode+Mono:wght@100;200;300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Inter+Tight:wght@400;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&display=swap');

* {
scrollbar-color: black transparent;
Expand Down
2 changes: 1 addition & 1 deletion frontend/webapp/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export default function RootLayout({ children }: { children: React.ReactNode })
return (
<html lang='en'>
<head>
<title>{METADATA.title}</title>
<meta name='description' content={METADATA.title} />
<link rel='icon' type='image/svg+xml' href={`/${METADATA.icons}`} />
<link rel='icon' type='image/x-icon' href='/favicon.ico' />
<link rel='icon' type='image/png' sizes='16x16' href='/favicon-16x16.png' />
<link rel='icon' type='image/png' sizes='32x32' href='/favicon-32x32.png' />
<link rel='apple-touch-icon' sizes='180x180' href='/apple-touch-icon.png' />
<link rel='manifest' href='/manifest.json' />
<title>{METADATA.title}</title>
</head>
<ApolloWrapper>
<ThemeProviderWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useEffect, useMemo, useState } from 'react';
import buildCard from './build-card';
import styled from 'styled-components';
import { useSourceCRUD } from '@/hooks';
import { useDrawerStore } from '@/store';
import buildDrawerItem from './build-drawer-item';
import { UpdateSourceBody } from '../update-source-body';
import { useDescribeSource, useSourceCRUD } from '@/hooks';
import OverviewDrawer from '../../overview/overview-drawer';
import { OVERVIEW_ENTITY_TYPES, type WorkloadId, type K8sActualSource } from '@/types';
import { ACTION, DATA_CARDS, getMainContainerLanguage, getProgrammingLanguageIcon } from '@/utils';
import { ConditionDetails, DataCard, DataCardRow, DataCardFieldTypes } from '@/reuseable-components';
import { ACTION, DATA_CARDS, getMainContainerLanguage, getProgrammingLanguageIcon, safeJsonStringify } from '@/utils';

interface Props {}

Expand Down Expand Up @@ -93,6 +93,7 @@ export const SourceDrawer: React.FC<Props> = () => {

if (!selectedItem?.item) return null;
const { id, item } = selectedItem as { id: WorkloadId; item: K8sActualSource };
const { data: describe } = useDescribeSource(id);

const handleEdit = (bool?: boolean) => {
setIsEditing(typeof bool === 'boolean' ? bool : true);
Expand Down Expand Up @@ -141,6 +142,15 @@ export const SourceDrawer: React.FC<Props> = () => {
<ConditionDetails conditions={item.instrumentedApplicationDetails.conditions} />
<DataCard title={DATA_CARDS.SOURCE_DETAILS} data={cardData} />
<DataCard title={DATA_CARDS.DETECTED_CONTAINERS} titleBadge={containersData.length} description={DATA_CARDS.DETECTED_CONTAINERS_DESCRIPTION} data={containersData} />
<DataCard
title={DATA_CARDS.DESCRIBE_SOURCE}
data={[
{
type: DataCardFieldTypes.CODE,
value: JSON.stringify({ language: 'json', code: safeJsonStringify(describe) }),
alonkeyval marked this conversation as resolved.
Show resolved Hide resolved
},
]}
/>
</DataContainer>
)}
</OverviewDrawer>
Expand Down
224 changes: 224 additions & 0 deletions frontend/webapp/graphql/queries/describe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
import { gql } from '@apollo/client';

export const DESCRIBE_SOURCE = gql`
query DescribeSource($namespace: String!, $kind: String!, $name: String!) {
describeSource(namespace: $namespace, kind: $kind, name: $name) {
name {
name
value
status
explain
}
kind {
name
value
status
explain
}
namespace {
name
value
status
explain
}
labels {
instrumented {
name
value
status
explain
}
workload {
name
value
status
explain
}
namespace {
name
value
status
explain
}
instrumentedText {
name
value
status
explain
}
}
instrumentationConfig {
created {
name
value
status
explain
}
createTime {
name
value
status
explain
}
}
runtimeInfo {
generation {
name
value
status
explain
}
containers {
containerName {
name
value
status
explain
}
language {
name
value
status
explain
}
runtimeVersion {
name
value
status
explain
}
envVars {
name
value
status
explain
}
}
}
instrumentedApplication {
created {
name
value
status
explain
}
createTime {
name
value
status
explain
}
containers {
containerName {
name
value
status
explain
}
language {
name
value
status
explain
}
runtimeVersion {
name
value
status
explain
}
envVars {
name
value
status
explain
}
}
}
instrumentationDevice {
statusText {
name
value
status
explain
}
containers {
containerName {
name
value
status
explain
}
devices {
name
value
status
explain
}
originalEnv {
name
value
status
explain
}
}
}
totalPods
podsPhasesCount
pods {
podName {
name
value
status
explain
}
nodeName {
name
value
status
explain
}
phase {
name
value
status
explain
}
containers {
containerName {
name
value
status
explain
}
actualDevices {
name
value
status
explain
}
instrumentationInstances {
healthy {
name
value
status
explain
}
message {
name
value
status
explain
}
identifyingAttributes {
name
value
status
explain
}
}
}
}
}
}
`;
1 change: 1 addition & 0 deletions frontend/webapp/graphql/queries/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './config';
export * from './compute-platform';
export * from './describe';
export * from './destination';
1 change: 1 addition & 0 deletions frontend/webapp/hooks/describe/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useDescribeSource';
16 changes: 16 additions & 0 deletions frontend/webapp/hooks/describe/useDescribeSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useQuery } from '@apollo/client';
import { DESCRIBE_SOURCE } from '@/graphql';
import type { DescribeSource, WorkloadId } from '@/types';

export const useDescribeSource = ({ namespace, name, kind }: WorkloadId) => {
const { data, loading, error } = useQuery<DescribeSource>(DESCRIBE_SOURCE, {
variables: { namespace, name, kind },
pollInterval: 5000,
});

return {
data: data?.describeSource,
loading,
error,
};
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export * from './actions';
export * from './common';
export * from './compute-platform';
export * from './config';
export * from './sources';
export * from './actions';
export * from './overview';
export * from './notification';
export * from './describe';
export * from './destinations';
export * from './compute-platform';
export * from './instrumentation-rules';
export * from './notification';
export * from './overview';
export * from './sources';
1 change: 1 addition & 0 deletions frontend/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"graphql": "^16.9.0",
"javascript-time-ago": "^2.5.11",
"next": "15.0.3",
"prism-react-renderer": "^2.4.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-flow-renderer": "^10.3.17",
Expand Down
37 changes: 37 additions & 0 deletions frontend/webapp/reuseable-components/code/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import styled from 'styled-components';
import { Highlight, themes as prismThemes } from 'prism-react-renderer';
import { flattenObjectKeys, safeJsonParse, safeJsonStringify } from '@/utils';

interface Props {
language: string;
code: string;
flatten?: boolean;
}

const Token = styled.span`
white-space: pre-wrap;
overflow-wrap: break-word;
opacity: 0.75;
font-size: 12px;
font-family: ${({ theme }) => theme.font_family.code};
`;

export const Code: React.FC<Props> = ({ language, code, flatten }) => {
const str = flatten && language === 'json' ? safeJsonStringify(flattenObjectKeys(safeJsonParse(code, {}))) : code;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move this outside of the component o make it more ruseable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the place to make it re-usable, placing it outside would then require copy-pasting of this logic throughout other files.


return (
<Highlight theme={prismThemes.palenight} language={language} code={str}>
{({ getLineProps, getTokenProps, tokens }) => (
<pre>
{tokens.map((line, i) => (
<div key={`line-${i}`} {...getLineProps({ line })}>
{line.map((token, ii) => (
<Token key={`line-${i}-token-${ii}`} {...getTokenProps({ token })} />
))}
</div>
))}
</pre>
)}
</Highlight>
);
};
Loading
Loading