Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,167 changes: 1,953 additions & 214 deletions src/server/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"apiserver",
"policymanager",
"monitoringserver",
"settingsservice",
]

[workspace.dependencies]
Expand Down
68 changes: 68 additions & 0 deletions src/server/settingsservice/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[package]
name = "settingsservice"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
description = "PICCOLO Settings Service - Central configuration and metrics management service"

[[bin]]
name = "settingsservice"
path = "src/main.rs"

[[bin]]
name = "settings-cli"
path = "src/bin/settings-cli.rs"

[dependencies]
# Core async runtime
tokio = { version = "1.43.1", features = ["full"] }
futures = "0.3"

# Web framework
axum = "0.7.7"
tower = "0.4"
tower-http = { version = "0.6.1", features = ["cors", "trace"] }

# Serialization
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"

# Validation
jsonschema = "0.18"

# Data storage
etcd-client = "0.14"

# CLI
clap = { version = "4.0", features = ["derive", "env"] }
rustyline = "14.0"

# Logging and errors
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
anyhow = "1.0"
thiserror = "2.0"

# Utilities
uuid = { version = "1.0", features = ["v4", "serde"] }
chrono = { version = "0.4", features = ["serde"] }
toml = "0.8"
url = "2.0"

# HTTP client
reqwest = { version = "0.12", features = ["json"] }

# Async utilities
async-trait = "0.1"

# Configuration
config = "0.14"

# Common shared library
common = { workspace = true }

[dev-dependencies]
tokio-test = "0.4"
tempfile = "3.0"
wiremock = "0.6"
48 changes: 48 additions & 0 deletions src/server/settingsservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-FileCopyrightText: Copyright 2024 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0

FROM rust:latest as builder

# Install system dependencies
RUN apt-get update && apt-get install -y \
protobuf-compiler \
libdbus-1-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy the entire project for build context
COPY . .

# Build the settings service
RUN cd src/server && cargo build --release

# Runtime stage
FROM debian:bookworm-slim

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libdbus-1-3 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Create non-root user
RUN useradd -r -s /bin/false settingsservice

# Copy binary from builder
COPY --from=builder /app/src/server/target/release/settingsservice /usr/local/bin/
COPY --from=builder /app/src/server/target/release/settings-cli /usr/local/bin/

# Create configuration directory
RUN mkdir -p /etc/piccolo && chown settingsservice:settingsservice /etc/piccolo

# Switch to non-root user
USER settingsservice

# Expose the default port
EXPOSE 8080

# Set default command
CMD ["settingsservice", "--bind-address", "0.0.0.0", "--bind-port", "8080"]
186 changes: 186 additions & 0 deletions src/server/settingsservice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# PICCOLO Settings Service

The Settings Service is a core component of the PICCOLO framework that provides centralized configuration management and metrics filtering capabilities.

## Features

- **Configuration Management**: Create, read, update, and delete YAML/JSON configurations
- **Schema Validation**: Validate configurations against JSON schemas
- **Change History**: Track configuration changes with rollback capabilities
- **Metrics Filtering**: Filter and serve monitoring metrics from ETCD
- **Multiple Interfaces**: REST API and CLI interfaces
- **ETCD Integration**: Uses ETCD as the backend storage

## Architecture

The Settings Service consists of the following modules:

- `settings_core`: Service initialization and coordination
- `settings_config`: Configuration management with YAML/JSON support
- `settings_history`: Change history tracking and rollback
- `settings_monitoring`: Metrics data filtering from ETCD
- `settings_storage`: ETCD client for data persistence
- `settings_api`: REST API server
- `settings_cli`: Command-line interface
- `settings_utils`: Common utilities

## Building

```bash
# Build the settings service
cd src/server/settingsservice
cargo build

# Or build the entire project
make build
```

## Running

### Server Mode

```bash
# Run the server with default settings
./target/debug/settingsservice

# Run with custom configuration
./target/debug/settingsservice \
--etcd-endpoints localhost:2379,localhost:2380 \
--bind-address 0.0.0.0 \
--bind-port 8080 \
--log-level info
```

### CLI Mode

```bash
# Run the CLI
./target/debug/settingsservice --cli

# Or use the dedicated CLI binary
./target/debug/settings-cli
```

## REST API

The Settings Service provides a comprehensive REST API:

### Configuration Management

