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 the metrics feature allows users to use horizontal pod autoscaling and to see container and node resource usage. This requires{' '} metrics server {' '} or{' '} prometheus {' '} to be running in your cluster.

On any subsequent disabling of the feature, existing deployed applications with autoscaling will still autoscale (you would have to remove their autoscaler definitions to stop this).

{ // 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 )} )}
); }