refactor: update health report to connection test and simplify proto definitions
This commit is contained in:
@@ -62,14 +62,14 @@ async fn main() {
|
|||||||
// send a dummy heartbeat to verify the connection is working
|
// send a dummy heartbeat to verify the connection is working
|
||||||
let client = master_connector.get_client();
|
let client = master_connector.get_client();
|
||||||
|
|
||||||
let request = nxmesh_proto::HealthReport {
|
let request = nxmesh_proto::TestRequest {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
match client.lock().await.report_health(request).await {
|
match client.lock().await.connection_test(request).await {
|
||||||
Ok(_) => info!("Successfully sent health report to master."),
|
Ok(_) => info!("Successfully sent connection test to master."),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to send health report to master: {}", e);
|
error!("Failed to send connection test to master: {}", e);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use nxmesh_proto::{
|
use nxmesh_proto::{AgentMessage, MasterMessage, agent_service_server::AgentService};
|
||||||
Ack, AgentMessage, HealthReport, MasterMessage, MetricsBatch,
|
|
||||||
agent_service_server::AgentService,
|
pub mod repo;
|
||||||
};
|
|
||||||
use tracing::warn;
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct AgentServerService {}
|
pub struct AgentServerService {}
|
||||||
@@ -25,30 +23,13 @@ impl AgentService for AgentServerService {
|
|||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = " ReportHealth sends a health report to the master"]
|
async fn connection_test(
|
||||||
#[allow(
|
|
||||||
mismatched_lifetime_syntaxes,
|
|
||||||
clippy::type_complexity,
|
|
||||||
clippy::type_repetition_in_bounds
|
|
||||||
)]
|
|
||||||
async fn report_health(
|
|
||||||
&self,
|
&self,
|
||||||
request: tonic::Request<HealthReport>,
|
_request: tonic::Request<nxmesh_proto::TestRequest>,
|
||||||
) -> Result<tonic::Response<Ack>, tonic::Status> {
|
) -> Result<tonic::Response<nxmesh_proto::TestResponse>, tonic::Status> {
|
||||||
warn!("Received health report: {:?}", request.get_ref());
|
Ok(tonic::Response::new(nxmesh_proto::TestResponse {
|
||||||
todo!()
|
success: true,
|
||||||
}
|
error_message: String::new(),
|
||||||
|
}))
|
||||||
#[doc = " ReportMetrics sends metrics batch to the master"]
|
|
||||||
#[allow(
|
|
||||||
mismatched_lifetime_syntaxes,
|
|
||||||
clippy::type_complexity,
|
|
||||||
clippy::type_repetition_in_bounds
|
|
||||||
)]
|
|
||||||
async fn report_metrics(
|
|
||||||
&self,
|
|
||||||
request: tonic::Request<MetricsBatch>,
|
|
||||||
) -> Result<tonic::Response<Ack>, tonic::Status> {
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,103 +11,53 @@ service AgentService {
|
|||||||
// Stream establishes a persistent connection for real-time communication
|
// Stream establishes a persistent connection for real-time communication
|
||||||
rpc Stream(stream AgentMessage) returns (stream MasterMessage);
|
rpc Stream(stream AgentMessage) returns (stream MasterMessage);
|
||||||
|
|
||||||
// ReportHealth sends a health report to the master
|
rpc ConnectionTest(TestRequest) returns (TestResponse);
|
||||||
rpc ReportHealth(HealthReport) returns (Ack);
|
}
|
||||||
|
|
||||||
// ReportMetrics sends metrics batch to the master
|
message TestRequest {
|
||||||
rpc ReportMetrics(MetricsBatch) returns (Ack);
|
// no fields needed for test request
|
||||||
|
}
|
||||||
|
|
||||||
|
message TestResponse {
|
||||||
|
bool success = 1;
|
||||||
|
string error_message = 2; // if success is false, this field should contain the error message
|
||||||
|
}
|
||||||
|
|
||||||
|
// Messages sent from master to agent
|
||||||
|
message MasterMessage {
|
||||||
|
int64 timestamp = 1;
|
||||||
|
string message_id = 2;
|
||||||
|
oneof payload {
|
||||||
|
// requests
|
||||||
|
ConfigUpdate config_update = 3;
|
||||||
|
Command command = 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Messages sent from agent to master
|
// Messages sent from agent to master
|
||||||
message AgentMessage {
|
message AgentMessage {
|
||||||
string agent_id = 1;
|
string agent_id = 1;
|
||||||
int64 timestamp = 2;
|
int64 timestamp = 2;
|
||||||
|
string message_id = 3;
|
||||||
oneof payload {
|
oneof payload {
|
||||||
RegistrationRequest registration = 3;
|
// responses
|
||||||
HealthReport health = 4;
|
ConfigUpdateResult config_update_result = 6;
|
||||||
ConfigStatus config_status = 5;
|
CommandResult command_result = 7;
|
||||||
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
|
// ConfigUpdate represents a request from master to agent to update the configuration
|
||||||
message RegistrationRequest {
|
|
||||||
string hostname = 1;
|
|
||||||
string ip_address = 2;
|
|
||||||
string version = 3;
|
|
||||||
repeated string capabilities = 4;
|
|
||||||
map<string, string> labels = 5;
|
|
||||||
DeploymentMode deployment_mode = 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
message ConfigUpdate {
|
||||||
string config_id = 1;
|
string config_id = 1; // unique identifier for this config update
|
||||||
int64 version = 2;
|
string version = 2;
|
||||||
repeated ConfigContent configs = 3;
|
// The root config is the main nginx.conf file, this file will be used as the entry point for nginx configuration. The content of this file should include references to other config files if needed. The agent will write this root config to the nginx config directory and use it to reload nginx.
|
||||||
repeated CertificateContent certificates = 4;
|
ConfigContent root_config = 3;
|
||||||
|
// The other config files that are referenced by the root config, e.g. "site.conf", "private/example.com.conf". If the root config does not reference any other config files, this field can be left empty. The agent will write these config files to the nginx config directory and ensure they are included in the root config.
|
||||||
|
repeated ConfigContent configs = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ConfigContent {
|
message ConfigContent {
|
||||||
@@ -116,113 +66,53 @@ message ConfigContent {
|
|||||||
string content = 2;
|
string content = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CertificateContent {
|
message ConfigUpdateResult {
|
||||||
string id = 1;
|
string config_id = 1; // should match the config_id in ConfigUpdate
|
||||||
// relative path from other config files, e.g. "certs/example.com.pem"
|
bool success = 2;
|
||||||
string path = 2;
|
ConfigUpdateError error_message = 3; // if success is false, this field should contain the error message
|
||||||
string certificate_pem = 3;
|
|
||||||
string private_key_pem = 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message ConfigStatus {
|
enum ConfigUpdateError {
|
||||||
string config_id = 1;
|
UNKNOWN = 0;
|
||||||
int64 version = 2;
|
INVALID_CONFIG = 1; // the config content is invalid, e.g. syntax error
|
||||||
ConfigApplyStatus status = 3;
|
WRITE_FAILED = 2; // failed to write the config file to disk
|
||||||
string error_message = 4;
|
RELOAD_FAILED = 3; // failed to reload nginx with the new config
|
||||||
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
|
// Command represents a request from master to agent to execute a command, e.g. "reload", "test"
|
||||||
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 {
|
message Command {
|
||||||
string command_id = 1;
|
|
||||||
oneof command {
|
oneof command {
|
||||||
ReloadCommand reload = 2;
|
ReloadCommand reload = 1;
|
||||||
RestartCommand restart = 3;
|
TestCommand test = 2;
|
||||||
StopCommand stop = 4;
|
|
||||||
GetStatusCommand get_status = 5;
|
|
||||||
ValidateConfigCommand validate_config = 6;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message ReloadCommand {
|
message ReloadCommand {
|
||||||
bool graceful = 1;
|
// no additional fields needed for reload command
|
||||||
}
|
}
|
||||||
|
|
||||||
message RestartCommand {
|
message TestCommand {
|
||||||
bool force = 1;
|
// no additional fields needed for test command
|
||||||
}
|
}
|
||||||
|
|
||||||
message StopCommand {
|
message CommandResult {
|
||||||
bool graceful = 1;
|
oneof result {
|
||||||
uint32 timeout_seconds = 2;
|
ReloadResult reload_result = 1;
|
||||||
|
TestResult test_result = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetStatusCommand {}
|
message ReloadResult {
|
||||||
|
bool success = 1;
|
||||||
message ValidateConfigCommand {
|
string error_message = 2; // if success is false, this field should contain the error message
|
||||||
string config_content = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events
|
message TestResult {
|
||||||
message Event {
|
bool success = 1;
|
||||||
string event_id = 1;
|
string error_message = 2; // if success is false, this field should contain the error message
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user