-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(hstore): JRaft Metrics miss #2604
base: master
Are you sure you want to change the base?
Changes from 5 commits
2a2250a
fc29ecd
acd3e35
d70ecea
fe2ef23
0442b1e
6e44a87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we refactor to this style |
||
registry = meterRegistry; | ||
registerMeters(); | ||
if (isInitialCall) { | ||
log.debug("JRaftMetrics initialized during application startup"); | ||
} else { | ||
log.debug("JRaftMetrics initialized during scheduled refresh"); | ||
} | ||
} else if (!isInitialCall) { | ||
registerNodeMetrics(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefer to add a new method like resetNodeMetrics() instead of adding a isInitialCall param There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your suggestion, I will optimize it |
||
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)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
JackyYangPassion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isInitialCall
-- Is there an elegant way to avoid this a bit complex branching?