Skip to content
Closed
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
8 changes: 6 additions & 2 deletions packages/common/logs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ impl Logs {
}

impl Logs {
pub async fn start(self) -> Result<tokio::task::JoinHandle<()>> {
pub async fn start(mut self) -> Result<tokio::task::JoinHandle<()>> {
// Create logs dir if it does not exist
fs::create_dir_all(&self.path).await?;

self.rotate().await?;

Ok(tokio::spawn(self.run()))
}

Expand Down Expand Up @@ -112,10 +114,12 @@ impl Logs {
}

impl Logs {
pub fn start_sync(self) -> Result<std::thread::JoinHandle<()>> {
pub fn start_sync(mut self) -> Result<std::thread::JoinHandle<()>> {
// Create logs dir if it does not exist
std::fs::create_dir_all(&self.path)?;

self.rotate_sync()?;

Ok(std::thread::spawn(|| self.run_sync()))
}

Expand Down
1 change: 0 additions & 1 deletion packages/common/server-cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ impl Opts {
.and_then(|x| x.rivet.edge.as_ref())
.and_then(|x| x.redirect_logs_dir.as_ref())
{
std::fs::create_dir_all(logs_dir)?;
rivet_logs::Logs::new(logs_dir.clone(), LOGS_RETENTION)
.start()
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ pub async fn gen_initialize(
)?);
script.push(components::rivet::guard::fetch_tls(server_token)?);
script.push(components::rivet::guard::configure(config)?);

prometheus_targets.insert(
"guard".into(),
components::vector::PrometheusTarget {
endpoint: "http://127.0.0.1:8091".into(),
scrape_interval: 15,
Comment on lines +236 to +237
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Port 8091 is already used by the worker service (see line 215). Consider using a different port for guard metrics to avoid conflicts.

},
Comment on lines +235 to +238
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Missing /metrics path in endpoint URL which is required for Prometheus scraping

Suggested change
components::vector::PrometheusTarget {
endpoint: "http://127.0.0.1:8091".into(),
scrape_interval: 15,
},
components::vector::PrometheusTarget {
endpoint: "http://127.0.0.1:8091/metrics".into(),
scrape_interval: 15,
},

);
}
}

Expand Down
77 changes: 64 additions & 13 deletions packages/edge/infra/guard/core/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,80 @@
use lazy_static::lazy_static;
use rivet_metrics::prometheus::*;
use rivet_metrics::{prometheus::*, REGISTRY};

lazy_static! {
pub static ref ACTOR_REQUEST_TOTAL: IntCounterVec = register_int_counter_vec!(
"actor_request_total",
// MARK: Internal
pub static ref ROUTE_CACHE_SIZE: IntGauge = register_int_gauge_with_registry!(
"guard_route_cache_size",
"Number of entries in the route cache",
*REGISTRY,
).unwrap();
pub static ref RATE_LIMITER_COUNT: IntGauge = register_int_gauge_with_registry!(
"guard_rate_limiter_count",
"Number of active rate limiters",
*REGISTRY,
).unwrap();
pub static ref IN_FLIGHT_COUNTER_COUNT: IntGauge = register_int_gauge_with_registry!(
"guard_in_flight_counter_count",
"Number of active in-flight counters",
*REGISTRY,
)
.unwrap();

// MARK: TCP
pub static ref TCP_CONNECTION_TOTAL: IntCounter = register_int_counter_with_registry!(
"guard_tcp_connection_total",
"Total number of TCP connections ever",
*REGISTRY,
)
.unwrap();
pub static ref TCP_CONNECTION_PENDING: IntGauge = register_int_gauge_with_registry!(
"guard_tcp_connection_pending",
"Total number of open TCP connections",
*REGISTRY,
)
.unwrap();
pub static ref TCP_CONNECTION_DURATION: Histogram = register_histogram_with_registry!(
"guard_tcp_connection_duration",
"TCP connection duration in seconds",
*REGISTRY,
)
.unwrap();

// MARK: Pre-proxy
pub static ref RESOLVE_ROUTE_DURATION: Histogram = register_histogram_with_registry!(
"guard_resolve_route_duration",
"Time to resolve request route in seconds",
*REGISTRY,
)
.unwrap();

// MARK: Proxy requests
pub static ref PROXY_REQUEST_TOTAL: IntCounterVec = register_int_counter_vec_with_registry!(
"guard_proxy_request_total",
"Total number of requests to actor",
&["actor_id", "server_id", "method", "path"]
&["actor_id", "server_id", "method", "path"],
*REGISTRY,
)
.unwrap();
pub static ref ACTOR_REQUEST_PENDING: IntGaugeVec = register_int_gauge_vec!(
"actor_request_pending",
pub static ref PROXY_REQUEST_PENDING: IntGaugeVec = register_int_gauge_vec_with_registry!(
"guard_proxy_request_pending",
"Number of pending requests to actor",
&["actor_id", "server_id", "method", "path"]
&["actor_id", "server_id", "method", "path"],
*REGISTRY,
)
.unwrap();
pub static ref ACTOR_REQUEST_DURATION: HistogramVec = register_histogram_vec!(
"actor_request_duration_seconds",
pub static ref PROXY_REQUEST_DURATION: HistogramVec = register_histogram_vec_with_registry!(
"guard_proxy_request_duration",
"Request duration in seconds",
&["actor_id", "server_id", "status"]
&["actor_id", "server_id", "status"],
*REGISTRY,
)
.unwrap();
pub static ref ACTOR_REQUEST_ERRORS: IntCounterVec = register_int_counter_vec!(
"actor_request_errors_total",
pub static ref PROXY_REQUEST_ERROR: IntCounterVec = register_int_counter_vec_with_registry!(
"guard_proxy_request_errors_total",
"Total number of errors when proxying requests to actor",
&["actor_id", "server_id", "error_type"]
&["actor_id", "server_id", "error_type"],
*REGISTRY,
)
.unwrap();
}
Loading
Loading