Skip to content

[Issue#12614] Display the number of days to retain the configuration history dynamically on the front end #12616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 30, 2024

Conversation

shengbinxu
Copy link
Contributor

@shengbinxu shengbinxu commented Sep 5, 2024

issue: #12614

What is the purpose of the change

Display the number of days to retain the configuration history dynamically on the front end, the current value displayed on the front end is hard-coded (30 days)

Brief changelog

  1. Add a field "config_retention_days": "720" to the response of the API v1/console/server/state.
image
  1. Display the value of the variable config_retention_days on the front end.

Verifying this change

image image

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@shengbinxu shengbinxu changed the title Issue#12614 Issue#12614 Display the number of days to retain the configuration history dynamically on the front end Sep 5, 2024
@shengbinxu shengbinxu changed the title Issue#12614 Display the number of days to retain the configuration history dynamically on the front end [Issue#12614] Display the number of days to retain the configuration history dynamically on the front end Sep 5, 2024
@shengbinxu
Copy link
Contributor Author

shengbinxu commented Sep 6, 2024

@Test
    public void testGetRetentionDays() throws Exception {
        Method method = DefaultHistoryConfigCleaner.class.getDeclaredMethod("getRetentionDays");
        method.setAccessible(true);
        envUtilMockedStatic.when(() -> EnvUtil.getProperty("nacos.config.retention.days")).thenReturn("-1");
        assertEquals((int) method.invoke(defaultHistoryConfigCleaner), 30);
        
        envUtilMockedStatic.when(() -> EnvUtil.getProperty("nacos.config.retention.days")).thenReturn("30");
        assertEquals((int) method.invoke(defaultHistoryConfigCleaner), 30);
        
        envUtilMockedStatic.when(() -> EnvUtil.getProperty("nacos.config.retention.days")).thenReturn("1");
        assertEquals((int) method.invoke(defaultHistoryConfigCleaner), 1);
    }

第三个单元测试不通过。
是因为现在的逻辑,我改为了在 Spring 应用程序上下文初始化阶段对configRententionDays进行赋值。因此应用启动后模拟EnvUtil.getProperty("nacos.config.retention.days")的返回值,getRetentionDays()的返回值是不会变化的。

请问,这种情况下,该如何做单元测试呢?

private void loadSetting() {
        try {
           ......
            setConfigRententionDays(getInt(PropertiesConstant.CONFIG_RENTENTION_DAYS, configRententionDays));
           ......
        } catch (Exception e) {
            LOGGER.error("read application.properties failed", e);
            throw e;
        }
    }

@KomachiSion
Copy link
Collaborator

KomachiSion commented Sep 18, 2024

如果一定放在PropertyUtil中的话, 可以通过反射调用loadSetting,修改PropertyUtil中的配置值。

当然调用前要先设置对应的配置值,比如用System.setProperty.

@shengbinxu
Copy link
Contributor Author

如果一定放在PropertyUtil中的话, 可以通过反射调用loadSetting,修改PropertyUtil中的配置值。

当然调用前要先设置对应的配置值,比如用System.setProperty.

@KomachiSion 非常感谢你的回复,按照你的思路,该问题已经解决。

同时,又遇到了新的问题,其他的单元测试不通过,我在本地执行以下命令,都能通过。实在找不到原因,麻烦帮忙看看。

Run `mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true` to make sure basic checks pass. Run `mvn clean install -DskipITs` to make sure unit-test pass. Run `mvn clean test-compile failsafe:integration-test`  to make sure integration-test pass.

我在本地执行上述命令,都能通过。

@codecov-commenter
Copy link

codecov-commenter commented Sep 25, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 69.61%. Comparing base (3a9003b) to head (ed316f6).
Report is 26 commits behind head on develop.

Files with missing lines Patch % Lines
...libaba/nacos/config/server/utils/PropertyUtil.java 84.61% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             develop   #12616      +/-   ##
=============================================
- Coverage      69.70%   69.61%   -0.09%     
+ Complexity      9431     9415      -16     
=============================================
  Files           1275     1275              
  Lines          41232    41236       +4     
  Branches        4374     4374              
=============================================
- Hits           28740    28707      -33     
- Misses         10412    10449      +37     
  Partials        2080     2080              
Files with missing lines Coverage Δ
...nfig/server/constant/ConfigModuleStateBuilder.java 100.00% <100.00%> (ø)
...libaba/nacos/config/server/constant/Constants.java 76.92% <ø> (ø)
...cos/config/server/constant/PropertiesConstant.java 0.00% <ø> (ø)
...rver/service/dump/DefaultHistoryConfigCleaner.java 94.11% <100.00%> (+4.83%) ⬆️
...libaba/nacos/config/server/utils/PropertyUtil.java 94.15% <84.61%> (-0.88%) ⬇️

... and 35 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91987b0...ed316f6. Read the comment docs.

@KomachiSion KomachiSion merged commit 7ce85a1 into alibaba:develop Sep 30, 2024
6 of 7 checks passed
@KomachiSion KomachiSion added this to the 2.5.0 milestone Sep 30, 2024
@KomachiSion KomachiSion added kind/enhancement Category issues or prs related to enhancement. area/Nacos console Related to Nacos consle labels Sep 30, 2024
@KomachiSion KomachiSion modified the milestones: 2.5.0, 2.4.3 Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Nacos console Related to Nacos consle kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants