Skip to content
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

feat: multiple onRequest handlers #1863

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

webbdays
Copy link
Contributor

@webbdays webbdays commented May 5, 2024

Summary:
multiple onRequest handlers

Issue Reference(s):
Fixes #1271

Build & Testing:

  • I ran cargo test successfully.
  • I have run ./lint.sh --mode=fix to fix all linting issues raised by ./lint.sh --mode=check.

Checklist:

  • I have added relevant unit & integration tests.
  • I have updated the documentation accordingly.
  • I have performed a self-review of my code.
  • [yes ] PR follows the naming convention of <type>(<optional scope>): <title>

@github-actions github-actions bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label May 5, 2024
Copy link

codecov bot commented May 5, 2024

Codecov Report

Attention: Patch coverage is 70.81340% with 61 lines in your changes are missing coverage. Please review.

Project coverage is 82.53%. Comparing base (e6d8e38) to head (539c98f).
Report is 1 commits behind head on main.

Files Patch % Lines
src/core/grpc/request.rs 0.00% 27 Missing ⚠️
tailcall-cloudflare/src/http.rs 0.00% 17 Missing ⚠️
tailcall-aws-lambda/src/http.rs 0.00% 12 Missing ⚠️
src/core/http/mod.rs 0.00% 3 Missing ⚠️
src/cli/javascript/request_filter.rs 93.33% 1 Missing ⚠️
src/core/data_loader/data_loader.rs 98.86% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1863      +/-   ##
==========================================
- Coverage   82.70%   82.53%   -0.17%     
==========================================
  Files         177      178       +1     
  Lines       18051    18215     +164     
==========================================
+ Hits        14929    15034     +105     
- Misses       3122     3181      +59     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@webbdays webbdays force-pushed the 1271 branch 2 times, most recently from f7ab336 to f9669b7 Compare May 10, 2024 03:25
Copy link

Action required: PR inactive for 2 days.
Status update or closure in 5 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label May 12, 2024
@tusharmath
Copy link
Contributor

@webbdays Can you please resolve the conflicts.

@tusharmath
Copy link
Contributor

Whenever you are ready, just mark it as ready to review.

@tusharmath tusharmath marked this pull request as draft May 15, 2024 12:15
@github-actions github-actions bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label May 15, 2024
@webbdays
Copy link
Contributor Author

ok.

@github-actions github-actions bot added the ci: benchmark Runs benchmarks label May 16, 2024
@webbdays webbdays marked this pull request as ready for review May 17, 2024 03:13
Copy link

github-actions bot commented May 17, 2024

🐰Bencher

ReportSat, May 18, 2024 at 13:28:55 UTC
Projecttailcall
Branch1863/merge
Testbedbenchmarking-runner

