Skip to content

Commit 8b0b0c8

Browse files
[Enhancement] add metrics for statistics collect jobs (backport StarRocks#56693) (StarRocks#56798)
Signed-off-by: silverbullet233 <[email protected]> Co-authored-by: eyes_on_me <[email protected]> Co-authored-by: silverbullet233 <[email protected]>
1 parent 524b6c9 commit 8b0b0c8

8 files changed

+51
-0
lines changed

fe/fe-core/src/main/java/com/starrocks/metric/MetricRepo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ public final class MetricRepo {
147147
() -> new LongCounterMetric("query_queue_v2_category_state", MetricUnit.REQUESTS,
148148
"the current state of each category"));
149149

150+
151+
public static final MetricWithLabelGroup<LongCounterMetric> COUNTER_RUNNING_STATS_COLLECT_JOB =
152+
new MetricWithLabelGroup<>("type",
153+
() -> new LongCounterMetric("running_stats_collect_job", MetricUnit.REQUESTS,
154+
"the number of running statistics collect jobs"));
155+
public static final MetricWithLabelGroup<LongCounterMetric> COUNTER_TOTAL_STATS_COLLECT_JOB =
156+
new MetricWithLabelGroup<>("type",
157+
() -> new LongCounterMetric("total_stats_collect_job", MetricUnit.REQUESTS,
158+
"the number of total statistics collect jobs"));
159+
public static final MetricWithLabelGroup<LongCounterMetric> COUNTER_FAILED_STATS_COLLECT_JOB =
160+
new MetricWithLabelGroup<>("type",
161+
() -> new LongCounterMetric("failed_stats_collect_job", MetricUnit.REQUESTS,
162+
"the number of failed statistics collect jobs"));
163+
164+
150165
public static LongCounterMetric COUNTER_UNFINISHED_BACKUP_JOB;
151166
public static LongCounterMetric COUNTER_UNFINISHED_RESTORE_JOB;
152167

fe/fe-core/src/main/java/com/starrocks/statistic/ExternalFullStatisticsCollectJob.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public List<String> getPartitionNames() {
9898
return partitionNames;
9999
}
100100

101+
@Override
102+
public String getName() {
103+
return "ExternalFull";
104+
}
105+
101106
@Override
102107
public void collect(ConnectContext context, AnalyzeStatus analyzeStatus) throws Exception {
103108
long finishedSQLNum = 0;

fe/fe-core/src/main/java/com/starrocks/statistic/ExternalHistogramStatisticsCollectJob.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public String getCatalogName() {
6969
return catalogName;
7070
}
7171

72+
@Override
73+
public String getName() {
74+
return "ExternalHistogram";
75+
}
76+
7277
@Override
7378
public void collect(ConnectContext context, AnalyzeStatus analyzeStatus) throws Exception {
7479
context.getSessionVariable().setNewPlanerAggStage(1);

fe/fe-core/src/main/java/com/starrocks/statistic/FullStatisticsCollectJob.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,9 @@ public String toString() {
382382
sb.append('}');
383383
return sb.toString();
384384
}
385+
386+
@Override
387+
public String getName() {
388+
return "Full";
389+
}
385390
}

fe/fe-core/src/main/java/com/starrocks/statistic/HistogramStatisticsCollectJob.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,9 @@ private String buildCollectHistogram(Database database, Table table, double samp
157157
builder.append(build(context, COLLECT_HISTOGRAM_STATISTIC_TEMPLATE));
158158
return builder.toString();
159159
}
160+
161+
@Override
162+
public String getName() {
163+
return "Histogram";
164+
}
160165
}

fe/fe-core/src/main/java/com/starrocks/statistic/SampleStatisticsCollectJob.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@ public void collect(ConnectContext context, AnalyzeStatus analyzeStatus) throws
8787
}
8888
}
8989

90+
@Override
91+
public String getName() {
92+
return "Sample";
93+
}
94+
9095
}

fe/fe-core/src/main/java/com/starrocks/statistic/StatisticExecutor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import com.starrocks.common.Status;
3232
import com.starrocks.common.util.DebugUtil;
3333
import com.starrocks.common.util.UUIDUtil;
34+
import com.starrocks.metric.LongCounterMetric;
35+
import com.starrocks.metric.MetricRepo;
3436
import com.starrocks.qe.ConnectContext;
3537
import com.starrocks.qe.StmtExecutor;
3638
import com.starrocks.server.GlobalStateMgr;
@@ -339,6 +341,11 @@ public AnalyzeStatus collectStatistics(ConnectContext statsConnectCtx,
339341
Database db = statsJob.getDb();
340342
Table table = statsJob.getTable();
341343

344+
LongCounterMetric runningJobs = MetricRepo.COUNTER_RUNNING_STATS_COLLECT_JOB.getMetric(statsJob.getName());
345+
LongCounterMetric totalJobs = MetricRepo.COUNTER_TOTAL_STATS_COLLECT_JOB.getMetric(statsJob.getName());
346+
runningJobs.increase(1L);
347+
totalJobs.increase(1L);
348+
342349
try {
343350
Stopwatch watch = Stopwatch.createStarted();
344351
statsConnectCtx.getSessionVariable().setEnableProfile(Config.enable_statistics_collect_profile);
@@ -356,8 +363,10 @@ public AnalyzeStatus collectStatistics(ConnectContext statsConnectCtx,
356363
analyzeStatus.setEndTime(LocalDateTime.now());
357364
analyzeStatus.setReason(e.getMessage());
358365
GlobalStateMgr.getCurrentState().getAnalyzeMgr().addAnalyzeStatus(analyzeStatus);
366+
MetricRepo.COUNTER_FAILED_STATS_COLLECT_JOB.getMetric(statsJob.getName()).increase(1L);
359367
return analyzeStatus;
360368
} finally {
369+
runningJobs.increase(-1L);
361370
GlobalStateMgr.getCurrentState().getAnalyzeMgr().unregisterConnection(analyzeStatus.getId(), false);
362371
}
363372

fe/fe-core/src/main/java/com/starrocks/statistic/StatisticsCollectJob.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public Priority getPriority() {
144144
return this.priority;
145145
}
146146

147+
abstract String getName();
148+
147149
protected void setDefaultSessionVariable(ConnectContext context) {
148150
SessionVariable sessionVariable = context.getSessionVariable();
149151
// Statistics collecting is not user-specific, which means response latency is not that important.

0 commit comments

Comments
 (0)