Skip to content

[Improvement-11773][api] Optimize the log printing of the api module according…#11782

Merged
brave-lee merged 11 commits intoapache:devfrom
guowei-su:api
Sep 17, 2022
Merged

[Improvement-11773][api] Optimize the log printing of the api module according…#11782
brave-lee merged 11 commits intoapache:devfrom
guowei-su:api

Conversation

@guowei-su
Copy link
Copy Markdown
Contributor

@guowei-su guowei-su commented Sep 5, 2022

Purpose of the pull request

This pull request optimizes the log printing of the api module.

Brief change log

Verify this pull request

This pull request is code cleanup without any test coverage.

(or)

This pull request is already covered by existing tests, such as (please describe tests).

(or)

If your pull request contain incompatible change, you should also add it to docs/docs/en/guide/upgrede/incompatible.md

@SbloodyS SbloodyS added the improvement make more easy to user or prompt friendly label Sep 6, 2022
@SbloodyS SbloodyS added this to the 3.1.0 milestone Sep 6, 2022
Copy link
Copy Markdown
Member

@SbloodyS SbloodyS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please associate the issue and resolves conflicts.

@guowei-su
Copy link
Copy Markdown
Contributor Author

issue #11773

@caishunfeng
Copy link
Copy Markdown
Contributor

Please add a doc of How to print logs better.

@caishunfeng caishunfeng added the miss:docs missing documents in PR label Sep 6, 2022
Copy link
Copy Markdown

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 11 potential problems in the proposed changes. Check the Files changed tab for more details.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 11, 2022

Codecov Report

Merging #11782 (3e19c8c) into dev (511149f) will decrease coverage by 0.03%.
The diff coverage is 37.11%.

@@             Coverage Diff              @@
##                dev   #11782      +/-   ##
============================================
- Coverage     38.67%   38.64%   -0.04%     
- Complexity     4049     4062      +13     
============================================
  Files           999      999              
  Lines         36728    37339     +611     
  Branches       4276     4286      +10     
============================================
+ Hits          14204    14428     +224     
- Misses        20901    21277     +376     
- Partials       1623     1634      +11     
Impacted Files Coverage Δ
...olphinscheduler/api/audit/AuditPublishService.java 34.61% <0.00%> (ø)
...phinscheduler/api/controller/TenantController.java 62.50% <ø> (ø)
...rg/apache/dolphinscheduler/api/k8s/K8sManager.java 58.53% <0.00%> (ø)
...lphinscheduler/api/permission/PermissionCheck.java 0.00% <0.00%> (ø)
...nscheduler/api/service/impl/DqRuleServiceImpl.java 59.18% <0.00%> (ø)
...r/plugin/datasource/api/utils/DataSourceUtils.java 0.00% <0.00%> (ø)
...er/api/service/impl/TaskDefinitionServiceImpl.java 22.40% <8.69%> (-1.51%) ⬇️
...i/service/impl/ProcessTaskRelationServiceImpl.java 21.32% <12.19%> (-1.13%) ⬇️
...inscheduler/api/controller/ExecutorController.java 22.22% <12.50%> (-0.86%) ⬇️
...heduler/api/service/impl/SchedulerServiceImpl.java 8.88% <13.51%> (+0.27%) ⬆️
... and 33 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Copy Markdown

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 84 potential problems in the proposed changes. Check the Files changed tab for more details.

if (projectCode == targetProjectCode) {
logger.warn("Project code is same as target project code, projectCode:{}.", projectCode);
return result;
}

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException

Potential uncaught 'java.lang.NumberFormatException'.
Copy link
Copy Markdown

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 24 potential problems in the proposed changes. Check the Files changed tab for more details.

@guowei-su guowei-su force-pushed the api branch 2 times, most recently from d69aca4 to 8c92b18 Compare September 13, 2022 08:12
Copy link
Copy Markdown

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 18 potential problems in the proposed changes. Check the Files changed tab for more details.

@guowei-su
Copy link
Copy Markdown
Contributor Author

Please add a doc of How to print logs better.

The doc refs this doc pr: Add log specification document to contribution guidelines.

@guowei-su
Copy link
Copy Markdown
Contributor Author

PLAT @caishunfeng

@guowei-su guowei-su force-pushed the api branch 2 times, most recently from c618a67 to 3e19c8c Compare September 15, 2022 09:35
brave-lee
brave-lee previously approved these changes Sep 16, 2022
Copy link
Copy Markdown
Contributor

@brave-lee brave-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

… to the log specification doc.

- Resolve conflict.
… to the log specification doc.

- fix ProcessDefinitionServiceImpl.java dependency
… to the log specification doc.

- Accept proposed change in ResourcePermissionCheckServiceImpl.java
… to the log specification doc.

- Update the UT case in TenantServiceTest.java, UsersServiceTest.java, TaskGroupServiceTest.java.
- Update log printing in TaskGroupServiceImpl.java.
- Fix NPE of log parameter in ExecutorServiceImpl.java when call python api.
… to the log specification doc.

- Fix NPE of log in WorkerGroupServiceImpl.java.
- Fix log parameter missing bug in ResourcesServiceImpl.java.
… to the log specification doc.

- Fix bugs and handle some vulnerability codes.
… to the log specification doc.

