Skip to content

Commit

Permalink
Replace Benchmark with Integration Tests (#41)
Browse files Browse the repository at this point in the history
* remove k6 tests

* Replace Benchmark with Integration Tests

* remove benchmark. resolves #40
* add webmock/vcr based integration tests
* test that api gets correct number fo request
* test that api gets correct data in each request

* fix flaky test

* udate version

* small test update

* update hive version in vcr

* use sized queue

* Update spec/spec_helper.rb

Co-authored-by: Nate Smith <[email protected]>

* review feedback

---------

Co-authored-by: Nate Smith <[email protected]>
  • Loading branch information
cassidycodes and nwjsmith authored Nov 2, 2024
1 parent d28cb02 commit 938e7ce
Show file tree
Hide file tree
Showing 30 changed files with 549 additions and 1,060 deletions.
67 changes: 0 additions & 67 deletions .github/workflows/benchmark.yml

This file was deleted.

1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.5
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ gemspec

group :development do
gem "bundler", "~> 2"
gem "debug", ">= 1.0.0"
gem "rack-test", "~> 2"
gem "rake", "~> 13"
gem "rspec", "~> 3"
gem "sinatra", "~> 2"
gem "standardrb", "~> 1"
gem "vcr", "~> 6"
gem "webmock", "~> 3"
end
49 changes: 48 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
PATH
remote: .
specs:
graphql-hive (0.5.0)
graphql-hive (0.5.1)
graphql (>= 2.3, < 3)

GEM
remote: https://rubygems.org/
specs:
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
crack (1.0.0)
bigdecimal
rexml
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.1)
graphql (2.3.7)
base64
hashdiff (1.1.1)
io-console (0.7.2)
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
mustermann (2.0.2)
ruby2_keywords (~> 0.0.1)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
racc
psych (5.1.2)
stringio
public_suffix (6.0.1)
racc (1.8.1)
rack (2.2.10)
rack-protection (2.2.4)
rack
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
rake (13.2.1)
rdoc (6.7.0)
psych (>= 4.0.0)
regexp_parser (2.9.2)
reline (0.5.10)
io-console (~> 0.5)
rexml (3.3.8)
rspec (3.13.0)
rspec-core (~> 3.13.0)
Expand Down Expand Up @@ -54,6 +82,12 @@ GEM
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sinatra (2.2.4)
mustermann (~> 2.0)
rack (~> 2.2)
rack-protection (= 2.2.4)
tilt (~> 2.0)
standard (1.40.1)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
Expand All @@ -68,18 +102,31 @@ GEM
rubocop-performance (~> 1.21.0)
standardrb (1.0.1)
standard
stringio (3.1.1)
tilt (2.4.0)
unicode-display_width (2.6.0)
vcr (6.3.1)
base64
webmock (3.24.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
arm64-darwin-23
ruby

DEPENDENCIES
bundler (~> 2)
debug (>= 1.0.0)
graphql-hive!
rack-test (~> 2)
rake (~> 13)
rspec (~> 3)
sinatra (~> 2)
standardrb (~> 1)
vcr (~> 6)
webmock (~> 3)

BUNDLED WITH
2.5.15
77 changes: 45 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GraphQL Hive: `graphql-ruby` integration
# GraphQL Hive: `graphql-ruby` integration
[![CI Suite](https://github.com/charlypoly/graphql-ruby-hive/actions/workflows/ci.yml/badge.svg)](https://github.com/charlypoly/graphql-ruby-hive/actions)
[![Gem Version](https://badge.fury.io/rb/graphql-hive.svg)](https://rubygems.org/gems/graphql-hive)

Expand Down Expand Up @@ -146,38 +146,53 @@ class MySchema < GraphQL::Schema
use(
GraphQL::Hive,
{
# mandatory
token: 'YOUR-TOKEN',

# optional
enabled: true, # enable/disable Hive Client
debug: false, # verbose logs
# Token is the only required configuration value.
token: 'YOUR-REGISTRY-TOKEN',
#
# The following are optional configuration values.
#
# Enable/disable Hive Client.
enabled: true,
# Verbose logs.
debug: false,
# A custom logger.
logger: MyLogger.new,
# Endpoint and port of the Hive API. Change this if you are using a self-hosted Hive instance.
endpoint: 'app.graphql-hive.com',
port: 80,
buffer_size: 50, # how many operations can be sent to hive in a single batch (AFTER sampling)

collect_usage: true, # report usage to Hive
# Number of operations sent to Hive in a batch (AFTER sampling).
buffer_size: 50,
# Size of the queue used to send operations to the buffer before sampling.
queue_size: 1000,
# Report usage to Hive.
collect_usage: true,
# Usage sampling configurations.
collect_usage_sampling: {
# optional members of `collect_usage_sampling`
sample_rate: 0.5, # % of operations reported
sampler: proc { |context| context.operation_name.includes?('someQuery') 1 : 0.5 }, # assign custom sampling rates (overrides `sampling rate`)
at_least_once: true, # sample every distinct operation at least once
key_generator: proc { |context| context.operation_name } # assign custom keys to distinguish between distinct operations
# % of operations recorded.
sample_rate: 0.5,
# Custom sampler to assign custom sampling rates.
sampler: proc { |context| context.operation_name.includes?('someQuery') 1 : 0.5 },
# Sample every distinct operation at least once.
at_least_once: true,
# Assign custom keys to distinguish between distinct operations.
key_generator: proc { |context| context.operation_name }
},
report_schema: true, # publish schema to Hive
# mandatory if `report_schema: true`
reporting: {
# mandatory members of `reporting`
# Publish schema to Hive.
report_schema: true,
# Mandatory if `report_schema: true`.
reporting: {
# Mandatory members of `reporting`.
author: 'Author of the latest change',
commit: 'git sha or any identifier',
# optional members of `reporting
# Optional members of `reporting`.
service_name: '',
service_url: '',
},

# pass an optional proc to client_info to help identify the client (ex: Apollo web app) that performed the query
client_info: proc { |context| { name: context.client_name, version: context.client_version } }
# Pass an optional proc to client_info to help identify the client (ex: Apollo web app) that performed the query.
client_info: proc { |context|
{ name: context.client_name, version: context.client_version }
}
}
)

Expand All @@ -186,16 +201,14 @@ class MySchema < GraphQL::Schema
end
```

See default options for the optional parameters [here](https://github.com/charlypoly/graphql-ruby-hive/blob/01407d8fed80912a7006fee503bf2967fa20a79c/lib/graphql-hive.rb#L53).
See default options for the optional parameters [here](https://github.com/rperryng/graphql-ruby-hive/blob/master/lib/graphql-hive.rb#L31-L41).

<br/>

**A note on `buffer_size` and performances**

The `graphql-hive` usage reporter, responsible for sending the operations data to Hive, is running in a separate `Thread` to avoid any significant impact on your GraphQL API performances.

The performance overhead (with the default `buffer_size` option) is around 1% and [is constantly evaluated for new PR](https://github.com/charlypoly/graphql-ruby-hive/actions/workflows/benchmark.yml).

If your GraphQL API has a high RPM, we encourage you to increase the `buffer_size` value.

However, please note that a higher `buffer_size` value will introduce some peak of increase in memory consumption.
> [!Important]
> `buffer_size` and `queue_size` will affect memory consumption.
>
> `buffer_size` is the number of operations sent to Hive in a batch after operations have been sampled.
> `queue_size` is the size of the queue used to send operations to the buffer before sampling.
> Adjust these values according to your application's memory constraints and throughput.
> High throughput applications will need a larger `queue_size`.
8 changes: 0 additions & 8 deletions examples/simple-api/Gemfile

This file was deleted.

48 changes: 0 additions & 48 deletions examples/simple-api/Gemfile.lock

This file was deleted.

31 changes: 0 additions & 31 deletions examples/simple-api/app.rb

This file was deleted.

2 changes: 0 additions & 2 deletions examples/simple-api/config.ru

This file was deleted.

Loading

0 comments on commit 938e7ce

Please sign in to comment.