Skip to content

Commit

Permalink
chore: Adds optional version to the namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
andyquinterom committed Oct 28, 2024
1 parent 65edeb0 commit c6c20ea
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 143 deletions.
20 changes: 17 additions & 3 deletions postgres.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
CREATE TABLE faucet_http_events (
request_uuid UUID,
namespace TEXT,
version TEXT,
target TEXT,
worker_route TEXT,
worker_id INT,
ip_addr INET,
method TEXT,
path TEXT,
query_params TEXT,
version TEXT,
http_version TEXT,
status SMALLINT,
user_agent TEXT,
elapsed BIGINT,
time TIMESTAMPTZ
);

CREATE INDEX faucet_http_events_request_uuid_idx
ON faucet_http_events USING BTREE (request_uuid);
CREATE TABLE faucet_error_reporting (
request_uuid UUID,
session_uuid UUID, -- Every Shiny Session has their own request uuid.
event_time TIMESTAMPTZ,
error_message TEXT,
context JSONB
);

CREATE INDEX idx_faucet_http_events_request_uuid
ON faucet_http_events (request_uuid);

CREATE INDEX idx_faucet_error_reporting_request_uuid
ON faucet_error_reporting (request_uuid);

CREATE INDEX idx_faucet_error_reporting_session_uuid
ON faucet_error_reporting (session_uuid);
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ pub struct Args {
/// Save HTTP events on PostgreSQL under a specific namespace.
#[arg(long, env = "FAUCET_TELEMETRY_NAMESPACE", default_value = "faucet")]
pub telemetry_namespace: String,

/// Represents the source code version of the service to run. This is useful for telemetry.
#[arg(long, env = "FAUCET_TELEMETRY_VERSION", default_value = None)]
pub telemetry_version: Option<String>,
}

impl StartArgs {
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ pub async fn main() -> FaucetResult<()> {
};

let telemetry = cli_args.pg_con_string.map(|pg_con| {
match TelemetryManager::start(cli_args.telemetry_namespace, pg_con) {
match TelemetryManager::start(
&cli_args.telemetry_namespace,
cli_args.telemetry_version.as_deref(),
&pg_con,
) {
Ok(telemetry) => telemetry,
Err(e) => {
eprintln!("Unable to start telemetry manager: {e}");
Expand Down Expand Up @@ -83,7 +87,7 @@ pub async fn main() -> FaucetResult<()> {
if let Some(telemetry) = telemetry {
log::debug!("Waiting to stop DB writes");
drop(telemetry.sender);
let _ = telemetry.join_handle.await;
let _ = telemetry.http_events_join_handle.await;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/server/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ where

log_data.log();
if let Some(telemetry) = &self.telemetry {
telemetry.send(log_data);
telemetry.send_http_event(log_data);
}

Ok(res)
Expand Down
2 changes: 1 addition & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod logging;
pub use logging::{logger, LogData, LogOption};
mod onion;
pub mod onion;
mod router;
mod service;
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion src/server/onion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::net::IpAddr;

pub trait Service<Request> {
pub trait Service<Request>: Send + Sync {
type Response;
type Error;
async fn call(
Expand Down
Loading

0 comments on commit c6c20ea

Please sign in to comment.