-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation with middleware collecting basic metrics
- Loading branch information
Showing
19 changed files
with
469 additions
and
59 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Publish release and push gem to RubyGems | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # Fetch current tag as annotated. See https://github.com/actions/checkout/issues/290 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: "3.0" | ||
- name: "Extract data from tag: version, message, body" | ||
id: tag | ||
run: | | ||
git fetch --tags --force # Really fetch annotated tag. See https://github.com/actions/checkout/issues/290#issuecomment-680260080 | ||
echo ::set-output name=version::${GITHUB_REF#refs/tags/v} | ||
echo ::set-output name=subject::$(git for-each-ref $GITHUB_REF --format='%(contents:subject)') | ||
BODY="$(git for-each-ref $GITHUB_REF --format='%(contents:body)')" | ||
# Extract changelog entries between this and previous version headers | ||
escaped_version=$(echo ${GITHUB_REF#refs/tags/v} | sed -e 's/[]\/$*.^[]/\\&/g') | ||
changelog=$(awk "BEGIN{inrelease=0} /## \[${escaped_version}\]/{inrelease=1;next} /## \[[0-9]+\.[0-9]+\.[0-9]+.*?\]/{inrelease=0;exit} {if (inrelease) print}" CHANGELOG.md) | ||
# Multiline body for release. See https://github.community/t/set-output-truncates-multiline-strings/16852/5 | ||
BODY="${BODY}"$'\n'"${changelog}" | ||
BODY="${BODY//'%'/'%25'}" | ||
BODY="${BODY//$'\n'/'%0A'}" | ||
BODY="${BODY//$'\r'/'%0D'}" | ||
echo "::set-output name=body::$BODY" | ||
# Add pre-release option if tag name has any suffix after vMAJOR.MINOR.PATCH | ||
if [[ ${GITHUB_REF#refs/tags/} =~ ^v[0-9]+\.[0-9]+\.[0-9]+.+ ]]; then | ||
echo ::set-output name=prerelease::true | ||
fi | ||
- name: Build gem | ||
run: gem build | ||
- name: Calculate checksums | ||
run: sha256sum yabeda-anycable-${{ steps.tag.outputs.version }}.gem > SHA256SUM | ||
- name: Check version | ||
run: ls -l yabeda-anycable-${{ steps.tag.outputs.version }}.gem | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: ${{ steps.tag.outputs.subject }} | ||
body: ${{ steps.tag.outputs.body }} | ||
draft: false | ||
prerelease: ${{ steps.tag.outputs.prerelease }} | ||
- name: Upload built gem as release asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: yabeda-anycable-${{ steps.tag.outputs.version }}.gem | ||
asset_name: yabeda-anycable-${{ steps.tag.outputs.version }}.gem | ||
asset_content_type: application/x-tar | ||
- name: Upload checksums as release asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: SHA256SUM | ||
asset_name: SHA256SUM | ||
asset_content_type: text/plain | ||
- name: Publish to GitHub packages | ||
env: | ||
GEM_HOST_API_KEY: Bearer ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gem push yabeda-anycable-${{ steps.tag.outputs.version }}.gem --host https://rubygems.pkg.github.com/${{ github.repository_owner }} | ||
- name: Publish to RubyGems | ||
env: | ||
GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}" | ||
run: | | ||
gem push yabeda-anycable-${{ steps.tag.outputs.version }}.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Run tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- '**' | ||
tags-ignore: | ||
- 'v*' | ||
|
||
jobs: | ||
test: | ||
name: "Run tests" | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- ruby: "3.0" | ||
- ruby: "2.7" | ||
- ruby: "2.6" | ||
container: | ||
image: ruby:${{ matrix.ruby }} | ||
env: | ||
CI: true | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: vendor/bundle | ||
key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }} | ||
restore-keys: | | ||
bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }} | ||
bundle-${{ matrix.ruby }}- | ||
- name: Upgrade Bundler to 2.0 (for older Rubies) | ||
run: gem install bundler -v '~> 2.0' | ||
- name: Bundle install | ||
run: | | ||
bundle config path vendor/bundle | ||
bundle install | ||
bundle update | ||
- name: Run Rubocop | ||
run: bundle exec rubocop | ||
- name: Run RSpec | ||
run: bundle exec rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ | |
|
||
# rspec failure tracking | ||
.rspec_status | ||
|
||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
yabeda-anycable (0.1.0) | ||
anycable-core (~> 1.1) | ||
yabeda (~> 0.10) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
anycable-core (1.1.1) | ||
anyway_config (>= 2.1.0) | ||
google-protobuf (>= 3.13) | ||
anyway_config (2.1.0) | ||
ruby-next-core (>= 0.11.0) | ||
ast (2.4.2) | ||
byebug (11.1.3) | ||
coderay (1.1.3) | ||
concurrent-ruby (1.1.9) | ||
diff-lcs (1.4.4) | ||
dry-initializer (3.0.4) | ||
google-protobuf (3.17.3-x86_64-linux) | ||
method_source (1.0.0) | ||
parallel (1.20.1) | ||
parser (3.0.2.0) | ||
ast (~> 2.4.1) | ||
pry (0.14.1) | ||
coderay (~> 1.1) | ||
method_source (~> 1.0) | ||
pry-byebug (3.8.0) | ||
byebug (~> 11.0) | ||
pry (~> 0.10) | ||
pry-doc (1.1.0) | ||
pry (~> 0.11) | ||
yard (~> 0.9.11) | ||
rainbow (3.0.0) | ||
rake (13.0.6) | ||
regexp_parser (2.1.1) | ||
rexml (3.2.5) | ||
rspec (3.10.0) | ||
rspec-core (~> 3.10.0) | ||
rspec-expectations (~> 3.10.0) | ||
rspec-mocks (~> 3.10.0) | ||
rspec-core (3.10.1) | ||
rspec-support (~> 3.10.0) | ||
rspec-expectations (3.10.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.10.0) | ||
rspec-mocks (3.10.2) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.10.0) | ||
rspec-support (3.10.2) | ||
rubocop (1.18.3) | ||
parallel (~> 1.10) | ||
parser (>= 3.0.0.0) | ||
rainbow (>= 2.2.2, < 4.0) | ||
regexp_parser (>= 1.8, < 3.0) | ||
rexml | ||
rubocop-ast (>= 1.7.0, < 2.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (>= 1.4.0, < 3.0) | ||
rubocop-ast (1.8.0) | ||
parser (>= 3.0.1.1) | ||
ruby-next-core (0.12.0) | ||
ruby-progressbar (1.11.0) | ||
unicode-display_width (2.0.0) | ||
yabeda (0.10.0) | ||
anyway_config (>= 1.3, < 3) | ||
concurrent-ruby | ||
dry-initializer | ||
yard (0.9.26) | ||
|
||
PLATFORMS | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
pry | ||
pry-byebug | ||
pry-doc | ||
rake (~> 13.0) | ||
rspec (~> 3.0) | ||
rubocop (~> 1.7) | ||
yabeda-anycable! | ||
|
||
BUNDLED WITH | ||
2.2.24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,91 @@ | ||
# Yabeda::Anycable | ||
# ![Yabeda::AnyCable](./yabeda-anycable-logo.png) | ||
|
||
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yabeda/anycable`. To experiment with that code, run `bin/console` for an interactive prompt. | ||
Built-in metrics for monitoring [AnyCable] RPC server out of the box! Part of the [Yabeda] suite. | ||
|
||
TODO: Delete this and the text above, and describe your gem | ||
See [AnyCable architecture](https://docs.anycable.io/architecture) on details on what AnyCable RPC server is. For monitoring of [AnyCable] websocket server you will need to use [monitoring capabilities](https://docs.anycable.io/anycable-go/instrumentation) built in [anycable-go] itself. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'yabeda-anycable' | ||
|
||
# Then add monitoring system adapter, e.g.: | ||
# gem 'yabeda-prometheus' | ||
|
||
# If you're using Rails, don't forget to add plugin for it: | ||
# gem 'yabeda-rails' | ||
# But if not then you should run `Yabeda.configure!` manually when your app is ready. | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle install | ||
$ bundle | ||
|
||
**And that is it!** AnyCable metrics are being collected! | ||
|
||
Additionally, depending on your adapter, you may want to setup metrics export. E.g. for [yabeda-prometheus]: | ||
|
||
Or install it yourself as: | ||
```ruby | ||
# config/initializers/anycable.rb or elsewhere | ||
AnyCable.configure_server do | ||
Yabeda::Prometheus::Exporter.start_metrics_server! | ||
end | ||
``` | ||
|
||
$ gem install yabeda-anycable | ||
## Metrics | ||
|
||
## Usage | ||
- Counter of total number of RPC calls: `anycable_rpc_call_count` (segmented by `method`, `command`, and `status`) | ||
- Histogram of RPC call duration: `anycable_rpc_call_runtime` (seconds per RPC call execution, segmented by `method`, `command`, and `status`) | ||
|
||
TODO: Write usage instructions here | ||
`status` label may be one of `SUCCESS` (all is good), `FAILURE` (e.g. connection rejected), or `ERROR` (exception raised). | ||
|
||
## Development | ||
|
||
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. | ||
|
||
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). | ||
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). | ||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yabeda-anycable. | ||
Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda-anycable. | ||
|
||
### Releasing | ||
|
||
1. Bump version number in `lib/yabeda/anycable/version.rb` | ||
|
||
In case of pre-releases keep in mind [rubygems/rubygems#3086](https://github.com/rubygems/rubygems/issues/3086) and check version with command like `Gem::Version.new(Yabeda::AnyCable::VERSION).to_s` | ||
|
||
2. Fill `CHANGELOG.md` with missing changes, add header with version and date. | ||
|
||
3. Make a commit: | ||
|
||
```sh | ||
git add lib/yabeda/anycable/version.rb CHANGELOG.md | ||
version=$(ruby -r ./lib/yabeda/anycable/version.rb -e "puts Gem::Version.new(Yabeda::AnyCable::VERSION)") | ||
git commit --message="${version}: " --edit | ||
``` | ||
|
||
4. Create annotated tag: | ||
|
||
```sh | ||
git tag v${version} --annotate --message="${version}: " --edit --sign | ||
``` | ||
|
||
5. Fill version name into subject line and (optionally) some description (list of changes will be taken from changelog and appended automatically) | ||
|
||
6. Push it: | ||
|
||
```sh | ||
git push --follow-tags | ||
``` | ||
|
||
7. GitHub Actions will create a new release, build and push gem into RubyGems! You're done! | ||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). | ||
|
||
[AnyCable]: https://anycable.io/ "Polyglot replacement for ActionCable server" | ||
[anycable-go]: https://github.com/anycable/anycable-go "AnyCable WebSocket server written in Go" | ||
[Yabeda]: https://github.com/yabeda-rb/yabeda "Extendable framework for collecting and exporting metrics from your Ruby application" | ||
[yabeda-prometheus]: https://github.com/yabeda-rb/yabeda-prometheus "Adapter to expose metrics collected by Yabeda plugins to Prometheus via its offical Ruby client" |
Oops, something went wrong.