hello-stephen commented on code in PR #71378:
URL: https://github.com/apache/doris/pull/71378#discussion_r4789263681


##########
fe/fe-core/src/main/java/org/apache/doris/metric/IvmRefreshSnapshotMetrics.java:
##########
@@ -29,23 +29,63 @@ private IvmRefreshSnapshotMetrics() {
     }
 
     static void visit(MetricVisitor visitor, ChangelogMonitorSnapshot 
snapshot) {
-        for (ChangelogMonitorSnapshot.IvmRefresh refresh : 
snapshot.ivmRefreshes()) {
+        List<ChangelogMonitorSnapshot.IvmRefresh> refreshes = 
snapshot.ivmRefreshes();
+        for (ChangelogMonitorSnapshot.IvmRefresh refresh : refreshes) {
+            visit(visitor, baseLabels(refresh), "ivm_consecutive_failures", 
MetricType.GAUGE, MetricUnit.NOUNIT,
+                    "Consecutive failed refresh tasks of this IVM materialized 
view",
+                    refresh.values().consecutiveFailures());
+        }
+        for (ChangelogMonitorSnapshot.IvmRefresh refresh : refreshes) {
+            visit(visitor, baseLabels(refresh), 
"ivm_refresh_failed_tasks_total", MetricType.COUNTER, MetricUnit.NOUNIT,
+                    "Total failed refresh tasks of this IVM materialized view",
+                    refresh.values().failedTaskCount());
+        }
+        for (ChangelogMonitorSnapshot.IvmRefresh refresh : refreshes) {
+            visit(visitor, baseLabels(refresh), "ivm_refresh_fallbacks_total", 
MetricType.COUNTER, MetricUnit.NOUNIT,
+                    "Total automatic refresh fallbacks of this IVM 
materialized view",
+                    refresh.values().fallbackCount());
+        }
+        for (ChangelogMonitorSnapshot.IvmRefresh refresh : refreshes) {
             IvmRefreshSummary.MetricValues values = refresh.values();
-            List<MetricLabel> labels = List.of(new MetricLabel("db_name", 
refresh.dbName()),
-                    new MetricLabel("mv_name", refresh.mvName()),
-                    new MetricLabel("mv_id", Long.toString(refresh.mvId())));
-            visit(visitor, labels, "ivm_consecutive_failures", 
MetricType.GAUGE, MetricUnit.NOUNIT,
-                    "Consecutive failed refresh tasks of this IVM materialized 
view", values.consecutiveFailures());
-            visit(visitor, labels, "ivm_refresh_failed_tasks_total", 
MetricType.COUNTER, MetricUnit.NOUNIT,
-                    "Total failed refresh tasks of this IVM materialized 
view", values.failedTaskCount());
-            visit(visitor, labels, "ivm_refresh_fallbacks_total", 
MetricType.COUNTER, MetricUnit.NOUNIT,
-                    "Total automatic refresh fallbacks of this IVM 
materialized view", values.fallbackCount());
             if (values.hasCompletedRefresh()) {
-                visit(visitor, labels, "ivm_refresh_duration_seconds", 
MetricType.GAUGE, MetricUnit.SECONDS,
+                visit(visitor, baseLabels(refresh), 
"ivm_refresh_duration_seconds", MetricType.GAUGE,
+                        MetricUnit.SECONDS,
                         "Duration of the last successful or failed refresh of 
this IVM materialized view",
                         values.lastRefreshDurationMs() / 1000.0);
             }
         }
+        for (ChangelogMonitorSnapshot.IvmRefresh refresh : refreshes) {
+            IvmRefreshSummary.MetricValues values = refresh.values();
+            visit(visitor, modeLabels(refresh, "incremental"), 
"ivm_refresh_execution_seconds_total",
+                    MetricType.COUNTER, MetricUnit.SECONDS,
+                    "Total execution time of refresh phases of this IVM 
materialized view, by mode "
+                            + "(excluding canceled refreshes)",
+                    values.incrementalDurationMs() / 1000.0);
+            visit(visitor, modeLabels(refresh, "rebuild"), 
"ivm_refresh_execution_seconds_total",
+                    MetricType.COUNTER, MetricUnit.SECONDS,
+                    "Total execution time of refresh phases of this IVM 
materialized view, by mode "
+                            + "(excluding canceled refreshes)",
+                    values.rebuildDurationMs() / 1000.0);
+        }
+        for (ChangelogMonitorSnapshot.IvmRefresh refresh : refreshes) {
+            visit(visitor, baseLabels(refresh), "ivm_refresh_rows_total", 
MetricType.COUNTER, MetricUnit.NOUNIT,
+                    "Total committed loaded rows written by refresh tasks of 
this IVM materialized view "

Review Comment:
   [P3] Describe both counters as totals for accepted refresh results. If a 
base-table schema change invalidates the MV after a batch commits, 
`MTMV.addTaskResult` can reject the stale result before the summary receives 
its rows or elapsed time. The HELP text currently implies that the only 
excluded work comes from canceled refreshes.



##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmIncrRefreshResult.java:
##########
@@ -53,6 +60,10 @@ public String getDetailMessage() {
         return detailMessage;
     }
 
+    public long getLoadedRows() {

Review Comment:
   [P3] Remove the unused loaded-row count from the incremental result. 
`IvmIncrRefreshManager` still copies `QueryState.getAffectedRows()` into this 
field on success, but the task never reads it. The transaction-aware extraction 
in `MTMVTask` already supplies the metric for successful and 
committed-but-timed-out inserts.



##########
regression-test/suites/mtmv_p0/ivm/test_ivm_refresh_cost_metrics.groovy:
##########
@@ -0,0 +1,177 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import org.apache.doris.regression.util.Http
+import org.awaitility.Awaitility
+
+import static java.util.concurrent.TimeUnit.SECONDS
+
+suite("test_ivm_refresh_cost_metrics", "nonConcurrent") {
+    sql "SET enable_materialized_view_rewrite = false"
+    sql "SET enable_dml_materialized_view_rewrite = false"
+
+    String masterMetricsUrl = 
"http://${getMasterIp()}:${getMasterPort()}/metrics"
+
+    def fetchMvCostMetrics = { String mvName ->
+        Map<String, Double> found = [:]
+        String mvFragment = "mv_name=\"${mvName}\""

Review Comment:
   [P3] Match the metric samples by MV identity. If this suite runs again on a 
shared cluster with a different default database, the previous run leaves an MV 
with the same name. This loop can overwrite the current view's samples with 
that view's counters. Match `db_name` and `mv_id` as well, as in 
`test_ivm_refresh_method_metrics.groovy`.



##########
regression-test/suites/mtmv_p0/ivm/test_ivm_refresh_cost_metrics.groovy:
##########
@@ -0,0 +1,177 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import org.apache.doris.regression.util.Http
+import org.awaitility.Awaitility
+
+import static java.util.concurrent.TimeUnit.SECONDS
+
+suite("test_ivm_refresh_cost_metrics", "nonConcurrent") {
+    sql "SET enable_materialized_view_rewrite = false"
+    sql "SET enable_dml_materialized_view_rewrite = false"
+
+    String masterMetricsUrl = 
"http://${getMasterIp()}:${getMasterPort()}/metrics"
+
+    def fetchMvCostMetrics = { String mvName ->
+        Map<String, Double> found = [:]
+        String mvFragment = "mv_name=\"${mvName}\""
+        for (String line : Http.GET(masterMetricsUrl, false, 
false).readLines()) {
+            if (!line.contains(mvFragment)) {
+                continue
+            }
+            if 
(line.startsWith("doris_fe_ivm_refresh_execution_seconds_total{")) {
+                int split = line.lastIndexOf(' ')
+                if (line.contains('mode="incremental"')) {
+                    found.put("incremental", 
Double.parseDouble(line.substring(split + 1)))
+                } else if (line.contains('mode="rebuild"')) {
+                    found.put("rebuild", 
Double.parseDouble(line.substring(split + 1)))
+                }
+            } else if (line.startsWith("doris_fe_ivm_refresh_rows_total{")) {
+                int split = line.lastIndexOf(' ')
+                found.put("rows", Double.parseDouble(line.substring(split + 
1)))
+            }
+        }
+        return found
+    }
+
+    def waitForLatestTaskFinished = { String mvName, String previousTaskId ->
+        def taskResult
+        Awaitility.await().atMost(180, SECONDS).pollInterval(1, 
SECONDS).until({
+            taskResult = sql_return_maparray("""
+                SELECT TaskId, Status FROM tasks('type'='mv')
+                WHERE MvDatabaseName = '${context.dbName}' AND MvName = 
'${mvName}'
+                ORDER BY CreateTime DESC, TaskId DESC LIMIT 1
+            """)
+            return !taskResult.isEmpty()
+                    && taskResult[0].TaskId.toString() != previousTaskId
+                    && taskResult[0].Status.toString() != 'PENDING'
+                    && taskResult[0].Status.toString() != 'RUNNING'
+        })
+        assertEquals("SUCCESS", taskResult[0].Status.toString())
+        return taskResult[0].TaskId.toString()
+    }
+
+    def oldMonitorIntervalRows = sql_return_maparray(

Review Comment:
   [P3] Read and restore the monitor interval on the master. With a follower 
JDBC endpoint, `ADMIN SHOW FRONTEND CONFIG` reads the follower's value, while 
both `ADMIN SET` calls target the master. If those values differ, the suite 
leaves the master with the follower's interval. Use the suite's master SQL 
helpers for all three operations.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to