feat: change metric crate from metrics to prometheus (#2655)

* feat: change metrics to prometheus

* chore: fix code advise

* chore: resolve merge conflict

* chore: fix code advise
This commit is contained in:
WU Jingdi
2023-10-31 23:46:57 +08:00
committed by GitHub
parent e3320c531d
commit 180bc64cb0
119 changed files with 1126 additions and 1133 deletions

View File

@@ -47,8 +47,10 @@ datafusion-physical-expr = { workspace = true, optional = true }
datatypes = { workspace = true }
futures-util.workspace = true
futures.workspace = true
lazy_static.workspace = true
once_cell.workspace = true
paste = { workspace = true, optional = true }
prometheus.workspace = true
query = { workspace = true }
# TODO(discord9): This is a forked and tweaked version of RustPython, please update it to newest original RustPython After RustPython support GC
pyo3 = { version = "0.19", optional = true, features = ["abi3", "abi3-py37"] }

View File

@@ -12,13 +12,30 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Script engine metrics
pub static METRIC_RSPY_INIT_ELAPSED: &str = "script.rspy.init_elapsed";
pub static METRIC_RSPY_EXEC_ELAPSED: &str = "script.rspy.exec_elapsed";
pub static METRIC_RSPY_EXEC_TOTAL_ELAPSED: &str = "script.rspy.exec_total_elapsed";
use lazy_static::lazy_static;
use prometheus::*;
lazy_static! {
pub static ref METRIC_RSPY_INIT_ELAPSED: Histogram =
register_histogram!("script_rspy_init_elapsed", "script rspy init elapsed").unwrap();
pub static ref METRIC_RSPY_EXEC_ELAPSED: Histogram =
register_histogram!("script_rspy_exec_elapsed", "script rspy exec elapsed").unwrap();
pub static ref METRIC_RSPY_EXEC_TOTAL_ELAPSED: Histogram = register_histogram!(
"script_rspy_exec_total_elapsed",
"script rspy exec total elapsed"
)
.unwrap();
}
#[cfg(feature = "pyo3_backend")]
pub static METRIC_PYO3_EXEC_ELAPSED: &str = "script.pyo3.exec_elapsed";
#[cfg(feature = "pyo3_backend")]
pub static METRIC_PYO3_INIT_ELAPSED: &str = "script.pyo3.init_elapsed";
#[cfg(feature = "pyo3_backend")]
pub static METRIC_PYO3_EXEC_TOTAL_ELAPSED: &str = "script.pyo3.exec_total_elapsed";
lazy_static! {
pub static ref METRIC_PYO3_EXEC_ELAPSED: Histogram =
register_histogram!("script_pyo3_exec_elapsed", "script pyo3 exec elapsed").unwrap();
pub static ref METRIC_PYO3_INIT_ELAPSED: Histogram =
register_histogram!("script_pyo3_init_elapsed", "script pyo3 init elapsed").unwrap();
pub static ref METRIC_PYO3_EXEC_TOTAL_ELAPSED: Histogram = register_histogram!(
"script_pyo3_exec_total_elapsed",
"script pyo3 exec total elapsed"
)
.unwrap();
}

View File

@@ -16,7 +16,6 @@ use std::collections::HashMap;
use arrow::compute;
use common_recordbatch::RecordBatch;
use common_telemetry::timer;
use datafusion_common::ScalarValue;
use datatypes::prelude::ConcreteDataType;
use datatypes::vectors::{Helper, VectorRef};
@@ -67,7 +66,7 @@ pub(crate) fn pyo3_exec_parsed(
rb: &Option<RecordBatch>,
params: &HashMap<String, String>,
) -> Result<RecordBatch> {
let _t = timer!(metric::METRIC_PYO3_EXEC_TOTAL_ELAPSED);
let _t = metric::METRIC_PYO3_EXEC_TOTAL_ELAPSED.start_timer();
// i.e params or use `vector(..)` to construct a PyVector
let arg_names = &copr.deco_args.arg_names.clone().unwrap_or_default();
let args: Vec<PyVector> = if let Some(rb) = rb {
@@ -80,7 +79,7 @@ pub(crate) fn pyo3_exec_parsed(
// Just in case cpython is not inited
init_cpython_interpreter().unwrap();
Python::with_gil(|py| -> Result<_> {
let _t = timer!(metric::METRIC_PYO3_EXEC_ELAPSED);
let _t = metric::METRIC_PYO3_EXEC_ELAPSED.start_timer();
let mut cols = (|| -> PyResult<_> {
let dummy_decorator = "

View File

@@ -15,7 +15,7 @@
use std::sync::{Arc, Mutex};
use arrow::pyarrow::PyArrowException;
use common_telemetry::{info, timer};
use common_telemetry::info;
use datafusion_common::ScalarValue;
use datafusion_expr::ColumnarValue;
use datatypes::arrow::datatypes::DataType as ArrowDataType;
@@ -40,7 +40,7 @@ pub(crate) fn to_py_err(err: impl ToString) -> PyErr {
/// init cpython interpreter with `greptime` builtins, if already inited, do nothing
pub(crate) fn init_cpython_interpreter() -> PyResult<()> {
let _t = timer!(metric::METRIC_PYO3_INIT_ELAPSED);
let _t = metric::METRIC_PYO3_INIT_ELAPSED.start_timer();
let mut start = START_PYO3.lock().unwrap();
if !*start {
pyo3::append_to_inittab!(greptime_builtins);

View File

@@ -18,7 +18,7 @@ use std::rc::Rc;
use std::result::Result as StdResult;
use common_recordbatch::RecordBatch;
use common_telemetry::{info, timer};
use common_telemetry::info;
use datatypes::vectors::VectorRef;
use rustpython_vm::builtins::{PyBaseExceptionRef, PyDict, PyStr, PyTuple};
use rustpython_vm::class::PyClassImpl;
@@ -45,7 +45,7 @@ pub(crate) fn rspy_exec_parsed(
rb: &Option<RecordBatch>,
params: &HashMap<String, String>,
) -> Result<RecordBatch> {
let _t = timer!(metric::METRIC_RSPY_EXEC_TOTAL_ELAPSED);
let _t = metric::METRIC_RSPY_EXEC_TOTAL_ELAPSED.start_timer();
// 3. get args from `rb`, and cast them into PyVector
let args: Vec<PyVector> = if let Some(rb) = rb {
let arg_names = copr.deco_args.arg_names.clone().unwrap_or_default();
@@ -102,7 +102,7 @@ pub(crate) fn exec_with_cached_vm(
vm: &Rc<Interpreter>,
) -> Result<RecordBatch> {
vm.enter(|vm| -> Result<RecordBatch> {
let _t = timer!(metric::METRIC_RSPY_EXEC_ELAPSED);
let _t = metric::METRIC_RSPY_EXEC_ELAPSED.start_timer();
// set arguments with given name and values
let scope = vm.new_scope_with_builtins();
@@ -189,7 +189,7 @@ fn try_into_columns(
/// init interpreter with type PyVector and Module: greptime
pub(crate) fn init_interpreter() -> Rc<Interpreter> {
let _t = timer!(metric::METRIC_RSPY_INIT_ELAPSED);
let _t = metric::METRIC_RSPY_INIT_ELAPSED.start_timer();
INTERPRETER.with(|i| {
i.borrow_mut()
.get_or_insert_with(|| {