import { Field, useFormikContext } from 'formik'; import { useState } from 'react'; import { CheckCircle, XCircle } from 'lucide-react'; import { useGetMetricsMutation } from '@/react/kubernetes/queries/useGetMetricsMutation'; import { TextTip } from '@@/Tip/TextTip'; import { FormControl } from '@@/form-components/FormControl'; import { Switch } from '@@/form-components/SwitchField/Switch'; import { InlineLoader } from '@@/InlineLoader'; import { ConfigureFormValues } from './types'; type Props = { environmentId: number; value: boolean; error?: string; }; export function EnableMetricsInput({ value, error, environmentId }: Props) { const { setFieldValue } = useFormikContext(); const [metricsFound, setMetricsFound] = useState(); const getMetricsMutation = useGetMetricsMutation(); return (

Enabling this feature will allow users to use specific features like autoscaling and to see container and node resource usage.

Ensure that  metrics server  or  prometheus  is running inside your cluster.

{ // if turning off, just set the value if (!checked) { setFieldValue('useServerMetrics', checked); return; } // if turning on, see if the metrics server is available, then set the value to on if it is getMetricsMutation.mutate(environmentId, { onSuccess: () => { setMetricsFound(true); setFieldValue('useServerMetrics', checked); }, onError: () => { setMetricsFound(false); }, }); }} data-cy="kubeSetup-metricsToggle" /> {getMetricsMutation.isLoading && ( Checking metrics API... )} {!getMetricsMutation.isLoading && ( <> {metricsFound === false && ( Unable to reach metrics API, make sure metrics server is properly deployed inside that cluster. )} {metricsFound === true && ( Successfully reached metrics API )} )}
); }