Skip to content

Commit 358ccb6

Browse files
authored
Merge pull request #5592 from rmosolgo/exec-next-perfetto
Exec-next: update Perfetto trace
2 parents 881655e + 24365ae commit 358ccb6

File tree

7 files changed

+129596
-10
lines changed

7 files changed

+129596
-10
lines changed

lib/graphql/tracing/perfetto_trace.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def begin_execute_field(field, object, arguments, query)
253253
packet = trace_packet(
254254
type: TrackEvent::Type::TYPE_SLICE_BEGIN,
255255
track_uuid: fid,
256-
name: query.context.current_path.join("."),
256+
name: query.context.current_path&.join(".") || field.path,
257257
category_iids: FIELD_EXECUTE_CATEGORY_IIDS,
258258
extra_counter_track_uuids: @counts_objects,
259259
extra_counter_values: [count_allocations],
@@ -269,7 +269,7 @@ def end_execute_field(field, object, arguments, query, app_result)
269269
if @create_debug_annotations
270270
start_field.track_event = dup_with(start_field.track_event,{
271271
debug_annotations: [
272-
payload_to_debug(nil, object.object, iid: DA_OBJECT_IID, intern_value: true),
272+
payload_to_debug(nil, (object.is_a?(GraphQL::Schema::Object) ? object.object : object), iid: DA_OBJECT_IID, intern_value: true),
273273
payload_to_debug(nil, arguments, iid: DA_ARGUMENTS_IID),
274274
payload_to_debug(nil, app_result, iid: DA_RESULT_IID, intern_value: true)
275275
]

spec/graphql/tracing/detailed_trace_spec.rb

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
describe GraphQL::Tracing::DetailedTrace do
55
class SamplerSchema < GraphQL::Schema
66
class Query < GraphQL::Schema::Object
7-
field :truthy, Boolean, fallback_value: true
7+
field :truthy, Boolean, fallback_value: true, resolve_static: true
8+
def self.truthy(ctx); true; end
89
end
910

1011
query(Query)
@@ -16,30 +17,48 @@ def self.detailed_trace?(query)
1617
query.context[:profile] != false
1718
end
1819
end
20+
21+
use GraphQL::Execution::Next
1922
end
2023

2124
before do
2225
SamplerSchema.detailed_trace.delete_all_traces
2326
end
2427

28+
def exec_query(...)
29+
if TESTING_EXEC_NEXT
30+
SamplerSchema.execute_next(...)
31+
else
32+
SamplerSchema.execute(...)
33+
end
34+
end
35+
36+
def exec_multiplex(...)
37+
if TESTING_EXEC_NEXT
38+
SamplerSchema.multiplex_next(...)
39+
else
40+
SamplerSchema.multiplex(...)
41+
end
42+
end
43+
2544
it "runs when the configured trace mode is set" do
2645
assert_equal 0, SamplerSchema.detailed_trace.traces.size
27-
res = SamplerSchema.execute("{ truthy }", context: { profile: false })
46+
res = exec_query("{ truthy }", context: { profile: false })
2847
assert_equal true, res["data"]["truthy"]
2948
assert_equal 0, SamplerSchema.detailed_trace.traces.size
3049

31-
SamplerSchema.execute("{ truthy }")
50+
exec_query("{ truthy }")
3251
assert_equal 1, SamplerSchema.detailed_trace.traces.size
3352
end
3453

3554
it "calls through to storage for access methods" do
36-
SamplerSchema.execute("{ truthy }")
55+
exec_query("{ truthy }")
3756
id = SamplerSchema.detailed_trace.traces.first.id
3857
assert_kind_of GraphQL::Tracing::DetailedTrace::StoredTrace, SamplerSchema.detailed_trace.find_trace(id)
3958
SamplerSchema.detailed_trace.delete_trace(id)
4059
assert_equal 0, SamplerSchema.detailed_trace.traces.size
4160

42-
SamplerSchema.execute("{ truthy }")
61+
exec_query("{ truthy }")
4362
assert_equal 1, SamplerSchema.detailed_trace.traces.size
4463
SamplerSchema.detailed_trace.delete_all_traces
4564
end
@@ -66,13 +85,13 @@ def self.detailed_trace?(query)
6685
it "calls detailed_profile? on a Multiplex" do
6786
assert_equal 0, SamplerSchema.detailed_trace.traces.size
6887

69-
SamplerSchema.multiplex([
88+
exec_multiplex([
7089
{ query: "{ truthy }", context: { profile: false } },
7190
{ query: "{ truthy }", context: { profile: true } },
7291
])
7392
assert_equal 0, SamplerSchema.detailed_trace.traces.size
7493

75-
SamplerSchema.multiplex([
94+
exec_multiplex([
7695
{ query: "{ truthy }", context: { profile: true } },
7796
{ query: "{ truthy }", context: { profile: true } },
7897
])

spec/graphql/tracing/perfetto_trace_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ def self.detailed_trace?(q)
176176
PerfettoSchema.execute(query_str, variables: { thingId: "Book-#{::Book.first.id}" })
177177

178178
res = PerfettoSchema.execute(query_str, variables: { thingId: "Book-#{::Book.first.id}" })
179+
assert_equal 4, res["data"]["authors"].size
180+
refute res.key?("errors")
181+
179182
if ENV["DUMP_PERFETTO"]
180183
res.context.query.current_trace.write(file: "perfetto.dump")
181184
end
@@ -184,7 +187,7 @@ def self.detailed_trace?(q)
184187
data = JSON.parse(json)
185188

186189

187-
check_snapshot(data, "example-rails-#{Rails::VERSION::MAJOR}-#{Rails::VERSION::MINOR}.json")
190+
check_snapshot(data, "example-rails-#{Rails::VERSION::MAJOR}-#{Rails::VERSION::MINOR}#{TESTING_EXEC_NEXT ? "-next" : ""}.json")
188191
end
189192

190193
it "replaces nil class name with (anonymous)" do

0 commit comments

Comments
 (0)