yabeda-gruf 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 825cbd87d9e02b2eb8197d8e50411689d52bcb74817642bc354359759b80a34b
4
+ data.tar.gz: 30f0c2b0080898575b86c4d8087371c911765055654c25e3f91769570f8abb12
5
+ SHA512:
6
+ metadata.gz: 373830ae75d21f3803ebd457e3394b15f323b737e739f8ffb6b88ec540e1371094d336e60621711f95ae800bcd23e72329ed72ea2900f7786e62cfdc2628779e
7
+ data.tar.gz: 7e64ebb48767fc6ed40d8d1e0fa6873cb5d3378a95080d201cdfb1dcf6dce906dbbd514b44ce636ab8b15605261c5c2d13717bb0f2c8354055ffc5be0531d9bf
data/.gitignore ADDED
@@ -0,0 +1,59 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby
3
+ # Edit at https://www.gitignore.io/?templates=ruby
4
+
5
+ ### Ruby ###
6
+ *.gem
7
+ *.rbc
8
+ /.config
9
+ /coverage/
10
+ /InstalledFiles
11
+ /pkg/
12
+ /spec/reports/
13
+ /spec/examples.txt
14
+ /test/tmp/
15
+ /test/version_tmp/
16
+ /tmp/
17
+
18
+ # Used by dotenv library to load environment variables.
19
+ # .env
20
+
21
+ ## Specific to RubyMotion:
22
+ .dat*
23
+ .repl_history
24
+ build/
25
+ *.bridgesupport
26
+ build-iPhoneOS/
27
+ build-iPhoneSimulator/
28
+
29
+ ## Specific to RubyMotion (use of CocoaPods):
30
+ #
31
+ # We recommend against adding the Pods directory to your .gitignore. However
32
+ # you should judge for yourself, the pros and cons are mentioned at:
33
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
34
+ #
35
+ # vendor/Pods/
36
+
37
+ ## Documentation cache and generated files:
38
+ /.yardoc/
39
+ /_yardoc/
40
+ /doc/
41
+ /rdoc/
42
+
43
+ ## Environment normalization:
44
+ /.bundle/
45
+ /vendor/bundle
46
+ /lib/bundler/man/
47
+
48
+ # for a library or gem, you might want to ignore these files since the code is
49
+ # intended to run in multiple environments; otherwise, check them in:
50
+ # Gemfile.lock
51
+ # .ruby-version
52
+ # .ruby-gemset
53
+
54
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
55
+ .rvmrc
56
+
57
+ # End of https://www.gitignore.io/api/ruby
58
+
59
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ ---
2
+ require:
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.3
7
+
8
+ Metrics/BlockLength:
9
+ Exclude:
10
+ - "Gemfile"
11
+ - "spec/**/*"
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Metrics/LineLength:
17
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in yabeda-gruf.gemspec
8
+ gemspec
9
+
10
+ group :development, :test do
11
+ gem 'pry'
12
+ gem 'pry-byebug', platform: :mri
13
+
14
+ gem 'rubocop'
15
+ gem 'rubocop-rspec'
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,99 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yabeda-gruf (1.0.0)
5
+ gruf
6
+ yabeda
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ ast (2.4.0)
17
+ byebug (10.0.2)
18
+ coderay (1.1.2)
19
+ concurrent-ruby (1.1.3)
20
+ diff-lcs (1.3)
21
+ dry-initializer (2.5.0)
22
+ google-protobuf (3.6.1)
23
+ googleapis-common-protos-types (1.0.2)
24
+ google-protobuf (~> 3.0)
25
+ grpc (1.17.0)
26
+ google-protobuf (~> 3.1)
27
+ googleapis-common-protos-types (~> 1.0.0)
28
+ grpc-tools (1.17.0)
29
+ gruf (2.5.1)
30
+ activesupport
31
+ concurrent-ruby
32
+ grpc (~> 1.10)
33
+ grpc-tools (~> 1.10)
34
+ slop (~> 4.6)
35
+ i18n (1.2.0)
36
+ concurrent-ruby (~> 1.0)
37
+ jaro_winkler (1.5.1)
38
+ method_source (0.9.0)
39
+ minitest (5.11.3)
40
+ parallel (1.12.1)
41
+ parser (2.5.1.2)
42
+ ast (~> 2.4.0)
43
+ powerpack (0.1.2)
44
+ pry (0.11.3)
45
+ coderay (~> 1.1.0)
46
+ method_source (~> 0.9.0)
47
+ pry-byebug (3.6.0)
48
+ byebug (~> 10.0)
49
+ pry (~> 0.10)
50
+ rainbow (3.0.0)
51
+ rake (10.5.0)
52
+ rspec (3.8.0)
53
+ rspec-core (~> 3.8.0)
54
+ rspec-expectations (~> 3.8.0)
55
+ rspec-mocks (~> 3.8.0)
56
+ rspec-core (3.8.0)
57
+ rspec-support (~> 3.8.0)
58
+ rspec-expectations (3.8.2)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.8.0)
61
+ rspec-mocks (3.8.0)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.8.0)
64
+ rspec-support (3.8.0)
65
+ rubocop (0.57.1)
66
+ jaro_winkler (~> 1.5.1)
67
+ parallel (~> 1.10)
68
+ parser (>= 2.5)
69
+ powerpack (~> 0.1)
70
+ rainbow (>= 2.2.2, < 4.0)
71
+ ruby-progressbar (~> 1.7)
72
+ unicode-display_width (~> 1.0, >= 1.0.1)
73
+ rubocop-rspec (1.24.0)
74
+ rubocop (>= 0.53.0)
75
+ ruby-progressbar (1.9.0)
76
+ slop (4.6.2)
77
+ thread_safe (0.3.6)
78
+ tzinfo (1.2.5)
79
+ thread_safe (~> 0.1)
80
+ unicode-display_width (1.4.0)
81
+ yabeda (0.1.2)
82
+ concurrent-ruby
83
+ dry-initializer
84
+
85
+ PLATFORMS
86
+ ruby
87
+
88
+ DEPENDENCIES
89
+ bundler (~> 1.16)
90
+ pry
91
+ pry-byebug
92
+ rake (~> 10.0)
93
+ rspec (~> 3.0)
94
+ rubocop
95
+ rubocop-rspec
96
+ yabeda-gruf!
97
+
98
+ BUNDLED WITH
99
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Boostcom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Yabeda::Gruf
2
+
3
+ Metrics for gruf.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'yabeda-gruf'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Add `Yabeda::Gruf::ServerInterceptor` in gruf configuration.
20
+ Preferably at the beginning of interceptor chain.
21
+
22
+ ```ruby
23
+ Gruf.configure do |c|
24
+ c.interceptors.use(Yabeda::Gruf::ServerInterceptor)
25
+ end
26
+ ```
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ 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).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Boostcom/yabeda-gruf.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'yabeda/gruf'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module Gruf
5
+ class ServerInterceptor < ::Gruf::Interceptors::ServerInterceptor
6
+ def call # rubocop:disable Metrics/MethodLength
7
+ response = nil
8
+ error = nil
9
+
10
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
11
+
12
+ begin
13
+ response = yield
14
+ rescue StandardError => e
15
+ error = e
16
+ end
17
+
18
+ stop_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
19
+
20
+ l = labels(response, error)
21
+
22
+ Yabeda.gruf_served_requests_total.increment(l)
23
+ Yabeda.gruf_served_request_duration.measure(l, stop_time - start_time)
24
+
25
+ raise error if error
26
+ response
27
+ end
28
+
29
+ private
30
+
31
+ def labels(_response, error)
32
+ {
33
+ grpcService: request.service_key,
34
+ grpcMethod: request.method_key,
35
+ grpcStatus: error ? error.class.name : 'GRPC::Ok',
36
+ status: status_code(error)
37
+ }
38
+ end
39
+
40
+ def status_code(error)
41
+ return '0' unless error
42
+ return 'error' unless error.respond_to?(:code)
43
+
44
+ error.code.to_s
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module Gruf
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yabeda/gruf/version'
4
+ require 'yabeda'
5
+ require 'gruf'
6
+
7
+ require 'yabeda/gruf/server_interceptor'
8
+
9
+ module Yabeda
10
+ module Gruf
11
+ LONG_RUNNING_REQUEST_BUCKETS = [
12
+ 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard
13
+ 30, 60, 120, 300, 600, # Sometimes requests may be really long-running
14
+ ].freeze
15
+
16
+ class << self
17
+ def install!
18
+ configure_yabeda!
19
+ end
20
+
21
+ private
22
+
23
+ def configure_yabeda!
24
+ Yabeda.configure do
25
+ group :gruf
26
+
27
+ # server
28
+ counter :served_requests_total, comment: 'A counter of the total number of gRPC requests processed.'
29
+ histogram :served_request_duration, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
30
+ comment: 'A histogram of the response latency.'
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ Yabeda::Gruf.install!
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'yabeda/gruf/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'yabeda-gruf'
9
+ spec.version = Yabeda::Gruf::VERSION
10
+ spec.authors = ['kruczjak']
11
+ spec.email = ['jakub.kruczek@boostcom.no']
12
+
13
+ spec.summary = 'Yabeda exporter for gruf'
14
+ spec.description = 'Yabeda exporter for gruf gRPC server'
15
+ spec.homepage = 'https://boostcom.no'
16
+ spec.license = 'MIT'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'gruf'
28
+ spec.add_dependency 'yabeda'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.16'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yabeda-gruf
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - kruczjak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gruf
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yabeda
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Yabeda exporter for gruf gRPC server
84
+ email:
85
+ - jakub.kruczek@boostcom.no
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/yabeda/gruf.rb
102
+ - lib/yabeda/gruf/server_interceptor.rb
103
+ - lib/yabeda/gruf/version.rb
104
+ - yabeda-gruf.gemspec
105
+ homepage: https://boostcom.no
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Yabeda exporter for gruf
129
+ test_files: []