Skip to content

Commit b73372b

Browse files
committed
rename the new pub type (requires moving the internal DTrace type with the same name)
1 parent 99c6e33 commit b73372b

File tree

6 files changed

+69
-65
lines changed

6 files changed

+69
-65
lines changed

dropshot/src/dtrace.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2023 Oxide Computer Company
2+
//! DTrace probes and support
3+
4+
// The `usdt` crate may require nightly, enabled if our consumer is enabling
5+
// DTrace probes.
6+
#![cfg_attr(all(feature = "usdt-probes", usdt_need_asm), feature(asm))]
7+
#![cfg_attr(
8+
all(feature = "usdt-probes", target_os = "macos", usdt_need_asm_sym),
9+
feature(asm_sym)
10+
)]
11+
12+
#[derive(Debug, Clone, serde::Serialize)]
13+
pub(crate) struct RequestInfo {
14+
id: String,
15+
local_addr: std::net::SocketAddr,
16+
remote_addr: std::net::SocketAddr,
17+
method: String,
18+
path: String,
19+
query: Option<String>,
20+
}
21+
22+
#[derive(Debug, Clone, serde::Serialize)]
23+
pub(crate) struct ResponseInfo {
24+
id: String,
25+
local_addr: std::net::SocketAddr,
26+
remote_addr: std::net::SocketAddr,
27+
status_code: u16,
28+
message: String,
29+
}
30+
31+
#[cfg(feature = "usdt-probes")]
32+
#[usdt::provider(provider = "dropshot")]
33+
mod probes {
34+
use super::{RequestInfo, ResponseInfo};
35+
fn request__start(_: &RequestInfo) {}
36+
fn request__done(_: &ResponseInfo) {}
37+
}
38+
39+
/// The result of registering a server's DTrace USDT probes.
40+
#[derive(Debug, Clone, PartialEq)]
41+
pub enum ProbeRegistration {
42+
/// The probes are explicitly disabled at compile time.
43+
Disabled,
44+
45+
/// Probes were successfully registered.
46+
Succeeded,
47+
48+
/// Registration failed, with an error message explaining the cause.
49+
Failed(String),
50+
}

dropshot/src/extractor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::fmt::Debug;
3131

3232
mod common;
3333

