Skip to content

Commit 3e3bbf7

Browse files
authored
Merge branch 'master' into 0804-yuluo/tets-1
2 parents 074b56b + 9b065f7 commit 3e3bbf7

File tree

990 files changed

+25686
-22727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

990 files changed

+25686
-22727
lines changed

.github/workflows/nightly-build.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Nightly CI
19+
20+
on:
21+
schedule:
22+
# trigger at 00:00 everyday
23+
- cron: '0 0 * * *'
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: docker/setup-qemu-action@v3
31+
- name: Set up JDK 17
32+
uses: actions/setup-java@v1
33+
with:
34+
java-version: 17
35+
- name: Build with Maven
36+
run: mvn clean -B package -Prelease --file pom.xml
37+
38+
- name: Build Image
39+
env:
40+
IMAGE_PUSH: false
41+
IMAGE_LOAD: true
42+
IMAGE_VERSION: nightly
43+
run: |
44+
docker buildx create --use --name myBuilder --driver docker-container
45+
docker buildx use myBuilder
46+
47+
./script/docker/server/build.sh
48+
49+
- name: Login to Docker Hub
50+
uses: docker/login-action@v3
51+
with:
52+
username: ${{ secrets.DOCKERHUB_USER }}
53+
password: ${{ secrets.DOCKERHUB_TOKEN }}
54+
55+
- name: Build and Push
56+
uses: docker/build-push-action@v6
57+
with:
58+
context: .
59+
push: true
60+
tags: apache/hertzbeat:nightly

.gitmodules

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
[submodule "script/helm/hertzbeat-helm-chart"]
19+
path = script/helm/hertzbeat-helm-chart
20+
url = git@github.com:apache/hertzbeat-helm-chart.git
21+
branch = main

