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

[HUDI-6313] Add metrics counters for compaction requested/completed events. #8759

Merged
merged 7 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -50,6 +50,8 @@ public class HoodieMetrics {
private String conflictResolutionTimerName = null;
private String conflictResolutionSuccessCounterName = null;
private String conflictResolutionFailureCounterName = null;
private String compactionStartCounterName = null;
private String compactionStopCounterName = null;
private HoodieWriteConfig config;
private String tableName;
private Timer rollbackTimer = null;
Expand All @@ -64,6 +66,8 @@ public class HoodieMetrics {
private Timer conflictResolutionTimer = null;
private Counter conflictResolutionSuccessCounter = null;
private Counter conflictResolutionFailureCounter = null;
private Counter compactionStartCounter = null;
private Counter compactionStopCounter = null;

public HoodieMetrics(HoodieWriteConfig config) {
this.config = config;
Expand All @@ -82,6 +86,8 @@ public HoodieMetrics(HoodieWriteConfig config) {
this.conflictResolutionTimerName = getMetricsName("timer", "conflict_resolution");
this.conflictResolutionSuccessCounterName = getMetricsName("counter", "conflict_resolution.success");
this.conflictResolutionFailureCounterName = getMetricsName("counter", "conflict_resolution.failure");
this.compactionStartCounterName = getMetricsName("counter", "compaction.start");
this.compactionStopCounterName = getMetricsName("counter", "compaction.stop");
}
}

Expand Down Expand Up @@ -297,6 +303,20 @@ public void emitConflictResolutionFailed() {
}
}

public void emitCompactionStart() {
if (config.isMetricsOn()) {
compactionStartCounter = getCounter(compactionStartCounter, compactionStartCounterName);
compactionStartCounter.inc();
}
}

public void emitCompactionStop() {
if (config.isMetricsOn()) {
compactionStopCounter = getCounter(compactionStopCounter, compactionStopCounterName);
compactionStopCounter.inc();
}
}

private Counter getCounter(Counter counter, String name) {
if (counter == null) {
return metrics.getRegistry().counter(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.exception.HoodieCompactionException;
import org.apache.hudi.internal.schema.utils.SerDeHelper;
import org.apache.hudi.metrics.HoodieMetrics;
import org.apache.hudi.table.HoodieCompactionHandler;
import org.apache.hudi.table.HoodieTable;
import org.apache.hudi.table.action.BaseActionExecutor;
import org.apache.hudi.table.action.HoodieWriteMetadata;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

import static org.apache.hudi.common.util.ValidationUtils.checkArgument;
Expand All @@ -48,10 +52,14 @@
public class RunCompactionActionExecutor<T> extends
BaseActionExecutor<T, HoodieData<HoodieRecord<T>>, HoodieData<HoodieKey>, HoodieData<WriteStatus>, HoodieWriteMetadata<HoodieData<WriteStatus>>> {

private static final Logger LOG = LoggerFactory.getLogger(LogCompactionExecutionHelper.class);

Copy link
Contributor

Choose a reason for hiding this comment

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

RunCompactionActionExecutor.class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

private final HoodieCompactor compactor;
private final HoodieCompactionHandler compactionHandler;
private WriteOperationType operationType;

private final HoodieMetrics metrics;

public RunCompactionActionExecutor(HoodieEngineContext context,
HoodieWriteConfig config,
HoodieTable table,
Expand All @@ -65,10 +73,14 @@ public RunCompactionActionExecutor(HoodieEngineContext context,
this.operationType = operationType;
checkArgument(operationType == WriteOperationType.COMPACT || operationType == WriteOperationType.LOG_COMPACT,
"Only COMPACT and LOG_COMPACT is supported");
metrics = new HoodieMetrics(config);
}

@Override
public HoodieWriteMetadata<HoodieData<WriteStatus>> execute() {
LOG.info("Compaction start.");
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this. or you added for debugging purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nsivabalan I added this based on our last discussion. It should help to get an idea of individual start / stop compaction events.

metrics.emitCompactionStart();

HoodieTimeline pendingMajorOrMinorCompactionTimeline = WriteOperationType.COMPACT.equals(operationType)
? table.getActiveTimeline().filterPendingCompactionTimeline()
: table.getActiveTimeline().filterPendingLogCompactionTimeline();
Expand Down Expand Up @@ -116,6 +128,8 @@ public HoodieWriteMetadata<HoodieData<WriteStatus>> execute() {
throw new HoodieCompactionException("Could not compact " + config.getBasePath(), e);
}

LOG.info("Compaction stop.");
metrics.emitCompactionStop();
return compactionMetadata;
}
}
Loading