1pub mod grpc;
27pub mod sql;
28
29use std::collections::HashMap;
30use std::sync::Arc;
31
32use api::prom_store::remote::ReadRequest;
33use api::v1::RowInsertRequests;
34use async_trait::async_trait;
35use catalog::CatalogManager;
36use common_query::Output;
37use datatypes::timestamp::TimestampNanosecond;
38use headers::HeaderValue;
39use log_query::LogQuery;
40use opentelemetry_proto::tonic::collector::logs::v1::ExportLogsServiceRequest;
41use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
42use otel_arrow_rust::proto::opentelemetry::collector::metrics::v1::ExportMetricsServiceRequest;
43use pipeline::{GreptimePipelineParams, Pipeline, PipelineInfo, PipelineVersion, PipelineWay};
44use serde_json::Value;
45use session::context::{QueryContext, QueryContextRef};
46
47#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
48pub struct DashboardDefinition {
49 pub name: String,
50 pub definition: String,
51}
52
53use crate::error::Result;
54use crate::http::jaeger::QueryTraceParams;
55use crate::influxdb::InfluxdbRequest;
56use crate::opentsdb::codec::DataPoint;
57use crate::prom_store::Metrics;
58pub type OpentsdbProtocolHandlerRef = Arc<dyn OpentsdbProtocolHandler + Send + Sync>;
59pub type InfluxdbLineProtocolHandlerRef = Arc<dyn InfluxdbLineProtocolHandler + Send + Sync>;
60pub type PromStoreProtocolHandlerRef = Arc<dyn PromStoreProtocolHandler + Send + Sync>;
61pub type OpenTelemetryProtocolHandlerRef = Arc<dyn OpenTelemetryProtocolHandler + Send + Sync>;
62pub type PipelineHandlerRef = Arc<dyn PipelineHandler + Send + Sync>;
63pub type LogQueryHandlerRef = Arc<dyn LogQueryHandler + Send + Sync>;
64pub type JaegerQueryHandlerRef = Arc<dyn JaegerQueryHandler + Send + Sync>;
65
66#[async_trait]
67pub trait InfluxdbLineProtocolHandler {
68 async fn exec(&self, request: InfluxdbRequest, ctx: QueryContextRef) -> Result<Output>;
71}
72
73#[async_trait]
74pub trait OpentsdbProtocolHandler {
75 async fn exec(&self, data_points: Vec<DataPoint>, ctx: QueryContextRef) -> Result<usize>;
78}
79
80pub struct PromStoreResponse {
81 pub content_type: HeaderValue,
82 pub content_encoding: HeaderValue,
83 pub resp_metrics: HashMap<String, Value>,
84 pub body: Vec<u8>,
85}
86
87#[async_trait]
88pub trait PromStoreProtocolHandler {
89 async fn pre_write(&self, _request: &RowInsertRequests, _ctx: QueryContextRef) -> Result<()> {
91 Ok(())
92 }
93
94 async fn write(
96 &self,
97 request: RowInsertRequests,
98 ctx: QueryContextRef,
99 with_metric_engine: bool,
100 ) -> Result<Output>;
101
102 async fn read(&self, request: ReadRequest, ctx: QueryContextRef) -> Result<PromStoreResponse>;
104 async fn ingest_metrics(&self, metrics: Metrics) -> Result<()>;
106}
107
108#[async_trait]
109pub trait OpenTelemetryProtocolHandler: PipelineHandler {
110 async fn metrics(
112 &self,
113 request: ExportMetricsServiceRequest,
114 ctx: QueryContextRef,
115 ) -> Result<Output>;
116
117 async fn traces(
119 &self,
120 pipeline_handler: PipelineHandlerRef,
121 request: ExportTraceServiceRequest,
122 pipeline: PipelineWay,
123 pipeline_params: GreptimePipelineParams,
124 table_name: String,
125 ctx: QueryContextRef,
126 ) -> Result<Output>;
127
128 async fn logs(
129 &self,
130 pipeline_handler: PipelineHandlerRef,
131 request: ExportLogsServiceRequest,
132 pipeline: PipelineWay,
133 pipeline_params: GreptimePipelineParams,
134 table_name: String,
135 ctx: QueryContextRef,
136 ) -> Result<Vec<Output>>;
137}
138
139#[async_trait]
147pub trait PipelineHandler {
148 async fn insert(&self, input: RowInsertRequests, ctx: QueryContextRef) -> Result<Output>;
149
150 async fn get_pipeline(
151 &self,
152 name: &str,
153 version: PipelineVersion,
154 query_ctx: QueryContextRef,
155 ) -> Result<Arc<Pipeline>>;
156
157 async fn insert_pipeline(
158 &self,
159 name: &str,
160 content_type: &str,
161 pipeline: &str,
162 query_ctx: QueryContextRef,
163 ) -> Result<PipelineInfo>;
164
165 async fn delete_pipeline(
166 &self,
167 name: &str,
168 version: PipelineVersion,
169 query_ctx: QueryContextRef,
170 ) -> Result<Option<()>>;
171
172 async fn get_table(
173 &self,
174 table: &str,
175 query_ctx: &QueryContext,
176 ) -> std::result::Result<Option<Arc<table::Table>>, catalog::error::Error>;
177
178 fn build_pipeline(&self, pipeline: &str) -> Result<Pipeline>;
180
181 async fn get_pipeline_str(
183 &self,
184 name: &str,
185 version: PipelineVersion,
186 query_ctx: QueryContextRef,
187 ) -> Result<(String, TimestampNanosecond)>;
188}
189
190pub type DashboardHandlerRef = Arc<dyn DashboardHandler + Send + Sync>;
192
193#[async_trait]
194pub trait DashboardHandler {
195 async fn save(&self, name: &str, definition: &str, ctx: QueryContextRef) -> Result<()>;
196
197 async fn list(&self, ctx: QueryContextRef) -> Result<Vec<DashboardDefinition>>;
198
199 async fn delete(&self, name: &str, ctx: QueryContextRef) -> Result<()>;
200}
201
202#[async_trait]
204pub trait LogQueryHandler {
205 async fn query(&self, query: LogQuery, ctx: QueryContextRef) -> Result<Output>;
207
208 fn catalog_manager(&self, ctx: &QueryContext) -> Result<&dyn CatalogManager>;
210}
211
212#[async_trait]
214pub trait JaegerQueryHandler {
215 async fn get_services(&self, ctx: QueryContextRef) -> Result<Output>;
217
218 async fn get_operations(
220 &self,
221 ctx: QueryContextRef,
222 service_name: &str,
223 span_kind: Option<&str>,
224 ) -> Result<Output>;
225
226 async fn get_trace(
231 &self,
232 ctx: QueryContextRef,
233 trace_id: &str,
234 start_time: Option<i64>,
235 end_time: Option<i64>,
236 limit: Option<usize>,
237 ) -> Result<Output>;
238
239 async fn find_traces(
241 &self,
242 ctx: QueryContextRef,
243 query_params: QueryTraceParams,
244 ) -> Result<Output>;
245}