servers/lib.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#![feature(try_blocks)]
16#![feature(exclusive_wrapper)]
17
18use datafusion_expr::LogicalPlan;
19use sql::statements::statement::Statement;
20// Re-export for use in add_service! macro
21#[doc(hidden)]
22pub use tower;
23
24pub mod addrs;
25pub mod configurator;
26pub(crate) mod elasticsearch;
27pub mod error;
28pub mod grpc;
29
30mod hint_headers;
31pub mod http;
32pub mod influxdb;
33pub mod interceptor;
34pub mod metrics;
35pub mod metrics_handler;
36pub mod mysql;
37pub mod opentsdb;
38pub mod otel_arrow;
39pub mod otlp;
40pub mod pending_rows_batcher;
41mod pipeline;
42pub mod postgres;
43pub mod prom_remote_write;
44pub(crate) mod prom_row_builder;
45pub mod prom_store;
46pub mod prometheus;
47pub mod prometheus_handler;
48pub mod query_handler;
49pub mod repeated_field;
50pub mod request_memory_limiter;
51pub mod request_memory_metrics;
52mod row_writer;
53pub mod server;
54pub mod tls;
55
56/// Cached sql plan or statement for database interfaces
57#[derive(Clone, Debug)]
58pub enum SqlPlan {
59 /// Empty Query
60 Empty,
61 /// Hardcoded SQL shortcuts
62 Shortcut(String),
63 /// Datafusion parsed execution plan with the original query string
64 Plan(LogicalPlan, String),
65 /// Parsed statement when execution is not managed by datafusion
66 /// eg. CREATE TABLE
67 /// The String is the original query string to avoid AST round-trip issues
68 Statement(Statement, String),
69}
70
71/// Install the ring crypto provider for rustls process-wide. see:
72///
73/// https://docs.rs/rustls/latest/rustls/crypto/struct.CryptoProvider.html#using-the-per-process-default-cryptoprovider
74///
75/// for more information.
76pub fn install_ring_crypto_provider() -> Result<(), String> {
77 rustls::crypto::CryptoProvider::install_default(rustls::crypto::ring::default_provider())
78 .map_err(|ret| {
79 format!(
80 "CryptoProvider already installed as: {:?}, but providing {:?}",
81 rustls::crypto::CryptoProvider::get_default(),
82 ret
83 )
84 })
85}