datafusion_server/response/handler/
sys_info.rs1use crate::statistics::Statistics;
6#[cfg(feature = "plugin")]
7use crate::PluginManager;
8use axum::{response::IntoResponse, Json};
9use serde::Serialize;
10
11#[cfg(feature = "plugin")]
12#[derive(Serialize)]
13struct PluginModule {
14 module: String,
15 version: String,
16}
17
18#[cfg(feature = "plugin")]
19#[derive(Serialize)]
20struct Plugin {
21 #[serde(rename = "pythonInterpreter")]
22 python_interpreter: String,
23 connectors: Vec<PluginModule>,
24 processors: Vec<PluginModule>,
25}
26
27#[cfg(feature = "plugin")]
28impl Plugin {
29 fn new(interpreter_version: String) -> Self {
30 Self {
31 python_interpreter: interpreter_version,
32 connectors: vec![],
33 processors: vec![],
34 }
35 }
36}
37
38#[derive(Serialize)]
39struct Stats {
40 #[serde(rename = "runningTime")]
41 running_time: u64,
42}
43
44#[derive(Serialize)]
45struct System {
46 name: String,
47 version: String,
48 #[cfg(feature = "plugin")]
49 plugin: Plugin,
50 statistics: Stats,
51}
52
53#[allow(clippy::unused_async)] pub async fn handler() -> impl IntoResponse {
55 log::info!("Accessing system information endpoint");
56
57 #[cfg(feature = "plugin")]
58 let mut plugin = Plugin::new(PluginManager::global().py_interpreter_info());
59
60 #[cfg(feature = "plugin")]
61 {
62 for (name, (_path, _entry, version)) in &PluginManager::global().plugin_map.scheme_py_map {
63 plugin.connectors.push(PluginModule {
64 module: name.clone(),
65 version: version.clone(),
66 });
67 }
68
69 for (name, (_path, _entry, version)) in &PluginManager::global().plugin_map.processor_py_map
70 {
71 plugin.processors.push(PluginModule {
72 module: name.clone(),
73 version: version.clone(),
74 });
75 }
76 }
77
78 let statistics = Stats {
79 running_time: Statistics::global()
80 .server_started_at
81 .elapsed()
82 .unwrap()
83 .as_secs(),
84 };
85
86 Json(System {
87 name: env!("CARGO_PKG_NAME").to_string(),
88 version: env!("CARGO_PKG_VERSION").to_string(),
89 #[cfg(feature = "plugin")]
90 plugin,
91 statistics,
92 })
93}