From 1850541ab187aac8d4ec47549da15269e9214cd2 Mon Sep 17 00:00:00 2001 From: Ayu <14359932+lin-Ayu0v0@user.noreply.gitee.com> Date: Sun, 1 Dec 2024 14:21:18 +0800 Subject: [PATCH 1/2] [bugfix] Fix NullPointerException --- .../collector/dispatch/CommonDispatcher.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java b/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java index 0293be0610f..6cfe433ff01 100644 --- a/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java +++ b/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java @@ -185,18 +185,21 @@ public void dispatchMetricsTask(Timeout timeout) { Job job = timerTask.getJob(); job.constructPriorMetrics(); Set metricsSet = job.getNextCollectMetrics(null, true); - metricsSet.forEach(metrics -> { - MetricsCollect metricsCollect = new MetricsCollect(metrics, timeout, this, - collectorIdentity, unitConvertList); - jobRequestQueue.addJob(metricsCollect); - if (metrics.getPrometheus() != null) { - metricsTimeoutMonitorMap.put(String.valueOf(job.getId()), - new MetricsTime(System.currentTimeMillis(), metrics, timeout)); - } else { - metricsTimeoutMonitorMap.put(job.getId() + "-" + metrics.getName(), - new MetricsTime(System.currentTimeMillis(), metrics, timeout)); - } - }); + // Avoid NullPointerException + if(null != metricsSet){ + metricsSet.forEach(metrics -> { + MetricsCollect metricsCollect = new MetricsCollect(metrics, timeout, this, + collectorIdentity, unitConvertList); + jobRequestQueue.addJob(metricsCollect); + if (metrics.getPrometheus() != null) { + metricsTimeoutMonitorMap.put(String.valueOf(job.getId()), + new MetricsTime(System.currentTimeMillis(), metrics, timeout)); + } else { + metricsTimeoutMonitorMap.put(job.getId() + "-" + metrics.getName(), + new MetricsTime(System.currentTimeMillis(), metrics, timeout)); + } + }); + } } @Override From c4537c51cd8f3fe86124c24466e2211b4fb67fdf Mon Sep 17 00:00:00 2001 From: Ayu <127600988+ayu-v0@users.noreply.github.com> Date: Wed, 4 Dec 2024 22:06:41 +0800 Subject: [PATCH 2/2] Update CommonDispatcher.java Signed-off-by: Ayu <127600988+ayu-v0@users.noreply.github.com> --- .../apache/hertzbeat/collector/dispatch/CommonDispatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java b/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java index 6cfe433ff01..9c266601afa 100644 --- a/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java +++ b/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java @@ -186,7 +186,7 @@ public void dispatchMetricsTask(Timeout timeout) { job.constructPriorMetrics(); Set metricsSet = job.getNextCollectMetrics(null, true); // Avoid NullPointerException - if(null != metricsSet){ + if (null != metricsSet){ metricsSet.forEach(metrics -> { MetricsCollect metricsCollect = new MetricsCollect(metrics, timeout, this, collectorIdentity, unitConvertList);