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 @@ -32,6 +32,8 @@ public class ReconcileContainerTask extends AbstractReplicationTask {
private final ReconcileContainerCommand command;
private final DNContainerOperationClient dnClient;
private final ContainerController controller;
public static final String METRIC_NAME = "ContainerReconciliations";
public static final String METRIC_DESCRIPTION_SEGMENT = "Container Reconciliations";

private static final Logger LOG =
LoggerFactory.getLogger(ReconcileContainerTask.class);
Expand Down Expand Up @@ -69,12 +71,12 @@ protected Object getCommandForDebug() {

@Override
public String getMetricName() {
return "ContainerReconciliations";
return METRIC_NAME;
}

@Override
public String getMetricDescriptionSegment() {
return "Container Reconciliations";
return METRIC_DESCRIPTION_SEGMENT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class ReconcileContainerCommandHandler implements CommandHandler {
private final ReplicationSupervisor supervisor;
private final DNContainerOperationClient dnClient;
private String metricsName;
private static final String METRIC_NAME = ReconcileContainerTask.METRIC_NAME;

public ReconcileContainerCommandHandler(ReplicationSupervisor supervisor, DNContainerOperationClient dnClient) {
this.supervisor = supervisor;
Expand All @@ -45,9 +45,6 @@ public void handle(SCMCommand command, OzoneContainer container, StateContext co
SCMConnectionManager connectionManager) {
ReconcileContainerCommand reconcileCommand = (ReconcileContainerCommand) command;
ReconcileContainerTask task = new ReconcileContainerTask(container.getController(), dnClient, reconcileCommand);
if (metricsName == null) {
metricsName = task.getMetricName();
}
supervisor.addTask(task);
}

Expand All @@ -58,29 +55,25 @@ public SCMCommandProto.Type getCommandType() {

@Override
public int getQueuedCount() {
return this.metricsName == null ? 0 : (int) this.supervisor
.getReplicationQueuedCount(metricsName);
return (int) this.supervisor.getReplicationQueuedCount(METRIC_NAME);
}

@Override
public int getInvocationCount() {
return this.metricsName == null ? 0 : (int) this.supervisor
.getReplicationRequestCount(metricsName);
return (int) this.supervisor.getReplicationRequestCount(METRIC_NAME);
}

@Override
public long getAverageRunTime() {
return this.metricsName == null ? 0 : (int) this.supervisor
.getReplicationRequestAvgTime(metricsName);
return this.supervisor.getReplicationRequestAvgTime(METRIC_NAME);
}

@Override
public long getTotalRunTime() {
return this.metricsName == null ? 0 : this.supervisor
.getReplicationRequestTotalTime(metricsName);
return this.supervisor.getReplicationRequestTotalTime(METRIC_NAME);
}

public String getMetricsName() {
return this.metricsName;
return METRIC_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ReconstructECContainersCommandHandler implements CommandHandler {
private final ReplicationSupervisor supervisor;
private final ECReconstructionCoordinator coordinator;
private final ConfigurationSource conf;
private String metricsName;
private static final String METRIC_NAME = ECReconstructionCoordinatorTask.METRIC_NAME;

public ReconstructECContainersCommandHandler(ConfigurationSource conf,
ReplicationSupervisor supervisor,
Expand All @@ -55,14 +55,11 @@ public void handle(SCMCommand<?> command, OzoneContainer container,
new ECReconstructionCommandInfo(ecContainersCommand);
ECReconstructionCoordinatorTask task = new ECReconstructionCoordinatorTask(
coordinator, reconstructionCommandInfo);
if (this.metricsName == null) {
this.metricsName = task.getMetricName();
}
this.supervisor.addTask(task);
}

public String getMetricsName() {
return this.metricsName;
return METRIC_NAME;
}

@Override
Expand All @@ -72,26 +69,22 @@ public Type getCommandType() {

@Override
public int getInvocationCount() {
return this.metricsName == null ? 0 : (int) this.supervisor
.getReplicationRequestCount(metricsName);
return (int) this.supervisor.getReplicationRequestCount(METRIC_NAME);
}

@Override
public long getAverageRunTime() {
return this.metricsName == null ? 0 : (int) this.supervisor
.getReplicationRequestAvgTime(metricsName);
return this.supervisor.getReplicationRequestAvgTime(METRIC_NAME);
}

@Override
public long getTotalRunTime() {
return this.metricsName == null ? 0 : this.supervisor
.getReplicationRequestTotalTime(metricsName);
return this.supervisor.getReplicationRequestTotalTime(METRIC_NAME);
}

@Override
public int getQueuedCount() {
return this.metricsName == null ? 0 : (int) this.supervisor
.getReplicationQueuedCount(metricsName);
return (int) this.supervisor.getReplicationQueuedCount(METRIC_NAME);
}

public ConfigurationSource getConf() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ReplicateContainerCommandHandler implements CommandHandler {

private ContainerReplicator pushReplicator;

private String metricsName;
private static final String METRIC_NAME = ReplicationTask.METRIC_NAME;

public ReplicateContainerCommandHandler(
ConfigurationSource conf,
Expand All @@ -61,7 +61,7 @@ public ReplicateContainerCommandHandler(
}

public String getMetricsName() {
return this.metricsName;
return METRIC_NAME;
}

@Override
Expand All @@ -84,16 +84,12 @@ public void handle(SCMCommand<?> command, OzoneContainer container,
downloadReplicator : pushReplicator;

ReplicationTask task = new ReplicationTask(replicateCommand, replicator);
if (metricsName == null) {
metricsName = task.getMetricName();
}
supervisor.addTask(task);
}

@Override
public int getQueuedCount() {
return this.metricsName == null ? 0 : (int) this.supervisor
.getReplicationQueuedCount(metricsName);
return (int) this.supervisor.getReplicationQueuedCount(METRIC_NAME);
}

@Override
Expand All @@ -103,19 +99,16 @@ public SCMCommandProto.Type getCommandType() {

@Override
public int getInvocationCount() {
return this.metricsName == null ? 0 : (int) this.supervisor
.getReplicationRequestCount(metricsName);
return (int) this.supervisor.getReplicationRequestCount(METRIC_NAME);
}

@Override
public long getAverageRunTime() {
return this.metricsName == null ? 0 : (int) this.supervisor
.getReplicationRequestAvgTime(metricsName);
return this.supervisor.getReplicationRequestAvgTime(METRIC_NAME);
}

@Override
public long getTotalRunTime() {
return this.metricsName == null ? 0 : this.supervisor
.getReplicationRequestTotalTime(metricsName);
return this.supervisor.getReplicationRequestTotalTime(METRIC_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class ECReconstructionCoordinatorTask
private final ECReconstructionCoordinator reconstructionCoordinator;
private final ECReconstructionCommandInfo reconstructionCommandInfo;
private final String debugString;
public static final String METRIC_NAME = "ECReconstructions";
public static final String METRIC_DESCRIPTION_SEGMENT = "EC reconstructions";

public ECReconstructionCoordinatorTask(
ECReconstructionCoordinator coordinator,
Expand All @@ -47,12 +49,12 @@ public ECReconstructionCoordinatorTask(

@Override
public String getMetricName() {
return "ECReconstructions";
return METRIC_NAME;
}

@Override
public String getMetricDescriptionSegment() {
return "EC reconstructions";
return METRIC_DESCRIPTION_SEGMENT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ReplicationTask extends AbstractReplicationTask {
private final ReplicateContainerCommand cmd;
private final ContainerReplicator replicator;
private final String debugString;
public static final String METRIC_NAME = "ContainerReplications";
public static final String METRIC_DESCRIPTION_SEGMENT = "container replications";

/**
* Counter for the transferred bytes.
Expand Down Expand Up @@ -66,12 +68,12 @@ protected ReplicationTask(

@Override
public String getMetricName() {
return "ContainerReplications";
return METRIC_NAME;
}

@Override
public String getMetricDescriptionSegment() {
return "container replications";
return METRIC_DESCRIPTION_SEGMENT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void testReconcileContainerCommandMetrics(ContainerLayoutVersion layout)
when(mockSupervisor.getReplicationRequestAvgTime(subject.getMetricsName())).thenReturn(3L);
when(mockSupervisor.getReplicationQueuedCount(subject.getMetricsName())).thenReturn(1L);

assertEquals(subject.getMetricsName(), "ContainerReconciliations");
assertEquals(subject.getMetricsName(), ReconcileContainerTask.METRIC_NAME);
assertEquals(NUM_CONTAINERS, subject.getInvocationCount());
assertEquals(subject.getQueuedCount(), 1);
assertEquals(subject.getTotalRunTime(), 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.hadoop.ozone.container.common.statemachine.SCMConnectionManager;
import org.apache.hadoop.ozone.container.common.statemachine.StateContext;
import org.apache.hadoop.ozone.container.ec.reconstruction.ECReconstructionCoordinator;
import org.apache.hadoop.ozone.container.ec.reconstruction.ECReconstructionCoordinatorTask;
import org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer;
import org.apache.hadoop.ozone.container.replication.ReplicationSupervisor;
import org.apache.hadoop.ozone.protocol.commands.ReconstructECContainersCommand;
Expand Down Expand Up @@ -91,7 +92,7 @@ public void testMetrics() {

commandHandler.handle(reconstructECContainersCommand, ozoneContainer,
stateContext, connectionManager);
String metricsName = "ECReconstructions";
String metricsName = ECReconstructionCoordinatorTask.METRIC_NAME;
assertEquals(commandHandler.getMetricsName(), metricsName);
when(supervisor.getReplicationRequestCount(metricsName)).thenReturn(1L);
assertEquals(commandHandler.getInvocationCount(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer;
import org.apache.hadoop.ozone.container.replication.ContainerReplicator;
import org.apache.hadoop.ozone.container.replication.ReplicationSupervisor;
import org.apache.hadoop.ozone.container.replication.ReplicationTask;
import org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void testMetrics() {
ReplicateContainerCommand command = ReplicateContainerCommand.fromSources(
1, sourceList);
commandHandler.handle(command, ozoneContainer, stateContext, connectionManager);
String metricsName = "ContainerReplications";
String metricsName = ReplicationTask.METRIC_NAME;
assertEquals(commandHandler.getMetricsName(), metricsName);
when(supervisor.getReplicationRequestCount(metricsName)).thenReturn(1L);
assertEquals(commandHandler.getInvocationCount(), 1);
Expand Down