Skip to content

Commit

Permalink
Add query to cache_hit trace event
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryTsepelev committed Apr 10, 2023
1 parent 876a39b commit 71fbfda
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## master

- [PR#64](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/64)
Add query to cache_hit trace event ([@DmitryTsepelev][])

## 1.7.0 (2023-02-02)

- [PR#62](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/62)
Expand Down
2 changes: 1 addition & 1 deletion docs/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MyPersistedQueriesTracer
case key
when "persisted_queries.fetch_query.cache_hit"
# data = { adapter: :redis }
# result = nil
# result = query string that got hit
# increment a counter metric to track cache hits
when "persisted_queries.fetch_query.cache_miss"
# data = { adapter: :redis }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ def fetch_query(hash, options = {})
key = build_key(hash, compiled_query)

fetch(key).tap do |result|
event = result ? "cache_hit" : "cache_miss"
trace("fetch_query.#{event}", adapter: @name)
if result
trace("fetch_query.cache_hit", adapter: @name) { result }
else
trace("fetch_query.cache_miss", adapter: @name)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/persisted_queries/schema_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def perform_request(with_tracer: false, with_query: true)
perform_request(with_tracer: true)
perform_request(with_tracer: true, with_query: false)
events = tracer.events["persisted_queries.fetch_query.cache_hit"]
expect(events).to eq([{ metadata: { adapter: :memory }, result: nil }])
expect(events).to eq([{ metadata: { adapter: :memory }, result: query }])
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def save(hash, query)
expect(tracer.events).to eq(
"persisted_queries.fetch_query.cache_hit" => [{
metadata: { adapter: :testable },
result: nil
result: "welcome-to-paradise"
}]
)
end
Expand Down

0 comments on commit 71fbfda

Please sign in to comment.