- `GET /api/v1/settings` - List all configurations
- `GET /api/v1/settings/{path}` - Get specific configuration
- `POST /api/v1/settings/{path}` - Create new configuration
- `PUT /api/v1/settings/{path}` - Update configuration
- `DELETE /api/v1/settings/{path}` - Delete configuration
- `POST /api/v1/settings/validate` - Validate configuration

### Metrics Management

- `GET /api/v1/metrics` - Get filtered metrics
- `GET /api/v1/metrics/{id}` - Get specific metric
- `GET /api/v1/metrics/component/{component}` - Get metrics by component
- `GET /api/v1/metrics/filters` - List metric filters
- `POST /api/v1/metrics/filters` - Create metric filter

### History Management

- `GET /api/v1/history/{path}` - Get configuration history
- `GET /api/v1/history/{path}/version/{version}` - Get specific version
- `POST /api/v1/history/{path}/rollback/{version}` - Rollback to version

### System Information

- `GET /api/v1/system/status` - Get system status
- `GET /api/v1/system/health` - Health check

## CLI Commands

The CLI provides an interactive shell with the following commands:

### Configuration Commands

```bash
config list [prefix] # List configurations
config get <path> # Get configuration
config set <path> <value> # Set configuration
config delete <path> # Delete configuration
config validate <path> # Validate configuration
```

### Metrics Commands

```bash
metrics list # List all metrics
metrics get <id> # Get specific metric
metrics filter <component> # Filter metrics by component
metrics filters # List all filters
```

### History Commands

```bash
history <path> # Show configuration history
history rollback <path> <ver> # Rollback to version
```

## Configuration

The service can be configured using command-line arguments or environment variables:

- `--config`: Configuration file path (default: `/etc/piccolo/settings.yaml`)
- `--etcd-endpoints`: ETCD endpoints (default: `localhost:2379`)
- `--bind-address`: HTTP server bind address (default: `0.0.0.0`)
- `--bind-port`: HTTP server bind port (default: `8080`)
- `--log-level`: Log level (default: `info`)

## Testing

```bash
# Run tests
cargo test

# Run with output
cargo test -- --nocapture
```

## Example Usage

### Create a Configuration

```bash
curl -X POST http://localhost:8080/api/v1/settings/myapp/config \
-H "Content-Type: application/json" \
-d '{
"content": {
"database": {
"host": "localhost",
"port": 5432
}
},
"schema_type": "database-config",
"author": "admin",
"comment": "Initial database configuration"
}'
```

### Get Configuration

```bash
curl http://localhost:8080/api/v1/settings/myapp/config
```

### Filter Metrics

```bash
curl "http://localhost:8080/api/v1/metrics?component=nodeagent&metric_type=gauge"
```

## Dependencies

- Rust 1.70+
- ETCD 3.5+
- Protocol Buffers compiler (protoc)

## License

Apache-2.0
55 changes: 55 additions & 0 deletions src/server/settingsservice/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SPDX-FileCopyrightText: Copyright 2024 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0

version: '3.8'

services:
etcd:
image: quay.io/coreos/etcd:v3.5.10
command:
- /usr/local/bin/etcd
- --name=etcd0
- --data-dir=/etcd-data
- --listen-client-urls=http://0.0.0.0:2379
- --advertise-client-urls=http://0.0.0.0:2379
- --listen-peer-urls=http://0.0.0.0:2380
- --initial-advertise-peer-urls=http://0.0.0.0:2380
- --initial-cluster=etcd0=http://0.0.0.0:2380
- --initial-cluster-token=etcd-cluster-1
- --initial-cluster-state=new
ports:
- "2379:2379"
- "2380:2380"
volumes:
- etcd-data:/etcd-data
healthcheck:
test: ["CMD", "etcdctl", "endpoint", "health"]
interval: 10s
timeout: 5s
retries: 5

settingsservice:
build:
context: ../../../ # Build from project root
dockerfile: src/server/settingsservice/Dockerfile
ports:
- "8080:8080"
environment:
- RUST_LOG=settingsservice=info,warn
command:
- settingsservice
- --etcd-endpoints=etcd:2379
- --bind-address=0.0.0.0
- --bind-port=8080
- --log-level=info
depends_on:
etcd:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/api/v1/system/health"]
interval: 30s
timeout: 10s
retries: 3

volumes:
etcd-data:
Loading
Loading