Skip to content

Commit 2f457e2

Browse files
authored
Merge pull request #282 from akshaylg0314/metric
feat(api)-Update Metrics strucutre,Load ContainerInfo from ETCD and Define more REST APIs on SettingsService
2 parents 649bb17 + 2e57e58 commit 2f457e2

File tree

4 files changed

+826
-190
lines changed

4 files changed

+826
-190
lines changed

src/server/settingsservice/README.md

Lines changed: 110 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# PICCOLO Settings Service
22

3-
The Settings Service is a core component of the PICCOLO framework that provides centralized configuration management and metrics filtering capabilities.
3+
The Settings Service is a core component of the PICCOLO framework that provides centralized configuration management and metrics filtering capabilities for vehicle service orchestration.
44

55
## Features
66

77
- **Configuration Management**: Create, read, update, and delete YAML/JSON configurations
88
- **Schema Validation**: Validate configurations against JSON schemas
99
- **Change History**: Track configuration changes with rollback capabilities
10-
- **Metrics Filtering**: Filter and serve monitoring metrics from ETCD
10+
- **Metrics Retrieval**: Retrieve and filter monitoring metrics from ETCD (NodeInfo, ContainerInfo, SocInfo, BoardInfo)
1111
- **Multiple Interfaces**: REST API and CLI interfaces
12-
- **ETCD Integration**: Uses ETCD as the backend storage
12+
- **ETCD Integration**: Direct integration with monitoring ETCD storage for real-time vehicle orchestration data
1313

1414
## Architecture
1515

@@ -18,22 +18,22 @@ The Settings Service consists of the following modules:
1818
- `settings_core`: Service initialization and coordination
1919
- `settings_config`: Configuration management with YAML/JSON support
2020
- `settings_history`: Change history tracking and rollback
21-
- `settings_monitoring`: Metrics data filtering from ETCD
22-
- `settings_storage`: ETCD client for data persistence
23-
- `settings_api`: REST API server
24-
- `settings_cli`: Command-line interface
25-
- `settings_utils`: Common utilities
21+
- `settings_monitoring`: High-level metrics data retrieval and filtering with caching
22+
- `monitoring_etcd`: Direct ETCD operations for monitoring data (`/piccolo/metrics/`, `/piccolo/logs/`)
23+
- `monitoring_types`: Type definitions for vehicle orchestration metrics (NodeInfo, SocInfo, BoardInfo)
24+
- `settings_storage`: ETCD client for configuration data persistence
25+
- `settings_api`: REST API server with comprehensive metrics endpoints
26+
- `settings_cli`: Command-line interface with interactive shell
27+
- `settings_utils`: Common utilities (error handling, logging, YAML processing)
2628

2729
## Building
2830

29-
```bash
3031
# Build the settings service
3132
cd src/server/settingsservice
3233
cargo build
3334

3435
# Or build the entire project
3536
make build
36-
```
3737

3838
## Running
3939

@@ -74,13 +74,25 @@ The Settings Service provides a comprehensive REST API:
7474
- `DELETE /api/v1/settings/{path}` - Delete configuration
7575
- `POST /api/v1/settings/validate` - Validate configuration
7676

77-
### Metrics Management
77+
### Metrics Management (Vehicle Orchestration)
7878

79-
- `GET /api/v1/metrics` - Get filtered metrics
80-
- `GET /api/v1/metrics/{id}` - Get specific metric
81-
- `GET /api/v1/metrics/component/{component}` - Get metrics by component
79+
**Enhanced endpoints with direct ETCD access:**
80+
81+
- `GET /api/v1/metrics` - Get all metrics from ETCD with optional filtering
82+
- `GET /api/v1/metrics/nodes` - Get all node metrics (NodeInfo) - **FIXED**
83+
- `GET /api/v1/metrics/containers` - Get all container metrics (ContainerInfo) - **FIXED**
84+
- `GET /api/v1/metrics/socs` - Get all SoC metrics (SocInfo) - **FIXED**
85+
- `GET /api/v1/metrics/boards` - Get all board metrics (BoardInfo) - **FIXED**
86+
- `GET /api/v1/metrics/nodes/{node_name}` - Get specific node metric - **FIXED**
87+
- `GET /api/v1/metrics/containers/{container_id}` - Get specific container metric - **FIXED**
8288
- `GET /api/v1/metrics/filters` - List metric filters
8389
- `POST /api/v1/metrics/filters` - Create metric filter
90+
- `DELETE /api/v1/metrics/{component}/{id}` - Delete specific metric
91+
92+
**Query parameters for filtering:**
93+
- `?component=node|container|soc|board` - Filter by component type
94+
- `?max_items=N` - Limit number of results
95+
- `?metric_type=NodeInfo|ContainerInfo|SocInfo|BoardInfo` - Filter by metric type
8496