- Fix bugs and handle some vulnerability codes.
… to the log specification doc.

- Fix e2e User test.
… to the log specification doc.

- Fix codeQL check & SonarCloud Code Analysis.
… to the log specification doc.

- Resolve import conflict.
… to the log specification doc.

- Fix codeQL check & SonarCloud Code Analysis.
@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 42 Code Smells

38.0% 38.0% Coverage
2.3% 2.3% Duplication

Copy link
Copy Markdown
Contributor

@brave-lee brave-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@brave-lee brave-lee merged commit 1a7c6ea into apache:dev Sep 17, 2022
@zhongjiajie
Copy link
Copy Markdown
Member

I do not think this is a good idea, we should directly throw error instead of print log, and actually I already throw error in #11912

@zhongjiajie
Copy link
Copy Markdown
Member

I do not think this is a good idea, we should directly throw error instead of print log, and actually I already throw error in #11912

We already have ExceptionHandleraccept ServiceException and package ServiceException code and message into Result object, and it uses in the controller layer

@ExceptionHandler(ServiceException.class)
public Result exceptionHandler(ServiceException e, HandlerMethod hm) {
logger.error("ServiceException: ", e);
return new Result(e.getCode(), e.getMessage());
}

so when we throw an exception in the service layer, we will catch it in the controller layer and return the new Result object. And we already have exists method in
if (!processInstance.getState().isFinished()) {
throw new ServiceException(PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstance.getName(), processInstance.getState(), "delete");
}
.

when exception throw in L658

throw new ServiceException(PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstance.getName(), processInstance.getState(), "delete");

controller will catch it and package into Result(code=Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR.getCode(), message=Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR.getMsg())

@guowei-su
Copy link
Copy Markdown
Contributor Author

I do not think this is a good idea, we should directly throw error instead of print log, and actually I already throw error in #11912

We already have ExceptionHandleraccept ServiceException and package ServiceException code and message into Result object, and it uses in the controller layer

@ExceptionHandler(ServiceException.class)
public Result exceptionHandler(ServiceException e, HandlerMethod hm) {
logger.error("ServiceException: ", e);
return new Result(e.getCode(), e.getMessage());
}

so when we throw an exception in the service layer, we will catch it in the controller layer and return the new Result object. And we already have exists method in

if (!processInstance.getState().isFinished()) {
throw new ServiceException(PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstance.getName(), processInstance.getState(), "delete");
}

.
when exception throw in L658

throw new ServiceException(PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstance.getName(), processInstance.getState(), "delete");

controller will catch it and package into Result(code=Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR.getCode(), message=Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR.getMsg())

Ok, I probably get it. I will take this approach to regulate the api module logging and exceptions in the new pr. Also, I will describe this specification in the logging specification doc.

xdu-chenrj pushed a commit to xdu-chenrj/dolphinscheduler that referenced this pull request Sep 17, 2022
…according… (apache#11782)

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Resolve conflict.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- fix ProcessDefinitionServiceImpl.java dependency

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Accept proposed change in ResourcePermissionCheckServiceImpl.java

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Update the UT case in TenantServiceTest.java, UsersServiceTest.java, TaskGroupServiceTest.java.
- Update log printing in TaskGroupServiceImpl.java.
- Fix NPE of log parameter in ExecutorServiceImpl.java when call python api.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix NPE of log in WorkerGroupServiceImpl.java.
- Fix log parameter missing bug in ResourcesServiceImpl.java.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix bugs and handle some vulnerability codes.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix bugs and handle some vulnerability codes.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix e2e User test.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix codeQL check & SonarCloud Code Analysis.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Resolve import conflict.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix codeQL check & SonarCloud Code Analysis.
@caishunfeng caishunfeng modified the milestones: 3.1.0, 3.2.0 Sep 19, 2022
Copy link
Copy Markdown
Contributor

@wen-hemin wen-hemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm.

* @param project project
* @return true if the user have permission to see the project, otherwise return false
*/
private boolean checkReadPermission(User user, Project project) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm whether it is referenced

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this method was not referenced and was incorrectly merged while I was handling the conflict.

xdu-chenrj pushed a commit to xdu-chenrj/dolphinscheduler that referenced this pull request Oct 13, 2022
…according… (apache#11782)

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Resolve conflict.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- fix ProcessDefinitionServiceImpl.java dependency

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Accept proposed change in ResourcePermissionCheckServiceImpl.java

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Update the UT case in TenantServiceTest.java, UsersServiceTest.java, TaskGroupServiceTest.java.
- Update log printing in TaskGroupServiceImpl.java.
- Fix NPE of log parameter in ExecutorServiceImpl.java when call python api.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix NPE of log in WorkerGroupServiceImpl.java.
- Fix log parameter missing bug in ResourcesServiceImpl.java.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix bugs and handle some vulnerability codes.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix bugs and handle some vulnerability codes.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix e2e User test.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix codeQL check & SonarCloud Code Analysis.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Resolve import conflict.

* [DS-11773][api] Optimize the log printing of the api module according to the log specification doc.
- Fix codeQL check & SonarCloud Code Analysis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend improvement make more easy to user or prompt friendly miss:docs missing documents in PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][api] Optimize the log printing of the api module according to the log specification.

8 participants