Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

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?

if (registry == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we refactor to this style JRaftMetrics.instance(registry)

registry = meterRegistry;
registerMeters();
if (isInitialCall) {
log.debug("JRaftMetrics initialized during application startup");
} else {
log.debug("JRaftMetrics initialized during scheduled refresh");
}
} else if (!isInitialCall) {
registerNodeMetrics();
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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");
}
}

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public MeterRegistryCustomizer<MeterRegistry> registerMeters() {
return (registry) -> {
StoreMetrics.init(registry);
RocksDBMetrics.init(registry);
JRaftMetrics.init(registry);
JRaftMetrics.init(registry, true);
ProcfsMetrics.init(registry);
GRpcExMetrics.init(registry);
};
Expand Down
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
}
}
Loading