8597
### History Management
8698

@@ -107,13 +119,16 @@ config delete <path> # Delete configuration
107119
config validate <path> # Validate configuration
108120
```
109121

110-
### Metrics Commands
122+
### Metrics Commands (Vehicle Orchestration)
111123

112124
```bash
113-
metrics list # List all metrics
114-
metrics get <id> # Get specific metric
115-
metrics filter <component> # Filter metrics by component
116-
metrics filters # List all filters
125+
metrics nodes # List all node metrics
126+
metrics containers # List all container metrics
127+
metrics socs # List all SoC metrics
128+
metrics boards # List all board metrics
129+
metrics node <name> # Get specific node metric
130+
metrics container <id> # Get specific container metric
131+
metrics stats # Show metrics statistics
117132
```
118133

119134
### History Commands
@@ -132,6 +147,7 @@ The service can be configured using command-line arguments or environment variab
132147
- `--bind-address`: HTTP server bind address (default: `0.0.0.0`)
133148
- `--bind-port`: HTTP server bind port (default: `8080`)
134149
- `--log-level`: Log level (default: `info`)
150+
- `--cli`: Run in CLI mode instead of server mode
135151

136152
## Testing
137153

@@ -148,33 +164,97 @@ cargo test -- --nocapture
148164
### Create a Configuration
149165

150166
```bash
151-
curl -X POST http://localhost:8080/api/v1/settings/myapp/config \
167+
curl -X POST http://localhost:8080/api/v1/settings/vehicle/orchestrator \
152168
-H "Content-Type: application/json" \
153169
-d '{
154170
"content": {
155-
"database": {
156-
"host": "localhost",
157-
"port": 5432
171+
"node_selection": {
172+
"strategy": "resource_based",
173+
"cpu_threshold": 80.0,
174+
"memory_threshold": 90.0
175+
},
176+
"container_policy": {
177+
"restart_policy": "always",
178+
"resource_limits": {
179+
"cpu": "2.0",
180+
"memory": "4Gi"
181+
}
158182
}
159183
},
160-
"schema_type": "database-config",
161-
"author": "admin",
162-
"comment": "Initial database configuration"
184+
"schema_type": "orchestrator-config",
185+
"author": "vehicle-admin",
186+
"comment": "Vehicle service orchestration configuration"
163187
}'
164188
```
165189

166190
### Get Configuration
167191

168192
```bash
169-
curl http://localhost:8080/api/v1/settings/myapp/config
193+
curl http://localhost:8080/api/v1/settings/vehicle/orchestrator
194+
```
195+
196+
### Get All Node Metrics - **WORKING**
197+
198+
```bash
199+
curl http://localhost:8080/api/v1/metrics/nodes
200+
```
201+
202+
### Get Specific Node Metrics
203+
204+
```bash
205+
curl http://localhost:8080/api/v1/metrics/nodes/vehicle-ecu-01
206+
```
207+
208+
### Get All Container Metrics - **WORKING**
209+
210+
```bash
211+
curl http://localhost:8080/api/v1/metrics/containers
170212
```
171213

172-
### Filter Metrics
214+
### Get Container Metrics for Specific Container
173215

174216
```bash
175-
curl "http://localhost:8080/api/v1/metrics?component=nodeagent&metric_type=gauge"
217+
curl http://localhost:8080/api/v1/metrics/containers/db368045fa4d40ffa3ba8cae61eeb9df36e120a2350e36d71e547b7ce3f1a9d5
176218
```
177219

220+
### Filter Metrics with Query Parameters
221+
222+
```bash
223+
# Get only node metrics, limit to 10 items
224+
curl "http://localhost:8080/api/v1/metrics?component=node&max_items=10"
225+
226+
# Get all container metrics
227+
curl "http://localhost:8080/api/v1/metrics?component=container"
228+
229+
# Get all SoC metrics
230+
curl "http://localhost:8080/api/v1/metrics/socs"
231+
232+
# Get all board metrics
233+
curl "http://localhost:8080/api/v1/metrics/boards"
234+
```
235+
236+
### Enable Debug Logging for Troubleshooting
237+
238+
```bash
239+
RUST_LOG=debug ./target/debug/settingsservice
240+
```
241+
242+
## Vehicle Service Orchestration Integration
243+
244+
The Settings Service integrates directly with the Pullpiri vehicle orchestration framework:
245+
246+
- **MonitoringServer**: Stores vehicle node, container, SoC, and board metrics in ETCD at `/piccolo/metrics/`
247+
- **NodeAgent**: Reports node resource utilization and container status to MonitoringServer
248+
- **APIServer**: Consumes configurations for orchestration policies
249+
- **ETCD**: Central storage for both configurations (`/piccolo/settings/`) and real-time metrics (`/piccolo/metrics/`)
250+
251+
## Port Usage
252+
253+
Following Pullpiri networking conventions:
254+
- **Settings Service**: `8080` (configurable within Pullpiri's 47001-47099 range)
255+
- **ETCD**: `2379, 2380` (standard ETCD ports)
256+
- **Other Pullpiri Services**: `47001-47099` (gRPC: 47001+, REST: up to 47099)
257+
178258
## Dependencies
179259

180260
- Rust 1.70+
@@ -183,4 +263,4 @@ curl "http://localhost:8080/api/v1/metrics?component=nodeagent&metric_type=gauge
183263

184264
## License
185265

186-
Apache-2.0
266+
Apache-2.0 (following Pullpiri framework licensing)

src/server/settingsservice/src/monitoring_etcd.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! Integration with monitoring server's etcd storage
55
66
use crate::monitoring_types::{BoardInfo, NodeInfo, SocInfo};
7+
use common::monitoringserver::ContainerInfo;
78
use serde::{de::DeserializeOwned, Serialize};
89
use thiserror::Error;
910
use tracing::{debug, warn};
@@ -149,6 +150,26 @@ pub async fn delete_board_info(board_id: &str) -> Result<()> {
149150
delete_info("boards", board_id).await
150151
}
151152

153+
/// Store ContainerInfo in etcd
154+
pub async fn store_container_info(container_info: &ContainerInfo) -> Result<()> {
155+
store_info("containers", &container_info.id, container_info).await
156+
}
157+
158+
/// Get ContainerInfo from etcd
159+
pub async fn get_container_info(container_id: &str) -> Result<ContainerInfo> {
160+
get_info("containers", container_id).await
161+
}
162+
163+
/// Get all containers from etcd
164+
pub async fn get_all_containers() -> Result<Vec<ContainerInfo>> {
165+
get_all_info("containers").await
166+
}
167+
168+
/// Delete ContainerInfo from etcd
169+
pub async fn delete_container_info(container_id: &str) -> Result<()> {
170+
delete_info("containers", container_id).await
171+
}
172+
152173
/// Get node logs from etcd
153174
pub async fn get_node_logs(node_name: &str) -> Result<Vec<String>> {
154175
get_logs("nodes", node_name).await
@@ -164,6 +185,11 @@ pub async fn get_board_logs(board_id: &str) -> Result<Vec<String>> {
164185
get_logs("boards", board_id).await
165186
}
166187

188+
/// Get container logs from etcd
189+
pub async fn get_container_logs(container_id: &str) -> Result<Vec<String>> {
190+
get_logs("containers", container_id).await
191+
}
192+
167193
/// Generic function to get logs from etcd
168194
async fn get_logs(resource_type: &str, resource_id: &str) -> Result<Vec<String>> {
169195
let prefix = format!("/piccolo/logs/{}/{}", resource_type, resource_id);
@@ -200,6 +226,14 @@ pub async fn store_board_metadata(board_id: &str, metadata: &serde_json::Value)
200226
store_metadata("boards", board_id, metadata).await
201227
}
202228

229+
/// Store container metadata in etcd
230+
pub async fn store_container_metadata(
231+
container_id: &str,
232+
metadata: &serde_json::Value,
233+
) -> Result<()> {
234+
store_metadata("containers", container_id, metadata).await
235+
}
236+
203237
/// Generic function to store metadata in etcd
204238
async fn store_metadata(
205239
resource_type: &str,

0 commit comments

Comments
 (0)