redis_enterprise/
endpoints.rs

1//! Database endpoint configuration and monitoring
2//!
3//! ## Overview
4//! - Configure database endpoints
5//! - Query endpoint statistics
6//! - Manage endpoint routing
7
8use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13/// Endpoint information
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct Endpoint {
16    pub uid: String,
17    pub bdb_uid: u32,
18    pub node_uid: u32,
19    pub addr: String,
20    pub port: u16,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub dns_name: Option<String>,
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub role: Option<String>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub ssl: Option<bool>,
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub status: Option<String>,
29    /// Description of the endpoint
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub description: Option<String>,
32    /// Error code if endpoint has an error
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub error_code: Option<String>,
35
36    #[serde(flatten)]
37    pub extra: Value,
38}
39
40/// Endpoint statistics
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct EndpointStats {
43    pub uid: String,
44    pub intervals: Vec<StatsInterval>,
45
46    #[serde(flatten)]
47    pub extra: Value,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct StatsInterval {
52    pub interval: String,
53    pub timestamps: Vec<i64>,
54    pub values: Vec<Value>,
55}
56
57/// Endpoints handler
58pub struct EndpointsHandler {
59    client: RestClient,
60}
61
62impl EndpointsHandler {
63    pub fn new(client: RestClient) -> Self {
64        EndpointsHandler { client }
65    }
66
67    /// List all endpoints
68    pub async fn list(&self) -> Result<Vec<Endpoint>> {
69        self.client.get("/v1/endpoints").await
70    }
71
72    /// Get specific endpoint
73    pub async fn get(&self, uid: &str) -> Result<Endpoint> {
74        self.client.get(&format!("/v1/endpoints/{}", uid)).await
75    }
76
77    /// Get endpoint statistics
78    pub async fn stats(&self, uid: &str) -> Result<EndpointStats> {
79        self.client
80            .get(&format!("/v1/endpoints/{}/stats", uid))
81            .await
82    }
83
84    /// Get all endpoint statistics
85    pub async fn all_stats(&self) -> Result<Vec<EndpointStats>> {
86        self.client.get("/v1/endpoints/stats").await
87    }
88
89    /// Get endpoints for a specific database
90    pub async fn list_by_database(&self, bdb_uid: u32) -> Result<Vec<Endpoint>> {
91        self.client
92            .get(&format!("/v1/bdbs/{}/endpoints", bdb_uid))
93            .await
94    }
95
96    /// Get endpoints for a specific node
97    pub async fn list_by_node(&self, node_uid: u32) -> Result<Vec<Endpoint>> {
98        self.client
99            .get(&format!("/v1/nodes/{}/endpoints", node_uid))
100            .await
101    }
102}