Skip to content
Open
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
46 changes: 40 additions & 6 deletions docs/docs/maintenance/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ From Flink Web-UI, go to the committer operator's metrics, it's shown as:
:::info

1. Please refer to [System Scope](https://nightlies.apache.org/flink/flink-docs-master/docs/ops/metrics/#system-scope) to understand Flink `scope`
2. Scan metrics are only supported by Flink versions >= 1.18
2. Scan metrics in the JobManager source enumerator scope are supported by Flink versions >= 1.18.

:::

Expand All @@ -66,9 +66,24 @@ From Flink Web-UI, go to the committer operator's metrics, it's shown as:
</thead>
<tbody>
<tr>
<td>Scan Metrics</td>
<td>Scan Metrics (Enumerator)</td>
<td>&lt;host&gt;.jobmanager.&lt;job_name&gt;</td>
<td>&lt;source_operator_name&gt;.coordinator. enumerator.paimon.table.&lt;table_name&gt;.scan</td>
<td>&lt;source_operator_name&gt;.coordinator.enumerator.paimon.table.&lt;table_name&gt;.scan</td>
</tr>
<tr>
<td>Scan Metrics (Monitor)</td>
<td>&lt;host&gt;.taskmanager.&lt;tm_id&gt;.&lt;job_name&gt;.&lt;monitor_operator_name&gt;.&lt;subtask_index&gt;</td>
<td>paimon.table.&lt;table_name&gt;.scan</td>
</tr>
<tr>
<td>Scan Metrics (Sink Writer)</td>
<td>&lt;host&gt;.taskmanager.&lt;tm_id&gt;.&lt;job_name&gt;.&lt;writer_operator_name&gt;.&lt;subtask_index&gt;</td>
<td>paimon.table.&lt;table_name&gt;.scan</td>
</tr>
<tr>
<td>Scan Metrics (Sink Coordinator)</td>
<td>&lt;host&gt;.jobmanager.&lt;job_name&gt;</td>
<td>&lt;writer_operator_name&gt;.coordinator.paimon.table.&lt;table_name&gt;.scan</td>
</tr>
<tr>
<td>Lookup Metrics</td>
Expand Down Expand Up @@ -113,6 +128,24 @@ From Flink Web-UI, go to the committer operator's metrics, it's shown as:
</tbody>
</table>

When dedicated split generation uses a `Monitor` operator, scan metrics are reported by that operator on
the TaskManager. This includes streaming queries with `consumer-id` and `consumer.mode = 'exactly-once'`
when `source.checkpoint-align.enabled` is disabled. The `last*` gauges describe the last completed scan
and start at zero after a restart, until the next scan completes.

Sink scan metrics measure manifest scans used to initialize or recover writers. With
`sink.writer-coordinator.enabled = false`, scans are reported by each writer subtask on the TaskManager.
With writer coordination enabled, use the JobManager sink coordinator metrics for the actual scans;
writer subtasks delegate recovery to the coordinator and their local scan metrics are not updated.
The coordinator reports both manifest prefetch scans and scans for individual partition/bucket requests
in the same metric group, including prefetch during startup and metadata refresh.

For sink scans, `lastScanDuration` and `scanDuration` measure metadata planning in milliseconds:
reading manifest lists and manifests, filtering entries, and merging file metadata. They exclude
index restoration, coordinator RPC waits, and data writes. Measurements update when a scan completes;
the `last*` gauges describe the latest scan, and `scanDuration` records the durations of recent scans.
When initialization skips data file metadata scanning, no scan duration sample is recorded.

## Choose Metrics for a Task

Use these groups to identify the operation to investigate. For tuning options, follow the related guide.
Expand Down Expand Up @@ -142,12 +175,12 @@ Below is lists of Paimon built-in metrics. They are summarized into types of sca
<tr>
<td>lastScanDuration</td>
<td>Gauge</td>
<td>The time it took to complete the last scan.</td>
<td>The time it took to complete the last scan, in milliseconds.</td>
</tr>
<tr>
<td>scanDuration</td>
<td>Histogram</td>
<td>Distributions of the time taken by the last few scans.</td>
<td>Distributions of the time taken by the last few scans, in milliseconds.</td>
</tr>
<tr>
<td>lastScannedSnapshotId</td>
Expand Down Expand Up @@ -623,7 +656,8 @@ When using Flink to read and write, Paimon has implemented some key standard Fli

:::info

Please note that if you specified `consumer-id` in your streaming query, the level of source metrics should turn into the reader operator, which is behind the `Monitor` operator.
When a query uses separate `Monitor` and `Reader` operators, the source reader metrics above are reported
by the downstream `Reader` operator. Scan metrics are reported by the `Monitor` operator.

:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.paimon.memory.MemoryPoolFactory;
import org.apache.paimon.metrics.MetricRegistry;
import org.apache.paimon.operation.metrics.CompactionMetrics;
import org.apache.paimon.operation.metrics.ScanMetrics;
import org.apache.paimon.partition.PartitionTimeExtractor;
import org.apache.paimon.table.sink.CommitMessage;
import org.apache.paimon.table.sink.CommitMessageImpl;
Expand Down Expand Up @@ -111,6 +112,7 @@ public abstract class AbstractFileStoreWrite<T> implements FileStoreWrite<T> {

protected final SnapshotManager snapshotManager;
protected CompactionMetrics compactionMetrics = null;
@Nullable private ScanMetrics scanMetrics;
protected final String tableName;
private final boolean legacyPartitionName;
private final CoreOptions options;
Expand Down Expand Up @@ -151,6 +153,9 @@ protected AbstractFileStoreWrite(
@Override
public FileStoreWrite<T> withWriteRestore(WriteRestore writeRestore) {
this.restore = writeRestore;
if (scanMetrics != null) {
restore.withMetrics(scanMetrics);
}
return this;
}

Expand Down Expand Up @@ -665,6 +670,8 @@ long startingMaxSequenceNumber(long restoredMaxSeqNumber, @Nullable Snapshot lat
@Override
public FileStoreWrite<T> withMetricRegistry(MetricRegistry metricRegistry) {
this.compactionMetrics = new CompactionMetrics(metricRegistry, tableName);
this.scanMetrics = new ScanMetrics(metricRegistry, tableName);
restore.withMetrics(scanMetrics);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.paimon.index.IndexFileMeta;
import org.apache.paimon.io.DataFileMeta;
import org.apache.paimon.manifest.ManifestEntry;
import org.apache.paimon.operation.metrics.ScanMetrics;
import org.apache.paimon.utils.SnapshotManager;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -76,6 +77,13 @@ private FileSystemWriteRestore(
}
}

@Override
public void withMetrics(ScanMetrics scanMetrics) {
if (scan != null) {
scan.withMetrics(scanMetrics);
}
}

@Override
public long latestCommittedIdentifier(String user) {
return snapshotManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.paimon.data.BinaryRow;
import org.apache.paimon.io.DataFileMeta;
import org.apache.paimon.manifest.ManifestEntry;
import org.apache.paimon.operation.metrics.ScanMetrics;

import javax.annotation.Nullable;

Expand All @@ -29,6 +30,9 @@
/** Restores data file metadata and indexes for write initialization. */
public interface WriteRestore {

/** Attaches metrics to manifest scans performed by this restore. */
default void withMetrics(ScanMetrics scanMetrics) {}

long latestCommittedIdentifier(String user);

/** Restores data file metadata and the requested indexes for a partition and bucket. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
import org.apache.paimon.index.IndexFileMeta;
import org.apache.paimon.io.DataFileMeta;
import org.apache.paimon.manifest.ManifestEntry;
import org.apache.paimon.metrics.MetricRegistry;
import org.apache.paimon.operation.FileStoreScan;
import org.apache.paimon.operation.WriteRestore;
import org.apache.paimon.operation.metrics.ScanMetrics;
import org.apache.paimon.table.FileStoreTable;

import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Cache;
import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Caffeine;

import javax.annotation.Nullable;

import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
Expand All @@ -57,6 +61,7 @@ public class TableWriteCoordinator {
private final FileStoreTable table;
private final Map<String, Long> latestCommittedIdentifiers;
private final FileStoreScan scan;
@Nullable private final ScanMetrics scanMetrics;
private final IndexFileHandler indexFileHandler;
private final int pageSize;
private final boolean prefetchManifests;
Expand All @@ -65,10 +70,19 @@ public class TableWriteCoordinator {
private volatile Snapshot snapshot;

public TableWriteCoordinator(FileStoreTable table) {
this(table, null);
}

public TableWriteCoordinator(FileStoreTable table, @Nullable MetricRegistry metricRegistry) {
this.table = table;
checkNotNull(table.getManifestCache());
this.latestCommittedIdentifiers = new ConcurrentHashMap<>();
this.scanMetrics =
metricRegistry == null ? null : new ScanMetrics(metricRegistry, table.name());
this.scan = table.store().newScan();
if (scanMetrics != null) {
scan.withMetrics(scanMetrics);
}
if (table.coreOptions().manifestDeleteFileDropStats()) {
scan.dropStats();
}
Expand Down Expand Up @@ -107,6 +121,9 @@ private synchronized void refresh() {
// used so the shared request `scan`'s bucket/partition state never narrows the
// warm-up.
FileStoreScan prefetchScan = table.store().newScan().withSnapshot(snapshot);
if (scanMetrics != null) {
prefetchScan.withMetrics(scanMetrics);
}
if (table.coreOptions().manifestDeleteFileDropStats()) {
prefetchScan.dropStats();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@
package org.apache.paimon.flink.sink.coordinator;

import org.apache.paimon.CoreOptions;
import org.apache.paimon.flink.metrics.FlinkMetricRegistry;
import org.apache.paimon.flink.sink.TableWriteOperator;
import org.apache.paimon.fs.Path;
import org.apache.paimon.metrics.MetricRegistry;
import org.apache.paimon.options.MemorySize;
import org.apache.paimon.options.Options;
import org.apache.paimon.table.FileStoreTable;
import org.apache.paimon.utils.SegmentsCache;

import org.apache.flink.metrics.MetricGroup;
import org.apache.flink.runtime.jobgraph.OperatorID;
import org.apache.flink.runtime.operators.coordination.CoordinationRequest;
import org.apache.flink.runtime.operators.coordination.CoordinationRequestHandler;
import org.apache.flink.runtime.operators.coordination.CoordinationResponse;
import org.apache.flink.runtime.operators.coordination.OperatorCoordinator;
import org.apache.flink.runtime.operators.coordination.OperatorEvent;

import javax.annotation.Nullable;

import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
Expand All @@ -51,6 +56,7 @@
public class WriteOperatorCoordinator implements OperatorCoordinator, CoordinationRequestHandler {

private final FileStoreTable table;
@Nullable private final MetricRegistry metricRegistry;

private final AtomicLong recoveryGeneration = new AtomicLong();

Expand All @@ -61,14 +67,19 @@ public class WriteOperatorCoordinator implements OperatorCoordinator, Coordinati
private TableWriteCoordinator coordinator;

public WriteOperatorCoordinator(FileStoreTable table) {
this(table, null);
}

public WriteOperatorCoordinator(FileStoreTable table, @Nullable MetricRegistry metricRegistry) {
this.table = table;
this.metricRegistry = metricRegistry;
}

@Override
public void start() throws Exception {
executor = createCachedThreadPool(1, "WriteCoordinator");
table.setManifestCache(buildManifestCache(table.coreOptions().toConfiguration()));
coordinator = new TableWriteCoordinator(table);
coordinator = new TableWriteCoordinator(table, metricRegistry);
}

/**
Expand Down Expand Up @@ -184,7 +195,9 @@ public OperatorID getOperatorId() {

@Override
public OperatorCoordinator create(Context context) {
return new WriteOperatorCoordinator(table);
MetricGroup metricGroup = context.metricGroup();
return new WriteOperatorCoordinator(
table, metricGroup == null ? null : new FlinkMetricRegistry(metricGroup));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

import org.apache.paimon.flink.FlinkConnectorOptions;
import org.apache.paimon.flink.NestedProjectedRowData;
import org.apache.paimon.flink.metrics.FlinkMetricRegistry;
import org.apache.paimon.flink.source.AbstractNonCoordinatedSource;
import org.apache.paimon.flink.source.AbstractNonCoordinatedSourceReader;
import org.apache.paimon.flink.source.NoOpEnumState;
import org.apache.paimon.flink.source.PaimonDataStreamSource;
import org.apache.paimon.flink.source.SimpleSourceSplit;
import org.apache.paimon.flink.source.SplitListState;
import org.apache.paimon.flink.utils.JavaTypeInfo;
import org.apache.paimon.metrics.MetricRegistry;
import org.apache.paimon.options.Options;
import org.apache.paimon.table.Table;
import org.apache.paimon.table.sink.ChannelComputer;
Expand Down Expand Up @@ -133,7 +135,7 @@ public Boundedness getBoundedness() {
@Override
public SourceReader<Split, SimpleSourceSplit> createReader(
SourceReaderContext sourceReaderContext) throws Exception {
return new Reader();
return new Reader(new FlinkMetricRegistry(sourceReaderContext.metricGroup()));
}

private class Reader extends AbstractNonCoordinatedSourceReader<Split> {
Expand All @@ -156,6 +158,11 @@ private class Reader extends AbstractNonCoordinatedSourceReader<Split> {
private final Deque<Long> inFlightNextSnapshots = new ArrayDeque<>();
private CompletableFuture<Void> availableFuture = CompletableFuture.completedFuture(null);

private Reader(MetricRegistry registry) {
TableScan activeScan = isBounded ? batchScan : scan;
activeScan.withMetricRegistry(registry);
}

@Override
public void notifyCheckpointComplete(long checkpointId) {
NavigableMap<Long, Long> nextSnapshots =
Expand Down
Loading
Loading