This is an automated email from the ASF dual-hosted git repository.
liaoxin01 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 608cfd3ea17 [improve](streaming-job) Add per-job metrics for streaming
insert jobs (#62224)
608cfd3ea17 is described below
commit 608cfd3ea17949f2c85a603eb15f54bb235c6780
Author: wudi <[email protected]>
AuthorDate: Fri Apr 24 15:25:27 2026 +0800
[improve](streaming-job) Add per-job metrics for streaming insert jobs
(#62224)
## Summary
- Add per-job granularity metrics for streaming insert jobs with
`job_id` and `job_name` labels
- New metrics: `streaming_job_per_job_scanned_rows`,
`streaming_job_per_job_load_bytes`,
`streaming_job_per_job_filtered_rows`,
`streaming_job_per_job_succeed_task_count`,
`streaming_job_per_job_failed_task_count`
- Existing global aggregated metrics remain unchanged
- Follow-up to #60493
## Approach
Follows `generateBackendsTabletMetrics()` pattern: on each `/metrics`
request, remove all previous per-job metrics then re-register with
current job data. This ensures values are always up-to-date and stale
jobs are cleaned up automatically.
Offset info is intentionally excluded from metric labels to avoid
Prometheus series churn and serialization issues. Offset can be viewed
via `SHOW STREAMING JOBS` or `jobs("type"="insert")` TVF.
## Test plan
- [ ] Verify per-job metrics appear in `/metrics?type=json` with correct
`job_id` and `job_name` labels
- [ ] Verify existing global streaming job metrics still present
- [ ] Verify FE replay is not affected
- [ ] Run `test_streaming_mysql_job_metrics.groovy` regression test
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
---
.../insert/streaming/StreamingInsertJob.java | 1 +
.../java/org/apache/doris/metric/MetricRepo.java | 111 +++++++++++++++++++++
.../cdc/test_streaming_mysql_job_metrics.groovy | 51 +++++++++-
3 files changed, 161 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/streaming/StreamingInsertJob.java
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/streaming/StreamingInsertJob.java
index 01e994e2e9d..025918bed5a 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/streaming/StreamingInsertJob.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/streaming/StreamingInsertJob.java
@@ -109,6 +109,7 @@ public class StreamingInsertJob extends
AbstractJob<StreamingJobSchedulerTask, M
private long dbId;
// Streaming job statistics, all persisted in txn attachment
// when checkpoint image replay need Serialized
+ @Getter
@SerializedName("jstc")
private StreamingJobStatistic jobStatistic = new StreamingJobStatistic();
// Non-txn persisted statistics, used for streaming multi task
diff --git a/fe/fe-core/src/main/java/org/apache/doris/metric/MetricRepo.java
b/fe/fe-core/src/main/java/org/apache/doris/metric/MetricRepo.java
index 083061f1394..30773721c95 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/metric/MetricRepo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/metric/MetricRepo.java
@@ -33,6 +33,7 @@ import org.apache.doris.common.util.NetUtils;
import org.apache.doris.job.common.JobStatus;
import org.apache.doris.job.common.TaskStatus;
import org.apache.doris.job.extensions.insert.streaming.StreamingInsertJob;
+import org.apache.doris.job.extensions.insert.streaming.StreamingJobStatistic;
import org.apache.doris.load.EtlJobType;
import org.apache.doris.load.loadv2.JobState;
import org.apache.doris.load.loadv2.LoadManager;
@@ -84,6 +85,12 @@ public final class MetricRepo {
public static final String TABLET_MAX_COMPACTION_SCORE =
"tablet_max_compaction_score";
public static final String TABLET_ACCESS_RECENT = "tablet_access_recent";
public static final String TABLET_ACCESS_TOTAL = "tablet_access_total";
+
+ public static final String STREAMING_JOB_PER_JOB_SCANNED_ROWS =
"streaming_job_per_job_scanned_rows";
+ public static final String STREAMING_JOB_PER_JOB_LOAD_BYTES =
"streaming_job_per_job_load_bytes";
+ public static final String STREAMING_JOB_PER_JOB_FILTERED_ROWS =
"streaming_job_per_job_filtered_rows";
+ public static final String STREAMING_JOB_PER_JOB_SUCCEED_TASK_COUNT =
"streaming_job_per_job_succeed_task_count";
+ public static final String STREAMING_JOB_PER_JOB_FAILED_TASK_COUNT =
"streaming_job_per_job_failed_task_count";
public static final String CLOUD_TAG = "cloud";
public static LongCounterMetric COUNTER_REQUEST_ALL;
@@ -1226,6 +1233,107 @@ public final class MetricRepo {
DORIS_METRIC_REGISTER.addMetrics(gauge);
}
+ // Generate per-job metrics for streaming insert jobs.
+ // Called on every /metrics request to keep labels (including offset)
up-to-date.
+ // Pattern follows generateBackendsTabletMetrics(): remove all previous
metrics, then re-register.
+ public static void updateStreamingJobPerJobMetrics() {
+ if (!Env.getCurrentEnv().isMaster()) {
+ return;
+ }
+
+
DORIS_METRIC_REGISTER.removeMetrics(STREAMING_JOB_PER_JOB_SCANNED_ROWS);
+ DORIS_METRIC_REGISTER.removeMetrics(STREAMING_JOB_PER_JOB_LOAD_BYTES);
+
DORIS_METRIC_REGISTER.removeMetrics(STREAMING_JOB_PER_JOB_FILTERED_ROWS);
+
DORIS_METRIC_REGISTER.removeMetrics(STREAMING_JOB_PER_JOB_SUCCEED_TASK_COUNT);
+
DORIS_METRIC_REGISTER.removeMetrics(STREAMING_JOB_PER_JOB_FAILED_TASK_COUNT);
+
+ try {
+ List<org.apache.doris.job.base.AbstractJob> jobs =
+
Env.getCurrentEnv().getJobManager().queryJobs(org.apache.doris.job.common.JobType.INSERT);
+
+ for (org.apache.doris.job.base.AbstractJob job : jobs) {
+ if (!(job instanceof StreamingInsertJob)) {
+ continue;
+ }
+ StreamingInsertJob sJob = (StreamingInsertJob) job;
+ String jobId = String.valueOf(sJob.getJobId());
+ String jobName = sJob.getJobName();
+
+ // tvfType != null: TVF mode, uses jobStatistic
+ // tvfType == null: multi-table mode (FROM...TO), uses
nonTxnJobStatistic
+ final StreamingJobStatistic stat;
+ if (sJob.getTvfType() != null) {
+ stat = sJob.getJobStatistic() != null ?
sJob.getJobStatistic() : new StreamingJobStatistic();
+ } else {
+ stat = sJob.getNonTxnJobStatistic() != null
+ ? sJob.getNonTxnJobStatistic() : new
StreamingJobStatistic();
+ }
+
+ GaugeMetric<Long> scannedRows = new GaugeMetric<Long>(
+ STREAMING_JOB_PER_JOB_SCANNED_ROWS, MetricUnit.ROWS,
+ "per job scanned rows of streaming job") {
+ @Override
+ public Long getValue() {
+ return stat.getScannedRows();
+ }
+ };
+ scannedRows.addLabel(new MetricLabel("job_id", jobId))
+ .addLabel(new MetricLabel("job_name", jobName));
+ DORIS_METRIC_REGISTER.addMetrics(scannedRows);
+
+ GaugeMetric<Long> loadBytes = new GaugeMetric<Long>(
+ STREAMING_JOB_PER_JOB_LOAD_BYTES, MetricUnit.BYTES,
+ "per job load bytes of streaming job") {
+ @Override
+ public Long getValue() {
+ return stat.getLoadBytes();
+ }
+ };
+ loadBytes.addLabel(new MetricLabel("job_id", jobId))
+ .addLabel(new MetricLabel("job_name", jobName));
+ DORIS_METRIC_REGISTER.addMetrics(loadBytes);
+
+ GaugeMetric<Long> filteredRows = new GaugeMetric<Long>(
+ STREAMING_JOB_PER_JOB_FILTERED_ROWS, MetricUnit.ROWS,
+ "per job filtered rows of streaming job") {
+ @Override
+ public Long getValue() {
+ return stat.getFilteredRows();
+ }
+ };
+ filteredRows.addLabel(new MetricLabel("job_id", jobId))
+ .addLabel(new MetricLabel("job_name", jobName));
+ DORIS_METRIC_REGISTER.addMetrics(filteredRows);
+
+ GaugeMetric<Long> succeedTaskCount = new GaugeMetric<Long>(
+ STREAMING_JOB_PER_JOB_SUCCEED_TASK_COUNT,
MetricUnit.NOUNIT,
+ "per job succeed task count of streaming job") {
+ @Override
+ public Long getValue() {
+ return sJob.getSucceedTaskCount().get();
+ }
+ };
+ succeedTaskCount.addLabel(new MetricLabel("job_id", jobId))
+ .addLabel(new MetricLabel("job_name", jobName));
+ DORIS_METRIC_REGISTER.addMetrics(succeedTaskCount);
+
+ GaugeMetric<Long> failedTaskCount = new GaugeMetric<Long>(
+ STREAMING_JOB_PER_JOB_FAILED_TASK_COUNT,
MetricUnit.NOUNIT,
+ "per job failed task count of streaming job") {
+ @Override
+ public Long getValue() {
+ return sJob.getFailedTaskCount().get();
+ }
+ };
+ failedTaskCount.addLabel(new MetricLabel("job_id", jobId))
+ .addLabel(new MetricLabel("job_name", jobName));
+ DORIS_METRIC_REGISTER.addMetrics(failedTaskCount);
+ }
+ } catch (Throwable t) {
+ LOG.warn("failed to update streaming job per-job metrics", t);
+ }
+ }
+
private static void initSystemMetrics() {
// TCP retransSegs
GaugeMetric<Long> tcpRetransSegs = (GaugeMetric<Long>) new
GaugeMetric<Long>(
@@ -1386,6 +1494,9 @@ public final class MetricRepo {
// update load job metrics
updateLoadJobMetrics();
+ // update per-job streaming job metrics
+ updateStreamingJobPerJobMetrics();
+
// jvm
JvmService jvmService = new JvmService();
JvmStats jvmStats = jvmService.stats();
diff --git
a/regression-test/suites/job_p0/streaming_job/cdc/test_streaming_mysql_job_metrics.groovy
b/regression-test/suites/job_p0/streaming_job/cdc/test_streaming_mysql_job_metrics.groovy
index 644e63ce5f0..e01e1d1908e 100644
---
a/regression-test/suites/job_p0/streaming_job/cdc/test_streaming_mysql_job_metrics.groovy
+++
b/regression-test/suites/job_p0/streaming_job/cdc/test_streaming_mysql_job_metrics.groovy
@@ -154,11 +154,58 @@ suite("test_streaming_mysql_job_metrics",
metricCount++
}
+ // check per-job metrics with job_id and job_name labels
+ def perJobScannedRows = result.find {
+ it.tags?.metric ==
"doris_fe_streaming_job_per_job_scanned_rows" &&
+ it.tags?.job_name == "${jobName}"
+ }
+ if (perJobScannedRows != null) {
+ log.info("per-job scanned_rows:
${perJobScannedRows}".toString())
+ metricCount++
+ }
+
+ def perJobLoadBytes = result.find {
+ it.tags?.metric ==
"doris_fe_streaming_job_per_job_load_bytes" &&
+ it.tags?.job_name == "${jobName}"
+ }
+ if (perJobLoadBytes != null) {
+ log.info("per-job load_bytes:
${perJobLoadBytes}".toString())
+ metricCount++
+ }
+
+ def perJobFilteredRows = result.find {
+ it.tags?.metric ==
"doris_fe_streaming_job_per_job_filtered_rows" &&
+ it.tags?.job_name == "${jobName}"
+ }
+ if (perJobFilteredRows != null) {
+ log.info("per-job filtered_rows:
${perJobFilteredRows}".toString())
+ metricCount++
+ }
+
+ def perJobSucceedTaskCount = result.find {
+ it.tags?.metric ==
"doris_fe_streaming_job_per_job_succeed_task_count" &&
+ it.tags?.job_name == "${jobName}"
+ }
+ if (perJobSucceedTaskCount != null) {
+ log.info("per-job succeed_task_count:
${perJobSucceedTaskCount}".toString())
+ metricCount++
+ }
+
+ def perJobFailedTaskCount = result.find {
+ it.tags?.metric ==
"doris_fe_streaming_job_per_job_failed_task_count" &&
+ it.tags?.job_name == "${jobName}"
+ }
+ if (perJobFailedTaskCount != null) {
+ log.info("per-job failed_task_count:
${perJobFailedTaskCount}".toString())
+ metricCount++
+ }
+
+
}
}
- // 9 streaming_job_* counters + 1 doris_fe_job RUNNING gauge
- if (metricCount >= 10) {
+ // 9 streaming_job_* counters + 1 doris_fe_job RUNNING gauge + 5
per-job metrics
+ if (metricCount >= 15) {
break
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]