servers/
prometheus_handler.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! prom supply the prometheus HTTP API Server compliance
16
17use std::sync::Arc;
18use std::time::SystemTime;
19
20use async_trait::async_trait;
21use catalog::CatalogManagerRef;
22use common_query::Output;
23use promql_parser::label::Matcher;
24use query::parser::PromQuery;
25use session::context::QueryContextRef;
26
27use crate::error::Result;
28
29pub const PROMETHEUS_API_VERSION: &str = "v1";
30
31pub type PrometheusHandlerRef = Arc<dyn PrometheusHandler + Send + Sync>;
32
33#[async_trait]
34pub trait PrometheusHandler {
35    async fn do_query(&self, query: &PromQuery, query_ctx: QueryContextRef) -> Result<Output>;
36
37    /// Query metric table names by the `__name__` matchers.
38    async fn query_metric_names(
39        &self,
40        matchers: Vec<Matcher>,
41        ctx: &QueryContextRef,
42    ) -> Result<Vec<String>>;
43
44    async fn query_label_values(
45        &self,
46        metric: String,
47        label_name: String,
48        matchers: Vec<Matcher>,
49        start: SystemTime,
50        end: SystemTime,
51        ctx: &QueryContextRef,
52    ) -> Result<Vec<String>>;
53
54    fn catalog_manager(&self) -> CatalogManagerRef;
55}