This is an automated email from the ASF dual-hosted git repository.
zhaoqingran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new 4627fb5a8 Replace deprecated methods with builder pattern for RedisURI
construction (#1772)
4627fb5a8 is described below
commit 4627fb5a8ba506ff077ed3f158b78b8381816cc8
Author: Hyeon Sung <[email protected]>
AuthorDate: Thu Apr 18 16:51:20 2024 +0900
Replace deprecated methods with builder pattern for RedisURI construction
(#1772)
Co-authored-by: Logic <[email protected]>
---
.../collector/collect/http/promethus/PrometheusLastParser.java | 4 +---
.../collector/collect/redis/RedisCommonCollectImpl.java | 10 +++++-----
.../org/apache/hertzbeat/collector/util/JsonPathParser.java | 6 ++++--
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/PrometheusLastParser.java
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/PrometheusLastParser.java
index 29cc3cf3c..17a0617d5 100644
---
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/PrometheusLastParser.java
+++
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/promethus/PrometheusLastParser.java
@@ -40,8 +40,6 @@ public class PrometheusLastParser extends
AbstractPrometheusParse {
@Override
public void parse(String resp, List<String> aliasFields, HttpProtocol
http, CollectRep.MetricsData.Builder builder) {
CollectRep.ValueRow.Builder valueRowBuilder =
CollectRep.ValueRow.newBuilder();
- for (String aliasField : aliasFields) {
- valueRowBuilder.addColumns(CommonConstants.NULL_VALUE);
- }
+ aliasFields.forEach(aliasField ->
valueRowBuilder.addColumns(CommonConstants.NULL_VALUE));
}
}
diff --git
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/redis/RedisCommonCollectImpl.java
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/redis/RedisCommonCollectImpl.java
index 459dae56a..08e78445d 100644
---
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/redis/RedisCommonCollectImpl.java
+++
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/redis/RedisCommonCollectImpl.java
@@ -268,16 +268,16 @@ public class RedisCommonCollectImpl extends
AbstractCollect {
}
private RedisURI redisUri(RedisProtocol redisProtocol) {
- RedisURI redisUri = RedisURI.create(redisProtocol.getHost(),
Integer.parseInt(redisProtocol.getPort()));
+ RedisURI.Builder redisUriBuilder =
RedisURI.builder().withHost(redisProtocol.getHost()).withPort(Integer.parseInt(redisProtocol.getPort()));
if (StringUtils.hasText(redisProtocol.getUsername())) {
- redisUri.setUsername(redisProtocol.getUsername());
+ redisUriBuilder.withClientName(redisProtocol.getUsername());
}
if (StringUtils.hasText(redisProtocol.getPassword())) {
- redisUri.setPassword(redisProtocol.getPassword().toCharArray());
+
redisUriBuilder.withPassword(redisProtocol.getPassword().toCharArray());
}
Duration timeout =
Duration.ofMillis(CollectUtil.getTimeout(redisProtocol.getTimeout()));
- redisUri.setTimeout(timeout);
- return redisUri;
+ redisUriBuilder.withTimeout(timeout);
+ return redisUriBuilder.build();
}
private String removeCr(String value) {
diff --git
a/collector/src/main/java/org/apache/hertzbeat/collector/util/JsonPathParser.java
b/collector/src/main/java/org/apache/hertzbeat/collector/util/JsonPathParser.java
index 63378f0fd..9b1424a47 100644
---
a/collector/src/main/java/org/apache/hertzbeat/collector/util/JsonPathParser.java
+++
b/collector/src/main/java/org/apache/hertzbeat/collector/util/JsonPathParser.java
@@ -23,6 +23,8 @@ import com.jayway.jsonpath.spi.cache.LRUCache;
import java.util.*;
+import org.apache.commons.lang3.StringUtils;
+
/**
* json path parser
*/
@@ -45,7 +47,7 @@ public class JsonPathParser {
* @return content [{'name': 'tom', 'speed': '433'},{'name': 'lili',
'speed': '543'}]
*/
public static List<Object> parseContentWithJsonPath(String content, String
jsonPath) {
- if (content == null || jsonPath == null || "".equals(content) ||
"".equals(jsonPath)) {
+ if (StringUtils.isAnyEmpty(content, jsonPath)) {
return Collections.emptyList();
}
return PARSER.parse(content).read(jsonPath);
@@ -58,7 +60,7 @@ public class JsonPathParser {
* @return content [{'name': 'tom', 'speed': '433'},{'name': 'lili',
'speed': '543'}]
*/
public static <T> T parseContentWithJsonPath(String content, String
jsonPath, TypeRef<T> typeRef) {
- if (content == null || jsonPath == null || "".equals(content) ||
"".equals(jsonPath)) {
+ if (StringUtils.isAnyEmpty(content, jsonPath)) {
return null;
}
return PARSER.parse(content).read(jsonPath, typeRef);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]