-
Notifications
You must be signed in to change notification settings - Fork 6
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
Update Integration Tests #34
Changes from all commits
277cda6
6d6257e
5017ceb
ae29b2c
cb40842
17944a5
c6fe94d
0927ffc
e605242
ceb192f
1e93cd6
7645e3a
4273f44
97fb54c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Integration | ||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
run-k6-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Use Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
cache: "yarn" | ||
cache-dependency-path: "k6/yarn.lock" | ||
|
||
- name: Use Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
working-directory: ./k6/graphql-api | ||
bundler-cache: true | ||
|
||
- name: Start Servers | ||
working-directory: ./k6 | ||
run: | | ||
./boot-servers.sh & | ||
yarn wait-on http://localhost:9292 --timeout 5s | ||
yarn wait-on http://localhost:9291 --timeout 5s | ||
yarn wait-on http://localhost:8888 --timeout 5s | ||
|
||
- uses: grafana/setup-k6-action@v1 | ||
- uses: grafana/run-k6-action@v1 | ||
with: | ||
path: | | ||
./k6/integration-test.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,61 @@ | ||
# 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) | ||
|
||
<p align="center"> | ||
<img src="cover.png" width="500" alt="GraphQL Hive" /> | ||
</p> | ||
|
||
[GraphQL Hive](https://graphql-hive.com/) provides all the tools to get | ||
visibility of your GraphQL architecture at all stages, from standalone APIs to | ||
composed schemas (Federation, Stitching): | ||
|
||
|
||
[GraphQL Hive](https://graphql-hive.com/) provides all the tools to get visibility of your GraphQL architecture at all stages, from standalone APIs to composed schemas (Federation, Stitching): | ||
- **Schema Registry** with custom breaking changes detection | ||
- **Monitoring** of RPM, latency, error rate, and more | ||
- **Integrations** with your favorite tools (Slack, Github Actions, and more) | ||
|
||
--- | ||
|
||
<br/> | ||
|
||
---- | ||
|
||
<br/> | ||
|
||
## Getting started | ||
|
||
# Getting started | ||
### Get your Hive token | ||
|
||
Please refer to the GraphQL Hive documentation: <https://docs.graphql-hive.com/features/tokens>. | ||
|
||
## 0. Get your Hive token | ||
### Install the `grahql-hive` gem | ||
|
||
If you are using Hive as a service, please refer to our documentation: https://docs.graphql-hive.com/features/tokens. | ||
|
||
## 1. Install the `graphql-hive` gem | ||
|
||
``` | ||
```sh | ||
gem install graphql-hive | ||
``` | ||
|
||
<br/> | ||
|
||
## 2. Configure `GraphQL::Hive` in your Schema | ||
**2. Configure `GraphQL::Hive` in your Schema** | ||
|
||
Add `GraphQL::Hive` **at the end** of your schema definition: | ||
|
||
```ruby | ||
class Schema < GraphQL::Schema | ||
query QueryType | ||
|
||
use( | ||
GraphQL::Hive, | ||
{ | ||
token: '<YOUR_TOKEN>', | ||
reporting: { | ||
author: ENV['GITHUB_USER'], | ||
commit: ENV['GITHUB_COMMIT'] | ||
}, | ||
} | ||
) | ||
use(GraphQL::Hive, { token: '<YOUR_TOKEN>' }) | ||
end | ||
|
||
``` | ||
|
||
The `reporting` configuration is required to push your GraphQL Schema to the Hive registry. | ||
Doing so will help better detect breaking changes and more upcoming features. | ||
If you only want to use the operations monitoring, replace the `reporting` option with the following `report_schema: false`. | ||
|
||
<br/> | ||
|
||
## 3. (Optional) Configure Lifecycle Hooks | ||
### (Optional) Configure Life-cycle Hooks | ||
|
||
Calling these hooks are situational - it's likely that you may not need to call | ||
them at all! | ||
|
||
### `on_start` | ||
`on_start` | ||
|
||
Call this hook if you are running `GraphQL::Hive` in a process that `fork`s | ||
itself. | ||
|
||
example: `puma` web server running in (["clustered | ||
Example: `puma` web server running in (["clustered | ||
mode"](https://github.com/puma/puma/tree/6d8b728b42a61bcf3c1e4c698c9165a45e6071e8#clustered-mode)) | ||
|
||
```ruby | ||
|
@@ -86,7 +67,7 @@ on_worker_boot do | |
end | ||
``` | ||
|
||
### `on_exit` | ||
`on_exit` | ||
|
||
If your GraphQL API process is shut down non-gracefully but has a shutdown hook | ||
to call into, call `on_worker_exit`. | ||
|
@@ -101,102 +82,96 @@ on_worker_shutdown do | |
end | ||
``` | ||
|
||
<br /> | ||
You are all set! 🚀 | ||
|
||
**You are all set! 🚀** | ||
Then deploying or starting up your GraphQL API, `graphql-hive` will immediately: | ||
|
||
When deploying or starting up your GraphQL API, `graphql-hive` will immediately: | ||
- publish the schema to the Hive registry | ||
- forward the operations metrics to Hive | ||
|
||
|
||
<br/> | ||
|
||
## 4. See how your GraphQL API is operating | ||
### See how your GraphQL API is operating | ||
|
||
You should now see operations information (RPM, error rate, queries performed) on your [GraphQL Hive dashboard](https://app.graphql-hive.com/): | ||
|
||
<p align="center"> | ||
<img src="operations-dashboard.png" width="500" alt="GraphQL Hive" /> | ||
</p> | ||
|
||
### Going further: use the Hive GitHub app | ||
|
||
<br/> | ||
Stay on top of your GraphQL Schema changes by installing the Hive GitHub Application and enabling Slack notifications about breaking changes: | ||
|
||
<https://docs.graphql-hive.com/features/integrations#github> | ||
|
||
## 5. Going further: use the Hive Github app | ||
--- | ||
|
||
Stay on top of your GraphQL Schema changes by installing the Hive Github Application and enabling Slack notifications about breaking changes: | ||
## Configuration | ||
|
||
https://docs.graphql-hive.com/features/integrations#github | ||
| Key | Description | Default | Example | | ||
| ------------------------------------ | ------------------------------------------------ | ----------------------------------------------------- | ------------------------------------------------------------------- | | ||
| token | Mandatory token for authentication | | | | ||
| enabled | Enable/disable Hive Client | `true` | | | ||
| debug | Enable verbose logs | `false` | | | ||
| logger | Custom logger instance | | | | ||
| endpoint | Endpoint URL for Hive | app.graphql-hive.com | | | ||
| port | Port number for Hive | 443 | | | ||
| buffer_size | Number of requests before forwarding to Hive | 50 | | | ||
| collect_usage | [DEPRECATED] Report usage to Hive | `false` | Use `collect_usage_sampling` instead | | ||
| collect_usage_sampling.sample_rate | Percentage of operations to report to Hive | `1` will track 100% of throughput | `0.5` will track 50% of the throughput | | ||
| collect_usage_sampling.sampler | Custom sampling rates logic | | `proc { \|c\| c.operation_name.includes?('someQuery') ? 1 : 0.5 }` | | ||
| collect_usage_sampling.at_least_once | Sample every distinct operation at least once | `nil` Will not sample unique operations at least once | `true` will sample unique operations at least once | | ||
| collect_usage_sampling.key_generator | Custom key generator for distinct operations | Creates an Md5 Hash of the operation by default | `proc { \|c\| c.operation_name }` | | ||
| client_info | Proc to identify the client performing the query | | `proc { \|c\| { name: c.client_name, version: c.client_version } }` | | ||
| report_schema | Publish schema to Hive | true | | | ||
| reporting.author | Author of the latest change | Author of the latest change | | | ||
| reporting.commit | Git SHA or any identifier | git sha or any identifier | | | ||
| reporting.service_name | (Optional) Name of the service | | | | ||
| reporting.service_url | (Optional) URL of the service | | | | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you using something to generate this table? seems like it would be a bit of a chore to update in the future but nbd There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I converted the former Ruby Hash to this table manually. I thought this was easier to read in the rendered markdown. I can revert this, though, if you prefer the Ruby Hash version. |
||
<br/> | ||
> [!IMPORTANT] | ||
> A note on `buffer_size` and performance overhead. A large buffer will increase | ||
> memory consumption of your application. A smaller buffer will result in more | ||
> frequent requests to Hive. Usage reporting is handled in a background thread | ||
> to avoid impacting the performance of your GraphQL API. | ||
|
||
---- | ||
## Contributing | ||
|
||
<br/> | ||
We welcome contributions to this project and are grateful for your interest in | ||
improving it. To ensure a smooth process, please follow these guidelines: | ||
|
||
### Getting Started | ||
|
||
# Configuration | ||
1. **Fork the Repository**: Click the "Fork" button at the top right of this | ||
repository to create a copy of the repository under your GitHub account. | ||
|
||
You will find below the complete list of options of `GraphQL::Hive`: | ||
2. **Clone the Forked Repository**: [Forking a Repository](docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo#forking-a-repository) | ||
|
||
```ruby | ||
class MySchema < GraphQL::Schema | ||
use( | ||
GraphQL::Hive, | ||
{ | ||
# mandatory | ||
token: 'YOUR-TOKEN', | ||
|
||
# optional | ||
enabled: true, # enable/disable Hive Client | ||
debug: false, # verbose logs | ||
logger: MyLogger.new, | ||
endpoint: 'app.graphql-hive.com', | ||
port: 80, | ||
buffer_size: 50, # forward the operations data to Hive every 50 requests | ||
|
||
collect_usage: true, # report usage to Hive | ||
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 | ||
} | ||
|
||
report_schema: true, # publish schema to Hive | ||
# 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 | ||
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 } } | ||
} | ||
) | ||
|
||
# ... | ||
3. **Install Dependencies**: | ||
Ensure you have [Bundler](https://bundler.io/) installed, then run: | ||
|
||
end | ||
```sh | ||
bundle install | ||
``` | ||
|
||
See default options for the optional parameters [here](https://github.com/charlypoly/graphql-ruby-hive/blob/01407d8fed80912a7006fee503bf2967fa20a79c/lib/graphql-hive.rb#L53). | ||
4. **Run Tests**: | ||
Make sure everything is working by running the test suite: | ||
|
||
<br/> | ||
```sh | ||
bundle exec rake test | ||
``` | ||
|
||
**A note on `buffer_size` and performances** | ||
5. **Run Integration Tests**: | ||
|
||
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. | ||
In one terminal, start the servers: | ||
|
||
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). | ||
```sh | ||
cd k6 | ||
./boot-servers.sh | ||
``` | ||
|
||
If your GraphQL API has a high RPM, we encourage you to increase the `buffer_size` value. | ||
In another terminal, run the tests: | ||
|
||
However, please note that a higher `buffer_size` value will introduce some peak of increase in memory consumption. | ||
```sh | ||
cd k6 | ||
k6 run integration-tests.js | ||
``` | ||
cassidycodes marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
22 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
boot-servers.sh
to clean this up and to make local testing simpler.