🚨 1 ALERT: Threshold Boundary Limit exceeded!
BenchmarkMeasure (units)ViewValueLower BoundaryUpper Boundary
input/vars.missingLatency (nanoseconds (ns))🚨 (view plot | view alert)11.72 (+36.35%)11.14 (105.23%)

Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns) | (Δ%)
Latency Upper Boundary
nanoseconds (ns) | (%)
group_by✅ (view plot)529.69 (-11.44%)650.03 (81.49%)
input/args.missing✅ (view plot)22.95 (-7.36%)27.36 (83.87%)
input/args.nested.existing✅ (view plot)41.77 (-19.53%)65.97 (63.31%)
input/args.nested.missing✅ (view plot)37.49 (-2.69%)40.61 (92.32%)
input/args.root✅ (view plot)38.54 (-20.48%)62.48 (61.69%)
input/headers.existing✅ (view plot)30.48 (-4.05%)33.48 (91.03%)
input/headers.missing✅ (view plot)29.20 (-5.08%)33.36 (87.52%)
input/value.missing✅ (view plot)23.06 (-2.03%)25.35 (90.98%)
input/value.nested.existing✅ (view plot)41.95 (+1.07%)43.95 (95.44%)
input/value.nested.missing✅ (view plot)37.22 (+2.20%)38.36 (97.04%)
input/value.root✅ (view plot)37.59 (-2.34%)40.38 (93.09%)
input/vars.existing✅ (view plot)7.43 (-8.89%)9.06 (82.07%)
input/vars.missing🚨 (view plot | view alert)11.72 (+36.35%)11.14 (105.23%)
test_batched_body✅ (view plot)2,695.80 (-99.68%)2,642,500.31 (0.10%)
test_batched_body #2✅ (view plot)1,647,800.00 (-5.20%)1,885,525.26 (87.39%)
test_data_loader✅ (view plot)465,820.00 (-1.37%)490,230.95 (95.02%)
test_handle_request✅ (view plot)157,350.00 (-7.51%)183,106.20 (85.93%)
with_mustache_expressions✅ (view plot)1,167.90 (-0.31%)1,235.71 (94.51%)
with_mustache_literal✅ (view plot)729.70 (+0.78%)772.16 (94.50%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

headers,
body: Bytes::default(),
}),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just call execute here? There is quite a bit of code duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@@ -65,6 +65,7 @@ impl Loader<DataLoaderRequest> for HttpDataLoader {
async fn load(
&self,
keys: &[DataLoaderRequest],
http_filter: HttpFilter,
Copy link
Contributor

Choose a reason for hiding this comment

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

Store the filter in HttpDataLoader as a field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please explain more. Where is it used later in the code?

Comment on lines 1 to 6
#[derive(Default, Clone, Debug)]
/// User can configure the filter/interceptor
/// for the http requests.
pub struct HttpFilter {
pub on_request: Option<String>,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can delete this file. Move it to http module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

let req = req_template.to_request(&ctx)?;
let is_get = req.method() == reqwest::Method::GET;

let res = if is_get && ctx.request_ctx.is_batching_enabled() {
let data_loader: Option<&DataLoader<DataLoaderRequest, HttpDataLoader>> =
dl_id.and_then(|index| ctx.request_ctx.http_data_loaders.get(index.0));
execute_request_with_dl(&ctx, req, data_loader).await?
execute_request_with_dl(&ctx, req, data_loader, http_filter.clone()).await?
Copy link
Contributor

Choose a reason for hiding this comment

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

This is hot path. Let's not perform any clones here. Pass the filter as a reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

@@ -27,6 +27,7 @@ pub enum IO {
req_template: http::RequestTemplate,
group_by: Option<GroupBy>,
dl_id: Option<DataLoaderId>,
http_filter: HttpFilter,
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be optional. If not specified, we should not unnecessarily make a round trip to the JS runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we dont have/want ant filter then we pass HttpFilter::default(). WE have a check in request Filter logic to call onRequest or execute directly.

&self,
req: reqwest::Request,
_http_filter: &'life0 HttpFilter,
) -> anyhow::Result<Response<Bytes>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Too much code here, can we reuse execute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

.await?;
tracing::info!("{} {} {}", method, url, res.status.as_u16());
Ok(res)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should just call execute here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

let res = Response::from_reqwest(response).await?;
tracing::info!("{} {}", req_str, res.status.as_u16());
Ok(res)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

just call execute here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

if !http.group_by.is_empty() && http.method == Method::GET {
Expression::IO(IO::Http {
req_template,
group_by: Some(GroupBy::new(http.group_by.clone())),
dl_id: None,
http_filter,
Copy link
Contributor

Choose a reason for hiding this comment

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

Filter should be optional

/// User can configure the filter/interceptor
/// for the http requests.
pub struct HttpFilter {
pub on_request: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think on_request should not be optional. There is no utility a HttpFilter that doesn't have any on_request.

@tusharmath tusharmath removed the ci: benchmark Runs benchmarks label May 18, 2024
Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
@github-actions github-actions bot added the ci: benchmark Runs benchmarks label May 18, 2024
Copy link

Action required: PR inactive for 2 days.
Status update or closure in 5 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label May 21, 2024
@tusharmath tusharmath removed the ci: benchmark Runs benchmarks label May 25, 2024
@github-actions github-actions bot added ci: benchmark Runs benchmarks and removed state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. labels May 25, 2024
Copy link

Action required: PR inactive for 2 days.
Status update or closure in 5 days.

@github-actions github-actions bot added state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. and removed state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci: benchmark Runs benchmarks type: feature Brand new functionality, features, pages, workflows, endpoints, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: ability to configure request handler
2 participants