Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -213,7 +213,7 @@ public void start() {
serviceRuntimeInfo.setStartTime();

RatisDropwizardExports.
registerRatisMetricReporters(ratisMetricsMap);
registerRatisMetricReporters(ratisMetricsMap, () -> isStopped.get());

OzoneConfiguration.activate();
HddsServerUtil.initializeMetrics(conf, "HddsDatanode");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.dropwizard.DropwizardExports;
import io.prometheus.client.dropwizard.samplebuilder.DefaultSampleBuilder;
import java.util.function.BooleanSupplier;
import org.apache.ratis.metrics.MetricRegistries;
import org.apache.ratis.metrics.MetricsReporting;
import org.apache.ratis.metrics.RatisMetricRegistry;
Expand All @@ -43,14 +44,15 @@ public RatisDropwizardExports(MetricRegistry registry) {
}

public static void registerRatisMetricReporters(
Map<String, RatisDropwizardExports> ratisMetricsMap) {
Map<String, RatisDropwizardExports> ratisMetricsMap,
BooleanSupplier checkStopped) {
//All the Ratis metrics (registered from now) will be published via JMX and
//via the prometheus exporter (used by the /prom servlet
MetricRegistries.global()
.addReporterRegistration(MetricsReporting.jmxReporter(),
MetricsReporting.stopJmxReporter());
MetricRegistries.global().addReporterRegistration(
r1 -> registerDropwizard(r1, ratisMetricsMap),
r1 -> registerDropwizard(r1, ratisMetricsMap, checkStopped),
r2 -> deregisterDropwizard(r2, ratisMetricsMap));
}

Expand All @@ -69,12 +71,19 @@ public static void clear(Map<String, RatisDropwizardExports>
}

private static void registerDropwizard(RatisMetricRegistry registry,
Map<String, RatisDropwizardExports> ratisMetricsMap) {
Map<String, RatisDropwizardExports> ratisMetricsMap,
BooleanSupplier checkStopped) {
if (checkStopped.getAsBoolean()) {
return;
}

RatisDropwizardExports rde = new RatisDropwizardExports(
registry.getDropWizardMetricRegistry());
CollectorRegistry.defaultRegistry.register(rde);
String name = registry.getMetricRegistryInfo().getName();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Keep name declared after rde, i.e.

     RatisDropwizardExports rde = new RatisDropwizardExports(
         registry.getDropWizardMetricRegistry());
     String name = registry.getMetricRegistryInfo().getName();

ratisMetricsMap.putIfAbsent(name, rde);
if (null == ratisMetricsMap.putIfAbsent(name, rde)) {
// new rde is added for the name, so need register
CollectorRegistry.defaultRegistry.register(rde);
}
}

private static void deregisterDropwizard(RatisMetricRegistry registry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.cache.RemovalListener;
import com.google.protobuf.BlockingService;

import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.HddsConfigKeys;
Expand Down Expand Up @@ -290,7 +291,8 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl
// Used to keep track of pending replication and pending deletes for
// container replicas.
private ContainerReplicaPendingOps containerReplicaPendingOps;

private final AtomicBoolean isStopped = new AtomicBoolean(false);

/**
* Creates a new StorageContainerManager. Configuration will be
* updated with information on the actual listening addresses used
Expand Down Expand Up @@ -584,7 +586,8 @@ private void initializeSystemManagers(OzoneConfiguration conf,
clusterMap = new NetworkTopologyImpl(conf);
}
// This needs to be done before initializing Ratis.
RatisDropwizardExports.registerRatisMetricReporters(ratisMetricsMap);
RatisDropwizardExports.registerRatisMetricReporters(ratisMetricsMap,
() -> isStopped.get());
if (configurator.getSCMHAManager() != null) {
scmHAManager = configurator.getSCMHAManager();
} else {
Expand Down Expand Up @@ -1519,6 +1522,10 @@ private void persistSCMCertificates() throws IOException {
*/
@Override
public void stop() {
if (isStopped.getAndSet(true)) {
LOG.info("Storage Container Manager is not running.");
return;
}
try {
if (containerBalancer.isBalancerRunning()) {
LOG.info("Stopping Container Balancer service.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ private void initializeRatisServer(boolean shouldBootstrap)
if (omRatisServer == null) {
// This needs to be done before initializing Ratis.
RatisDropwizardExports.
registerRatisMetricReporters(ratisMetricsMap);
registerRatisMetricReporters(ratisMetricsMap, () -> isStopped());
omRatisServer = OzoneManagerRatisServer.newOMRatisServer(
configuration, this, omNodeDetails, peerNodesMap,
secConfig, certClient, shouldBootstrap);
Expand Down