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

Measure overall query execution times by operation name #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/yabeda/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class Error < StandardError; end
tags: %i[type field deprecated],
buckets: REQUEST_BUCKETS

histogram :operation_resolve_runtime, comment: "A histogram of operation resolving time",
unit: :seconds, per: :operation,
tags: %i[operation deprecated],
buckets: REQUEST_BUCKETS

counter :fields_request_count, comment: "A counter for specific fields requests",
tags: %i[type field deprecated]

Expand Down
4 changes: 4 additions & 0 deletions lib/yabeda/graphql/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def before_query(query)
def after_query(query)
cache(query).each do |_path, options|
Yabeda.graphql.field_resolve_runtime.measure(options[:tags], options[:duration])
Yabeda.graphql.operation_resolve_runtime.measure({
operation: query.operation_name,
deprecated: options[:tags][:deprecated]
}, options[:duration])
Yabeda.graphql.fields_request_count.increment(options[:tags])
end
end
Expand Down
11 changes: 10 additions & 1 deletion spec/yabeda/graphql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
describe "queries" do
let(:query) do
<<~GRAPHQL
query {
query getProductsAndUsers {
products {
id title shmitle price { amount currency }
}
Expand All @@ -40,6 +40,15 @@
)
end

it "measures operation executions" do
Yabeda.graphql.operation_resolve_runtime.sums.clear # This is a hack
subject
expect(Yabeda.graphql.operation_resolve_runtime.sums).to match(
{ operation: "getProductsAndUsers", deprecated: false } => kind_of(Numeric),
{ operation: "getProductsAndUsers", deprecated: true } => kind_of(Numeric),
)
end

it "increment counters" do
Yabeda.graphql.fields_request_count.values.clear # This is a hack
subject
Expand Down