Skip to content

Commit fd1b0c1

Browse files
authored
fix: InterpreterMetrics could subtract with overflow (#17461)
InterpreterMetrics could subtract with overflow
1 parent b5cd7f2 commit fd1b0c1

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

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

+4-11
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::time::Duration;
1615
use std::time::SystemTime;
17-
use std::time::UNIX_EPOCH;
1816

1917
use databend_common_config::GlobalConfig;
2018
use databend_common_exception::ErrorCode;
@@ -47,9 +45,10 @@ impl InterpreterMetrics {
4745
}
4846

4947
fn record_query_detail(ctx: &QueryContext, labels: &Vec<(&'static str, String)>) {
50-
let event_time = convert_query_timestamp(SystemTime::now());
51-
let query_start_time = convert_query_timestamp(ctx.get_created_time());
52-
let query_duration_ms = (event_time - query_start_time) as f64 / 1_000.0;
48+
let query_duration_ms = SystemTime::now()
49+
.duration_since(ctx.get_created_time())
50+
.map(|d| d.as_micros() as f64 / 1000.0)
51+
.unwrap_or(0.0);
5352

5453
let data_metrics = ctx.get_data_metrics();
5554

@@ -129,9 +128,3 @@ impl InterpreterMetrics {
129128
};
130129
}
131130
}
132-
133-
fn convert_query_timestamp(time: SystemTime) -> u128 {
134-
time.duration_since(UNIX_EPOCH)
135-
.unwrap_or(Duration::new(0, 0))
136-
.as_micros()
137-
}

0 commit comments

Comments
 (0)