INFRA-3746 | Abhishek | Ensure heap dump steps are based on language of the service
This commit is contained in:
@@ -10,18 +10,13 @@ import CpuIcon from '../assets/images/CpuIcon.svg';
|
||||
import { DiagnosticType } from './utils';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { Alert } from '@material-ui/lab';
|
||||
import { languageFeatureMap } from './useDiagnosticMapping';
|
||||
interface Button {
|
||||
id: DiagnosticType;
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
}
|
||||
|
||||
const languageFeatureMap = {
|
||||
Golang: [DiagnosticType.HeapDump, DiagnosticType.CpuProfile],
|
||||
Java: [DiagnosticType.HeapDump, DiagnosticType.ThreadDump, DiagnosticType.CpuProfile],
|
||||
Kotlin: [DiagnosticType.HeapDump, DiagnosticType.ThreadDump, DiagnosticType.CpuProfile],
|
||||
};
|
||||
|
||||
const buttons: Button[] = [
|
||||
{
|
||||
id: DiagnosticType.HeapDump,
|
||||
|
||||
@@ -81,7 +81,7 @@ const GenerateDiagnostic: React.FC<GenerateDiagnosticProps> = (props: GenerateDi
|
||||
</Button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
{currentStep >= 0 && <Step />}
|
||||
{currentStep >= 0 && <Step language={language} />}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -32,10 +32,14 @@ import {
|
||||
import './GenerateDump.module.css';
|
||||
import useDiagnosticMapping from './useDiagnosticMapping';
|
||||
|
||||
interface StepProps {
|
||||
language: string;
|
||||
}
|
||||
|
||||
const createDumpEndpoint: string = `/api/diagnostic`;
|
||||
const Step: React.FC = () => {
|
||||
const Step = (props: StepProps) => {
|
||||
const state: Diagnostic = useSelector((state: RootState) => state?.diagnostic);
|
||||
const diagnosticMapping = useDiagnosticMapping();
|
||||
const diagnosticMapping = useDiagnosticMapping(props.language);
|
||||
const currentDiag = diagnosticMapping?.[state?.diagnosticType] ?? {};
|
||||
const { currentStep, title, content } = currentDiag?.[state?.currentStep] ?? {};
|
||||
const dispatch = useDispatch();
|
||||
|
||||
@@ -13,7 +13,14 @@ interface DiagnosticData {
|
||||
steps: React.JSX.Element[];
|
||||
};
|
||||
}
|
||||
const useDiagnosticMapping = () => {
|
||||
|
||||
export const languageFeatureMap = {
|
||||
Golang: [DiagnosticType.HeapDump, DiagnosticType.CpuProfile],
|
||||
Java: [DiagnosticType.HeapDump, DiagnosticType.ThreadDump, DiagnosticType.CpuProfile],
|
||||
Kotlin: [DiagnosticType.HeapDump, DiagnosticType.ThreadDump, DiagnosticType.CpuProfile],
|
||||
};
|
||||
|
||||
const useDiagnosticMapping = (language: string) => {
|
||||
const [diagnosticMapping, setDiagnosticMapping] = useState({});
|
||||
const defaultDiagnosticStep = [<DefaultDiagnostic />];
|
||||
const threadDumpSteps: React.JSX.Element[] = [
|
||||
@@ -24,42 +31,57 @@ const useDiagnosticMapping = () => {
|
||||
...defaultDiagnosticStep,
|
||||
<CpuProfilePodsSelection />,
|
||||
];
|
||||
const heapDumpSteps: React.JSX.Element[] = [
|
||||
...defaultDiagnosticStep,
|
||||
<HeapDumpTypeSelection />,
|
||||
<HeapDumpPodsSelection />,
|
||||
];
|
||||
|
||||
const heapDumpSteps = (language: string) => {
|
||||
const steps = {
|
||||
Java: [...defaultDiagnosticStep, <HeapDumpTypeSelection />, <HeapDumpPodsSelection />],
|
||||
Kotlin: [...defaultDiagnosticStep, <HeapDumpTypeSelection />, <HeapDumpPodsSelection />],
|
||||
Golang: [...defaultDiagnosticStep, <HeapDumpPodsSelection />],
|
||||
};
|
||||
return steps[language];
|
||||
};
|
||||
|
||||
const defaultTitles: string[] = ['Select Diagnostic Type'];
|
||||
const heapDumpTitles: string[] = [...defaultTitles, 'Select Heap Dump Type', 'Select Pods'];
|
||||
const threadDumpTitles: string[] = [...defaultTitles, 'Select Pods'];
|
||||
const cpuProfileTitles: string[] = [...defaultTitles, 'Select Pods'];
|
||||
const heapDumpTitles = (language): string[] => {
|
||||
const titles = {
|
||||
Java: [...defaultTitles, 'Select Heap Dump Type', 'Select Pods'],
|
||||
Kotlin: [...defaultTitles, 'Select Heap Dump Type', 'Select Pods'],
|
||||
Golang: [...defaultTitles, 'Select Pods'],
|
||||
};
|
||||
return titles[language];
|
||||
};
|
||||
|
||||
const diagnosticData: DiagnosticData = {
|
||||
[DiagnosticType.Default]: {
|
||||
title: defaultTitles,
|
||||
steps: defaultDiagnosticStep,
|
||||
},
|
||||
[DiagnosticType.HeapDump]: {
|
||||
title: heapDumpTitles,
|
||||
steps: heapDumpSteps,
|
||||
},
|
||||
[DiagnosticType.ThreadDump]: {
|
||||
title: threadDumpTitles,
|
||||
steps: threadDumpSteps,
|
||||
},
|
||||
[DiagnosticType.CpuProfile]: {
|
||||
title: cpuProfileTitles,
|
||||
steps: cpuProfileSteps,
|
||||
},
|
||||
const diagnosticData = (language: string) => {
|
||||
return {
|
||||
[DiagnosticType.Default]: {
|
||||
title: defaultTitles,
|
||||
steps: defaultDiagnosticStep,
|
||||
},
|
||||
[DiagnosticType.HeapDump]: {
|
||||
title: heapDumpTitles(language),
|
||||
steps: heapDumpSteps(language),
|
||||
},
|
||||
[DiagnosticType.ThreadDump]: {
|
||||
title: threadDumpTitles,
|
||||
steps: threadDumpSteps,
|
||||
},
|
||||
[DiagnosticType.CpuProfile]: {
|
||||
title: cpuProfileTitles,
|
||||
steps: cpuProfileSteps,
|
||||
},
|
||||
};
|
||||
};
|
||||
useEffect(() => {
|
||||
const mapping = generateMapping(diagnosticData);
|
||||
const mapping = generateMapping(diagnosticData(language));
|
||||
setDiagnosticMapping(mapping);
|
||||
}, []);
|
||||
|
||||
return diagnosticMapping;
|
||||
};
|
||||
const generateMapping = (diagnosticData: DiagnosticData) => {
|
||||
const generateMapping = diagnosticData => {
|
||||
console.log(diagnosticData);
|
||||
return Object.keys(diagnosticData).reduce((acc, type) => {
|
||||
const { title, steps } = diagnosticData[type];
|
||||
acc[type] = title.map((title, index) => ({
|
||||
|
||||
Reference in New Issue
Block a user