Skip to content

feat(expr): enhance expr with JQ functionality#3191

Closed
karatakis wants to merge 34 commits intotailcallhq:mainfrom
karatakis:feat/jq-template-hybrid
Closed

feat(expr): enhance expr with JQ functionality#3191
karatakis wants to merge 34 commits intotailcallhq:mainfrom
karatakis:feat/jq-template-hybrid

Conversation

@karatakis
Copy link
Contributor

@karatakis karatakis commented Dec 3, 2024

Summary:

  • Enable jq syntax inside the mustache of @expr directives and select operations.
  • Report template execution (runtime) errors on response
  • Optimized handling of mustache: if it is read-only we use the faster Mustache implementation, otherwise we use Jq

Broken changes:

  • On the select argument of @http, ... directives we cannot prepend the .args selector. So the users have to manually add it if they use Jq features only.

From:

@http(..., select: {id: "{{.id | tostring }}")

Becomes

@http(..., select: {id: "{{.args.id | tostring }}")

Example:

schema
  @server(port: 8000) {
  query: Query
}

type Query {
  users: [User] @http(url: "http://jsonplaceholder.typicode.com/users")
}

type User {
  id: Int!
  posts: [Post] @http(url: "http://jsonplaceholder.typicode.com/users/{{.value.id}}/posts")
}

type Post {
  id: Int!
  title: String!
  body: String!
  bodyParts: BodyParts! @expr(body: "{{ .value.body | split(\" \") | {first: .[0], second: .[1]} }}")
}

type BodyParts {
  first: String!
  second: String!
}

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.
  • 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 Dec 3, 2024
@karatakis karatakis changed the title feat(mustache): enhance mustache with JQ funtionality feat(expr): enhance expr with JQ funtionality Dec 5, 2024
@codecov
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 56.08365% with 462 lines in your changes missing coverage. Please review.

Project coverage is 85.34%. Comparing base (52d515c) to head (1c55d91).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/core/mustache/jq_value.rs 21.51% 332 Missing ⚠️
src/core/mustache/jq_transform.rs 77.51% 105 Missing ⚠️
src/core/path.rs 29.41% 12 Missing ⚠️
src/core/mustache/render_value.rs 91.93% 5 Missing ⚠️
src/core/mustache/eval.rs 57.14% 3 Missing ⚠️
src/core/http/request_template.rs 0.00% 2 Missing ⚠️
src/core/blueprint/dynamic_value.rs 87.50% 1 Missing ⚠️
src/core/ir/error.rs 50.00% 1 Missing ⚠️
src/core/mustache/parse.rs 97.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3191      +/-   ##
==========================================
- Coverage   86.44%   85.34%   -1.10%     
==========================================
  Files         282      285       +3     
  Lines       28756    29734     +978     
==========================================
+ Hits        24858    25377     +519     
- Misses       3898     4357     +459     

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

@karatakis karatakis marked this pull request as ready for review December 5, 2024 13:45
@karatakis karatakis marked this pull request as draft December 5, 2024 16:01
@tusharmath tusharmath changed the title feat(expr): enhance expr with JQ funtionality feat(expr): enhance expr with JQ functionality Dec 9, 2024
@github-actions github-actions bot added the ci: benchmark Runs benchmarks label Dec 10, 2024
@karatakis
Copy link
Contributor Author

karatakis commented Dec 10, 2024

Benchmarks: before/after JQ Template

TC_LOG_LEVEL=error cargo run --release start main.graphql

schema @server(port: 8000, hostname: "0.0.0.0") {
  query: Query
}

type Query {
  args(text: String!): String! @expr(body: "{{.args.text}}")
}
request = function()
    local headers = {}
    headers["Content-Type"] = "application/json"

    local body = [[
    {
        "query": "query { args(text: \"Hello, World!\") }"
    }
    ]]

    return wrk.format("POST", "/graphql", headers, body)
end

Before

$ wrk -t12 -c400 -d30s -s bench.lua http://127.0.0.1:8000/graphql
Running 30s test @ http://127.0.0.1:8000/graphql
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.90ms  648.63us  10.81ms   75.83%
    Req/Sec    35.51k     3.33k   46.54k    67.11%
  12732725 requests in 30.04s, 1.67GB read
Requests/sec: 423842.17
Transfer/sec:     56.99MB

After

$ wrk -t12 -c400 -d30s -s bench.lua http://127.0.0.1:8000/graphql
Running 30s test @ http://127.0.0.1:8000/graphql
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.88ms  633.52us   9.94ms   76.60%
    Req/Sec    36.78k     3.90k   48.32k    67.31%
  13190038 requests in 30.05s, 1.73GB read
Requests/sec: 439007.72
Transfer/sec:     59.03MB

@github-actions
Copy link

github-actions bot commented Dec 10, 2024

🐰 Bencher Report

Branchfeat/jq-template-hybrid
Testbedbenchmarking-runner
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
from_json_bench📈 view plot
🚷 view threshold
6,260,600.00
(+0.95%)
6,873,135.30
(91.09%)
group_by📈 view plot
🚷 view threshold
480.16
(-1.27%)
546.14
(87.92%)
input/args.missing📈 view plot
🚷 view threshold
22.56
(-6.26%)
29.17
(77.34%)
input/args.nested.existing📈 view plot
🚷 view threshold
43.30
(-1.45%)
50.15
(86.34%)
input/args.nested.missing📈 view plot
🚷 view threshold
37.03
(-1.32%)
43.78
(84.59%)
input/args.root📈 view plot
🚷 view threshold
37.45
(-5.47%)
45.23
(82.79%)
input/headers.existing📈 view plot
🚷 view threshold
32.70
(+3.43%)
35.44
(92.27%)
input/headers.missing📈 view plot
🚷 view threshold
31.67
(+2.59%)
35.12
(90.17%)
input/value.missing📈 view plot
🚷 view threshold
22.72
(-1.92%)
26.03
(87.30%)
input/value.nested.existing📈 view plot
🚷 view threshold
40.90
(-4.08%)
47.87
(85.44%)
input/value.nested.missing📈 view plot
🚷 view threshold
33.50
(-7.20%)
41.40
(80.93%)
input/value.root📈 view plot
🚷 view threshold
43.10
(+9.91%)
44.40
(97.06%)
input/vars.existing📈 view plot
🚷 view threshold
8.39
(+3.08%)
9.60
(87.35%)
input/vars.missing📈 view plot
🚷 view threshold
8.70
(-16.30%)
13.51
(64.40%)
synth_nested📈 view plot
🚷 view threshold
103,130.00
(-15.34%)
158,658.45
(65.00%)
synth_nested_borrow📈 view plot
🚷 view threshold
37,900.00
(-44.01%)
111,116.66
(34.11%)
test_batched_body📈 view plot
🚷 view threshold
1,884.30
(-0.32%)
2,087.63
(90.26%)
test_batched_body #2📈 view plot
🚷 view threshold
1,527,800.00
(+0.60%)
1,677,799.63
(91.06%)
test_data_loader📈 view plot
🚷 view threshold
400,190.00
(+0.62%)
430,894.48
(92.87%)
test_handle_request📈 view plot
🚷 view threshold
52,748.00
(-59.11%)
152,164.01
(34.67%)
test_handle_request_jit📈 view plot
🚷 view threshold
53,410.00
(-41.93%)
154,111.34
(34.66%)
test_http_execute_method📈 view plot
🚷 view threshold
15,238.00
(+5.07%)
16,219.53
(93.95%)
with_mustache_expressions📈 view plot
🚷 view threshold
1,014.70
(-7.56%)
1,256.80
(80.74%)
with_mustache_literal📈 view plot
🚷 view threshold
619.50
(-11.51%)
811.35
(76.35%)
🐰 View full continuous benchmarking report in Bencher

@tusharmath tusharmath marked this pull request as draft December 10, 2024 20:27
@karatakis karatakis marked this pull request as ready for review December 12, 2024 15:02
@github-actions
Copy link

Action required: PR inactive for 5 days.
Status update or closure in 10 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 Dec 17, 2024
@github-actions
Copy link

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

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Dec 23, 2024
@github-actions github-actions bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Dec 25, 2024
@github-actions
Copy link

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

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

PR closed after 10 days of inactivity.

@github-actions github-actions bot closed this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: benchmark Runs benchmarks state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants