Skip to content
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

[Feature-14832][Listener]Implementation of Listener Mechanism #14981

Merged
merged 18 commits into from
Oct 29, 2023

Conversation

weixiaonan1
Copy link
Contributor

This closes #14832

Purpose of the pull request

This pull request adds a new type of alert plugin instance: global alert plugin instance. The global alert plugin instance will receive and post all system-generated events by default. Now support 10 types of events.

Brief change log

  1. add a global alert group (id: 2) which users cannot modify/delete, the global alert instance will be added into/ removed from this group automatically.
    image

  2. In addition to the original alarm instance type, add a new option for global alarm instances.
    image

  3. add 10 types of events: ServerDownListenerEvent, ProcessDefinitionCreatedLitenerEvent, ProcessDefinitionUpdatedLitenerEvent, ProcessDefinitionDeletedLitenerEvent, ProcessStartListenerEvent, ProcessEndListenerEvent, ProcessFailListenerEvent, TaskStartListenerEvent, TaskEndListenerEvent, TaskFailListenerEvent. The event will be saved in table t_ds_listener_event.

  4. In addition to AlertBootstrapService, add ListenerEventPostService in AlertServer: get pending listener events from t_ds_listener_event, get global alert instances and post these events.

database change

  1. insert global alert group into t_ds_alertgroup
  2. add instance_type, warning_type in t_ds_alert_plugin_instance. alert instance type: 0 normal; 1 global. warning_type: warning type of normal alert instance which existed in plugin_instance_params previously.
  3. new table t_ds_listener_event: save global listener events, which is simpler than t_ds_alert.

Brief change log

@mergeable
Copy link

mergeable bot commented Sep 30, 2023

⚠️ This PR do not change database DDL synchronize.

@github-actions github-actions bot added UI ui and front end related backend labels Sep 30, 2023
@weixiaonan1
Copy link
Contributor Author

Due to OSPP time constraints, some improments need to be done in future PRs.

  1. Refine global alert instances: when creating global alert instance, we can choose event types to subscribe to. The current global alert instance subscribes to all events by default. If we can choose event types, there is no longer a need for the default admin warning group. We can create a global alert instance that only subscribe to ServerDownListenerEventto replace the default admin warning group.
  2. Is it necessary to choose warning type for normal alert instances? In order to be compatible with the logic of normal alert instances, we have reserved the option of warning type (success, fail, all). Warning type is actually a collection of event types: success is a collection of ProcessEndEvent; fail is a collection of ProcessFailEvent, ProcessTimeoutEvent, etc. It is necessary for global alert instances to choose event types. However, for normal alert instances, the generation of events is manually triggered by the user (select the alarm strategy and the alarm group bound to the workflow), the types of events generated (ProcessEndEvent, ProcessTimeoutEvent, and ProcessFailEvent) are also fixed. Users have already explicitly bound the alert group and normal alert instances, and the event types which normal alert instance can subscribe to are also fixed, it is fine to send the message directly througn these normal instances. Is it still necessary for users to choose the warning type for normal alert instances?
  3. listener_event and alert: alert content can be abstracted as listener events, and the content stored in t_ds_listener_event is actually alert which global alert group need to process. In this submission, we just add limited logic of global alert events, which is relatively independent with alert. It’s difficult to merge listener_event and alert in this submission because t_ds_alert contains process_definition_code, project_code and other information besides the event itself, And the process of generating alerts in WorkflowExecuteRunnable and ProcessAlertManager is relatively complex. Afterwards, we can consider merging the two.

