Skip to content

Conversation

@xjlgod
Copy link
Contributor

@xjlgod xjlgod commented Oct 25, 2023

Purpose of the pull request

To add alert-api for prometheus alertmanager close #14654.
The implementation principle is to request its alert interface through http client to generate an alert.
api document

Brief change log

a new moudle dolphinscheduler-alert-prometheus be added

Verify this pull request

create alert instance to test it.
9cc27e4905f8721471eb14f138a8d39
3e577f7f5471e1bc3f567b5fb2752c5

@github-actions github-actions bot added UI ui and front end related backend labels Oct 25, 2023
@xjlgod xjlgod changed the title [feature#14654] alert-spi support prometheus alertmanager [WIP][feature#14654] alert-spi support prometheus alertmanager Oct 25, 2023
@xjlgod xjlgod changed the title [WIP][feature#14654] alert-spi support prometheus alertmanager [feature#14654] alert-spi support prometheus alertmanager Oct 25, 2023
songjianet
songjianet previously approved these changes Oct 26, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 26, 2023

Codecov Report

Merging #15079 (36aa3fa) into dev (0121c5d) will increase coverage by 0.07%.
Report is 1 commits behind head on dev.
The diff coverage is 66.94%.

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

@@             Coverage Diff              @@
##                dev   #15079      +/-   ##
============================================
+ Coverage     38.17%   38.24%   +0.07%     
- Complexity     4681     4693      +12     
============================================
  Files          1281     1285       +4     
  Lines         45350    45412      +62     
  Branches       4941     4926      -15     
============================================
+ Hits          17311    17367      +56     
- Misses        26151    26154       +3     
- Partials       1888     1891       +3     
Files Coverage Δ
...nscheduler/api/service/impl/DqRuleServiceImpl.java 59.18% <100.00%> (ø)
...cheduler/plugin/task/dq/utils/RuleParserUtils.java 87.03% <100.00%> (ø)
...lert/prometheus/PrometheusAlertChannelFactory.java 95.65% <95.65%> (ø)
...gin/alert/prometheus/PrometheusAlertConstants.java 0.00% <0.00%> (ø)
...apache/dolphinscheduler/dao/utils/DqRuleUtils.java 0.00% <0.00%> (ø)
...inscheduler/plugin/task/api/enums/dp/DataType.java 88.88% <85.71%> (ø)
...er/runner/execute/TaskExecutionContextFactory.java 0.00% <0.00%> (ø)
...lugin/alert/prometheus/PrometheusAlertChannel.java 16.66% <16.66%> (ø)
...plugin/alert/prometheus/PrometheusAlertSender.java 62.16% <62.16%> (ø)

... and 27 files with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

}

private static CloseableHttpClient getDefaultClient() {
return HttpClients.createDefault();
Copy link
Member

Choose a reason for hiding this comment

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

public String getResponseString(HttpRequestBase httpRequest) throws IOException {
CloseableHttpClient httpClient =
HttpClients.custom().setRetryHandler(HttpServiceRetryStrategy.retryStrategy).build();
CloseableHttpResponse response = httpClient.execute(httpRequest);
HttpEntity entity = response.getEntity();
return EntityUtils.toString(entity, DEFAULT_CHARSET);
}

Based on the implementation of other plugins, it is recommended to use an HTTP client that supports retrying

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

Copy link
Member

@Gallardot Gallardot left a comment

Choose a reason for hiding this comment

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

Rest LGTM.


@BeforeEach
public void initConfig() {
config.put(AlertManagerConstants.NAME_ALERT_MANAGER_URL, "http://127.0.0.1:9093");
Copy link
Member

Choose a reason for hiding this comment

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

How does this unit test mock an AlertManager-Server and pass the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I set the unit test result to false. If need, I can add test to mock an AlertManager-Server. I did not add it for there is no mock for third server in any other alert plugins.

Copy link
Member

Choose a reason for hiding this comment

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

Got it. LGTM.

@Gallardot
Copy link
Member

@SbloodyS @Radeity @EricGao888 @qingwli PTAL.

@Radeity
Copy link
Member

Radeity commented Nov 1, 2023

In addition, file name in package org.apache.dolphinscheduler.plugin.alert.prometheus should start with Prometheus, like PrometheusAlertChannel and PrometheusSender.

@xjlgod
Copy link
Contributor Author

xjlgod commented Nov 2, 2023

In addition, file name in package org.apache.dolphinscheduler.plugin.alert.prometheus should start with Prometheus, like PrometheusAlertChannel and PrometheusSender.

OK

log.error("send prometheus alert manager alert msg exception: {}", e.getMessage());
alertResult = new AlertResult();
alertResult.setStatus("false");
alertResult.setMessage("send prometheus alert manager alert fail.");
Copy link
Member

Choose a reason for hiding this comment

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

Please add error into the message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CC

Copy link
Member

@qingwli qingwli left a comment

Choose a reason for hiding this comment

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

Others LGTM

…cheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertSender.java

Co-authored-by: 旺阳 <[email protected]>
Copy link
Member

@qingwli qingwli left a comment

Choose a reason for hiding this comment

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

LGTM

@qingwli
Copy link
Member

qingwli commented Nov 13, 2023

PTAL @Radeity

@sonarqubecloud
Copy link

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 15 Code Smells

66.2% 66.2% Coverage
0.0% 0.0% Duplication

@qingwli qingwli merged commit 6096c58 into apache:dev Nov 13, 2023
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][Alert] Add prometheus's Alertmanager

8 participants