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 write(
91 &self,
92 request: RowInsertRequests,
93 ctx: QueryContextRef,
94 with_metric_engine: bool,
95 ) -> Result<Output>;
96
97 async fn read(&self, request: ReadRequest, ctx: QueryContextRef) -> Result<PromStoreResponse>;
99 async fn ingest_metrics(&self, metrics: Metrics) -> Result<()>;
101}
102
103#[async_trait]
104pub trait OpenTelemetryProtocolHandler: PipelineHandler {
105 async fn metrics(
107 &self,
108 request: ExportMetricsServiceRequest,
109 ctx: QueryContextRef,
110 ) -> Result<Output>;
111
112 async fn traces(
114 &self,
115 pipeline_handler: PipelineHandlerRef,
116 request: ExportTraceServiceRequest,
117 pipeline: PipelineWay,
118 pipeline_params: GreptimePipelineParams,
119 table_name: String,
120 ctx: QueryContextRef,
121 ) -> Result<Output>;
122
123 async fn logs(
124 &self,
125 pipeline_handler: PipelineHandlerRef,
126 request: ExportLogsServiceRequest,
127 pipeline: PipelineWay,
128 pipeline_params: GreptimePipelineParams,
129 table_name: String,
130 ctx: QueryContextRef,
131 ) -> Result<Vec<Output>>;
132}
133
134#[async_trait]
142pub trait PipelineHandler {
143 async fn insert(&self, input: RowInsertRequests, ctx: QueryContextRef) -> Result<Output>;
144
145 async fn get_pipeline(
146 &self,
147 name: &str,
148 version: PipelineVersion,
149 query_ctx: QueryContextRef,
150 ) -> Result<Arc<Pipeline>>;
151
152 async fn insert_pipeline(
153 &self,
154 name: &str,
155 content_type: &str,
156 pipeline: &str,
157 query_ctx: QueryContextRef,
158 ) -> Result<PipelineInfo>;
159
160 async fn delete_pipeline(
161 &self,
162 name: &str,
163 version: PipelineVersion,
164 query_ctx: QueryContextRef,
165 ) -> Result<Option<()>>;
166
167 async fn get_table(
168 &self,
169 table: &str,
170 query_ctx: &QueryContext,
171 ) -> std::result::Result<Option<Arc<table::Table>>, catalog::error::Error>;
172
173 fn build_pipeline(&self, pipeline: &str) -> Result<Pipeline>;
175
176 async fn get_pipeline_str(
178 &self,
179 name: &str,
180 version: PipelineVersion,
181 query_ctx: QueryContextRef,
182 ) -> Result<(String, TimestampNanosecond)>;
183}
184
185pub type DashboardHandlerRef = Arc<dyn DashboardHandler + Send + Sync>;
187
188#[async_trait]
189pub trait DashboardHandler {
190 async fn save(&self, name: &str, definition: &str, ctx: QueryContextRef) -> Result<()>;
191
192 async fn list(&self, ctx: QueryContextRef) -> Result<Vec<DashboardDefinition>>;
193
194 async fn delete(&self, name: &str, ctx: QueryContextRef) -> Result<()>;
195}
196
197#[async_trait]
199pub trait LogQueryHandler {
200 async fn query(&self, query: LogQuery, ctx: QueryContextRef) -> Result<Output>;
202
203 fn catalog_manager(&self, ctx: &QueryContext) -> Result<&dyn CatalogManager>;
205}
206
207#[async_trait]
209pub trait JaegerQueryHandler {
210 async fn get_services(&self, ctx: QueryContextRef) -> Result<Output>;
212
213 async fn get_operations(
215 &self,
216 ctx: QueryContextRef,
217 service_name: &str,
218 span_kind: Option<&str>,
219 ) -> Result<Output>;
220
221 async fn get_trace(
226 &self,
227 ctx: QueryContextRef,
228 trace_id: &str,
229 start_time: Option<i64>,
230 end_time: Option<i64>,
231 limit: Option<usize>,
232 ) -> Result<Output>;
233
234 async fn find_traces(
236 &self,
237 ctx: QueryContextRef,
238 query_params: QueryTraceParams,
239 ) -> Result<Output>;
240}