Skip to content

Commit

Permalink
Merge branch 'develop' into release/v0.7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
prashant-shahi committed Apr 7, 2022
2 parents 1d6ddd4 + 041a524 commit f4cc2a3
Show file tree
Hide file tree
Showing 22 changed files with 306 additions and 186 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"react-graph-vis": "^1.0.5",
"react-grid-layout": "^1.2.5",
"react-i18next": "^11.16.1",
"react-query": "^3.34.19",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"react-use": "^17.3.2",
Expand Down
165 changes: 99 additions & 66 deletions frontend/src/container/GeneralSettings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/cognitive-complexity */
import { Button, Col, Modal, notification, Row, Typography } from 'antd';
import getDisks from 'api/disks/getDisks';
import getRetentionPeriodApi from 'api/settings/getRetention';
Expand All @@ -12,12 +13,7 @@ import { IDiskType } from 'types/api/disks/getDisks';
import { PayloadProps } from 'types/api/settings/getRetention';

import Retention from './Retention';
import {
ButtonContainer,
ErrorText,
ErrorTextContainer,
ToolTipContainer,
} from './styles';
import { ButtonContainer, ErrorText, ErrorTextContainer } from './styles';

function GeneralSettings(): JSX.Element {
const { t } = useTranslation();
Expand All @@ -31,10 +27,17 @@ function GeneralSettings(): JSX.Element {
getDisks().then((response) => setAvailableDisks(response.payload));
}, []);

const { payload: currentTTLValues, loading, error, errorMessage } = useFetch<
const { payload, loading, error, errorMessage } = useFetch<
PayloadProps,
undefined
>(getRetentionPeriodApi, undefined);

const [currentTTLValues, setCurrentTTLValues] = useState(payload);

useEffect(() => {
setCurrentTTLValues(payload);
}, [payload]);

const [metricsTotalRetentionPeriod, setMetricsTotalRetentionPeriod] = useState<
number | null
>(null);
Expand Down Expand Up @@ -63,6 +66,7 @@ function GeneralSettings(): JSX.Element {
: null,
);
}
console.log({ changed: currentTTLValues });
}, [currentTTLValues]);

