Skip to content

Commit

Permalink
Merge branch 'tailcallhq:main' into grpc_error_handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hazyone authored Apr 11, 2024
2 parents 22bd2ea + a9bfc78 commit 4fc1e61
Show file tree
Hide file tree
Showing 28 changed files with 278 additions and 61 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./aws-lambda
working-directory: ./tailcall-aws-lambda

steps:
- uses: actions/checkout@v4
Expand All @@ -63,7 +63,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./cloudflare
working-directory: ./tailcall-cloudflare

steps:
- uses: actions/checkout@v4
Expand All @@ -75,7 +75,7 @@ jobs:

- name: Build WASM
run: cargo check --lib --target wasm32-unknown-unknown
working-directory: ./cloudflare
working-directory: ./tailcall-cloudflare
- name: Install Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -424,18 +424,18 @@ jobs:
env:
APP_VERSION: ${{ needs.draft_release.outputs.create_release_name }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: cargo lambda build -p aws-lambda --release
run: cargo lambda build -p tailcall-aws-lambda --release

- name: Rename Binary with Target Name
run: |
pwd
cp target/lambda/aws-lambda/bootstrap target/lambda/aws-lambda/tailcall-aws-lambda-bootstrap
cp target/lambda/tailcall-aws-lambda/bootstrap target/lambda/tailcall-aws-lambda/tailcall-aws-lambda-bootstrap
- name: Upload AWS Lambda Bootstrap Binary
uses: xresloader/upload-to-github-release@v1
with:
release_id: ${{ needs.draft_release.outputs.create_release_id }}
file: target/lambda/aws-lambda/tailcall-aws-lambda-bootstrap
file: target/lambda/tailcall-aws-lambda/tailcall-aws-lambda-bootstrap
overwrite: true
semantic_release:
name: Semantic Release
Expand Down
78 changes: 39 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ default = ["cli", "js"]


[workspace]
members = [".", "autogen", "aws-lambda", "cloudflare"]
members = [".", "autogen", "tailcall-aws-lambda", "tailcall-cloudflare"]

# Boost execution_spec snapshot diffing performance
[profile.dev.package]
Expand All @@ -196,7 +196,7 @@ debug = false
incremental = false
overflow-checks = false

[profile.release.package.cloudflare]
[profile.release.package.tailcall-cloudflare]
strip = true
codegen-units = 1
opt-level = 'z'
Expand Down
68 changes: 68 additions & 0 deletions src/config/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,25 @@ pub struct ScriptOptions {
pub timeout: Option<u64>,
}

impl MergeRight for ScriptOptions {
fn merge_right(self, other: Self) -> Self {
ScriptOptions { timeout: self.timeout.merge_right(other.timeout) }
}
}

#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone, Default, schemars::JsonSchema)]
pub enum HttpVersion {
#[default]
HTTP1,
HTTP2,
}

impl MergeRight for HttpVersion {
fn merge_right(self, other: Self) -> Self {
other
}
}

impl Server {
pub fn enable_apollo_tracing(&self) -> bool {
self.apollo_tracing.unwrap_or(false)
Expand Down Expand Up @@ -195,6 +207,7 @@ impl Server {
self.pipeline_flush.unwrap_or(true)
}
}

impl MergeRight for Server {
fn merge_right(mut self, other: Self) -> Self {
self.apollo_tracing = self.apollo_tracing.merge_right(other.apollo_tracing);
Expand Down Expand Up @@ -229,3 +242,58 @@ impl MergeRight for Server {
self
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::config::ScriptOptions;

fn server_with_script_options(so: ScriptOptions) -> Server {
Server { script: Some(so), ..Default::default() }
}

#[test]
fn script_options_merge_both() {
let a = server_with_script_options(ScriptOptions { timeout: Some(100) });
let b = server_with_script_options(ScriptOptions { timeout: Some(200) });
let merged = a.merge_right(b);
let expected = ScriptOptions { timeout: Some(200) };
assert_eq!(merged.script, Some(expected));
}

#[test]
fn script_options_merge_first() {
let a = server_with_script_options(ScriptOptions { timeout: Some(100) });
let b = server_with_script_options(ScriptOptions { timeout: None });
let merged = a.merge_right(b);
let expected = ScriptOptions { timeout: Some(100) };
assert_eq!(merged.script, Some(expected));
}

#[test]
fn script_options_merge_second() {
let a = server_with_script_options(ScriptOptions { timeout: None });
let b = server_with_script_options(ScriptOptions { timeout: Some(100) });
let merged = a.merge_right(b);
let expected = ScriptOptions { timeout: Some(100) };
assert_eq!(merged.script, Some(expected));
}

#[test]
fn script_options_merge_second_default() {
let a = server_with_script_options(ScriptOptions { timeout: Some(100) });
let b = Server::default();
let merged = a.merge_right(b);
let expected = ScriptOptions { timeout: Some(100) };
assert_eq!(merged.script, Some(expected));
}

#[test]
fn script_options_merge_first_default() {
let a = Server::default();
let b = server_with_script_options(ScriptOptions { timeout: Some(100) });
let merged = a.merge_right(b);
let expected = ScriptOptions { timeout: Some(100) };
assert_eq!(merged.script, Some(expected));
}
}
68 changes: 60 additions & 8 deletions src/config/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct Batch {
pub headers: BTreeSet<String>,
pub max_size: usize,
}

impl Default for Batch {
fn default() -> Self {
Batch { max_size: 100, delay: 0, headers: BTreeSet::new() }
Expand All @@ -24,6 +25,12 @@ pub struct Proxy {
pub url: String,
}

impl MergeRight for Proxy {
fn merge_right(self, other: Self) -> Self {
other
}
}

#[derive(
Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Setters, Default, schemars::JsonSchema,
)]
Expand Down Expand Up @@ -170,14 +177,7 @@ impl Upstream {
impl MergeRight for Upstream {
// TODO: add unit tests for merge
fn merge_right(mut self, other: Self) -> Self {
self.allowed_headers = other.allowed_headers.map(|other| {
if let Some(mut self_headers) = self.allowed_headers {
self_headers = self_headers.merge_right(other);
self_headers
} else {
other
}
});
self.allowed_headers = self.allowed_headers.merge_right(other.allowed_headers);
self.base_url = self.base_url.merge_right(other.base_url);
self.connect_timeout = self.connect_timeout.merge_right(other.connect_timeout);
self.http_cache = self.http_cache.merge_right(other.http_cache);
Expand Down Expand Up @@ -212,3 +212,55 @@ impl MergeRight for Upstream {
self
}
}

#[cfg(test)]
mod tests {
use super::*;

fn setup_upstream_with_headers(headers: &[&str]) -> Upstream {
Upstream {
allowed_headers: Some(headers.iter().map(|s| s.to_string()).collect()),
..Default::default()
}
}

#[test]
fn allowed_headers_merge_both() {
let a = setup_upstream_with_headers(&["a", "b", "c"]);
let b = setup_upstream_with_headers(&["d", "e", "f"]);
let merged = a.merge_right(b);
assert_eq!(
merged.allowed_headers,
Some(
["a", "b", "c", "d", "e", "f"]
.iter()
.map(|s| s.to_string())
.collect()
)
);
}

#[test]
fn allowed_headers_merge_first() {
let a = setup_upstream_with_headers(&["a", "b", "c"]);
let b = Upstream::default();
let merged = a.merge_right(b);

assert_eq!(
merged.allowed_headers,
Some(["a", "b", "c"].iter().map(|s| s.to_string()).collect())
);
}

#[test]
fn allowed_headers_merge_second() {
let a = Upstream::default();
let b = setup_upstream_with_headers(&["a", "b", "c"]);
let merged = a.merge_right(b);

assert_eq!(
merged.allowed_headers,
Some(["a", "b", "c"].iter().map(|s| s.to_string()).collect())
);
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod lambda;
pub mod merge_right;
pub mod mustache;
pub mod path;
pub mod primitive;
pub mod print_schema;
mod proto_reader;
mod resource_reader;
Expand Down
12 changes: 8 additions & 4 deletions src/merge_right.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ pub trait MergeRight {
fn merge_right(self, other: Self) -> Self;
}

impl<A> MergeRight for Option<A> {
fn merge_right(mut self, other: Self) -> Self {
self = other.or(self);
self
impl<A: MergeRight> MergeRight for Option<A> {
fn merge_right(self, other: Self) -> Self {
match (self, other) {
(Some(this), Some(that)) => Some(this.merge_right(that)),
(None, Some(that)) => Some(that),
(Some(this), None) => Some(this),
(None, None) => None,
}
}
}

Expand Down
Loading

0 comments on commit 4fc1e61

Please sign in to comment.