-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge https://github.com/apache/hertzbeat into 0716-yuluo/add-unit-test
- Loading branch information
Showing
8 changed files
with
385 additions
and
55 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
common/src/test/java/org/apache/hertzbeat/common/queue/impl/InMemoryCommonDataQueueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hertzbeat.common.queue.impl; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.hertzbeat.common.entity.alerter.Alert; | ||
import org.apache.hertzbeat.common.entity.message.CollectRep; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
/** | ||
* Test case for {@link InMemoryCommonDataQueue} | ||
*/ | ||
class InMemoryCommonDataQueueTest { | ||
|
||
private InMemoryCommonDataQueue queue; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
queue = new InMemoryCommonDataQueue(); | ||
} | ||
|
||
@Test | ||
void testAlertsData() throws InterruptedException { | ||
|
||
var alert = new Alert(); | ||
|
||
queue.sendAlertsData(alert); | ||
assertEquals(1, queue.getQueueSizeMetricsInfo().get("alertDataQueue")); | ||
|
||
var polledAlert = queue.pollAlertsData(); | ||
assertEquals(0, queue.getQueueSizeMetricsInfo().get("alertDataQueue")); | ||
|
||
assertNotNull(polledAlert); | ||
assertEquals(alert, polledAlert); | ||
} | ||
|
||
@Test | ||
void testMetricsData() throws InterruptedException { | ||
|
||
var metricsData = CollectRep.MetricsData.newBuilder().build(); | ||
|
||
queue.sendMetricsData(metricsData); | ||
|
||
CollectRep.MetricsData polledMetricsData = queue.pollMetricsDataToAlerter(); | ||
|
||
assertNotNull(polledMetricsData); | ||
assertEquals(metricsData, polledMetricsData); | ||
|
||
polledMetricsData = queue.pollMetricsDataToPersistentStorage(); | ||
|
||
assertNotNull(polledMetricsData); | ||
assertEquals(metricsData, polledMetricsData); | ||
|
||
polledMetricsData = queue.pollMetricsDataToRealTimeStorage(); | ||
|
||
assertNotNull(polledMetricsData); | ||
assertEquals(metricsData, polledMetricsData); | ||
} | ||
|
||
@Test | ||
void testGetQueueSizeMetricsInfo() { | ||
|
||
Map<String, Integer> metricsInfo = queue.getQueueSizeMetricsInfo(); | ||
|
||
assertEquals(0, metricsInfo.get("alertDataQueue")); | ||
assertEquals(0, metricsInfo.get("metricsDataToAlertQueue")); | ||
assertEquals(0, metricsInfo.get("metricsDataToPersistentStorageQueue")); | ||
assertEquals(0, metricsInfo.get("metricsDataToMemoryStorageQueue")); | ||
|
||
queue.sendAlertsData(new Alert()); | ||
queue.sendMetricsData(CollectRep.MetricsData.newBuilder().build()); | ||
|
||
metricsInfo = queue.getQueueSizeMetricsInfo(); | ||
|
||
assertEquals(1, metricsInfo.get("alertDataQueue")); | ||
assertEquals(1, metricsInfo.get("metricsDataToAlertQueue")); | ||
assertEquals(1, metricsInfo.get("metricsDataToPersistentStorageQueue")); | ||
assertEquals(1, metricsInfo.get("metricsDataToMemoryStorageQueue")); | ||
} | ||
|
||
@Test | ||
void testDestroy() { | ||
|
||
queue.sendAlertsData(new Alert()); | ||
queue.sendMetricsData(CollectRep.MetricsData.newBuilder().build()); | ||
|
||
queue.destroy(); | ||
|
||
Map<String, Integer> metricsInfo = queue.getQueueSizeMetricsInfo(); | ||
|
||
assertEquals(0, metricsInfo.get("alertDataQueue")); | ||
assertEquals(0, metricsInfo.get("metricsDataToAlertQueue")); | ||
assertEquals(0, metricsInfo.get("metricsDataToPersistentStorageQueue")); | ||
assertEquals(0, metricsInfo.get("metricsDataToMemoryStorageQueue")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: Welcome to HertzBeat Community Committer! | ||
author: LiuTianyou | ||
author_title: LiuTianyou | ||
author_url: https://github.com/LiuTianyou | ||
author_image_url: https://avatars.githubusercontent.com/u/30208283?v=4 | ||
tags: [opensource, practice] | ||
keywords: [open source monitoring system, alerting system] | ||
--- | ||
|
||
|
||
![hertzBeat](/img/blog/new-committer.png) | ||
|
||
Hello everyone, I am very honored to receive an invitation from the community to be nominated as a Committer for Apache HertzBeat. Let me introduce myself briefly. I have been working as a backend developer since 2019, mainly using Java. Currently, I am working at a network security company, focusing on the backend development of network security-related products. | ||
|
||
### Encounter | ||
|
||
In my work, several physical servers are deployed, running various databases and middleware. Although we have deployed the Prometheus + Grafana monitoring combination, most services and servers require additional installation of exporters. As a result, this monitoring system does not cover the entire project. Sometimes, we only realize a service is down when it is too late. One day in April, I came across an article introducing HertzBeat. I was immediately attracted by its unique features, such as no need for agents and fully visualized configuration, along with support for one-click deployment via Docker. I quickly deployed HertzBeat and put it into use. | ||
|
||
### Familiarization | ||
|
||
Due to the fully visualized operation, I quickly incorporated the servers, databases, and middleware used in the project into HertzBeat's management. Afterwards, the community was preparing to release the first Apache version and needed to supplement a large amount of documentation. I attempted to submit some documents to familiarize myself with the community's process for submitting code and documentation, and at the same time, I got familiar with the relevant parts of the code while supplementing the documents. | ||
|
||
### Trying to Add Something | ||
|
||
The first major change I made was to enable HertzBeat to support querying metrics from NebulaGraph using NGQL statements. Additionally, I added a monitoring template for NebulaGraph clusters based on this protocol. The idea initially came from my own needs. When I submitted this idea to the community, I quickly received a response and affirmation from the community, which greatly increased my confidence in continuously participating in this project. | ||
|
||
### Joining | ||
|
||
Due to my continuous writing of documents and contributing code, I started to become familiar with this community and this project, and began to make some of my own suggestions. Many of these suggestions were adopted by the community and released in new versions. After the first Apache version was released, I received an invitation from @tomsun28 and @TJxiaobao to be nominated as a Committer. | ||
|
||
### Conclusion | ||
|
||
I am very honored to be able to participate in this project and be recognized by the community. I would like to thank @tomsun28, @TJxiaobao, @zqr10159, @tuohai666, @yuluo-yx, @crossoverJie, @zhangshenghang, and @pwallk for reviewing my code, providing guidance, and helping me. Finally, I wish Apache HertzBeat to grow strong and have more and more contributors participating. |
35 changes: 35 additions & 0 deletions
35
home/i18n/zh-cn/docusaurus-plugin-content-blog/2024-07-15-new-committer.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: 热烈欢迎 HertzBeat 小伙伴新晋社区 Committer! | ||
author: LiuTianyou | ||
author_title: LiuTianyou | ||
author_url: https://github.com/LiuTianyou | ||
author_image_url: https://avatars.githubusercontent.com/u/30208283?v=4 | ||
tags: [opensource, practice] | ||
keywords: [open source monitoring system, alerting system] | ||
--- | ||
|
||
|
||
![hertzBeat](/img/blog/new-committer.png) | ||
|
||
大家好,非常荣幸可以收到社区邀请被提名为 Apache HertzBeat 的 Committer。我先做一个简单的自我介绍,从2019年工作开始,一直从事后端开发工作,主要使用Java语言,目前在一家网络安全公司从事网络安全相关产品后端开发工作。 | ||
|
||
|
||
### 遇见 | ||
|
||
我工作的项目里部署着数台物理服务器,其中运行着各种数据库,中间件,尽管部署了 Prometheus + grafana 的监控组合,但由于大多数的服务和服务器都需要额外安装 exporter,这套监控系统并没有覆盖到项目的全部,有时候服务宕机了,被用到了才发现。四月份的某一天我刷到了一篇公众号文章介绍了 HertzBeat,我马上被不需要 agent,全程可视化配置的特新吸引加上支持docker一键部署,我迅速的部署起来了 HertzBeat 并投入了使用。 | ||
|
||
### 熟悉 | ||
|
||
由于完全可视化操作,很快就将项目中用到的服务器,数据库,中间件纳入了 HertzBeat 的管理。之后,恰好社区为发布第一个Apache版本做准备,需要补充大量的文档。我尝试提交一些文档,来熟悉社区的提交代码和文档的流程,也顺便在补充的文档的过程的熟悉相关部分的代码。 | ||
|
||
### 尝试加一点东西 | ||
|
||
我做的第一个大的改动是让 HertzBeat 支持使用NGQL语句从NebulaGraph中查询指标,并且这个基于协议增加了NebulaGraph集群的监控模板。最开始有这个想法来源于自己的需求,当我把这个想法提交给社区时,很快就得到了社区的回应,并得到了肯定,这也让对持续参与这个项目信心倍增。 | ||
|
||
### 加入 | ||
|
||
由于我不停的写文档,贡献代码,我开始熟悉这个社区,熟悉这个项目,开始尝试提出一些自己的建议。很多建议都被社区采纳,并且在新版本中发布,在第一个Apache版本发布后,我收到了@tomsun28和@TJxiaobao的邀请被提名为Committer。 | ||
|
||
### 结语 | ||
|
||
非常荣幸可以参与到这个项目中并被社区认可,感谢帮我review代码,给我指导和帮助的 @tomsun28,@TJxiaobao,@zqr10159,@tuohai666,@yuluo-yx,@crossoverJie,@zhangshenghang,@pwallk。最后祝 Apache HertzBeat 茁壮成长,有越来越多的贡献者参与其中。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.