mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 13:46:00 +08:00
feat: final touches to the ttl
This commit is contained in:
parent
24d6a1e7b2
commit
c9e02a8b25
@ -1,12 +1,10 @@
|
|||||||
import { DownOutlined } from '@ant-design/icons';
|
import { Col, Row, Select } from 'antd';
|
||||||
import { Button, Col, Menu, Row, Select } from 'antd';
|
|
||||||
import { find } from 'lodash-es';
|
import { find } from 'lodash-es';
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { Dropdown, Input, RetentionContainer, Typography } from './styles';
|
import { Input, RetentionContainer, Typography } from './styles';
|
||||||
import {
|
import {
|
||||||
convertHoursValueToRelevantUnit,
|
convertHoursValueToRelevantUnit,
|
||||||
ITimeUnit,
|
|
||||||
SettingPeriod,
|
SettingPeriod,
|
||||||
TimeUnits,
|
TimeUnits,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
@ -18,24 +16,22 @@ function Retention({
|
|||||||
setRetentionValue,
|
setRetentionValue,
|
||||||
text,
|
text,
|
||||||
hide,
|
hide,
|
||||||
}: RetentionProps): JSX.Element {
|
}: RetentionProps): JSX.Element | null {
|
||||||
const {
|
const {
|
||||||
value: initialValue,
|
value: initialValue,
|
||||||
timeUnitValue: initialTimeUnitValue,
|
timeUnitValue: initialTimeUnitValue,
|
||||||
} = convertHoursValueToRelevantUnit(retentionValue);
|
} = convertHoursValueToRelevantUnit(Number(retentionValue));
|
||||||
const [selectedTimeUnit, setSelectTimeUnit] = useState(initialTimeUnitValue);
|
const [selectedTimeUnit, setSelectTimeUnit] = useState(initialTimeUnitValue);
|
||||||
const [selectedValue, setSelectedValue] = useState<number | null>(null);
|
const [selectedValue, setSelectedValue] = useState<number | null>(null);
|
||||||
|
const interacted = useRef(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedValue(initialValue);
|
if (!interacted.current) setSelectedValue(initialValue);
|
||||||
}, [initialValue]);
|
}, [initialValue]);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectTimeUnit(initialTimeUnitValue);
|
if (!interacted.current) setSelectTimeUnit(initialTimeUnitValue);
|
||||||
}, [initialTimeUnitValue]);
|
}, [initialTimeUnitValue]);
|
||||||
|
|
||||||
|
|
||||||
const menuItems = TimeUnits.map((option) => (
|
const menuItems = TimeUnits.map((option) => (
|
||||||
<Option key={option.value} value={option.value}>
|
<Option key={option.value} value={option.value}>
|
||||||
{option.key}
|
{option.key}
|
||||||
@ -62,6 +58,7 @@ function Retention({
|
|||||||
e: React.ChangeEvent<HTMLInputElement>,
|
e: React.ChangeEvent<HTMLInputElement>,
|
||||||
func: React.Dispatch<React.SetStateAction<number | null>>,
|
func: React.Dispatch<React.SetStateAction<number | null>>,
|
||||||
): void => {
|
): void => {
|
||||||
|
interacted.current = true;
|
||||||
const { value } = e.target;
|
const { value } = e.target;
|
||||||
const integerValue = parseInt(value, 10);
|
const integerValue = parseInt(value, 10);
|
||||||
|
|
||||||
@ -93,7 +90,7 @@ function Retention({
|
|||||||
<Col flex="150px">
|
<Col flex="150px">
|
||||||
<div style={{ display: 'inline-flex' }}>
|
<div style={{ display: 'inline-flex' }}>
|
||||||
<Input
|
<Input
|
||||||
value={selectedValue >= 0 ? selectedValue : ''}
|
value={selectedValue && selectedValue >= 0 ? selectedValue : ''}
|
||||||
onChange={(e): void => onChangeHandler(e, setSelectedValue)}
|
onChange={(e): void => onChangeHandler(e, setSelectedValue)}
|
||||||
style={{ width: 75 }}
|
style={{ width: 75 }}
|
||||||
/>
|
/>
|
||||||
|
@ -5,8 +5,6 @@ import setRetentionApi from 'api/settings/setRetention';
|
|||||||
import Spinner from 'components/Spinner';
|
import Spinner from 'components/Spinner';
|
||||||
import TextToolTip from 'components/TextToolTip';
|
import TextToolTip from 'components/TextToolTip';
|
||||||
import useFetch from 'hooks/useFetch';
|
import useFetch from 'hooks/useFetch';
|
||||||
import convertIntoHr from 'lib/convertIntoHr';
|
|
||||||
import getSettingsPeroid from 'lib/getSettingsPeroid';
|
|
||||||
import { find } from 'lodash-es';
|
import { find } from 'lodash-es';
|
||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { IDiskType } from 'types/api/disks/getDisks';
|
import { IDiskType } from 'types/api/disks/getDisks';
|
||||||
@ -21,19 +19,12 @@ import {
|
|||||||
} from './styles';
|
} from './styles';
|
||||||
|
|
||||||
function GeneralSettings(): JSX.Element {
|
function GeneralSettings(): JSX.Element {
|
||||||
const [
|
|
||||||
selectedMetricsPeroid,
|
|
||||||
setSelectedMetricsPeroid,
|
|
||||||
] = useState<SettingPeriod>('month');
|
|
||||||
const [notifications, Element] = notification.useNotification();
|
const [notifications, Element] = notification.useNotification();
|
||||||
|
|
||||||
const [modal, setModal] = useState<boolean>(false);
|
const [modal, setModal] = useState<boolean>(false);
|
||||||
const [postApiLoading, setPostApiLoading] = useState<boolean>(false);
|
const [postApiLoading, setPostApiLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
const [isDefaultMetrics, setIsDefaultMetrics] = useState<boolean>(false);
|
const [availableDisks, setAvailableDisks] = useState<IDiskType[] | null>(null);
|
||||||
const [isDefaultTrace, setIsDefaultTrace] = useState<boolean>(false);
|
|
||||||
|
|
||||||
const [availableDisks, setAvailableDisks] = useState<IDiskType | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getDisks().then((response) => setAvailableDisks(response.payload));
|
getDisks().then((response) => setAvailableDisks(response.payload));
|
||||||
@ -62,7 +53,6 @@ function GeneralSettings(): JSX.Element {
|
|||||||
setMetricsS3RetentionPeriod(currentTTLValues.metrics_move_ttl_duration_hrs);
|
setMetricsS3RetentionPeriod(currentTTLValues.metrics_move_ttl_duration_hrs);
|
||||||
setTracesTotalRetentionPeriod(currentTTLValues.traces_ttl_duration_hrs);
|
setTracesTotalRetentionPeriod(currentTTLValues.traces_ttl_duration_hrs);
|
||||||
setTracesS3RetentionPeriod(currentTTLValues.traces_move_ttl_duration_hrs);
|
setTracesS3RetentionPeriod(currentTTLValues.traces_move_ttl_duration_hrs);
|
||||||
console.log({ currentTTLValues });
|
|
||||||
}
|
}
|
||||||
}, [currentTTLValues]);
|
}, [currentTTLValues]);
|
||||||
|
|
||||||
@ -74,20 +64,6 @@ function GeneralSettings(): JSX.Element {
|
|||||||
onModalToggleHandler();
|
onModalToggleHandler();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const checkMetricTraceDefault = (trace: number, metric: number): void => {
|
|
||||||
if (metric === -1) {
|
|
||||||
setIsDefaultMetrics(true);
|
|
||||||
} else {
|
|
||||||
setIsDefaultMetrics(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trace === -1) {
|
|
||||||
setIsDefaultTrace(true);
|
|
||||||
} else {
|
|
||||||
setIsDefaultTrace(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// const retentionRenderConfig = () => { };
|
|
||||||
const s3Enabled = useMemo(
|
const s3Enabled = useMemo(
|
||||||
() => !!find(availableDisks, (disks: IDiskType) => disks?.type === 's3'),
|
() => !!find(availableDisks, (disks: IDiskType) => disks?.type === 's3'),
|
||||||
[availableDisks],
|
[availableDisks],
|
||||||
@ -153,15 +129,6 @@ function GeneralSettings(): JSX.Element {
|
|||||||
const onOkHandler = async (): Promise<void> => {
|
const onOkHandler = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
setPostApiLoading(true);
|
setPostApiLoading(true);
|
||||||
// const retentionTraceValue =
|
|
||||||
// retentionPeroidTrace === '0' && (payload?.traces_ttl_duration_hrs || 0) < 0
|
|
||||||
// ? payload?.traces_ttl_duration_hrs || 0
|
|
||||||
// : parseInt(retentionPeroidTrace, 10);
|
|
||||||
// const retentionMetricsValue =
|
|
||||||
// retentionPeroidMetrics === '0' &&
|
|
||||||
// (payload?.metrics_ttl_duration_hrs || 0) < 0
|
|
||||||
// ? payload?.metrics_ttl_duration_hrs || 0
|
|
||||||
// : parseInt(retentionPeroidMetrics, 10);
|
|
||||||
const [metricsTTLApiResponse, tracesTTLApiResponse] = await Promise.all([
|
const [metricsTTLApiResponse, tracesTTLApiResponse] = await Promise.all([
|
||||||
setRetentionApi({
|
setRetentionApi({
|
||||||
type: 'metrics',
|
type: 'metrics',
|
||||||
@ -192,8 +159,6 @@ function GeneralSettings(): JSX.Element {
|
|||||||
placement: 'topRight',
|
placement: 'topRight',
|
||||||
description: `Congrats. The retention periods for ${name} has been updated successfully.`,
|
description: `Congrats. The retention periods for ${name} has been updated successfully.`,
|
||||||
});
|
});
|
||||||
// checkMetricTraceDefault(retentionTraceValue, retentionMetricsValue);
|
|
||||||
onModalToggleHandler();
|
|
||||||
} else {
|
} else {
|
||||||
notifications.error({
|
notifications.error({
|
||||||
message: 'Error',
|
message: 'Error',
|
||||||
@ -202,6 +167,7 @@ function GeneralSettings(): JSX.Element {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
onModalToggleHandler();
|
||||||
setPostApiLoading(false);
|
setPostApiLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error({
|
notifications.error({
|
||||||
@ -294,32 +260,7 @@ function GeneralSettings(): JSX.Element {
|
|||||||
/>
|
/>
|
||||||
</ToolTipContainer>
|
</ToolTipContainer>
|
||||||
)}
|
)}
|
||||||
<Row justify="space-around" style={{ gap: '4%' }}>
|
<Row justify="space-around">{renderConfig}</Row>
|
||||||
{/* {renderConfig.map((category): JSX.Element | null => {
|
|
||||||
if (
|
|
||||||
Array.isArray(category.retentionFields) &&
|
|
||||||
category.retentionFields.length > 0
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<Col flex="40%" style={{ minWidth: 475 }} key={category.name}>
|
|
||||||
<Typography.Title level={3}>{category.name}</Typography.Title>
|
|
||||||
|
|
||||||
{category.retentionFields.map((retentionField) => (
|
|
||||||
<Retention
|
|
||||||
key={retentionField.name}
|
|
||||||
text={retentionField.name}
|
|
||||||
retentionValue={retentionField.value}
|
|
||||||
setRetentionValue={retentionField.setValue}
|
|
||||||
hide={!!retentionField.hide}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</Col>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
})} */}
|
|
||||||
{renderConfig}
|
|
||||||
</Row>
|
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
title="Are you sure you want to change the retention period?"
|
title="Are you sure you want to change the retention period?"
|
||||||
|
@ -26,6 +26,7 @@ export const TimeUnits: ITimeUnit[] = [
|
|||||||
export const convertHoursValueToRelevantUnit = (
|
export const convertHoursValueToRelevantUnit = (
|
||||||
value: number,
|
value: number,
|
||||||
): { value: number; timeUnitValue: SettingPeriod } => {
|
): { value: number; timeUnitValue: SettingPeriod } => {
|
||||||
|
if (value)
|
||||||
for (let idx = TimeUnits.length - 1; idx >= 0; idx -= 1) {
|
for (let idx = TimeUnits.length - 1; idx >= 0; idx -= 1) {
|
||||||
const timeUnit = TimeUnits[idx];
|
const timeUnit = TimeUnits[idx];
|
||||||
const convertedValue = timeUnit.multiplier * value;
|
const convertedValue = timeUnit.multiplier * value;
|
||||||
|
@ -26,8 +26,7 @@ function SettingsPage(): JSX.Element {
|
|||||||
route: ROUTES.ALL_CHANNELS,
|
route: ROUTES.ALL_CHANNELS,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
activeKey:
|
activeKey: pathName === ROUTES.SETTINGS ? 'General' : 'Alert Channels',
|
||||||
pathName === ROUTES.SETTINGS ? 'General' : 'Alert Channels',
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -23,8 +23,7 @@ function SettingsPage(): JSX.Element {
|
|||||||
route: ROUTES.ALL_CHANNELS,
|
route: ROUTES.ALL_CHANNELS,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
activeKey:
|
activeKey: pathName === ROUTES.ALL_CHANNELS ? 'Alert Channels' : 'General',
|
||||||
pathName === ROUTES.ALL_CHANNELS ? 'Alert Channels' : 'General',
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user