Skip to content

Commit 4bbb5d5

Browse files
authored
chore(query): refactor metrics (#15421)
* chore(query): refactor metrics * chore(query): refactor metrics * chore(query): fix VACUUM TEMPORARY FILES
1 parent 29514e7 commit 4bbb5d5

File tree

5 files changed

+19
-26
lines changed

5 files changed

+19
-26
lines changed

src/common/metrics/src/metrics/interpreter.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use databend_common_base::runtime::metrics::FamilyHistogram;
2222
use crate::VecLabels;
2323

2424
const METRIC_QUERY_START: &str = "query_start";
25-
const METRIC_QUERY_ERROR: &str = "query_error";
2625
const METRIC_QUERY_SUCCESS: &str = "query_success";
2726
const METRIC_QUERY_FAILED: &str = "query_failed";
2827

@@ -42,8 +41,6 @@ const METRIC_QUERY_RESULT_BYTES: &str = "query_result_bytes";
4241

4342
pub static QUERY_START: LazyLock<FamilyCounter<VecLabels>> =
4443
LazyLock::new(|| register_counter_family(METRIC_QUERY_START));
45-
pub static QUERY_ERROR: LazyLock<FamilyCounter<VecLabels>> =
46-
LazyLock::new(|| register_counter_family(METRIC_QUERY_ERROR));
4744
pub static QUERY_SUCCESS: LazyLock<FamilyCounter<VecLabels>> =
4845
LazyLock::new(|| register_counter_family(METRIC_QUERY_SUCCESS));
4946
pub static QUERY_FAILED: LazyLock<FamilyCounter<VecLabels>> =

src/query/service/src/interpreters/interpreter.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,40 +63,40 @@ pub trait Interpreter: Sync + Send {
6363
#[async_backtrace::framed]
6464
#[minitrace::trace]
6565
async fn execute(&self, ctx: Arc<QueryContext>) -> Result<SendableDataBlockStream> {
66-
ctx.set_status_info("building pipeline");
67-
InterpreterMetrics::record_query_start(&ctx);
6866
log_query_start(&ctx);
69-
70-
if let Err(err) = ctx.check_aborting() {
71-
log_query_finished(&ctx, Some(err.clone()), false);
72-
return Err(err);
67+
match self.execute_inner(ctx.clone()).await {
68+
Ok(stream) => Ok(stream),
69+
Err(err) => {
70+
log_query_finished(&ctx, Some(err.clone()), false);
71+
Err(err)
72+
}
7373
}
74+
}
75+
76+
async fn execute_inner(&self, ctx: Arc<QueryContext>) -> Result<SendableDataBlockStream> {
77+
ctx.set_status_info("building pipeline");
78+
ctx.check_aborting()?;
7479
if self.is_ddl() {
7580
CommitInterpreter::try_create(ctx.clone())?
7681
.execute2()
7782
.await?;
7883
ctx.clear_tables_cache();
7984
}
8085
if !self.is_txn_command() && ctx.txn_mgr().lock().is_fail() {
81-
let error = ErrorCode::CurrentTransactionIsAborted(
86+
let err = ErrorCode::CurrentTransactionIsAborted(
8287
"current transaction is aborted, commands ignored until end of transaction block",
8388
);
84-
log_query_finished(&ctx, Some(error.clone()), false);
85-
return Err(error);
89+
return Err(err);
8690
}
8791
let mut build_res = match self.execute2().await {
8892
Ok(build_res) => build_res,
89-
Err(build_error) => {
90-
InterpreterMetrics::record_query_error(&ctx);
91-
log_query_finished(&ctx, Some(build_error.clone()), false);
92-
return Err(build_error);
93+
Err(err) => {
94+
return Err(err);
9395
}
9496
};
9597

9698
if build_res.main_pipeline.is_empty() {
97-
InterpreterMetrics::record_query_finished(&ctx, None);
9899
log_query_finished(&ctx, None, false);
99-
100100
return Ok(Box::pin(DataBlockStream::create(None, vec![])));
101101
}
102102

@@ -137,9 +137,7 @@ pub trait Interpreter: Sync + Send {
137137
Err(e) => Some(e.clone()),
138138
};
139139

140-
InterpreterMetrics::record_query_finished(&query_ctx, err_opt.clone());
141140
log_query_finished(&query_ctx, err_opt, has_profiles);
142-
143141
match may_error {
144142
Ok(_) => Ok(()),
145143
Err(error) => Err(error.clone()),
@@ -190,6 +188,7 @@ pub trait Interpreter: Sync + Send {
190188
pub type InterpreterPtr = Arc<dyn Interpreter>;
191189

192190
fn log_query_start(ctx: &QueryContext) {
191+
InterpreterMetrics::record_query_start(ctx);
193192
let now = SystemTime::now();
194193
let session = ctx.get_current_session();
195194

@@ -203,6 +202,8 @@ fn log_query_start(ctx: &QueryContext) {
203202
}
204203

205204
fn log_query_finished(ctx: &QueryContext, error: Option<ErrorCode>, has_profiles: bool) {
205+
InterpreterMetrics::record_query_finished(ctx, error.clone());
206+
206207
let now = SystemTime::now();
207208
let session = ctx.get_current_session();
208209

src/query/service/src/interpreters/interpreter_metrics.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ impl InterpreterMetrics {
128128
}
129129
};
130130
}
131-
132-
pub fn record_query_error(ctx: &QueryContext) {
133-
let labels = Self::common_labels(ctx);
134-
QUERY_ERROR.get_or_create(&labels).inc();
135-
}
136131
}
137132

138133
fn convert_query_timestamp(time: SystemTime) -> u128 {

src/query/sql/src/planner/plans/plan.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ impl Plan {
509509
| Plan::Presign(_)
510510
| Plan::VacuumTable(_)
511511
| Plan::VacuumDropTable(_)
512+
| Plan::VacuumTemporaryFiles(_)
512513
| Plan::DescDatamaskPolicy(_)
513514
| Plan::DescNetworkPolicy(_)
514515
| Plan::ShowNetworkPolicies(_)

tests/sqllogictests/suites/ee/03_ee_vacuum/03_0000_vacuum_temporary_files.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ SELECT sleep(2) from numbers(1);
2424
----
2525
0
2626

27-
onlyif mysql
2827
statement ok
2928
VACUUM TEMPORARY FILES RETAIN 2 SECONDS;
3029

0 commit comments

Comments
 (0)