34-
use crate::RequestHeader;
34+
use crate::RequestInfo;
3535
pub use common::ExclusiveExtractor;
3636
pub use common::ExtractorMetadata;
3737
pub use common::RequestExtractor;
@@ -58,7 +58,7 @@ impl<QueryType: DeserializeOwned + JsonSchema + Send + Sync> Query<QueryType> {
5858
/// Given an HTTP request, pull out the query string and attempt to deserialize
5959
/// it as an instance of `QueryType`.
6060
fn http_request_load_query<QueryType>(
61-
request: &RequestHeader,
61+
request: &RequestInfo,
6262
) -> Result<Query<QueryType>, HttpError>
6363
where
6464
QueryType: DeserializeOwned + JsonSchema + Send + Sync,

dropshot/src/handler.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,22 @@ pub struct RequestContext<Context: ServerContext> {
8585
pub log: Logger,
8686

8787
/// basic request information (method, URI, etc.)
88-
pub request: RequestHeader,
88+
pub request: RequestInfo,
8989
}
9090

9191
// This is deliberately as close to compatible with `hyper::Request` as
9292
// reasonable.
93-
// XXX-dap TODO This could use a better name.
9493
#[derive(Debug)]
95-
pub struct RequestHeader {
94+
pub struct RequestInfo {
9695
method: http::Method,
9796
uri: http::Uri,
9897
version: http::Version,
9998
headers: http::HeaderMap<http::HeaderValue>,
10099
}
101100

102-
impl<B> From<&hyper::Request<B>> for RequestHeader {
101+
impl<B> From<&hyper::Request<B>> for RequestInfo {
103102
fn from(request: &hyper::Request<B>) -> Self {
104-
RequestHeader {
103+
RequestInfo {
105104
method: request.method().clone(),
106105
uri: request.uri().clone(),
107106
version: request.version().clone(),
@@ -110,7 +109,7 @@ impl<B> From<&hyper::Request<B>> for RequestHeader {
110109
}
111110
}
112111

113-
impl RequestHeader {
112+
impl RequestInfo {
114113
pub fn method(&self) -> &http::Method {
115114
&self.method
116115
}

dropshot/src/lib.rs

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@
504504
//! Dropshot optionally exposes two DTrace probes, `request_start` and
505505
//! `request_finish`. These provide detailed information about each request,
506506
//! such as their ID, the local and remote IPs, and the response information.
507-
//! See the [`RequestInfo`] and [`ResponseInfo`] types for a complete listing
508-
//! of what's available.
507+
//! See the dropshot::dtrace::RequestInfo` and `dropshot::dtrae::ResponseInfo`
508+
//! types for a complete listing of what's available.
509509
//!
510510
//! These probes are implemented via the [`usdt`] crate. They may require a
511511
//! nightly toolchain if built on macOS prior to Rust version 1.66. Otherwise a
@@ -543,56 +543,10 @@
543543
// Clippy's style advice is definitely valuable, but not worth the trouble for
544544
// automated enforcement.
545545
#![allow(clippy::style)]
546-
// The `usdt` crate may require nightly, enabled if our consumer is enabling
547-
// DTrace probes.
548-
#![cfg_attr(all(feature = "usdt-probes", usdt_need_asm), feature(asm))]
549-
#![cfg_attr(
550-
all(feature = "usdt-probes", target_os = "macos", usdt_need_asm_sym),
551-
feature(asm_sym)
552-
)]
553-
554-
#[derive(Debug, Clone, serde::Serialize)]
555-
pub(crate) struct RequestInfo {
556-
id: String,
557-
local_addr: std::net::SocketAddr,
558-
remote_addr: std::net::SocketAddr,
559-
method: String,
560-
path: String,
561-
query: Option<String>,
562-
}
563-
564-
#[derive(Debug, Clone, serde::Serialize)]
565-
pub(crate) struct ResponseInfo {
566-
id: String,
567-
local_addr: std::net::SocketAddr,
568-
remote_addr: std::net::SocketAddr,
569-
status_code: u16,
570-
message: String,
571-
}
572-
573-
#[cfg(feature = "usdt-probes")]
574-
#[usdt::provider(provider = "dropshot")]
575-
mod probes {
576-
use crate::{RequestInfo, ResponseInfo};
577-
fn request__start(_: &RequestInfo) {}
578-
fn request__done(_: &ResponseInfo) {}
579-
}
580-
581-
/// The result of registering a server's DTrace USDT probes.
582-
#[derive(Debug, Clone, PartialEq)]
583-
pub enum ProbeRegistration {
584-
/// The probes are explicitly disabled at compile time.
585-
Disabled,
586-
587-
/// Probes were successfully registered.
588-
Succeeded,
589-
590-
/// Registration failed, with an error message explaining the cause.
591-
Failed(String),
592-
}
593546

594547
mod api_description;
595548
mod config;
549+
mod dtrace;
596550
mod error;
597551
mod extractor;
598552
mod from_map;
@@ -626,6 +580,7 @@ pub use api_description::TagDetails;
626580
pub use api_description::TagExternalDocs;
627581
pub use config::ConfigDropshot;
628582
pub use config::ConfigTls;
583+
pub use dtrace::ProbeRegistration;
629584
pub use error::HttpError;
630585
pub use error::HttpErrorResponseBody;
631586
pub use extractor::ExclusiveExtractor;
@@ -653,7 +608,7 @@ pub use handler::HttpResponseTemporaryRedirect;
653608
pub use handler::HttpResponseUpdatedNoContent;
654609
pub use handler::NoHeaders;
655610
pub use handler::RequestContext;
656-
pub use handler::RequestHeader;
611+
pub use handler::RequestInfo;
657612
pub use http_util::CONTENT_TYPE_JSON;
658613
pub use http_util::CONTENT_TYPE_NDJSON;
659614
pub use http_util::CONTENT_TYPE_OCTET_STREAM;

dropshot/src/server.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Oxide Computer Company
1+
// Copyright 2023 Oxide Computer Company
22
//! Generic server-wide state and facilities
33
44
use super::api_description::ApiDescription;
@@ -38,7 +38,7 @@ use tokio::net::{TcpListener, TcpStream};
3838
use tokio_rustls::{server::TlsStream, TlsAcceptor};
3939
use uuid::Uuid;
4040

41-
use crate::RequestHeader;
41+
use crate::RequestInfo;
4242
use slog::Logger;
4343

4444
// TODO Replace this with something else?
@@ -679,7 +679,7 @@ async fn http_request_handle_wrap<C: ServerContext>(
679679
#[cfg(feature = "usdt-probes")]
680680
probes::request__start!(|| {
681681
let uri = request.uri();
682-
crate::RequestInfo {
682+
crate::dtrace::RequestInfo {
683683
id: request_id.clone(),
684684
local_addr: server.local_addr,
685685
remote_addr,
@@ -710,7 +710,7 @@ async fn http_request_handle_wrap<C: ServerContext>(
710710

711711
#[cfg(feature = "usdt-probes")]
712712
probes::request__done!(|| {
713-
crate::ResponseInfo {
713+
crate::dtrace::ResponseInfo {
714714
id: request_id.clone(),
715715
local_addr,
716716
remote_addr,
@@ -771,7 +771,7 @@ async fn http_request_handle<C: ServerContext>(
771771
server.router.lookup_route(&method, uri.path().into())?;
772772
let rqctx = RequestContext {
773773
server: Arc::clone(&server),
774-
request: RequestHeader::from(&request),
774+
request: RequestInfo::from(&request),
775775
path_variables: lookup_result.variables,
776776
body_content_type: lookup_result.body_content_type,
777777
request_id: request_id.to_string(),

dropshot/src/websocket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ mod tests {
297297
use crate::router::HttpRouter;
298298
use crate::server::{DropshotState, ServerConfig};
299299
use crate::{
300-
ExclusiveExtractor, HttpError, RequestContext, RequestHeader,
300+
ExclusiveExtractor, HttpError, RequestContext, RequestInfo,
301301
WebsocketUpgrade,
302302
};
303303
use http::Request;
@@ -332,7 +332,7 @@ mod tests {
332332
),
333333
tls_acceptor: None,
334334
}),
335-
request: RequestHeader::from(&request),
335+
request: RequestInfo::from(&request),
336336
path_variables: Default::default(),
337337
body_content_type: Default::default(),
338338
request_id: "".to_string(),

0 commit comments

Comments
 (0)