299 lines
5.9 KiB
Protocol Buffer
299 lines
5.9 KiB
Protocol Buffer
syntax = "proto3";
|
|
package nxmesh.agent.v1;
|
|
|
|
option go_package = "github.com/nxmesh/api/agent/v1";
|
|
|
|
// AgentService defines the bidirectional communication between master and agents
|
|
service AgentService {
|
|
// Stream establishes a persistent connection for real-time communication
|
|
rpc Stream(stream AgentMessage) returns (stream MasterMessage);
|
|
|
|
// ReportHealth sends a health report to the master
|
|
rpc ReportHealth(HealthReport) returns (Ack);
|
|
|
|
// ReportMetrics sends metrics batch to the master
|
|
rpc ReportMetrics(MetricsBatch) returns (Ack);
|
|
}
|
|
|
|
// Messages sent from agent to master
|
|
message AgentMessage {
|
|
string agent_id = 1;
|
|
int64 timestamp = 2;
|
|
oneof payload {
|
|
RegistrationRequest registration = 3;
|
|
HealthReport health = 4;
|
|
ConfigStatus config_status = 5;
|
|
MetricsBatch metrics = 6;
|
|
LogBatch logs = 7;
|
|
Event event = 8;
|
|
}
|
|
}
|
|
|
|
// Messages sent from master to agent
|
|
message MasterMessage {
|
|
int64 timestamp = 1;
|
|
oneof payload {
|
|
RegistrationResponse registration_response = 2;
|
|
ConfigUpdate config_update = 3;
|
|
Command command = 4;
|
|
Ack ack = 5;
|
|
Error error = 6;
|
|
}
|
|
}
|
|
|
|
// Registration
|
|
message RegistrationRequest {
|
|
string token = 1;
|
|
string hostname = 2;
|
|
string ip_address = 3;
|
|
string version = 4;
|
|
repeated string capabilities = 5;
|
|
map<string, string> labels = 6;
|
|
DeploymentMode deployment_mode = 7;
|
|
}
|
|
|
|
message RegistrationResponse {
|
|
string agent_id = 1;
|
|
bool success = 2;
|
|
string error_message = 3;
|
|
int64 heartbeat_interval_seconds = 4;
|
|
}
|
|
|
|
enum DeploymentMode {
|
|
DEPLOYMENT_MODE_UNSPECIFIED = 0;
|
|
DOCKER_SIDECAR = 1;
|
|
KUBERNETES_SIDECAR = 2;
|
|
STANDALONE = 3;
|
|
}
|
|
|
|
// Health Reporting
|
|
message HealthReport {
|
|
NginxStatus nginx = 1;
|
|
SystemMetrics system = 2;
|
|
string config_checksum = 3;
|
|
int64 config_version = 4;
|
|
repeated Alert alerts = 5;
|
|
}
|
|
|
|
message NginxStatus {
|
|
bool is_running = 1;
|
|
uint32 pid = 2;
|
|
uint64 uptime_seconds = 3;
|
|
uint32 active_connections = 4;
|
|
uint64 total_requests = 5;
|
|
float requests_per_second = 6;
|
|
}
|
|
|
|
message SystemMetrics {
|
|
float cpu_percent = 1;
|
|
uint64 memory_used_bytes = 2;
|
|
uint64 memory_total_bytes = 3;
|
|
uint64 disk_used_bytes = 4;
|
|
uint64 disk_total_bytes = 5;
|
|
float load_average_1m = 6;
|
|
}
|
|
|
|
message Alert {
|
|
string id = 1;
|
|
string severity = 2; // info, warning, error, critical
|
|
string message = 3;
|
|
int64 timestamp = 4;
|
|
}
|
|
|
|
// Configuration
|
|
message ConfigUpdate {
|
|
string config_id = 1;
|
|
int64 version = 2;
|
|
repeated VirtualHost virtual_hosts = 3;
|
|
repeated Upstream upstreams = 4;
|
|
map<string, Certificate> certificates = 5;
|
|
GlobalSettings global_settings = 6;
|
|
}
|
|
|
|
message VirtualHost {
|
|
string id = 1;
|
|
string name = 2;
|
|
string server_name = 3;
|
|
uint32 listen_port = 4;
|
|
bool ssl_enabled = 5;
|
|
string ssl_certificate_id = 6;
|
|
bool http2_enabled = 7;
|
|
bool http3_enabled = 8;
|
|
repeated Location locations = 9;
|
|
map<string, string> custom_directives = 10;
|
|
}
|
|
|
|
message Location {
|
|
string path = 1;
|
|
string proxy_pass = 2;
|
|
string upstream_id = 3;
|
|
string root = 4;
|
|
string index = 5;
|
|
repeated Header custom_headers = 6;
|
|
repeated RewriteRule rewrite_rules = 7;
|
|
map<string, string> custom_directives = 8;
|
|
}
|
|
|
|
message Header {
|
|
string name = 1;
|
|
string value = 2;
|
|
bool always = 3;
|
|
}
|
|
|
|
message RewriteRule {
|
|
string pattern = 1;
|
|
string replacement = 2;
|
|
string flag = 3;
|
|
}
|
|
|
|
message Upstream {
|
|
string id = 1;
|
|
string name = 2;
|
|
LoadBalanceAlgorithm algorithm = 3;
|
|
repeated UpstreamServer servers = 4;
|
|
HealthCheckConfig health_check = 5;
|
|
uint32 keepalive_connections = 6;
|
|
}
|
|
|
|
enum LoadBalanceAlgorithm {
|
|
LOAD_BALANCE_ALGORITHM_UNSPECIFIED = 0;
|
|
ROUND_ROBIN = 1;
|
|
LEAST_CONNECTIONS = 2;
|
|
IP_HASH = 3;
|
|
WEIGHTED_ROUND_ROBIN = 4;
|
|
}
|
|
|
|
message UpstreamServer {
|
|
string address = 1;
|
|
uint32 weight = 2;
|
|
bool backup = 3;
|
|
bool down = 4;
|
|
uint32 max_fails = 5;
|
|
uint32 fail_timeout_seconds = 6;
|
|
}
|
|
|
|
message HealthCheckConfig {
|
|
bool enabled = 1;
|
|
string path = 2;
|
|
uint32 interval_seconds = 3;
|
|
uint32 timeout_seconds = 4;
|
|
uint32 healthy_threshold = 5;
|
|
uint32 unhealthy_threshold = 6;
|
|
}
|
|
|
|
message Certificate {
|
|
string id = 1;
|
|
string domain = 2;
|
|
string certificate_pem = 3;
|
|
string private_key_pem = 4;
|
|
int64 expires_at = 5;
|
|
}
|
|
|
|
message GlobalSettings {
|
|
map<string, string> nginx_directives = 1;
|
|
map<string, string> env_vars = 2;
|
|
}
|
|
|
|
message ConfigStatus {
|
|
string config_id = 1;
|
|
int64 version = 2;
|
|
ConfigApplyStatus status = 3;
|
|
string error_message = 4;
|
|
int64 applied_at = 5;
|
|
}
|
|
|
|
enum ConfigApplyStatus {
|
|
CONFIG_APPLY_STATUS_UNSPECIFIED = 0;
|
|
PENDING = 1;
|
|
VALIDATING = 2;
|
|
APPLYING = 3;
|
|
SUCCESS = 4;
|
|
FAILED = 5;
|
|
ROLLED_BACK = 6;
|
|
}
|
|
|
|
// Metrics
|
|
message MetricsBatch {
|
|
int64 timestamp = 1;
|
|
repeated Metric metrics = 2;
|
|
}
|
|
|
|
message Metric {
|
|
string name = 1;
|
|
double value = 2;
|
|
int64 timestamp = 3;
|
|
map<string, string> labels = 4;
|
|
MetricType type = 5;
|
|
}
|
|
|
|
enum MetricType {
|
|
METRIC_TYPE_UNSPECIFIED = 0;
|
|
GAUGE = 1;
|
|
COUNTER = 2;
|
|
HISTOGRAM = 3;
|
|
}
|
|
|
|
// Logs
|
|
message LogBatch {
|
|
repeated LogEntry entries = 1;
|
|
}
|
|
|
|
message LogEntry {
|
|
int64 timestamp = 1;
|
|
string level = 2;
|
|
string message = 3;
|
|
map<string, string> fields = 4;
|
|
}
|
|
|
|
// Commands
|
|
message Command {
|
|
string command_id = 1;
|
|
oneof command {
|
|
ReloadCommand reload = 2;
|
|
RestartCommand restart = 3;
|
|
StopCommand stop = 4;
|
|
GetStatusCommand get_status = 5;
|
|
ValidateConfigCommand validate_config = 6;
|
|
}
|
|
}
|
|
|
|
message ReloadCommand {
|
|
bool graceful = 1;
|
|
}
|
|
|
|
message RestartCommand {
|
|
bool force = 1;
|
|
}
|
|
|
|
message StopCommand {
|
|
bool graceful = 1;
|
|
uint32 timeout_seconds = 2;
|
|
}
|
|
|
|
message GetStatusCommand {}
|
|
|
|
message ValidateConfigCommand {
|
|
string config_content = 1;
|
|
}
|
|
|
|
// Events
|
|
message Event {
|
|
string event_id = 1;
|
|
string event_type = 2;
|
|
int64 timestamp = 3;
|
|
map<string, string> data = 4;
|
|
}
|
|
|
|
// Common messages
|
|
message Ack {
|
|
string message_id = 1;
|
|
bool success = 2;
|
|
string error_message = 3;
|
|
}
|
|
|
|
message Error {
|
|
string code = 1;
|
|
string message = 2;
|
|
map<string, string> details = 3;
|
|
}
|