Skip to content

Commit 3314c38

Browse files
committed
feat(enterprise): add endpoint management commands (#159)
- Implement endpoint stats command to get aggregate statistics - Add endpoint availability command for database endpoints - Support JMESPath query filtering for output - Add comprehensive mdBook documentation - Include unit tests for command parsing
1 parent c61c6ee commit 3314c38

File tree

6 files changed

+342
-0
lines changed

6 files changed

+342
-0
lines changed

crates/redisctl/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ pub enum EnterpriseCommands {
977977
#[command(subcommand)]
978978
Diagnostics(crate::commands::enterprise::diagnostics::DiagnosticsCommands),
979979

980+
/// Endpoint operations
981+
#[command(subcommand)]
982+
Endpoint(crate::commands::enterprise::endpoint::EndpointCommands),
983+
980984
/// Node operations
981985
#[command(subcommand)]
982986
Node(EnterpriseNodeCommands),
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
use anyhow::Context;
2+
use clap::Subcommand;
3+
4+
use crate::{cli::OutputFormat, connection::ConnectionManager, error::Result as CliResult};
5+
6+
#[allow(dead_code)]
7+
pub async fn handle_endpoint_command(
8+
conn_mgr: &ConnectionManager,
9+
profile_name: Option<&str>,
10+
endpoint_cmd: EndpointCommands,
11+
output_format: OutputFormat,
12+
query: Option<&str>,
13+
) -> CliResult<()> {
14+
endpoint_cmd
15+
.execute(conn_mgr, profile_name, output_format, query)
16+
.await
17+
}
18+
19+
#[derive(Debug, Clone, Subcommand)]
20+
pub enum EndpointCommands {
21+
/// Get endpoint statistics
22+
Stats,
23+
24+
/// Check endpoint availability for a database
25+
Availability {
26+
/// Database UID
27+
bdb_uid: u64,
28+
},
29+
}
30+
31+
impl EndpointCommands {
32+
#[allow(dead_code)]
33+
pub async fn execute(
34+
&self,
35+
conn_mgr: &ConnectionManager,
36+
profile_name: Option<&str>,
37+
output_format: OutputFormat,
38+
query: Option<&str>,
39+
) -> CliResult<()> {
40+
handle_endpoint_command_impl(conn_mgr, profile_name, self, output_format, query).await
41+
}
42+
}
43+
44+
#[allow(dead_code)]
45+
async fn handle_endpoint_command_impl(
46+
conn_mgr: &ConnectionManager,
47+
profile_name: Option<&str>,
48+
command: &EndpointCommands,
49+
output_format: OutputFormat,
50+
query: Option<&str>,
51+
) -> CliResult<()> {
52+
let client = conn_mgr.create_enterprise_client(profile_name).await?;
53+
54+
match command {
55+
EndpointCommands::Stats => {
56+
let response: serde_json::Value = client
57+
.get("/v1/endpoints/stats")
58+
.await
59+
.context("Failed to get endpoint statistics")?;
60+
61+
let output_data = if let Some(q) = query {
62+
super::utils::apply_jmespath(&response, q)?
63+
} else {
64+
response
65+
};
66+
67+
super::utils::print_formatted_output(output_data, output_format)?;
68+
}
69+
EndpointCommands::Availability { bdb_uid } => {
70+
let response: serde_json::Value = client
71+
.get(&format!("/v1/local/bdbs/{}/endpoint/availability", bdb_uid))
72+
.await
73+
.context(format!(
74+
"Failed to check endpoint availability for database {}",
75+
bdb_uid
76+
))?;
77+
78+
let output_data = if let Some(q) = query {
79+
super::utils::apply_jmespath(&response, q)?
80+
} else {
81+
response
82+
};
83+
84+
super::utils::print_formatted_output(output_data, output_format)?;
85+
}
86+
}
87+
88+
Ok(())
89+
}
90+
91+
#[cfg(test)]
92+
mod tests {
93+
use super::*;
94+
95+
#[test]
96+
fn test_endpoint_command_parsing() {
97+
use clap::Parser;
98+
99+
#[derive(Parser)]
100+
struct TestCli {
101+
#[command(subcommand)]
102+
cmd: EndpointCommands,
103+
}
104+
105+
// Test stats command
106+
let cli = TestCli::parse_from(["test", "stats"]);
107+
assert!(matches!(cli.cmd, EndpointCommands::Stats));
108+
109+
// Test availability command
110+
let cli = TestCli::parse_from(["test", "availability", "1"]);
111+
if let EndpointCommands::Availability { bdb_uid } = cli.cmd {
112+
assert_eq!(bdb_uid, 1);
113+
} else {
114+
panic!("Expected Availability command");
115+
}
116+
}
117+
}

crates/redisctl/src/commands/enterprise/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod crdb_task;
1010
pub mod database;
1111
pub mod database_impl;
1212
pub mod diagnostics;
13+
pub mod endpoint;
1314
pub mod job_scheduler;
1415
pub mod logs;
1516
pub mod logs_impl;

crates/redisctl/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ async fn execute_enterprise_command(
232232
)
233233
.await
234234
}
235+
Endpoint(endpoint_cmd) => {
236+
commands::enterprise::endpoint::handle_endpoint_command(
237+
conn_mgr,
238+
profile,
239+
endpoint_cmd.clone(),
240+
output,
241+
query,
242+
)
243+
.await
244+
}
235245
Node(node_cmd) => {
236246
commands::enterprise::node::handle_node_command(
237247
conn_mgr, profile, node_cmd, output, query,

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- [CRDB Tasks](./enterprise/crdb-tasks.md)
4040
- [Actions (Tasks)](./enterprise/actions.md)
4141
- [Diagnostics](./enterprise/diagnostics.md)
42+
- [Endpoints](./enterprise/endpoints.md)
4243
- [Job Scheduler](./enterprise/job-scheduler.md)
4344
- [Workflows](./enterprise/workflows.md)
4445
- [Raw API Access](./enterprise/api-access.md)

docs/src/enterprise/endpoints.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Endpoint Management
2+
3+
The endpoint commands provide access to Redis Enterprise database endpoint statistics and availability monitoring.
4+
5+
> **Note**: Redis Enterprise manages most endpoint configurations through database commands. These commands provide monitoring and statistics capabilities.
6+
7+
## Available Commands
8+
9+
### Get Endpoint Statistics
10+
11+
Get aggregate statistics for all database endpoints in the cluster:
12+
13+
```bash
14+
# Get all endpoint statistics
15+
redisctl enterprise endpoint stats
16+
17+
# Get statistics as YAML
18+
redisctl enterprise endpoint stats -o yaml
19+
20+
# Filter to specific metrics
21+
redisctl enterprise endpoint stats -q '[].{name: endpoint_name, connections: current_connections}'
22+
23+
# Get statistics for endpoints with high connection counts
24+
redisctl enterprise endpoint stats -q "[?current_connections > `100`]"
25+
```
26+
27+
The statistics include:
28+
- Connection metrics (current, total, failed)
29+
- Request/response rates
30+
- Latency information
31+
- Error counts
32+
- Bandwidth usage
33+
34+
### Check Endpoint Availability
35+
36+
Check the availability status of a specific database endpoint:
37+
38+
```bash
39+
# Check endpoint availability for database 1
40+
redisctl enterprise endpoint availability 1
41+
42+
# Get availability as table
43+
redisctl enterprise endpoint availability 1 -o table
44+
45+
# Extract specific availability information
46+
redisctl enterprise endpoint availability 1 -q 'available'
47+
```
48+
49+
Availability information includes:
50+
- Current availability status
51+
- Node availability
52+
- Shard distribution
53+
- Failover status
54+
- Connection health
55+
56+
## Output Examples
57+
58+
### Endpoint Statistics
59+
```json
60+
[
61+
{
62+
"endpoint_name": "redis-12345.cluster.local:16379",
63+
"bdb_uid": 1,
64+
"current_connections": 45,
65+
"total_connections": 12543,
66+
"failed_connections": 2,
67+
"requests_per_sec": 5432,
68+
"responses_per_sec": 5430,
69+
"avg_latency_ms": 0.8,
70+
"bandwidth_in_mbps": 12.5,
71+
"bandwidth_out_mbps": 8.3,
72+
"errors_per_sec": 0.1
73+
}
74+
]
75+
```
76+
77+
### Endpoint Availability
78+
```json
79+
{
80+
"bdb_uid": 1,
81+
"available": true,
82+
"endpoints": [
83+
{
84+
"addr": "redis-12345.cluster.local:16379",
85+
"node": 1,
86+
"role": "master",
87+
"status": "active"
88+
}
89+
],
90+
"shards_placement": "optimal",
91+
"last_failover": null
92+
}
93+
```
94+
95+
## Common Use Cases
96+
97+
### Monitoring Endpoint Health
98+
99+
Monitor endpoint statistics and set up alerts:
100+
101+
```bash
102+
# Check endpoints with high error rates
103+
redisctl enterprise endpoint stats -q "[?errors_per_sec > `10`]"
104+
105+
# Monitor endpoints with connection issues
106+
redisctl enterprise endpoint stats -q "[?failed_connections > `0`].{name: endpoint_name, failed: failed_connections}"
107+
108+
# Check latency across all endpoints
109+
redisctl enterprise endpoint stats -q "[].{endpoint: endpoint_name, latency: avg_latency_ms}" -o table
110+
```
111+
112+
### Availability Monitoring
113+
114+
Check database endpoint availability during maintenance:
115+
116+
```bash
117+
# Check availability for critical databases
118+
for db in 1 2 3; do
119+
echo "Database $db:"
120+
redisctl enterprise endpoint availability $db -q 'available'
121+
done
122+
123+
# Get detailed availability for troubleshooting
124+
redisctl enterprise endpoint availability 1 -o yaml
125+
```
126+
127+
### Performance Analysis
128+
129+
Analyze endpoint performance metrics:
130+
131+
```bash
132+
# Get top endpoints by connection count
133+
redisctl enterprise endpoint stats -q "reverse(sort_by([],&current_connections))[:5]" -o table
134+
135+
# Find endpoints with bandwidth issues
136+
redisctl enterprise endpoint stats -q "[?bandwidth_in_mbps > `100` || bandwidth_out_mbps > `100`]"
137+
138+
# Compare request/response rates
139+
redisctl enterprise endpoint stats -q "[].{endpoint: endpoint_name, req_rate: requests_per_sec, resp_rate: responses_per_sec, diff: requests_per_sec - responses_per_sec}"
140+
```
141+
142+
## Integration with Monitoring
143+
144+
Export endpoint metrics for monitoring systems:
145+
146+
```bash
147+
# Export to monitoring format
148+
redisctl enterprise endpoint stats -o json > endpoint_metrics.json
149+
150+
# Create CSV for analysis
151+
redisctl enterprise endpoint stats -q "[].{endpoint: endpoint_name, connections: current_connections, latency: avg_latency_ms, errors: errors_per_sec}" | jq -r '["endpoint","connections","latency","errors"], (.[] | [.endpoint, .connections, .latency, .errors]) | @csv'
152+
153+
# Stream to monitoring pipeline
154+
while true; do
155+
redisctl enterprise endpoint stats -q '[].{timestamp: now(), metrics: @}' | \
156+
curl -X POST http://metrics-collector/ingest -d @-
157+
sleep 60
158+
done
159+
```
160+
161+
## Troubleshooting
162+
163+
### High Connection Counts
164+
165+
If endpoints show high connection counts:
166+
167+
```bash
168+
# Identify affected endpoints
169+
redisctl enterprise endpoint stats -q "[?current_connections > `1000`]"
170+
171+
# Check database configuration
172+
redisctl enterprise database get <bdb_uid> -q '{max_connections: max_connections, current: @ | current_connections}'
173+
174+
# Monitor connection trends
175+
for i in {1..10}; do
176+
redisctl enterprise endpoint stats -q "[].{endpoint: endpoint_name, connections: current_connections}" -o table
177+
sleep 30
178+
done
179+
```
180+
181+
### Availability Issues
182+
183+
When endpoints report availability problems:
184+
185+
```bash
186+
# Check specific database endpoint
187+
redisctl enterprise endpoint availability <bdb_uid>
188+
189+
# Verify node status
190+
redisctl enterprise node list -q "[?status != 'active']"
191+
192+
# Check shard distribution
193+
redisctl enterprise database get <bdb_uid> -q 'shards_placement'
194+
```
195+
196+
## Best Practices
197+
198+
1. **Regular Monitoring**: Set up regular checks of endpoint statistics to catch issues early
199+
2. **Baseline Metrics**: Establish baseline performance metrics for comparison
200+
3. **Alert Thresholds**: Configure alerts based on your specific workload patterns
201+
4. **Correlation**: Correlate endpoint metrics with database and node statistics
202+
5. **Capacity Planning**: Use connection and bandwidth metrics for capacity planning
203+
204+
## Related Commands
205+
206+
- `redisctl enterprise database` - Manage databases and their endpoints
207+
- `redisctl enterprise stats` - View detailed statistics
208+
- `redisctl enterprise node` - Check node status affecting endpoints
209+
- `redisctl enterprise cluster` - View cluster-wide endpoint configuration

0 commit comments

Comments
 (0)