-
Notifications
You must be signed in to change notification settings - Fork 4
fix: reduce parallelism in default config creation and improved logging #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yuvrajjsingh0
wants to merge
1
commit into
main
Choose a base branch
from
make-default-config-creation-serial
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+192
−58
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,85 @@ | ||
| use actix_web::middleware::Next; | ||
| use actix_web::{ | ||
| body::BoxBody, | ||
| dev::{ServiceRequest, ServiceResponse}, | ||
| Error, | ||
| http::{header::HeaderName, header::HeaderValue}, | ||
| middleware::Next, | ||
| Error, HttpMessage, | ||
| }; | ||
| use tracing::{info_span, Instrument}; | ||
|
|
||
| pub async fn request_id_mw( | ||
| mut req: ServiceRequest, | ||
| next: Next<BoxBody>, | ||
| ) -> Result<ServiceResponse<BoxBody>, Error> { | ||
| let rid = req | ||
| .headers() | ||
| .get("x-request-id") | ||
| .and_then(|v| v.to_str().ok()) | ||
| .map(|s| s.to_string()) | ||
| .unwrap_or_else(|| uuid::Uuid::new_v4().to_string()); | ||
|
|
||
| req.headers_mut().insert( | ||
| actix_web::http::header::HeaderName::from_static("x-request-id"), | ||
| rid.parse().unwrap(), | ||
| ); | ||
|
|
||
| let span = info_span!("http_request", request_id = %rid); | ||
|
|
||
| // instrument the future so all logs during it are attached to the span | ||
| let res = async move { | ||
| let mut res = next.call(req).await?; | ||
| // add request_id to response headers | ||
| use tracing::Span; | ||
| use tracing_actix_web::RootSpanBuilder; | ||
| use uuid::Uuid; | ||
|
|
||
| #[derive(Clone)] | ||
| struct RequestId(pub String); | ||
|
|
||
| pub struct WithRequestId; | ||
|
|
||
| impl RootSpanBuilder for WithRequestId { | ||
| fn on_request_start(req: &ServiceRequest) -> Span { | ||
| let req_id = req | ||
| .headers() | ||
| .get("x-request-id") | ||
| .and_then(|h| h.to_str().ok()) | ||
| .map(str::to_owned) | ||
| .unwrap_or_else(|| Uuid::new_v4().to_string()); | ||
|
|
||
| req.extensions_mut().insert(RequestId(req_id.clone())); | ||
|
|
||
| let dimensions = req | ||
| .headers() | ||
| .get("x-dimension") | ||
| .and_then(|h| h.to_str().ok()) | ||
| .map(str::to_owned) | ||
| .unwrap_or_default(); | ||
|
|
||
| let org = req | ||
| .headers() | ||
| .get("x-organisation") | ||
| .and_then(|h| h.to_str().ok()) | ||
| .map(str::to_owned) | ||
| .or_else(|| req.match_info().get("org").map(str::to_owned)) | ||
| .or_else(|| req.match_info().get("organisation").map(str::to_owned)) | ||
| .unwrap_or_default(); | ||
|
|
||
| let app = req | ||
| .headers() | ||
| .get("x-application") | ||
| .and_then(|h| h.to_str().ok()) | ||
| .map(str::to_owned) | ||
| .or_else(|| req.match_info().get("app").map(str::to_owned)) | ||
| .or_else(|| req.match_info().get("application").map(str::to_owned)) | ||
| .unwrap_or_default(); | ||
|
|
||
| tracing::info_span!( | ||
| "HTTP request", | ||
| request_id = %req_id, | ||
| dimensions = %dimensions, | ||
| method = %req.method(), | ||
| org_id = %org, | ||
| app_id = %app, | ||
| superposition_workspace = tracing::field::Empty, | ||
| route = %req.match_pattern().unwrap_or("<unmatched>".to_string()), | ||
| ) | ||
| } | ||
|
|
||
| fn on_request_end<B: actix_web::body::MessageBody>( | ||
| _: Span, | ||
| _: &Result<ServiceResponse<B>, Error>, | ||
| ) { | ||
| } | ||
| } | ||
|
|
||
| pub async fn req_id_header_mw<B>( | ||
| req: ServiceRequest, | ||
| next: Next<B>, | ||
| ) -> Result<ServiceResponse<B>, Error> { | ||
| let mut res = next.call(req).await?; | ||
|
|
||
| let req_id = res.request().extensions().get::<RequestId>().cloned(); | ||
| if let Some(RequestId(id)) = req_id { | ||
| res.headers_mut().insert( | ||
| actix_web::http::header::HeaderName::from_static("x-request-id"), | ||
| rid.parse().unwrap(), | ||
| HeaderName::from_static("x-request-id"), | ||
| HeaderValue::from_str(&id).unwrap_or(HeaderValue::from_static("invalid-req-id")), | ||
| ); | ||
| Ok::<_, actix_web::Error>(res) | ||
| } | ||
| .instrument(span) | ||
| .await?; | ||
| Ok(res) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this PR have other changes, Or is this needed to sequentialise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has changes for request_id other than sequentialise