mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-22 07:50:38 +00:00
feat: add timers for promql query (#1994)
feat: add timer for promql query
This commit is contained in:
@@ -580,6 +580,7 @@ impl PrometheusHandler for Instance {
|
||||
query: &PromQuery,
|
||||
query_ctx: QueryContextRef,
|
||||
) -> server_error::Result<Output> {
|
||||
let _timer = timer!(metrics::METRIC_HANDLE_PROMQL_ELAPSED);
|
||||
let interceptor = self
|
||||
.plugins
|
||||
.get::<PromQueryInterceptorRef<server_error::Error>>();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
pub(crate) const METRIC_HANDLE_SQL_ELAPSED: &str = "frontend.handle_sql_elapsed";
|
||||
pub(crate) const METRIC_HANDLE_PROMQL_ELAPSED: &str = "frontend.handle_promql_elapsed";
|
||||
pub(crate) const METRIC_EXEC_PLAN_ELAPSED: &str = "frontend.exec_plan_elapsed";
|
||||
pub(crate) const METRIC_HANDLE_SCRIPTS_ELAPSED: &str = "frontend.handle_scripts_elapsed";
|
||||
pub(crate) const METRIC_RUN_SCRIPT_ELAPSED: &str = "frontend.run_script_elapsed";
|
||||
|
||||
@@ -46,6 +46,16 @@ pub(crate) const METRIC_HTTP_PROM_STORE_READ_ELAPSED: &str = "servers.http_prome
|
||||
pub(crate) const METRIC_HTTP_OPENTELEMETRY_ELAPSED: &str = "servers.http_otlp_elapsed";
|
||||
pub(crate) const METRIC_TCP_OPENTSDB_LINE_WRITE_ELAPSED: &str =
|
||||
"servers.opentsdb_line_write_elapsed";
|
||||
pub(crate) const METRIC_HTTP_PROMQL_INSTANT_QUERY_ELAPSED: &str =
|
||||
"servers.http_promql_instant_query_elapsed";
|
||||
pub(crate) const METRIC_HTTP_PROMQL_RANGE_QUERY_ELAPSED: &str =
|
||||
"servers.http_promql_range_query_elapsed";
|
||||
pub(crate) const METRIC_HTTP_PROMQL_LABEL_QUERY_ELAPSED: &str =
|
||||
"servers.http_promql_label_query_elapsed";
|
||||
pub(crate) const METRIC_HTTP_PROMQL_SERIES_QUERY_ELAPSED: &str =
|
||||
"servers.http_promql_series_query_elapsed";
|
||||
pub(crate) const METRIC_HTTP_PROMQL_LABEL_VALUE_QUERY_ELAPSED: &str =
|
||||
"servers.http_promql_label_value_query_elapsed";
|
||||
|
||||
pub(crate) const METRIC_MYSQL_CONNECTIONS: &str = "servers.mysql_connection_count";
|
||||
pub(crate) const METRIC_MYSQL_QUERY_TIMER: &str = "servers.mysql_query_elapsed";
|
||||
|
||||
@@ -26,7 +26,7 @@ use common_error::ext::ErrorExt;
|
||||
use common_error::status_code::StatusCode;
|
||||
use common_query::Output;
|
||||
use common_recordbatch::RecordBatches;
|
||||
use common_telemetry::info;
|
||||
use common_telemetry::{info, timer};
|
||||
use common_time::util::{current_time_rfc3339, yesterday_rfc3339};
|
||||
use datatypes::prelude::ConcreteDataType;
|
||||
use datatypes::scalars::ScalarVector;
|
||||
@@ -91,7 +91,7 @@ impl PrometheusServer {
|
||||
}
|
||||
|
||||
pub fn make_app(&self) -> Router {
|
||||
// TODO(ruihang): implement format_query, series, values, query_examplars and targets methods
|
||||
// TODO(ruihang): implement format_query, series, values, query_exemplars and targets methods
|
||||
|
||||
let router = Router::new()
|
||||
.route("/query", routing::post(instant_query).get(instant_query))
|
||||
@@ -428,6 +428,7 @@ pub async fn instant_query(
|
||||
Query(params): Query<InstantQuery>,
|
||||
Form(form_params): Form<InstantQuery>,
|
||||
) -> Json<PrometheusJsonResponse> {
|
||||
let _timer = timer!(crate::metrics::METRIC_HTTP_PROMQL_INSTANT_QUERY_ELAPSED);
|
||||
// Extract time from query string, or use current server time if not specified.
|
||||
let time = params
|
||||
.time
|
||||
@@ -471,6 +472,7 @@ pub async fn range_query(
|
||||
Query(params): Query<RangeQuery>,
|
||||
Form(form_params): Form<RangeQuery>,
|
||||
) -> Json<PrometheusJsonResponse> {
|
||||
let _timer = timer!(crate::metrics::METRIC_HTTP_PROMQL_RANGE_QUERY_ELAPSED);
|
||||
let prom_query = PromQuery {
|
||||
query: params.query.or(form_params.query).unwrap_or_default(),
|
||||
start: params.start.or(form_params.start).unwrap_or_default(),
|
||||
@@ -543,6 +545,7 @@ pub async fn labels_query(
|
||||
Query(params): Query<LabelsQuery>,
|
||||
Form(form_params): Form<LabelsQuery>,
|
||||
) -> Json<PrometheusJsonResponse> {
|
||||
let _timer = timer!(crate::metrics::METRIC_HTTP_PROMQL_LABEL_QUERY_ELAPSED);
|
||||
let mut queries = params.matches.0;
|
||||
if queries.is_empty() {
|
||||
queries = form_params.matches.0;
|
||||
@@ -779,6 +782,7 @@ pub async fn label_values_query(
|
||||
Path(label_name): Path<String>,
|
||||
Query(params): Query<LabelValueQuery>,
|
||||
) -> Json<PrometheusJsonResponse> {
|
||||
let _timer = timer!(crate::metrics::METRIC_HTTP_PROMQL_LABEL_VALUE_QUERY_ELAPSED);
|
||||
let queries = params.matches.0;
|
||||
if queries.is_empty() {
|
||||
return PrometheusJsonResponse::error("Invalid argument", "match[] parameter is required");
|
||||
@@ -891,6 +895,7 @@ pub async fn series_query(
|
||||
Query(params): Query<SeriesQuery>,
|
||||
Form(form_params): Form<SeriesQuery>,
|
||||
) -> Json<PrometheusJsonResponse> {
|
||||
let _timer = timer!(crate::metrics::METRIC_HTTP_PROMQL_SERIES_QUERY_ELAPSED);
|
||||
let mut queries: Vec<String> = params.matches.0;
|
||||
if queries.is_empty() {
|
||||
queries = form_params.matches.0;
|
||||
|
||||
Reference in New Issue
Block a user