Skip to content

Commit

Permalink
fix oxidecomputer#664: Generalize dtrace support to allow other traci…
Browse files Browse the repository at this point in the history
…ng tools
  • Loading branch information
adamchalmers committed May 5, 2023
1 parent 1b67aea commit 1cc4e3e
Show file tree
Hide file tree
Showing 21 changed files with 335 additions and 179 deletions.
14 changes: 10 additions & 4 deletions dropshot/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! Example use of Dropshot.
use dropshot::endpoint;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand Down Expand Up @@ -43,10 +44,15 @@ async fn main() -> Result<(), String> {
let api_context = ExampleContext::new();

// Set up the server.
let server =
HttpServerStarter::new(&config_dropshot, api, api_context, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
api_context,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();

// Wait for the server to stop. Note that there's not any code to shut down
// this server, so we should never get past this point.
Expand Down
13 changes: 10 additions & 3 deletions dropshot/examples/file_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//! Example using Dropshot to serve files
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigLogging;
use dropshot::ConfigLoggingLevel;
Expand Down Expand Up @@ -44,9 +45,15 @@ async fn main() -> Result<(), String> {
let context = FileServerContext { base: PathBuf::from(".") };

// Set up the server.
let server = HttpServerStarter::new(&config_dropshot, api, context, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
context,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();

// Wait for the server to stop. Note that there's not any code to shut down
// this server, so we should never get past this point.
Expand Down
14 changes: 10 additions & 4 deletions dropshot/examples/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Example use of Dropshot with TLS enabled
use dropshot::endpoint;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand Down Expand Up @@ -87,10 +88,15 @@ async fn main() -> Result<(), String> {
let api_context = ExampleContext::new();

// Set up the server.
let server =
HttpServerStarter::new(&config_dropshot, api, api_context, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
api_context,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();

// Wait for the server to stop. Note that there's not any code to shut down
// this server, so we should never get past this point.
Expand Down
13 changes: 10 additions & 3 deletions dropshot/examples/index.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 Oxide Computer Company
//! Example use of Dropshot for matching wildcard paths to serve static content.
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand Down Expand Up @@ -35,9 +36,15 @@ async fn main() -> Result<(), String> {
api.register(index).unwrap();

// Set up the server.
let server = HttpServerStarter::new(&config_dropshot, api, (), &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
(),
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();

// Wait for the server to stop. Note that there's not any code to shut down
// this server, so we should never get past this point.
Expand Down
14 changes: 10 additions & 4 deletions dropshot/examples/module-basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Oxide Computer Company
//! Example use of Dropshot.
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigLogging;
use dropshot::ConfigLoggingLevel;
Expand Down Expand Up @@ -35,10 +36,15 @@ async fn main() -> Result<(), String> {
let api_context = ExampleContext::new();

// Set up the server.
let server =
HttpServerStarter::new(&config_dropshot, api, api_context, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
api_context,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();

// Wait for the server to stop. Note that there's not any code to shut down
// this server, so we should never get past this point.
Expand Down
2 changes: 2 additions & 0 deletions dropshot/examples/module-shared-context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! a custom context object that outlives endpoint functions.
use dropshot::endpoint;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigLogging;
use dropshot::ConfigLoggingLevel;
Expand Down Expand Up @@ -47,6 +48,7 @@ async fn main() -> Result<(), String> {
api,
api_context.clone(),
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
Expand Down
16 changes: 11 additions & 5 deletions dropshot/examples/multiple-servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
//! process will also note the shutdown of server B.
use dropshot::endpoint;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand Down Expand Up @@ -167,7 +168,7 @@ impl Drop for MultiServerContext {

/// Context shared by all running servers.
struct SharedMultiServerContext {
servers: Mutex<HashMap<String, HttpServer<MultiServerContext>>>,
servers: Mutex<HashMap<String, HttpServer<MultiServerContext, Noop>>>,
started_server_shutdown_handles: mpsc::Sender<ServerShutdownFuture>,
}

Expand Down Expand Up @@ -218,10 +219,15 @@ impl SharedMultiServerContext {
name: name.to_string(),
log: log.clone(),
};
let server =
HttpServerStarter::new(&config_dropshot, api, context, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
context,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let shutdown_handle = server.wait_for_shutdown();

slot.insert(server);
Expand Down
13 changes: 10 additions & 3 deletions dropshot/examples/pagination-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//! next page token from the response as a query parameter, too.
use dropshot::endpoint;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand Down Expand Up @@ -128,8 +129,14 @@ async fn main() -> Result<(), String> {
.map_err(|error| format!("failed to create logger: {}", error))?;
let mut api = ApiDescription::new();
api.register(example_list_projects).unwrap();
let server = HttpServerStarter::new(&config_dropshot, api, ctx, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
ctx,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
server.await
}
13 changes: 10 additions & 3 deletions dropshot/examples/pagination-multiple-resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! about how to run this.
use dropshot::endpoint;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand Down Expand Up @@ -290,9 +291,15 @@ async fn main() -> Result<(), String> {
api.register(example_list_projects).unwrap();
api.register(example_list_disks).unwrap();
api.register(example_list_instances).unwrap();
let server = HttpServerStarter::new(&config_dropshot, api, ctx, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
ctx,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();

server.await
}
Expand Down
13 changes: 10 additions & 3 deletions dropshot/examples/pagination-multiple-sorts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ use chrono::offset::TimeZone;
use chrono::DateTime;
use chrono::Utc;
use dropshot::endpoint;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand Down Expand Up @@ -304,9 +305,15 @@ async fn main() -> Result<(), String> {
.map_err(|error| format!("failed to create logger: {}", error))?;
let mut api = ApiDescription::new();
api.register(example_list_projects).unwrap();
let server = HttpServerStarter::new(&config_dropshot, api, ctx, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
ctx,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();

// Print out some example requests to start with.
print_example_requests(log, &server.local_addr());
Expand Down
14 changes: 10 additions & 4 deletions dropshot/examples/request-headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//! comments on the common code.
use dropshot::endpoint;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand All @@ -32,10 +33,15 @@ async fn main() -> Result<(), String> {
api.register(example_api_get_header_generic).unwrap();

let api_context = ();
let server =
HttpServerStarter::new(&config_dropshot, api, api_context, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
api_context,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
server.await
}

Expand Down
14 changes: 10 additions & 4 deletions dropshot/examples/self-referential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! An example that demonstrates server shutdown (and waiting for shutdown).
use dropshot::endpoint;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand Down Expand Up @@ -33,10 +34,15 @@ async fn main() -> Result<(), String> {
let api_context = Arc::new(ExampleContext::new());

// Set up the server.
let server =
HttpServerStarter::new(&config_dropshot, api, api_context, &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
api_context,
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let shutdown = server.wait_for_shutdown();

tokio::task::spawn(async move {
Expand Down
13 changes: 10 additions & 3 deletions dropshot/examples/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! Example use of Dropshot with a websocket endpoint.
use dropshot::channel;
use dropshot::tracing::Noop;
use dropshot::ApiDescription;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
Expand Down Expand Up @@ -37,9 +38,15 @@ async fn main() -> Result<(), String> {
api.register(example_api_websocket_counter).unwrap();

// Set up the server.
let server = HttpServerStarter::new(&config_dropshot, api, (), &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
(),
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();

// Wait for the server to stop. Note that there's not any code to shut down
// this server, so we should never get past this point.
Expand Down
14 changes: 10 additions & 4 deletions dropshot/examples/well-tagged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! proper tagging innate.
use dropshot::{
endpoint, ApiDescription, ConfigLogging, ConfigLoggingLevel,
endpoint, tracing::Noop, ApiDescription, ConfigLogging, ConfigLoggingLevel,
EndpointTagPolicy, HttpError, HttpResponseOk, HttpServerStarter,
RequestContext, TagConfig, TagDetails, TagExternalDocs,
};
Expand Down Expand Up @@ -99,9 +99,15 @@ async fn main() -> Result<(), String> {
api.register(get_fryism).unwrap();

// Set up the server.
let server = HttpServerStarter::new(&config_dropshot, api, (), &log)
.map_err(|error| format!("failed to create server: {}", error))?
.start();
let server = HttpServerStarter::new(
&config_dropshot,
api,
(),
&log,
Noop::default(),
)
.map_err(|error| format!("failed to create server: {}", error))?
.start();

// Wait for the server to stop. Note that there's not any code to shut down
// this server, so we should never get past this point.
Expand Down
4 changes: 2 additions & 2 deletions dropshot/src/dtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! DTrace probes and support
#[derive(Debug, Clone, serde::Serialize)]
pub(crate) struct RequestInfo {
pub struct RequestInfo {
pub id: String,
pub local_addr: std::net::SocketAddr,
pub remote_addr: std::net::SocketAddr,
Expand All @@ -12,7 +12,7 @@ pub(crate) struct RequestInfo {
}

#[derive(Debug, Clone, serde::Serialize)]
pub(crate) struct ResponseInfo {
pub struct ResponseInfo {
pub id: String,
pub local_addr: std::net::SocketAddr,
pub remote_addr: std::net::SocketAddr,
Expand Down
Loading

0 comments on commit 1cc4e3e

Please sign in to comment.