Skip to content

Commit

Permalink
[Issue#12614] Display the number of days to retain the configuration …
Browse files Browse the repository at this point in the history
…history dynamically on the front end (#12616)

* Display the number of days to retain the configuration history dynamically on the front end

* checkstyle

* Display the number of days to retain the configuration history dynamically on the front end
  • Loading branch information
shengbinxu authored Sep 30, 2024
1 parent 33ae058 commit 7ce85a1
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public ModuleState build() {
moduleState.newState(PropertiesConstant.DEFAULT_MAX_SIZE, PropertyUtil.getDefaultMaxSize());
moduleState.newState(PropertiesConstant.DEFAULT_MAX_AGGR_COUNT, PropertyUtil.getDefaultMaxAggrCount());
moduleState.newState(PropertiesConstant.DEFAULT_MAX_AGGR_SIZE, PropertyUtil.getDefaultMaxAggrSize());

moduleState.newState(Constants.CONFIG_RENTENTION_DAYS_PROPERTY_STATE, PropertyUtil.getConfigRententionDays());

return moduleState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public class Constants {
public static final String DEFAULT_GROUP = "DEFAULT_GROUP";

public static final String DATASOURCE_PLATFORM_PROPERTY_STATE = "datasource_platform";


public static final String CONFIG_RENTENTION_DAYS_PROPERTY_STATE = "config_retention_days";

/**
* Config file directory in server side.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class PropertiesConstant {
public static final String DUMP_CHANGE_ON = "dumpChangeOn";

public static final String DUMP_CHANGE_WORKER_INTERVAL = "dumpChangeWorkerInterval";



public static final String CONFIG_RENTENTION_DAYS = "nacos.config.retention.days";

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.alibaba.nacos.config.server.service.dump;

import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.config.server.utils.TimeUtils;
import com.alibaba.nacos.sys.env.EnvUtil;
import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,8 +27,6 @@
import java.text.SimpleDateFormat;
import java.util.Calendar;

import static com.alibaba.nacos.config.server.utils.LogUtil.FATAL_LOG;

/**
* The type Default history config cleaner.
*
Expand All @@ -40,8 +38,6 @@ public class DefaultHistoryConfigCleaner implements HistoryConfigCleaner {

private HistoryConfigInfoPersistService historyConfigInfoPersistService;

private int retentionDays = 30;

@Override
public void cleanHistoryConfig() {
Timestamp startTime = getBeforeStamp(TimeUtils.getCurrentTime(), 24 * getRetentionDays());
Expand All @@ -66,22 +62,7 @@ private Timestamp getBeforeStamp(Timestamp date, int step) {
}

private int getRetentionDays() {
String val = EnvUtil.getProperty("nacos.config.retention.days");
if (null == val) {
return retentionDays;
}

int tmp = 0;
try {
tmp = Integer.parseInt(val);
if (tmp > 0) {
retentionDays = tmp;
}
} catch (NumberFormatException nfe) {
FATAL_LOG.error("read nacos.config.retention.days wrong", nfe);
}

return retentionDays;
return PropertyUtil.getConfigRententionDays();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

import static com.alibaba.nacos.config.server.utils.LogUtil.FATAL_LOG;

/**
* Properties util.
*
Expand Down Expand Up @@ -100,7 +102,12 @@ public class PropertyUtil implements ApplicationContextInitializer<ConfigurableA
private static int correctUsageDelay = 10 * 60;

private static boolean dumpChangeOn = true;


/**
* The number of days to retain the configuration history, the default is 30 days.
*/
private static int configRententionDays = 30;

/**
* dumpChangeWorkerInterval, default 30 seconds.
*/
Expand Down Expand Up @@ -241,7 +248,26 @@ public static int getCorrectUsageDelay() {
public static void setCorrectUsageDelay(int correctUsageDelay) {
PropertyUtil.correctUsageDelay = correctUsageDelay;
}


public static int getConfigRententionDays() {
return configRententionDays;
}

private void setConfigRententionDays() {
String val = getProperty(PropertiesConstant.CONFIG_RENTENTION_DAYS);
if (null != val) {
int tmp = 0;
try {
tmp = Integer.parseInt(val);
if (tmp > 0) {
PropertyUtil.configRententionDays = tmp;
}
} catch (NumberFormatException nfe) {
FATAL_LOG.error("read nacos.config.retention.days wrong", nfe);
}
}
}

public static boolean isStandaloneMode() {
return EnvUtil.getStandaloneMode();
}
Expand Down Expand Up @@ -275,6 +301,7 @@ private void loadSetting() {
setDefaultMaxAggrSize(getInt(PropertiesConstant.DEFAULT_MAX_AGGR_SIZE, defaultMaxAggrSize));
setCorrectUsageDelay(getInt(PropertiesConstant.CORRECT_USAGE_DELAY, correctUsageDelay));
setInitialExpansionPercent(getInt(PropertiesConstant.INITIAL_EXPANSION_PERCENT, initialExpansionPercent));
setConfigRententionDays();
setDumpChangeOn(getBoolean(PropertiesConstant.DUMP_CHANGE_ON, dumpChangeOn));
setDumpChangeWorkerInterval(
getLong(PropertiesConstant.DUMP_CHANGE_WORKER_INTERVAL, dumpChangeWorkerInterval));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
import com.alibaba.nacos.config.server.utils.ConfigExecutor;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.sys.env.EnvUtil;
import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -90,13 +91,20 @@ public void testCleanHistoryConfig() throws Exception {
public void testGetRetentionDays() throws Exception {
Method method = DefaultHistoryConfigCleaner.class.getDeclaredMethod("getRetentionDays");
method.setAccessible(true);

Method setRetentionDaysMethod = PropertyUtil.class.getDeclaredMethod("setConfigRententionDays");
setRetentionDaysMethod.setAccessible(true);

envUtilMockedStatic.when(() -> EnvUtil.getProperty("nacos.config.retention.days")).thenReturn("-1");
setRetentionDaysMethod.invoke(new PropertyUtil());
assertEquals((int) method.invoke(defaultHistoryConfigCleaner), 30);

envUtilMockedStatic.when(() -> EnvUtil.getProperty("nacos.config.retention.days")).thenReturn("30");
setRetentionDaysMethod.invoke(new PropertyUtil());
assertEquals((int) method.invoke(defaultHistoryConfigCleaner), 30);

envUtilMockedStatic.when(() -> EnvUtil.getProperty("nacos.config.retention.days")).thenReturn("1");
setRetentionDaysMethod.invoke(new PropertyUtil());
assertEquals((int) method.invoke(defaultHistoryConfigCleaner), 1);
}
}
3 changes: 2 additions & 1 deletion console-ui/src/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ const I18N_CONF = {
details: 'Details',
rollback: 'Roll Back',
pubNoData: 'No results found.',
toConfigure: 'Historical Versions (Configuration record is retained for 30 days.)',
toConfigureBegin: 'Historical Versions (Configuration record is retained for ',
toConfigureEnd: ' days.)',
dataId: 'Enter Data ID',
dataIdCanNotBeEmpty: 'Data ID cannot be empty',
group: 'Enter Group',
Expand Down
3 changes: 2 additions & 1 deletion console-ui/src/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ const I18N_CONF = {
details: '详情',
rollback: '回滚',
pubNoData: '没有数据',
toConfigure: '历史版本(保留30天)',
toConfigureBegin: '历史版本(保留',
toConfigureEnd: '天)',
dataId: '请输入Data ID',
dataIdCanNotBeEmpty: 'Data ID不能为空',
group: '请输入Group',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ import './index.scss';
import DiffEditorDialog from '../../../components/DiffEditorDialog';
import QueryResult from '../../../components/QueryResult';
import PageTitle from '../../../components/PageTitle';
import { connect } from 'react-redux';
import { getState } from '../../../reducers/base';

@connect(state => ({ ...state.base }), { getState })
@ConfigProvider.config
class HistoryRollback extends React.Component {
static displayName = 'HistoryRollback';

static propTypes = {
locale: PropTypes.object,
history: PropTypes.object,
configRetentionDays: PropTypes.any,
};

constructor(props) {
Expand Down Expand Up @@ -77,6 +81,7 @@ class HistoryRollback extends React.Component {
componentDidMount() {
this.field.setValue('group', this.group);
this.field.setValue('dataId', this.dataId);
this.props.getState();
// this.getData()
}

Expand Down Expand Up @@ -337,7 +342,7 @@ class HistoryRollback extends React.Component {
color="#333"
>
<PageTitle
title={locale.toConfigure}
title={locale.toConfigureBegin + this.props.configRetentionDays + locale.toConfigureEnd}
desc={nowNamespaceDesc}
namespaceId={nowNamespaceId}
namespaceName={nowNamespaceName}
Expand Down
2 changes: 2 additions & 0 deletions console-ui/src/reducers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const initialState = {
consoleUiEnable: '',
authAdminRequest: '',
guideMsg: '',
configRetentionDays: 30, // config default retention days is 30
};

/**
Expand Down Expand Up @@ -62,6 +63,7 @@ const getState = () => dispatch =>
authAdminRequest: res.auth_admin_request,
consoleUiEnable: res.console_ui_enabled,
startupMode: res.startup_mode,
configRetentionDays: res.config_retention_days,
},
});
})
Expand Down

0 comments on commit 7ce85a1

Please sign in to comment.