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

bugfix duplicate collect job when update monitor templates #1332

Merged
merged 4 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion home/blog/2022-07-10-hertzbeat-v1.1.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Have Fun!

> `HertzBeat`'s multi-type support, easy expansion, low coupling, hope to help developers and micro teams to quickly build their own monitoring tool.

**If you like HertzBeat, give us a star on GitHub**
**If you like HertzBeat, star us on GitHub**

[Github](https://github.com/dromara/hertzbeat) https://github.com/dromara/hertzbeat
[Gitee](https://gitee.com/dromara/hertzbeat) https://gitee.com/dromara/hertzbeat
Expand Down
2 changes: 1 addition & 1 deletion home/docs/advanced/extend-http-example-hertzbeat.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ metrics:

This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!

If you think hertzbeat is a good open source project, please give us a star on GitHub Gitee, thank you very much.
If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much.

**github: https://github.com/dromara/hertzbeat**

Expand Down
2 changes: 1 addition & 1 deletion home/docs/advanced/extend-http-example-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ metrics:

This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!

If you think hertzbeat is a good open source project, please give us a star on GitHub Gitee, thank you very much.
If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much.

**github: https://github.com/dromara/hertzbeat**

Expand Down
2 changes: 1 addition & 1 deletion home/docs/advanced/extend-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ metrics:

This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!

If you think hertzbeat is a good open source project, please give us a star on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!
If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!

**github: https://github.com/dromara/hertzbeat**

Expand Down
2 changes: 1 addition & 1 deletion home/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
announcementBar: {
id: 'github-star',
content:
'<font style="font-size: medium; font-weight: bolder">If you like HertzBeat,</font> <a target="_blank" style="font-size: medium; font-weight: bolder" rel="noopener noreferrer" href="https://github.com/dromara/hertzbeat">give us a star on GitHub </a> <font style="font-size: medium; font-weight: bolder"> or </font><a target="_blank" style="font-size: medium; font-weight: bolder" rel="noopener noreferrer" href="https://gitee.com/dromara/hertzbeat">Gitee! </a>⭐️⭐️',
'<font style="font-size: medium; font-weight: bolder">If you like HertzBeat,</font> <a target="_blank" style="font-size: medium; font-weight: bolder" rel="noopener noreferrer" href="https://github.com/dromara/hertzbeat">star us on GitHub </a> <font style="font-size: medium; font-weight: bolder"> or </font><a target="_blank" style="font-size: medium; font-weight: bolder" rel="noopener noreferrer" href="https://gitee.com/dromara/hertzbeat">Gitee! </a>⭐️⭐️',
backgroundColor: '#7228B5',
textColor: '#fafbfc',
isCloseable: true,
Expand Down
4 changes: 2 additions & 2 deletions home/i18n/en/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@
"go github": {
"message": "Go To Github"
},
"If you like HertzBeat, give us a star on GitHub": {
"message": "If you like HertzBeat, give us a star on GitHub."
"If you like HertzBeat, star us on GitHub": {
"message": "If you like HertzBeat, star us on GitHub."
},
"We will grow better with your support.": {
"message": "We will grow better with your support and is our greatest motivation."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ metrics:

This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!

If you think hertzbeat is a good open source project, please give us a star on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!
If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!

**github: https://github.com/dromara/hertzbeat**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ metrics:

This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!

If you think hertzbeat is a good open source project, please give us a star on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!
If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!

**github: https://github.com/dromara/hertzbeat**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ metrics:

This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!

If you think hertzbeat is a good open source project, please give us a star on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!
If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!

**github: https://github.com/dromara/hertzbeat**

Expand Down
4 changes: 2 additions & 2 deletions home/i18n/zh-cn/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@
"go github": {
"message": "前往 Github"
},
"If you like HertzBeat, give us a star on GitHub": {
"message": "如果您喜欢 HertzBeat,欢迎给 HertzBeat 一个 Star。"
"If you like HertzBeat, star us on GitHub": {
"message": "如果您喜欢 HertzBeat,欢迎给 HertzBeat Star。"
},
"We will grow better with your support.": {
"message": "有您的支持 HertzBeat 社区会发展得更好,也是我们的最大动力。"
Expand Down
2 changes: 1 addition & 1 deletion home/src/pages/components/DiaLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function DiaLog() {
</div>
}>
<p style={{lineHeight: 1.5, textAlign: "center"}}>
<Translate>If you like HertzBeat, give us a star on GitHub</Translate>
<Translate>If you like HertzBeat, star us on GitHub</Translate>
</p>
<p style={{lineHeight: 1.5}}>
<Translate>We will grow better with your support.</Translate>
Expand Down
12 changes: 0 additions & 12 deletions home/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,12 @@ function Home() {
src={useBaseUrl('/img/home/2.png')}
/>
</SwiperSlide>
<SwiperSlide>
<img
style={{ width: '1000px', display: 'block', margin: '0 auto' }}
src={useBaseUrl('/img/home/3.png')}
/>
</SwiperSlide>
<SwiperSlide>
<img
style={{ width: '1000px', display: 'block', margin: '0 auto' }}
src={useBaseUrl('/img/home/4.png')}
/>
</SwiperSlide>
<SwiperSlide>
<img
style={{ width: '1000px', display: 'block', margin: '0 auto' }}
src={useBaseUrl('/img/home/5.png')}
/>
</SwiperSlide>
<SwiperSlide>
<img
style={{ width: '1000px', display: 'block', margin: '0 auto' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ metrics:

This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!

If you think hertzbeat is a good open source project, please give us a star on GitHub Gitee, thank you very much.
If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much.

**github: https://github.com/dromara/hertzbeat**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ metrics:

This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!

If you think hertzbeat is a good open source project, please give us a star on GitHub Gitee, thank you very much.
If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much.

**github: https://github.com/dromara/hertzbeat**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ metrics:

This is the end of the practice of custom monitoring of the HTTP protocol. The HTTP protocol also has other parameters such as headers and params. We can define it like postman, and the playability is also very high!

If you think hertzbeat is a good open source project, please give us a star on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!
If you think hertzbeat is a good open source project, please star us on GitHub Gitee, thank you very much. Thanks for the old iron support. Refill!

**github: https://github.com/dromara/hertzbeat**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.List;
import java.util.Optional;
import java.util.Set;


/**
Expand All @@ -41,6 +42,13 @@ public interface CollectorMonitorBindDao extends JpaRepository<CollectorMonitorB
* @return monitor bind
*/
List<CollectorMonitorBind> findCollectorMonitorBindsByCollector(String collector);

/**
* find monitor collector bind by monitor ids
* @param monitorIds monitor ids
* @return binds
*/
List<CollectorMonitorBind> findCollectorMonitorBindsByMonitorIdIn(Set<Long> monitorIds);

/**
* find bind collector by monitor id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,29 +741,28 @@ public void copyMonitors(List<Long> ids) {

@Override
public void updateAppCollectJob(Job job) {
List<Monitor> availableMonitors = monitorDao.findMonitorsByAppEquals(job.getApp()).
stream().filter(monitor -> monitor.getStatus() == CommonConstants.AVAILABLE_CODE)
List<Monitor> monitors = monitorDao.findMonitorsByAppEquals(job.getApp()).
stream().filter(monitor -> monitor.getStatus() != CommonConstants.UN_MANAGE_CODE)
.collect(Collectors.toList());
if (!availableMonitors.isEmpty()) {
for (Monitor monitor : availableMonitors) {
Job appDefine = JsonUtil.fromJson(JsonUtil.toJson(job), Job.class);
if (monitor == null || appDefine == null) {
continue;
}
if (monitor.getId() != null) {
appDefine.setMonitorId(monitor.getId());
} else {
continue;
}
if (monitor.getIntervals() != null) {
appDefine.setInterval(monitor.getIntervals());
} else {
List<CollectorMonitorBind> monitorBinds = collectorMonitorBindDao.findCollectorMonitorBindsByMonitorIdIn(
monitors.stream().map(Monitor::getId).collect(Collectors.toSet()));
Map<Long, String> monitorIdCollectorMap = monitorBinds.stream().collect(
Collectors.toMap(CollectorMonitorBind::getMonitorId, CollectorMonitorBind::getCollector));
for (Monitor monitor : monitors) {
try {
Job appDefine = job.clone();
if (monitor == null || appDefine == null || monitor.getId() == null || monitor.getJobId() == null) {
log.error("update monitor job error when template modify, define | id | jobId is null. continue");
continue;
}
appDefine.setId(monitor.getJobId());
appDefine.setMonitorId(monitor.getId());
appDefine.setInterval(monitor.getIntervals());
appDefine.setCyclic(true);
appDefine.setTimestamp(System.currentTimeMillis());
List<Param> params = paramDao.findParamsByMonitorId(monitor.getId());
List<Configmap> configmaps = params.stream().map(param -> new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
List<Configmap> configmaps = params.stream().map(param -> new Configmap(param.getField(),
param.getValue(), param.getType())).collect(Collectors.toList());
List<ParamDefine> paramDefaultValue = appDefine.getParams().stream()
.filter(item -> StringUtils.hasText(item.getDefaultValue()))
.collect(Collectors.toList());
Expand All @@ -774,10 +773,14 @@ public void updateAppCollectJob(Job job) {
}
});
appDefine.setConfigmap(configmaps);
// if is pinned collector
String collector = monitorIdCollectorMap.get(monitor.getId());
// 下发采集任务
long newJobId = collectJobScheduling.addAsyncCollectJob(appDefine, null);
long newJobId = collectJobScheduling.updateAsyncCollectJob(appDefine, collector);
monitor.setJobId(newJobId);
monitorDao.save(monitor);
monitorDao.save(monitor);
} catch (Exception e) {
log.error("update monitor job error when template modify: {}.continue", e.getMessage(), e);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions script/docker/collector/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ fi
# 编译上下文目录
CONTEXT_DIR=`pwd`

COMMAND="docker buildx build --platform linux/arm64,linux/amd64 -t tancloud/hertzbeat-collector:v$VERSION -f $CURRENT_DIR/Dockerfile $CONTEXT_DIR --build-arg VERSION="$VERSION" --push"
#COMMAND="docker buildx build --platform linux/arm64,linux/amd64 -t tancloud/hertzbeat-collector:v$VERSION -f $CURRENT_DIR/Dockerfile $CONTEXT_DIR --build-arg VERSION="$VERSION" --push"

#COMMAND="docker buildx build --platform linux/arm64,linux/amd64 -t tancloud/hertzbeat-collector:latest -f $CURRENT_DIR/Dockerfile $CONTEXT_DIR --build-arg VERSION="$VERSION" --push"

#COMMAND="docker buildx build --platform linux/arm64,linux/amd64 -t quay.io/tancloud/hertzbeat-collector:v$VERSION -f $CURRENT_DIR/Dockerfile $CONTEXT_DIR --build-arg VERSION="$VERSION" --push"
COMMAND="docker buildx build --platform linux/arm64,linux/amd64 -t quay.io/tancloud/hertzbeat-collector:v$VERSION -f $CURRENT_DIR/Dockerfile $CONTEXT_DIR --build-arg VERSION="$VERSION" --push"

#COMMAND="docker buildx build --platform linux/arm64,linux/amd64 -t quay.io/tancloud/hertzbeat-collector:latest -f $CURRENT_DIR/Dockerfile $CONTEXT_DIR --build-arg VERSION="$VERSION" --push"

Expand Down
Loading