From 2a2250a574f784473163af923ae22a5aac0db534 Mon Sep 17 00:00:00 2001 From: YangJiaqi Date: Mon, 29 Jul 2024 22:28:19 +0800 Subject: [PATCH 1/3] fix JRaft Metrics miss --- .../store/node/metrics/JRaftMetrics.java | 14 +++++-- .../store/node/metrics/MetricsConfig.java | 2 +- .../store/node/metrics/MetricsRefresher.java | 41 +++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java index a9b53de2db..af1523e040 100644 --- a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java @@ -65,10 +65,18 @@ public class JRaftMetrics { private JRaftMetrics() { } - public synchronized static void init(MeterRegistry meterRegistry) { + public synchronized static void init(MeterRegistry meterRegistry, boolean isInitialCall) { if (registry == null) { registry = meterRegistry; registerMeters(); + if (isInitialCall) { + log.debug("JRaftMetrics initialized during application startup"); + } else { + log.debug("JRaftMetrics initialized during scheduled refresh"); + } + } else if (!isInitialCall) { + registerNodeMetrics(); + log.debug("JRaftMetrics refreshed during scheduled refresh"); } } @@ -108,9 +116,7 @@ private static void registerNodeMetrics() { synchronized (groupSet) { map.forEach((group, metrics) -> { - if (!groupSet.add(group)) { - return; - } + groupSet.add(group); metrics.getMetricRegistry().getGauges() .forEach((k, v) -> registerGauge(group, k, v)); diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsConfig.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsConfig.java index 7062ee7eb8..c739fad1ee 100644 --- a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsConfig.java +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsConfig.java @@ -39,7 +39,7 @@ public MeterRegistryCustomizer registerMeters() { return (registry) -> { StoreMetrics.init(registry); RocksDBMetrics.init(registry); - JRaftMetrics.init(registry); + JRaftMetrics.init(registry, true); ProcfsMetrics.init(registry); GRpcExMetrics.init(registry); }; diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java new file mode 100644 index 0000000000..521cc78a03 --- /dev/null +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java @@ -0,0 +1,41 @@ +/* + * 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.hugegraph.store.node.metrics; + +import io.micrometer.core.instrument.MeterRegistry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +public class MetricsRefresher { + private static final Logger log = LoggerFactory.getLogger(MetricsRefresher.class); + + private final MeterRegistry registry; + + public MetricsRefresher(MeterRegistry registry) { + this.registry = registry; + } + + @Scheduled(fixedRate = 30000) + public void refreshMetrics() { + log.info("Refreshing metrics"); + JRaftMetrics.init(registry,false); + } +} From fc29ecd9e72d52d3c21edbc197debefeb2d85f01 Mon Sep 17 00:00:00 2001 From: YangJiaqi Date: Mon, 29 Jul 2024 22:28:51 +0800 Subject: [PATCH 2/3] fix JRaft Metrics miss --- .../org/apache/hugegraph/store/node/StoreNodeApplication.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/StoreNodeApplication.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/StoreNodeApplication.java index c74ccc3295..b925fc967b 100644 --- a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/StoreNodeApplication.java +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/StoreNodeApplication.java @@ -25,10 +25,13 @@ import com.alipay.remoting.util.StringUtils; +import org.springframework.scheduling.annotation.EnableScheduling; + /** * */ @SpringBootApplication +@EnableScheduling public class StoreNodeApplication { //TODO Is this OK? From 0442b1ea0570a949da025a830d9e6f683647a7cb Mon Sep 17 00:00:00 2001 From: yangjiaqi Date: Tue, 22 Oct 2024 21:02:52 +0800 Subject: [PATCH 3/3] fix code style --- .../apache/hugegraph/store/node/metrics/MetricsRefresher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java index 521cc78a03..42b7113255 100644 --- a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java @@ -36,6 +36,6 @@ public MetricsRefresher(MeterRegistry registry) { @Scheduled(fixedRate = 30000) public void refreshMetrics() { log.info("Refreshing metrics"); - JRaftMetrics.init(registry,false); + JRaftMetrics.init(registry, false); } }