alerter/src/main/java/org/apache/hertzbeat/alert/dto/TenCloudAlertReport.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public Map<String, String> getAnnotations() {
174174
@Override
175175
public String getContent() {
176176
StringBuilder contentBuilder = new StringBuilder();
177-
// 判断类型
177+
// Check Type.
178178
if (EVENT.equals(getAlarmType())) {
179179
contentBuilder
180180
.append("[")
@@ -225,5 +225,3 @@ public String getContent() {
225225
}
226226

227227
}
228-
229-

alerter/src/main/java/org/apache/hertzbeat/alert/reduce/AlarmConvergeReduce.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean filterConverge(Alert currentAlert) {
6060
// restored alert
6161
boolean isHasIgnore = false;
6262
Map<String, String> tags = currentAlert.getTags();
63-
if (tags.containsKey(CommonConstants.IGNORE)) {
63+
if (Objects.requireNonNull(tags).containsKey(CommonConstants.IGNORE)) {
6464
isHasIgnore = true;
6565
tags.remove(CommonConstants.IGNORE);
6666
}

alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineServiceImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.hertzbeat.alert.service.AlertDefineImExportService;
3939
import org.apache.hertzbeat.alert.service.AlertDefineService;
4040
import org.apache.hertzbeat.common.constants.ExportFileConstants;
41+
import org.apache.hertzbeat.common.constants.SignConstants;
4142
import org.apache.hertzbeat.common.entity.alerter.AlertDefine;
4243
import org.apache.hertzbeat.common.entity.alerter.AlertDefineMonitorBind;
4344
import org.apache.hertzbeat.common.entity.manager.Monitor;
@@ -49,6 +50,7 @@
4950
import org.springframework.data.domain.Sort;
5051
import org.springframework.data.jpa.domain.Specification;
5152
import org.springframework.http.HttpHeaders;
53+
import org.springframework.http.MediaType;
5254
import org.springframework.stereotype.Service;
5355
import org.springframework.transaction.annotation.Transactional;
5456
import org.springframework.util.StringUtils;
@@ -73,6 +75,8 @@ public class AlertDefineServiceImpl implements AlertDefineService {
7375

7476
private final Map<String, AlertDefineImExportService> alertDefineImExportServiceMap = new HashMap<>();
7577

78+
private static final String CONTENT_TYPE = MediaType.APPLICATION_OCTET_STREAM_VALUE + SignConstants.SINGLE_MARK + "charset=" + StandardCharsets.UTF_8;
79+
7680
public AlertDefineServiceImpl(List<AlertDefineImExportService> alertDefineImExportServiceList) {
7781
alertDefineImExportServiceList.forEach(it -> alertDefineImExportServiceMap.put(it.type(), it));
7882
}
@@ -229,10 +233,10 @@ public void export(List<Long> ids, String type, HttpServletResponse res) throws
229233
throw new IllegalArgumentException("not support export type: " + type);
230234
}
231235
var fileName = imExportService.getFileName();
232-
res.setHeader("content-type", "application/octet-stream;charset=UTF-8");
233-
res.setContentType("application/octet-stream;charset=UTF-8");
236+
res.setHeader(HttpHeaders.CONTENT_TYPE, CONTENT_TYPE);
237+
res.setContentType(CONTENT_TYPE);
234238
res.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8));
235-
res.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
239+
res.setHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
236240
imExportService.exportConfig(res.getOutputStream(), ids);
237241
}
238242

alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineYamlImExportServiceTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,20 @@ class AlertDefineYamlImExportServiceTest {
5858
private AlertDefineYamlImExportServiceImpl service;
5959

6060
private static final String YAML_DATA =
61-
"- alertDefine:\n" +
62-
" app: App1\n" +
63-
" metric: Metric1\n" +
64-
" field: Field1\n" +
65-
" preset: true\n" +
66-
" expr: Expr1\n" +
67-
" priority: 1\n" +
68-
" times: 1\n" +
69-
" tags: []\n" +
70-
" enable: true\n" +
71-
" recoverNotice: true\n" +
72-
" template: Template1\n";
61+
"""
62+
- alertDefine:
63+
app: App1
64+
metric: Metric1
65+
field: Field1
66+
preset: true
67+
expr: Expr1
68+
priority: 1
69+
times: 1
70+
tags: []
71+
enable: true
72+
recoverNotice: true
73+
template: Template1
74+
""";
7375

7476
private InputStream inputStream;
7577
private List<ExportAlertDefineDTO> alertDefineList;
@@ -99,7 +101,7 @@ public void setup() {
99101
}
100102

101103
@Test
102-
void testParseImport() throws IllegalAccessException {
104+
void testParseImport() {
103105

104106
List<ExportAlertDefineDTO> result = service.parseImport(inputStream);
105107

collector/src/main/java/org/apache/hertzbeat/collector/collect/AbstractCollect.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.hertzbeat.collector.collect;
1919

20-
2120
import org.apache.hertzbeat.common.entity.job.Metrics;
2221
import org.apache.hertzbeat.common.entity.message.CollectRep;
2322

collector/src/main/java/org/apache/hertzbeat/collector/collect/common/cache/ConnectionCommonCache.java

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
2222
import java.util.Map;
2323
import java.util.Optional;
24-
import java.util.concurrent.ArrayBlockingQueue;
2524
import java.util.concurrent.ConcurrentHashMap;
2625
import java.util.concurrent.ScheduledThreadPoolExecutor;
2726
import java.util.concurrent.ThreadFactory;
28-
import java.util.concurrent.ThreadPoolExecutor;
2927
import java.util.concurrent.TimeUnit;
3028
import lombok.extern.slf4j.Slf4j;
3129

@@ -34,16 +32,11 @@
3432
*/
3533
@Slf4j
3634
public class ConnectionCommonCache<T, C extends AbstractConnection<?>> {
37-
38-
/**
39-
* default cache time 200s
40-
*/
41-
private static final long DEFAULT_CACHE_TIMEOUT = 200 * 1000L;
42-
35+
4336
/**
44-
* default max cache num
37+
* default cache time 600s
4538
*/
46-
private static final int DEFAULT_MAX_CAPACITY = 10000;
39+
private static final long DEFAULT_CACHE_TIMEOUT = 600 * 1000L;
4740

4841
/**
4942
* cacheTime length
@@ -60,19 +53,14 @@ public class ConnectionCommonCache<T, C extends AbstractConnection<?>> {
6053
*/
6154
private ConcurrentLinkedHashMap<T, C> cacheMap;
6255

63-
/**
64-
* the executor who clean cache when timeout
65-
*/
66-
private ThreadPoolExecutor timeoutCleanerExecutor;
67-
6856
public ConnectionCommonCache() {
69-
init();
57+
initCache();
7058
}
7159

72-
private void init() {
60+
private void initCache() {
7361
cacheMap = new ConcurrentLinkedHashMap
7462
.Builder<T, C>()
75-
.maximumWeightedCapacity(DEFAULT_MAX_CAPACITY)
63+
.maximumWeightedCapacity(Integer.MAX_VALUE)
7664
.listener((key, value) -> {
7765
timeoutMap.remove(key);
7866
try {
@@ -82,70 +70,37 @@ private void init() {
8270
}
8371
log.info("connection common cache discard key: {}, value: {}.", key, value);
8472
}).build();
85-
timeoutMap = new ConcurrentHashMap<>(DEFAULT_MAX_CAPACITY >> 6);
86-
// last-first-coverage algorithm, run the first and last thread, discard mid
87-
timeoutCleanerExecutor = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS,
88-
new ArrayBlockingQueue<>(1),
89-
r -> new Thread(r, "connection-cache-timeout-cleaner"),
90-
new ThreadPoolExecutor.DiscardOldestPolicy());
73+
timeoutMap = new ConcurrentHashMap<>(16);
9174
// init monitor available detector cyc task
9275
ThreadFactory threadFactory = new ThreadFactoryBuilder()
93-
.setNameFormat("connection-cache-ava-detector-%d")
76+
.setNameFormat("connection-cache-timout-detector-%d")
9477
.setDaemon(true)
9578
.build();
9679
ScheduledThreadPoolExecutor scheduledExecutor = new ScheduledThreadPoolExecutor(1, threadFactory);
97-
scheduledExecutor.scheduleWithFixedDelay(this::detectCacheAvailable, 2, 20, TimeUnit.MINUTES);
80+
scheduledExecutor.scheduleWithFixedDelay(this::cleanTimeoutOrUnHealthCache, 2, 100, TimeUnit.SECONDS);
9881
}
9982

10083
/**
101-
* detect all cache available, cleanup not ava connection
84+
* clean and remove timeout cache
10285
*/
103-
private void detectCacheAvailable() {
86+
private void cleanTimeoutOrUnHealthCache() {
10487
try {
10588
cacheMap.forEach((key, value) -> {
89+
// index 0 is startTime, 1 is timeDiff
10690
Long[] cacheTime = timeoutMap.get(key);
10791
long currentTime = System.currentTimeMillis();
10892
if (cacheTime == null || cacheTime.length != CACHE_TIME_LENGTH
10993
|| cacheTime[0] + cacheTime[1] < currentTime) {
110-
cacheMap.remove(key);
111-
timeoutMap.remove(key);
112-
try {
113-
value.close();
114-
} catch (Exception e) {
115-
log.error("connection close error: {}.", e.getMessage(), e);
116-
}
117-
118-
}
119-
});
120-
} catch (Exception e) {
121-
log.error("connection common cache detect cache available error: {}.", e.getMessage(), e);
122-
}
123-
}
124-
125-
/**
126-
* clean timeout cache
127-
*/
128-
private void cleanTimeoutCache() {
129-
try {
130-
cacheMap.forEach((key, value) -> {
131-
// index 0 is startTime, 1 is timeDiff
132-
Long[] cacheTime = timeoutMap.get(key);
133-
long currentTime = System.currentTimeMillis();
134-
if (cacheTime == null || cacheTime.length != CACHE_TIME_LENGTH) {
135-
timeoutMap.put(key, new Long[]{currentTime, DEFAULT_CACHE_TIMEOUT});
136-
} else if (cacheTime[0] + cacheTime[1] < currentTime) {
137-
// timeout, remove this object cache
13894
log.warn("[connection common cache] clean the timeout cache, key {}", key);
13995
timeoutMap.remove(key);
14096
cacheMap.remove(key);
14197
try {
14298
value.close();
14399
} catch (Exception e) {
144-
log.error("connection close error: {}.", e.getMessage(), e);
100+
log.error("clean connection close error: {}.", e.getMessage(), e);
145101
}
146102
}
147103
});
148-
Thread.sleep(20 * 1000);
149104
} catch (Exception e) {
150105
log.error("[connection common cache] clean timeout cache error: {}.", e.getMessage(), e);
151106
}
@@ -165,7 +120,6 @@ public void addCache(T key, C value, Long timeDiff) {
165120
}
166121
cacheMap.put(key, value);
167122
timeoutMap.put(key, new Long[]{System.currentTimeMillis(), timeDiff});
168-
timeoutCleanerExecutor.execute(this::cleanTimeoutCache);
169123
}
170124

171125
/**

collector/src/main/java/org/apache/hertzbeat/collector/collect/database/JdbcCommonCollect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import org.apache.hertzbeat.collector.collect.common.cache.CacheIdentifier;
3232
import org.apache.hertzbeat.collector.collect.common.cache.ConnectionCommonCache;
3333
import org.apache.hertzbeat.collector.collect.common.cache.JdbcConnect;
34+
import org.apache.hertzbeat.collector.constants.CollectorConstants;
3435
import org.apache.hertzbeat.collector.dispatch.DispatchConstants;
3536
import org.apache.hertzbeat.collector.util.CollectUtil;
36-
import org.apache.hertzbeat.common.constants.CollectorConstants;
3737
import org.apache.hertzbeat.common.constants.CommonConstants;
3838
import org.apache.hertzbeat.common.entity.job.Metrics;
3939
import org.apache.hertzbeat.common.entity.job.protocol.JdbcProtocol;

0 commit comments

Comments
 (0)