globalAlertGroup.setAlertInstanceIds(String.valueOf(alertPluginInstance.getId()));
} else {
List<Integer> ids = Arrays.stream(globalAlertGroup.getAlertInstanceIds().split(","))
.map(s -> Integer.parseInt(s.trim()))

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
// global instance will be removed from global alert group automatically
AlertGroup globalAlertGroup = alertGroupMapper.selectById(2);
List<Integer> ids = Arrays.stream(globalAlertGroup.getAlertInstanceIds().split(","))
.map(s -> Integer.parseInt(s.trim()))

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
@mergeable mergeable bot removed the sql not sync label Oct 12, 2023
2. front-end: change to ternary expression
3. back-end: correct license header in ListenerEvent.java
@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2023

Codecov Report

Merging #14981 (f882ed8) into dev (99214d0) will increase coverage by 0.31%.
The diff coverage is 69.65%.

❗ Current head f882ed8 differs from pull request most recent head ca324ce. Consider uploading reports for the commit ca324ce to get more accurate results

@@             Coverage Diff              @@
##                dev   #14981      +/-   ##
============================================
+ Coverage     37.80%   38.11%   +0.31%     
- Complexity     4596     4643      +47     
============================================
  Files          1248     1262      +14     
  Lines         44711    45155     +444     
  Branches       4912     4944      +32     
============================================
+ Hits          16903    17211     +308     
- Misses        25928    26050     +122     
- Partials       1880     1894      +14     
Files Coverage Δ
...phinscheduler/alert/plugin/AlertPluginManager.java 3.33% <ø> (+0.89%) ⬆️
...scheduler/api/controller/AlertGroupController.java 80.00% <100.00%> (+1.42%) ⬆️
.../api/controller/AlertPluginInstanceController.java 100.00% <100.00%> (ø)
.../org/apache/dolphinscheduler/api/enums/Status.java 100.00% <100.00%> (ø)
...lphinscheduler/common/enums/ListenerEventType.java 100.00% <100.00%> (ø)
...java/org/apache/dolphinscheduler/dao/AlertDao.java 26.89% <ø> (ø)
...y/event/ProcessDefinitionCreatedListenerEvent.java 100.00% <100.00%> (ø)
...y/event/ProcessDefinitionUpdatedListenerEvent.java 100.00% <100.00%> (ø)
.../master/runner/WorkflowExecuteRunnableFactory.java 0.00% <ø> (ø)
...org/apache/dolphinscheduler/alert/AlertServer.java 0.00% <0.00%> (ø)
... and 19 more

... and 4 files with indirect coverage changes

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

@caishunfeng caishunfeng added the feature new feature label Oct 23, 2023
@zixi0825 zixi0825 added this to the 3.3.0 milestone Oct 24, 2023
songjianet
songjianet previously approved these changes Oct 24, 2023
@SbloodyS SbloodyS added 3.3.0 first time contributor First-time contributor labels Oct 26, 2023
Copy link
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.

Generally LGTM. Just some NIT.

Comment on lines +315 to +317
listenerEventAlertManager.publishProcessDefinitionCreatedListenerEvent(loginUser, processDefinition,
taskDefinitionLogs,
taskRelationList);
Copy link
Member

Choose a reason for hiding this comment

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

Can we put this in audit aspect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to add annotation on the methods where generate events to make publish events unified? I think it's hard. Because we cannot get enougn information from arguments and return value of the method for most events such as ProcessStartListenerEvent, ProcessDefinitionDeletedListenerEvent.

@sonarcloud
Copy link

sonarcloud bot commented Oct 28, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

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

69.7% 69.7% Coverage
18.3% 18.3% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@zixi0825
Copy link
Member

LGTM

Copy link
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.

+1

@SbloodyS SbloodyS merged commit c0ed681 into apache:dev Oct 29, 2023
58 of 60 checks passed
xdu-chenrj pushed a commit to xdu-chenrj/dolphinscheduler that referenced this pull request Oct 30, 2023
…#14981)

* first commit

* 1. sql: sync ddl
2. front-end: change to ternary expression
3. back-end: correct license header in ListenerEvent.java

* test case

* frontend: remove unnecessary console

* fix unit test

* remove log depends on user-provided value

* fix dolphinscheduler_postgresql.sql

* sync database schema

* fix unit test

* fix unit test

* fix some NIT.

* extract GLOBAL_ALERT_GROUP_ID into variable

* fix ddl bug

* add column task_type in t_ds_fav_task in upgrade/3.2.0_schema

* add unit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.3.0 backend feature new feature first time contributor First-time contributor ready-to-merge UI ui and front end related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature][Listener]Implementation of Listener Mechanism
7 participants