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

Add checkpoint.delete.processingTime metric #817

Merged
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 @@ -137,7 +137,12 @@ public final class MetricConstants {
*/
public static final String OUTPUT_TOTAL_RECORDS_WRITTEN = "output.totalRecordsWritten.count";

/**
* Metric for tracking the latency of checkpoint deletion
*/
public static final String CHECKPOINT_DELETE_TIME_METRIC = "checkpoint.delete.processingTime";

private MetricConstants() {
// Private constructor to prevent instantiation
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.codahale.metrics.Gauge;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import java.util.function.Supplier;
import org.apache.spark.SparkEnv;
import org.apache.spark.metrics.source.FlintMetricSource;
import org.apache.spark.metrics.source.FlintIndexMetricSource;
Expand Down Expand Up @@ -133,6 +134,21 @@ public static void addHistoricGauge(String metricName, final long value) {
}
}

/**
* Automatically emit latency metric as Historic Gauge for the execution of supplier
* @param supplier the lambda to be metered
* @param metricName name of the metric
* @return value returned by supplier
*/
public static <T> T withLatencyAsHistoricGauge(Supplier<T> supplier, String metricName) {
long startTime = System.currentTimeMillis();
try {
return supplier.get();
} finally {
addHistoricGauge(metricName, System.currentTimeMillis() - startTime);
}
}

private static HistoricGauge getOrCreateHistoricGauge(String metricName) {
MetricRegistry metricRegistry = getMetricRegistry(false);
return metricRegistry != null ? metricRegistry.gauge(metricName, HistoricGauge::new) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.opensearch.flint.spark
import java.util.UUID

import org.apache.hadoop.fs.{FSDataOutputStream, Path}
import org.opensearch.flint.core.metrics.{MetricConstants, MetricsUtil}

import org.apache.spark.internal.Logging
import org.apache.spark.sql.SparkSession
Expand Down Expand Up @@ -75,7 +76,9 @@ class FlintSparkCheckpoint(spark: SparkSession, val checkpointLocation: String)
*/
def delete(): Unit = {
try {
checkpointManager.delete(checkpointRootDir)
MetricsUtil.withLatencyAsHistoricGauge(
() => checkpointManager.delete(checkpointRootDir),
MetricConstants.CHECKPOINT_DELETE_TIME_METRIC)
logInfo(s"Checkpoint directory $checkpointRootDir deleted")
} catch {
case e: Exception =>
Expand Down
Loading