grpc_prometheus 0.1.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: 5b31a8cfde8948d7419f8cdb0e00eed65a5c3f8b33f67775f462c6f3e20bed4e
4
+ data.tar.gz: cb725e58d6cc5c9a357d4ad40b63e7bb9d98a4c485522ca6f2b6b7c8d1b1684b
5
+ SHA512:
6
+ metadata.gz: fb12831d915a5f25221c9dddd82f9d4c4ba511f03730bacbf5552d3d3d895b337055a23451498039c27606a58926ac9cb2ca826bf9e227b4e66bc92e6302a55e
7
+ data.tar.gz: 03c5a64d3a5c923e4e5646dbc3b6144ac5f73af7867c3aab681aef51aacd56534e57517fb0f15c09fbfc0bc462468fbd055bade77898a48ba964b2e6aea3901c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - "2.4.6"
5
+ - "2.5.5"
6
+ - "2.6.3"
7
+
8
+ gemfile:
9
+ - Gemfile
10
+
11
+ script:
12
+ - bundle exec rake
13
+
14
+ sudo: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Change Log
2
+
3
+ ## [0.1.0] - 2019-06-15
4
+
5
+ * Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Dockerfile ADDED
@@ -0,0 +1,6 @@
1
+ FROM ruby:2.6.2
2
+
3
+ ENV BUNDLE_PATH /vendor/bundle
4
+ ENV BUNDLE_FORCE_RUBY_PLATFORM 1
5
+ WORKDIR /app
6
+ ADD . /app
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in grpc_prometheus.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ grpc_prometheus (0.1.0)
5
+ grpc (~> 1.7)
6
+ prometheus-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ google-protobuf (3.7.1)
12
+ googleapis-common-protos-types (1.0.4)
13
+ google-protobuf (~> 3.0)
14
+ grpc (1.19.0)
15
+ google-protobuf (~> 3.1)
16
+ googleapis-common-protos-types (~> 1.0.0)
17
+ grpc-tools (1.21.0)
18
+ minitest (5.11.3)
19
+ prometheus-client (0.9.0)
20
+ quantile (~> 0.2.1)
21
+ quantile (0.2.1)
22
+ rake (10.5.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.17)
29
+ grpc-tools
30
+ grpc_prometheus!
31
+ minitest (~> 5.0)
32
+ rake (~> 10.0)
33
+
34
+ BUNDLED WITH
35
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yuya Takeyama
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,59 @@
1
+ # GRPCPrometheus
2
+
3
+ Export a metric endpoint of gRPC services in Ruby for Prometheus.
4
+
5
+ This aims to behave basically the same as [grpc-ecosystem/go-grpc-prometheus](https://github.com/grpc-ecosystem/go-grpc-prometheus)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'grpc_prometheus'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install grpc_prometheus
22
+
23
+ ## Usage
24
+
25
+ This gem collect metrics from a server interceptor.
26
+
27
+ ```rb
28
+ # Create an instance of server metrics
29
+ metrics = GRPCPrometheus::ServerMetrics.new
30
+ # Launch a web server to expose the metric endpoint using WEBrick.
31
+ # All of the arguments are default values (you can omit them).
32
+ metrics.start_metric_endpoint_in_background(bind: '0.0.0.0', port: 19191, metrics_path: '/metrics')
33
+
34
+ # Create a gRPC server with server interceptor of server metrics
35
+ server = GRPC::RpcServer.new(interceptors: [metrics.server_interceptor])
36
+ server.add_http2_port('0.0.0.0:3000', :this_port_is_insecure)
37
+ server.handle(UsersService)
38
+ # Pre-register 0 to metrics for every methods and error codes
39
+ metrics.initialize_metrics(server)
40
+ server.run_till_terminated
41
+ ```
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ 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).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yuya-takeyama/ruby-grpc_prometheus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
56
+
57
+ ## Code of Conduct
58
+
59
+ Everyone interacting in the GRPCPrometheus project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yuya-takeyama/ruby-grpc_prometheus/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "grpc/prometheus"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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,6 @@
1
+ #!/bin/bash
2
+
3
+ set -eu
4
+ set -o pipefail
5
+
6
+ docker-compose run --rm gem bundle exec grpc_tools_ruby_protoc -I test/fixtures/protos --ruby_out test/fixtures/lib --grpc_out test/fixtures/lib test/fixtures/protos/foo.proto
@@ -0,0 +1,12 @@
1
+ version: '3'
2
+
3
+ services:
4
+ gem:
5
+ build:
6
+ context: .
7
+ volumes:
8
+ - ./:/app
9
+ - bundle:/vendor/bundle
10
+
11
+ volumes:
12
+ bundle:
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "grpc_prometheus/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grpc_prometheus"
8
+ spec.version = GRPCPrometheus::VERSION
9
+ spec.authors = ["Yuya Takeyama"]
10
+ spec.email = ["sign.of.the.wolf.pentagram@gmail.com"]
11
+
12
+ spec.summary = %q{Monitor gRPC server}
13
+ spec.description = %q{Expose a Prometheus metric endpoint to monitor gRPC server}
14
+ spec.homepage = "https://github.com/yuya-takeyama/ruby-grpc_prometheus"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "grpc", "~> 1.7"
27
+ spec.add_dependency "prometheus-client"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.17"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+ spec.add_development_dependency "grpc-tools"
33
+ end
@@ -0,0 +1,13 @@
1
+ require 'grpc'
2
+
3
+ require "grpc_prometheus/grpc_type"
4
+ require "grpc_prometheus/server_interceptor"
5
+ require "grpc_prometheus/server_metrics"
6
+ require "grpc_prometheus/server_reporter"
7
+ require "grpc_prometheus/util"
8
+ require "grpc_prometheus/version"
9
+
10
+ module GRPCPrometheus
11
+ class Error < StandardError; end
12
+ # Your code goes here...
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ module GRPCPrometheus
3
+ module GRPCType
4
+ UNARY = 'unary'
5
+ CLIENT_STREAM = 'client_stream'
6
+ SERVER_STREAM = 'server_stream'
7
+ BIDI_STREAM = 'bidi_stream'
8
+ end
9
+ end
@@ -0,0 +1,106 @@
1
+ module GRPCPrometheus
2
+ class ServerInterceptor < ::GRPC::ServerInterceptor
3
+ def initialize(server_metrics)
4
+ @server_metrics = server_metrics
5
+ end
6
+
7
+ def request_response(request: nil, call: nil, method: nil)
8
+ reporter = ServerReporter.new(
9
+ server_metrics: @server_metrics,
10
+ method: method,
11
+ grpc_type: GRPCType::UNARY,
12
+ )
13
+ grpc_err = nil
14
+ yield
15
+ rescue => err
16
+ grpc_err = to_grpc_err(err)
17
+ raise err
18
+ ensure
19
+ if grpc_err
20
+ reporter.handled(Util::ALL_CODES[grpc_err.code])
21
+ else
22
+ reporter.handled(Util::ALL_CODES[::GRPC::Core::StatusCodes::OK])
23
+ end
24
+ end
25
+
26
+ # These metrics for streaming messages can't be collected
27
+ # with the current gRPC implementation in Ruby
28
+ #
29
+ # - grpc_server_msg_received_total
30
+ # - grpc_server_msg_sent_total
31
+ #
32
+ # Need to wait for this Pull Request to be released:
33
+ #
34
+ # - https://github.com/grpc/grpc/pull/17651
35
+
36
+ def client_streamer(call: nil, method: nil)
37
+ reporter = ServerReporter.new(
38
+ server_metrics: @server_metrics,
39
+ method: method,
40
+ grpc_type: GRPCType::CLIENT_STREAM,
41
+ )
42
+ grpc_err = nil
43
+ yield
44
+ rescue => err
45
+ grpc_err = to_grpc_err(err)
46
+ raise err
47
+ ensure
48
+ if grpc_err
49
+ reporter.handled(Util::ALL_CODES[grpc_err.code])
50
+ else
51
+ reporter.handled(Util::ALL_CODES[::GRPC::Core::StatusCodes::OK])
52
+ end
53
+ end
54
+
55
+ def server_streamer(request: nil, call: nil, method: nil)
56
+ reporter = ServerReporter.new(
57
+ server_metrics: @server_metrics,
58
+ method: method,
59
+ grpc_type: GRPCType::SERVER_STREAM,
60
+ )
61
+ grpc_err = nil
62
+ yield
63
+ rescue => err
64
+ grpc_err = to_grpc_err(err)
65
+ raise err
66
+ ensure
67
+ if grpc_err
68
+ reporter.handled(Util::ALL_CODES[grpc_err.code])
69
+ else
70
+ reporter.handled(Util::ALL_CODES[::GRPC::Core::StatusCodes::OK])
71
+ end
72
+ end
73
+
74
+ def bidi_streamer(requests: nil, call: nil, method: nil)
75
+ reporter = ServerReporter.new(
76
+ server_metrics: @server_metrics,
77
+ method: method,
78
+ grpc_type: GRPCType::BIDI_STREAM,
79
+ )
80
+ grpc_err = nil
81
+ yield
82
+ rescue => err
83
+ grpc_err = to_grpc_err(err)
84
+ raise err
85
+ ensure
86
+ if grpc_err
87
+ reporter.handled(Util::ALL_CODES[grpc_err.code])
88
+ else
89
+ reporter.handled(Util::ALL_CODES[::GRPC::Core::StatusCodes::OK])
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def to_grpc_err(err)
96
+ if err.is_a?(::GRPC::BadStatus)
97
+ err
98
+ else
99
+ ::GRPC::BadStatus.new_status_exception(
100
+ ::GRPC::Core::StatusCodes::UNKNOWN,
101
+ err.message
102
+ )
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,80 @@
1
+ require 'prometheus/client'
2
+ require 'prometheus/client/formats/text'
3
+ require 'webrick'
4
+
5
+ module GRPCPrometheus
6
+ class ServerMetrics
7
+ attr_reader :server_started_counter,
8
+ :server_handled_counter
9
+
10
+ def initialize
11
+ @registry = ::Prometheus::Client.registry
12
+ @server_started_counter = @registry.counter(
13
+ :grpc_server_started_total,
14
+ 'Total number of RPCs started on the server.',
15
+ )
16
+ @server_handled_counter = @registry.counter(
17
+ :grpc_server_handled_total,
18
+ 'Total number of RPCs completed on the server, regardless of success or failure.',
19
+ )
20
+ end
21
+
22
+ def server_interceptor
23
+ ServerInterceptor.new(self)
24
+ end
25
+
26
+ def initialize_metrics(server)
27
+ # FIXME
28
+ server.instance_variable_get(:@rpc_descs).each do |full_method_name, method_info|
29
+ matches = full_method_name.match(%r{^/([^/]+)/})
30
+ service_name = matches[1]
31
+ method_name = matches[2]
32
+ pre_register_method(service_name, method_info)
33
+ end
34
+ end
35
+
36
+ def pre_register_method(service_name, method_info)
37
+ labels = {
38
+ grpc_service: service_name,
39
+ grpc_method: method_info.name.to_s,
40
+ grpc_type: Util.type_from_method_info(method_info),
41
+ }
42
+ server_started_counter.increment(labels, 0)
43
+ Util::ALL_CODES.each do |code, code_as_str|
44
+ labels_with_code = labels.dup.merge({ grpc_code: code_as_str })
45
+ server_handled_counter.increment(labels_with_code, 0)
46
+ end
47
+ end
48
+
49
+ def start_metric_endpoint_in_background(bind: '0.0.0.0', port: 19191, metrics_path: '/metrics')
50
+ config = {
51
+ BindAddress: bind,
52
+ Port: port,
53
+ MaxClients: 5,
54
+ Logger: ::WEBrick::Log.new(STDERR, ::WEBrick::Log::FATAL),
55
+ AccessLog: [],
56
+ }
57
+ server = ::WEBrick::HTTPServer.new(config)
58
+ server.mount(metrics_path, MonitorServlet, @registry)
59
+ Thread.start do
60
+ server.start
61
+ end
62
+ end
63
+
64
+ class MonitorServlet < ::WEBrick::HTTPServlet::AbstractServlet
65
+ def initialize(server, registry)
66
+ @registry = registry
67
+ end
68
+
69
+ def do_GET(req, res)
70
+ res.status = 200
71
+ res['Content-Type'] = ::Prometheus::Client::Formats::Text::CONTENT_TYPE
72
+ res.body = ::Prometheus::Client::Formats::Text.marshal(@registry)
73
+ rescue
74
+ res.status = 500
75
+ res['Content-Type'] = 'text/plain'
76
+ res.body = $!.to_s
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,23 @@
1
+ module GRPCPrometheus
2
+ class ServerReporter
3
+ def initialize(server_metrics:, method:, grpc_type:)
4
+ @server_metrics = server_metrics
5
+ @labels = {
6
+ grpc_service: method.owner.service_name,
7
+ grpc_method: method.name.to_s.split('_').map(&:capitalize).join(''),
8
+ grpc_type: grpc_type,
9
+ }.freeze
10
+
11
+ @server_metrics.
12
+ server_started_counter.
13
+ increment(@labels)
14
+ end
15
+
16
+ def handled(code)
17
+ labels = @labels.dup.merge({ grpc_code: code })
18
+ @server_metrics.
19
+ server_handled_counter.
20
+ increment(labels)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GRPCPrometheus
4
+ module Util
5
+ ALL_CODES = {
6
+ ::GRPC::Core::StatusCodes::OK => 'Ok',
7
+ ::GRPC::Core::StatusCodes::CANCELLED => 'Cancelled',
8
+ ::GRPC::Core::StatusCodes::UNKNOWN => 'Unknown',
9
+ ::GRPC::Core::StatusCodes::INVALID_ARGUMENT => 'InvalidArgument',
10
+ ::GRPC::Core::StatusCodes::DEADLINE_EXCEEDED => 'DeadlineExceeded',
11
+ ::GRPC::Core::StatusCodes::NOT_FOUND => 'NotFound',
12
+ ::GRPC::Core::StatusCodes::ALREADY_EXISTS => 'AlreadyExists',
13
+ ::GRPC::Core::StatusCodes::PERMISSION_DENIED => 'PermissionDenied',
14
+ ::GRPC::Core::StatusCodes::UNAUTHENTICATED => 'Unauthenticated',
15
+ ::GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED => 'ResourceExhausted',
16
+ ::GRPC::Core::StatusCodes::FAILED_PRECONDITION => 'FailedPrecondition',
17
+ ::GRPC::Core::StatusCodes::ABORTED => 'Aborted',
18
+ ::GRPC::Core::StatusCodes::OUT_OF_RANGE => 'OutOfRange',
19
+ ::GRPC::Core::StatusCodes::UNIMPLEMENTED => 'Unimplemented',
20
+ ::GRPC::Core::StatusCodes::INTERNAL => 'Internal',
21
+ ::GRPC::Core::StatusCodes::UNAVAILABLE => 'Unavailable',
22
+ ::GRPC::Core::StatusCodes::DATA_LOSS => 'DataLoss',
23
+ }.freeze
24
+
25
+ module_function
26
+
27
+ def type_from_method_info(method_info)
28
+ if method_info.input.is_a?(::GRPC::RpcDesc::Stream)
29
+ if method_info.output.is_a?(::GRPC::RpcDesc::Stream)
30
+ 'bidi_stream'
31
+ else
32
+ 'client_stream'
33
+ end
34
+ else
35
+ if method_info.output.is_a?(::GRPC::RpcDesc::Stream)
36
+ 'server_stream'
37
+ else
38
+ 'unary'
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module GRPCPrometheus
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grpc_prometheus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuya Takeyama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: prometheus-client
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.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
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: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: grpc-tools
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Expose a Prometheus metric endpoint to monitor gRPC server
98
+ email:
99
+ - sign.of.the.wolf.pentagram@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - CHANGELOG.md
107
+ - CODE_OF_CONDUCT.md
108
+ - Dockerfile
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - bin/update-fixture-service
117
+ - docker-compose.yml
118
+ - grpc_prometheus.gemspec
119
+ - lib/grpc_prometheus.rb
120
+ - lib/grpc_prometheus/grpc_type.rb
121
+ - lib/grpc_prometheus/server_interceptor.rb
122
+ - lib/grpc_prometheus/server_metrics.rb
123
+ - lib/grpc_prometheus/server_reporter.rb
124
+ - lib/grpc_prometheus/util.rb
125
+ - lib/grpc_prometheus/version.rb
126
+ homepage: https://github.com/yuya-takeyama/ruby-grpc_prometheus
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 3.0.3
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Monitor gRPC server
149
+ test_files: []