const onModalToggleHandler = (): void => {
Expand Down Expand Up @@ -138,43 +142,65 @@ function GeneralSettings(): JSX.Element {
const onOkHandler = async (): Promise<void> => {
try {
setPostApiLoading(true);
const [metricsTTLApiResponse, tracesTTLApiResponse] = await Promise.all([
setRetentionApi({
type: 'metrics',
totalDuration: `${metricsTotalRetentionPeriod || -1}h`,
coldStorage: s3Enabled ? 's3' : null,
toColdDuration: `${metricsS3RetentionPeriod || -1}h`,
}),
setRetentionApi({
type: 'traces',
totalDuration: `${tracesTotalRetentionPeriod || -1}h`,
coldStorage: s3Enabled ? 's3' : null,
toColdDuration: `${tracesS3RetentionPeriod || -1}h`,
}),
]);
[
{
apiResponse: metricsTTLApiResponse,
name: 'metrics',
},
{
apiResponse: tracesTTLApiResponse,
name: 'traces',
},
].forEach(({ apiResponse, name }) => {
if (apiResponse.statusCode === 200) {
notifications.success({
message: 'Success!',
placement: 'topRight',

description: t('settings.retention_success_message', { name }),
});
} else {
notifications.error({
message: 'Error',
description: t('settings.retention_error_message', { name }),
placement: 'topRight',
});
const apiCalls = [];

if (
!(
currentTTLValues?.metrics_move_ttl_duration_hrs ===
metricsS3RetentionPeriod &&
currentTTLValues.metrics_ttl_duration_hrs === metricsTotalRetentionPeriod
)
) {
apiCalls.push(() =>
setRetentionApi({
type: 'metrics',
totalDuration: `${metricsTotalRetentionPeriod || -1}h`,
coldStorage: s3Enabled ? 's3' : null,
toColdDuration: `${metricsS3RetentionPeriod || -1}h`,
}),
);
} else {
apiCalls.push(() => Promise.resolve(null));
}

if (
!(
currentTTLValues?.traces_move_ttl_duration_hrs ===
tracesS3RetentionPeriod &&
currentTTLValues.traces_ttl_duration_hrs === tracesTotalRetentionPeriod
)
) {
apiCalls.push(() =>
setRetentionApi({
type: 'traces',
totalDuration: `${tracesTotalRetentionPeriod || -1}h`,
coldStorage: s3Enabled ? 's3' : null,
toColdDuration: `${tracesS3RetentionPeriod || -1}h`,
}),
);
} else {
apiCalls.push(() => Promise.resolve(null));
}
const apiCallSequence = ['metrics', 'traces'];
const apiResponses = await Promise.all(apiCalls.map((api) => api()));

apiResponses.forEach((apiResponse, idx) => {
const name = apiCallSequence[idx];
if (apiResponse) {
if (apiResponse.statusCode === 200) {
notifications.success({
message: 'Success!',
placement: 'topRight',

description: t('settings.retention_success_message', { name }),
});
} else {
notifications.error({
message: 'Error',
description: t('settings.retention_error_message', { name }),
placement: 'topRight',
});
}
}
});
onModalToggleHandler();
Expand All @@ -186,10 +212,18 @@ function GeneralSettings(): JSX.Element {
placement: 'topRight',
});
}
// Updates the currentTTL Values in order to avoid pushing the same values.
setCurrentTTLValues({
metrics_ttl_duration_hrs: metricsTotalRetentionPeriod || -1,
metrics_move_ttl_duration_hrs: metricsS3RetentionPeriod || -1,
traces_ttl_duration_hrs: tracesTotalRetentionPeriod || -1,
traces_move_ttl_duration_hrs: tracesS3RetentionPeriod || -1,
});

setModal(false);
};

const [isDisabled, errorText] = useMemo(() => {
const [isDisabled, errorText] = useMemo((): [boolean, string] => {
// Various methods to return dynamic error message text.
const messages = {
compareError: (name: string | number): string =>
Expand Down Expand Up @@ -228,8 +262,18 @@ function GeneralSettings(): JSX.Element {
errorText = messages.nullValueError('traces');
}
}
if (
currentTTLValues?.metrics_ttl_duration_hrs === metricsTotalRetentionPeriod &&
currentTTLValues.metrics_move_ttl_duration_hrs ===
metricsS3RetentionPeriod &&
currentTTLValues.traces_ttl_duration_hrs === tracesTotalRetentionPeriod &&
currentTTLValues.traces_move_ttl_duration_hrs === tracesS3RetentionPeriod
) {
isDisabled = true;
}
return [isDisabled, errorText];
}, [
currentTTLValues,
metricsS3RetentionPeriod,
metricsTotalRetentionPeriod,
s3Enabled,
Expand All @@ -249,27 +293,16 @@ function GeneralSettings(): JSX.Element {
return (
<Col xs={24} md={22} xl={20} xxl={18} style={{ margin: 'auto' }}>
{Element}
{errorText ? (
<ErrorTextContainer>
<ErrorText>{errorText}</ErrorText>

<TextToolTip
{...{
text: `More details on how to set retention period`,
url: 'https://signoz.io/docs/userguide/retention-period/',
}}
/>
</ErrorTextContainer>
) : (
<ToolTipContainer>
<TextToolTip
{...{
text: `More details on how to set retention period`,
url: 'https://signoz.io/docs/userguide/retention-period/',
}}
/>
</ToolTipContainer>
)}
<ErrorTextContainer>
<TextToolTip
{...{
text: `More details on how to set retention period`,
url: 'https://signoz.io/docs/userguide/retention-period/',
}}
/>
{errorText && <ErrorText>{errorText}</ErrorText>}
</ErrorTextContainer>

<Row justify="space-around">{renderConfig}</Row>

<Modal
Expand Down
1 change: 1 addition & 0 deletions frontend/src/container/GeneralSettings/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const ErrorTextContainer = styled.div`
margin-bottom: 2rem;
display: flex;
align-items: center;
gap: 1rem;
> article {
margin-right: 1rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function Application({ getWidget }: DashboardProps): JSX.Element {
history.replace(
`${
ROUTES.TRACE
}?${urlParams.toString()}&selected={"serviceName":["${servicename}"],"status":["ok","error"]}&filterToFetchData=["duration","status","serviceName"]&userSelectedFilter={"status":["error","ok"],"serviceName":["${servicename}"]}&isSelectedFilterSkipped=true`,
}?${urlParams.toString()}&selected={"serviceName":["${servicename}"]}&filterToFetchData=["duration","status","serviceName"]&spanAggregateCurrentPage=1&selectedTags=[]&&isFilterExclude={"serviceName":false}&userSelectedFilter={"status":["error","ok"],"serviceName":["${servicename}"]}&spanAggregateCurrentPage=1&spanAggregateOrder=ascend`,
);
};

Expand Down Expand Up @@ -88,7 +88,7 @@ function Application({ getWidget }: DashboardProps): JSX.Element {
history.replace(
`${
ROUTES.TRACE
}?${urlParams.toString()}&selected={"serviceName":["${servicename}"],"status":["error"]}&filterToFetchData=["duration","status","serviceName"]&userSelectedFilter={"status":["error"],"serviceName":["${servicename}"]}&isSelectedFilterSkipped=true`,
}?${urlParams.toString()}?selected={"serviceName":["${servicename}"],"status":["error"]}&filterToFetchData=["duration","status","serviceName"]&spanAggregateCurrentPage=1&selectedTags=[]&isFilterExclude={"serviceName":false,"status":false}&userSelectedFilter={"serviceName":["${servicename}"],"status":["error"]}&spanAggregateCurrentPage=1&spanAggregateOrder=ascend`,
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function TopEndpointsTable(props: TopEndpointsTableProps): JSX.Element {
history.push(
`${
ROUTES.TRACE
}?${urlParams.toString()}&selected={"status":["error","ok"],"serviceName":["${servicename}"],"operation":["${operation}"]}&filterToFetchData=["duration","status","serviceName","operation"]&isSelectedFilterSkipped=true&userSelectedFilter={"status":["error","ok"],"serviceName":["${servicename}"],"operation":["${operation}"]}&isSelectedFilterSkipped=true`,
}?${urlParams.toString()}&selected={"serviceName":["${servicename}"],"operation":["${operation}"]}&filterToFetchData=["duration","status","serviceName","operation"]&spanAggregateCurrentPage=1&selectedTags=[]&&isFilterExclude={"serviceName":false,"operation":false}&userSelectedFilter={"status":["error","ok"],"serviceName":["${servicename}"],"operation":["${operation}"]}&spanAggregateCurrentPage=1&spanAggregateOrder=ascend`,
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ function CheckBoxComponent(props: CheckBoxProps): JSX.Element {
filterToFetchData,
spansAggregate.currentPage,
selectedTags,
updatedFilter,
preIsFilterExclude,
preUserSelectedMap,
spansAggregate.order,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ function Duration(): JSX.Element {
filterToFetchData,
spansAggregate.currentPage,
selectedTags,
preFilter,
isFilterExclude,
userSelectedFilter,
spansAggregate.order,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ function PanelHeading(props: PanelHeadingProps): JSX.Element {
updatedFilterData,
spansAggregate.currentPage,
selectedTags,
updatedFilter,
isFilterExclude,
getPreUserSelected,
spansAggregate.order,
Expand Down Expand Up @@ -139,7 +138,7 @@ function PanelHeading(props: PanelHeadingProps): JSX.Element {
...filterToFetchData.filter((name) => name !== PanelName),
];

preSelectedFilter.delete(PanelName);
// preSelectedFilter.delete(PanelName);

dispatch({
type: UPDATE_ALL_FILTERS,
Expand All @@ -160,7 +159,6 @@ function PanelHeading(props: PanelHeadingProps): JSX.Element {
preFilterToFetchTheData,
spansAggregate.currentPage,
selectedTags,
filter,
isFilterExclude,
userSelectedFilter,
spansAggregate.order,
Expand Down Expand Up @@ -210,7 +208,6 @@ function PanelHeading(props: PanelHeadingProps): JSX.Element {
filterToFetchData,
spansAggregate.currentPage,
selectedTags,
getUpdatedFilter,
postIsFilterExclude,
preUserSelected,
spansAggregate.order,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function TagValue(props: TagValueProps): JSX.Element {

return (
<SelectComponent
value={selectedValues[0]}
onSelect={(value: unknown): void => {
if (typeof value === 'string') {
setLocalSelectedTags((tags) => [
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/container/Trace/Search/AllTags/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ function AllTags({
</Wrapper>

<ButtonContainer>
<Button onClick={onResetHandler}>Reset</Button>
<Button
type="primary"
onClick={onRunQueryHandler}
icon={<CaretRightFilled />}
>
Run Query
</Button>
<Space align="start">
<Button onClick={onResetHandler}>Reset</Button>
<Button
type="primary"
onClick={onRunQueryHandler}
icon={<CaretRightFilled />}
>
Run Query
</Button>
</Space>
</ButtonContainer>
</Container>
);
Expand Down
16 changes: 6 additions & 10 deletions frontend/src/container/Trace/Search/AllTags/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const Container = styled(Card)`
min-height: 20vh;
width: 100%;
z-index: 2;
position: absolute;
position: absolute !important;
.ant-card-body {
padding-bottom: 0;
Expand Down Expand Up @@ -35,20 +35,16 @@ export const Wrapper = styled.div`
}
`;

export const ButtonContainer = styled.div`
export const ButtonContainer = styled(Card)`
display: flex;
justify-content: flex-end;
align-items: center;
background-color: #303030;
padding-top: 11px;
padding-bottom: 11px;
padding-right: 38.01px;
margin-top: 1rem;
padding-top: 11px !important;
padding-bottom: 11px !important;
padding-right: 38.01px !important;
> button:nth-child(1) {
margin-right: 1rem;
}
margin-top: 1rem !important;
`;

export const CurrentTagsContainer = styled.div`
Expand Down
Loading

0 comments on commit f4cc2a3

Please sign in to comment.