|
37 | 37 | import org.apache.doris.job.common.TaskStatus; |
38 | 38 | import org.apache.doris.job.extensions.insert.streaming.StreamingInsertJob; |
39 | 39 | import org.apache.doris.job.extensions.insert.streaming.StreamingJobStatistic; |
| 40 | +import org.apache.doris.job.extensions.mtmv.MTMVTask; |
40 | 41 | import org.apache.doris.load.EtlJobType; |
41 | 42 | import org.apache.doris.load.loadv2.JobState; |
42 | 43 | import org.apache.doris.load.loadv2.LoadManager; |
|
50 | 51 | import org.apache.doris.mtmv.MTMVRefreshEnum.RefreshMethod; |
51 | 52 | import org.apache.doris.mtmv.MTMVRefreshEnum.RefreshTrigger; |
52 | 53 | import org.apache.doris.mtmv.MTMVUtil; |
| 54 | +import org.apache.doris.mtmv.ivm.IvmRefreshMethod; |
53 | 55 | import org.apache.doris.mysql.privilege.Auth; |
54 | 56 | import org.apache.doris.nereids.NereidsPlanner; |
55 | 57 | import org.apache.doris.persist.EditLog; |
@@ -272,6 +274,20 @@ public final class MetricRepo { |
272 | 274 | public static GaugeMetric<Integer> GAUGE_ASYNC_MATERIALIZED_VIEW_TASK_RUNNING_NUM; |
273 | 275 | public static GaugeMetric<Integer> GAUGE_ASYNC_MATERIALIZED_VIEW_TASK_PENDING_NUM; |
274 | 276 |
|
| 277 | + // The refresh tasks of IVM materialized views, counted on the Master as each one ends. |
| 278 | + // The result label of COUNTER_IVM_REFRESH_TASKS: no_change is a SUCCESS that committed nothing. |
| 279 | + public static final String IVM_REFRESH_RESULT_SUCCESS = "success"; |
| 280 | + public static final String IVM_REFRESH_RESULT_NO_CHANGE = "no_change"; |
| 281 | + public static final String IVM_REFRESH_RESULT_FAILED = "failed"; |
| 282 | + public static final String IVM_REFRESH_RESULT_CANCELED = "canceled"; |
| 283 | + // by result, then by IvmRefreshMethod |
| 284 | + public static Map<String, Map<IvmRefreshMethod, LongCounterMetric>> COUNTER_IVM_REFRESH_TASKS; |
| 285 | + public static Map<IvmRefreshMethod, DoubleCounterMetric> COUNTER_IVM_REFRESH_DURATION_SECONDS; |
| 286 | + // by MTMVTask.IVM_FALLBACK_REASONS and MTMVTask.IVM_FAILURE_REASONS |
| 287 | + public static Map<String, LongCounterMetric> COUNTER_IVM_FALLBACKS; |
| 288 | + public static Map<String, LongCounterMetric> COUNTER_IVM_REFRESH_FAILURES; |
| 289 | + public static LongCounterMetric COUNTER_IVM_SCHEDULE_REJECTED; |
| 290 | + |
275 | 291 | // Statistics |
276 | 292 | public static GaugeMetric<Double> GAUGE_STATISTICS_UNHEALTHY_TABLE_RATE; |
277 | 293 | public static GaugeMetric<Double> GAUGE_STATISTICS_UNHEALTHY_COLUMN_RATE; |
@@ -1146,6 +1162,44 @@ public Integer getValue() { |
1146 | 1162 | } |
1147 | 1163 | }; |
1148 | 1164 | DORIS_METRIC_REGISTER.addMetrics(GAUGE_ASYNC_MATERIALIZED_VIEW_TASK_PENDING_NUM); |
| 1165 | + |
| 1166 | + // IVM refresh tasks, counted by MTMVTask as each task of an IVM MV ends. Every combination of labels is |
| 1167 | + // registered here, so that each series exists from 0 rather than appearing with its first event. |
| 1168 | + COUNTER_IVM_REFRESH_TASKS = Maps.newHashMap(); |
| 1169 | + for (String result : new String[] {IVM_REFRESH_RESULT_SUCCESS, IVM_REFRESH_RESULT_NO_CHANGE, |
| 1170 | + IVM_REFRESH_RESULT_FAILED, IVM_REFRESH_RESULT_CANCELED}) { |
| 1171 | + Map<IvmRefreshMethod, LongCounterMetric> byMethod = Maps.newEnumMap(IvmRefreshMethod.class); |
| 1172 | + for (IvmRefreshMethod method : IvmRefreshMethod.values()) { |
| 1173 | + LongCounterMetric counter = new LongCounterMetric("ivm_refresh_tasks_total", MetricUnit.NOUNIT, |
| 1174 | + "number of the refresh tasks of IVM materialized views that ended, by result and by the" |
| 1175 | + + " kinds of work that committed data"); |
| 1176 | + counter.addLabel(new MetricLabel("result", result)) |
| 1177 | + .addLabel(new MetricLabel("method", method.name().toLowerCase())); |
| 1178 | + DORIS_METRIC_REGISTER.addMetrics(counter); |
| 1179 | + byMethod.put(method, counter); |
| 1180 | + } |
| 1181 | + COUNTER_IVM_REFRESH_TASKS.put(result, byMethod); |
| 1182 | + } |
| 1183 | + COUNTER_IVM_REFRESH_DURATION_SECONDS = Maps.newEnumMap(IvmRefreshMethod.class); |
| 1184 | + for (IvmRefreshMethod method : IvmRefreshMethod.values()) { |
| 1185 | + DoubleCounterMetric counter = new DoubleCounterMetric("ivm_refresh_duration_seconds_total", |
| 1186 | + MetricUnit.SECONDS, "how long the refresh tasks of IVM materialized views that succeeded or" |
| 1187 | + + " failed ran, from start to finish, in seconds"); |
| 1188 | + counter.addLabel(new MetricLabel("method", method.name().toLowerCase())); |
| 1189 | + DORIS_METRIC_REGISTER.addMetrics(counter); |
| 1190 | + COUNTER_IVM_REFRESH_DURATION_SECONDS.put(method, counter); |
| 1191 | + } |
| 1192 | + COUNTER_IVM_FALLBACKS = addIvmRefreshReasonCounters("ivm_fallbacks_total", |
| 1193 | + "number of the refresh tasks of IVM materialized views that fell back from the incremental refresh" |
| 1194 | + + " and committed data in the refresh that replaced it, by the reason", |
| 1195 | + MTMVTask.IVM_FALLBACK_REASONS); |
| 1196 | + COUNTER_IVM_REFRESH_FAILURES = addIvmRefreshReasonCounters("ivm_refresh_failures_total", |
| 1197 | + "number of the refresh tasks of IVM materialized views that failed, by the reason", |
| 1198 | + MTMVTask.IVM_FAILURE_REASONS); |
| 1199 | + COUNTER_IVM_SCHEDULE_REJECTED = new LongCounterMetric("ivm_schedule_rejected_total", MetricUnit.NOUNIT, |
| 1200 | + "number of the refresh tasks of IVM materialized views that the full task queue turned away"); |
| 1201 | + DORIS_METRIC_REGISTER.addMetrics(COUNTER_IVM_SCHEDULE_REJECTED); |
| 1202 | + |
1149 | 1203 | GAUGE_MAX_TABLE_SIZE_BYTES = new GaugeMetricImpl<>("max_table_size_bytes", MetricUnit.BYTES, "", 0L); |
1150 | 1204 | DORIS_METRIC_REGISTER.addMetrics(GAUGE_MAX_TABLE_SIZE_BYTES); |
1151 | 1205 |
|
@@ -1761,6 +1815,19 @@ public static synchronized String getMetric(MetricVisitor visitor) { |
1761 | 1815 | return visitor.finish(); |
1762 | 1816 | } |
1763 | 1817 |
|
| 1818 | + // One counter per reason, keyed by the reason as the task records it and labeled with it in lower case. |
| 1819 | + private static Map<String, LongCounterMetric> addIvmRefreshReasonCounters(String name, String description, |
| 1820 | + List<String> reasons) { |
| 1821 | + Map<String, LongCounterMetric> counters = Maps.newHashMap(); |
| 1822 | + for (String reason : reasons) { |
| 1823 | + LongCounterMetric counter = new LongCounterMetric(name, MetricUnit.NOUNIT, description); |
| 1824 | + counter.addLabel(new MetricLabel("reason", reason.toLowerCase())); |
| 1825 | + DORIS_METRIC_REGISTER.addMetrics(counter); |
| 1826 | + counters.put(reason, counter); |
| 1827 | + } |
| 1828 | + return counters; |
| 1829 | + } |
| 1830 | + |
1764 | 1831 | public static <M extends Metric<?>> AutoMappedMetric<M> addLabeledMetrics(String label, Supplier<M> metric) { |
1765 | 1832 | return new AutoMappedMetric<>(value -> { |
1766 | 1833 | M m = metric.get(); |
|
0 commit comments