-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
feat: Add apollo audit log common solution backend #4985
Conversation
add ApolloAuditLogApi for manually logging needs. add ApolloAuditLogDataInfluenceTableId (maybe multi-primary-key in the future). add ApolloAuditController by @bean registered
- add @DomainEvents to BaseEntity.java - change the way that data influences append - add annotations and codes to make app audited - change some classes' name - make api to query and record api - add event and listener to catch data influences
- try to reduce the affection of audit module on other modules
# Conflicts: # apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
…ServiceTest.class
Codecov Report
@@ Coverage Diff @@
## master #4985 +/- ##
============================================
+ Coverage 48.93% 49.34% +0.41%
- Complexity 1782 1894 +112
============================================
Files 348 372 +24
Lines 10991 11538 +547
Branches 1095 1123 +28
============================================
+ Hits 5378 5693 +315
- Misses 5284 5507 +223
- Partials 329 338 +9
|
@@ -65,6 +65,7 @@ | |||
<li><a href="{{ '/delete_app_cluster_namespace.html' | prefixPath }}" target="_blank">{{'Common.Nav.DeleteApp-Cluster-Namespace' | translate }}</a></li> | |||
<li><a href="{{ '/system_info.html' | prefixPath }}" target="_blank">{{'Common.Nav.SystemInfo' | translate }}</a></li> | |||
<li><a href="{{ '/config_export.html' | prefixPath }}" target="_blank">{{'Common.Nav.ConfigExport' | translate }}</a></li> | |||
<li><a href="{{ '/audit_log_menu.html' | prefixPath }}" target="_blank">{{'ApolloAuditLog.Title' | translate }}</a></li> |
Check warning
Code scanning / CodeQL
Potentially unsafe external link Medium
The result is very charming!!! How could I post my jmeter-output-html on here? |
- add API for get isEnabled of audit log feature - fix sql problem and add it to delta - remove 2 classes
finished deploy! test account is (username: apollo/ password: admin) |
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ApolloAuditLog { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need javadoc in all annotation and api
|
||
@GetMapping("/enabled") | ||
public String isEnabled() { | ||
return "{\"enabled\": "+ properties.isEnabled() +"}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ApolloAuditProperties directly?
return "{\"enabled\": "+ properties.isEnabled() +"}"; | |
return properties; |
List<ApolloAuditLog> findByOpName(String opName, Pageable page); | ||
|
||
@Query("SELECT log FROM ApolloAuditLog log WHERE log.opName = :opName AND (log.dataChangeCreatedTime >= :startDate) AND (log.dataChangeCreatedTime <= :endDate)") | ||
List<ApolloAuditLog> findByOpNameAndTime(@Param("opName") String opName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use jpa's method name instead of write sql by self.
reference https://stackoverflow.com/questions/39784344/check-date-between-two-other-dates-spring-data-jpa
try use findByOpNameAndCreatedTimeGreaterThanEqualAndCreatedTimeGreaterLessThanEqual
or another method name.
Fantastic work, you've really put in the effort! Kudos to you! 🌟 |
- add javadoc - Update ApolloAuditController to return ApolloAuditProperties directly
@@ -16,7 +16,7 @@ | |||
# | |||
SERVICE_NAME=apollo-adminservice | |||
## Adjust log dir if necessary | |||
LOG_DIR=/opt/logs | |||
LOG_DIR=/home/luke/apollo/logs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot change here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sorry! I pushed this accidentally, I will change it back quickly.
|
||
/** | ||
* This annotation is mainly used for operations(mainly reflected through methods) that need to be | ||
* audited. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark which method should be audit, add to controller or service's method
* Example usage: | ||
* <pre> | ||
* {@code | ||
* public App batchDeleteByAppId( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add ApolloAuditLog on the method too
import java.lang.annotation.Target; | ||
|
||
/** | ||
* It is mainly used to mark the method's parameters that need to be audited. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conbine with {@link ApolloAuditLog}, mark which method's parameter is audit log's data change.
- add README.md
Thanks! I have added the README.md ~ If it weren't for my mentor who took great care of me, I wouldn't be able to complete this task. 🥹 |
apollo-audit/README.md
Outdated
@@ -0,0 +1,114 @@ | |||
# Features: Apollo-Audit-Log | |||
|
|||
This module mainly provides audit log functions for other Apollo modules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module mainly provides audit log functions for other Apollo modules. | |
This module provides audit log functions for other Apollo modules. | |
Only apolloconfig's developer need to read it, | |
apolloconfig's user doesn't need. |
apollo-audit/README.md
Outdated
|
||
This module mainly provides audit log functions for other Apollo modules. | ||
|
||
## How to switch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## How to switch | |
## How to enable/disable |
apollo-audit/README.md
Outdated
apollo.audit.log.enabled = true | ||
``` | ||
|
||
## How to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## How to use | |
## How to generate audit log |
|
||
```java | ||
public App create() { | ||
Autocloseable auditScope = api.appendAuditLog(type, name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try with resources?
|
||
```java | ||
public App create() { | ||
Autocloseable auditScope = api.appendAuditLog(type, name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try with resources?
|
||
### Append an AuditLog | ||
|
||
We can do this by using annotations: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may use 5W1H to describe it.
|
||
### Append DataInfluence | ||
|
||
This function can also be implemented automatically and manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes there is not DataInfluence, we should tell developer about it.
apollo-audit/README.md
Outdated
|
||
This function can also be implemented automatically and manually. | ||
|
||
#### Automatically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#### Automatically | |
#### Mark which data change |
apollo-audit/README.md
Outdated
* Append DataInfluences by a list of entities needs to be audited, and their | ||
* audit-bean-definition. | ||
*/ | ||
ApolloAuditLogApi.appendDataInfluences(List<Object> entities, Class<?> beanDefinition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recomand use annotation instead of api, so we can left the api to the bottom of README.md?
|
||
And this will call appendDataInfluences automatically by the listener. | ||
|
||
#### Manually |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should describe how to verify the audit log work too...
For example, which table's data change, or how to check it by UI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What's the purpose of this PR
add audit log module, PR for code review and further discussion
Which issue(s) this PR fixes:
Fixes #
#3505
Brief changelog
Add Apollo-Audit module which contains 4 modules of annotation, api, impl, springbootstarter
Add basic front-end pages
Follow this checklist to help us incorporate your contribution quickly and easily:
mvn clean test
to make sure this pull request doesn't break anything.CHANGES
log.