emrb 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6e20fbc173d54e5dee120c775aa0e7c151c24c1522ca31f7fc1fe5836efaf9f
4
- data.tar.gz: e372fbfef1ffe52102c001cc67a48e04c20e2ffc1eae7d0544f98dec19721d4f
3
+ metadata.gz: bfc0b3aabe0d926c2a7c7ef914fbbf2c064bf3db8a27aefa68f4bd348d6d3d43
4
+ data.tar.gz: 9d689ec83548b4ed363f5872779b50069e42d70e3f34028074b5eaaab1d27de0
5
5
  SHA512:
6
- metadata.gz: d318b59fd1d34d7b56100827935318c890840a1c4277ae79ba88e43f882ca6bc8e2c0d692d176b3c0e244777a76e22d6ef1d1d4944d5dce5d036a236734403c6
7
- data.tar.gz: 04f4decea7589c1af30961ab387c2fb99fab85cb3de1cdfc6db24947a013e37b303be7baad099d83d8a802d7e5549ac32881ee8a50c9c571a5b2403bb2f420a1
6
+ metadata.gz: 2b25cede10a5a9baec6060076ccbd0d7b7b7ef3839d2ba6b0f8a97c1f1b5b915b2516b61bd3a45257f692ea3a8e4406e8438e993d7ab48aeb165f14130213bd9
7
+ data.tar.gz: 24baf13019ce92585d581578404c532a4e44b2d89471339e5bdd51e2fdc90af70076aedf697ba59377f6c8094c159611061e4f58965f1ee7924a65b7ed672d3d
data/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+
7
+ [*.{rb,yml,yaml,jbuilder}]
8
+ charset = utf-8
9
+ indent_style = space
10
+ indent_size = 2
data/.rubocop.yml CHANGED
@@ -29,3 +29,12 @@ Layout/ArgumentAlignment:
29
29
 
30
30
  Layout/MultilineMethodCallIndentation:
31
31
  EnforcedStyle: indented
32
+
33
+ Metrics/MethodLength:
34
+ Exclude:
35
+ - lib/emrb/server.rb
36
+
37
+ Style/Documentation:
38
+ Exclude:
39
+ - lib/emrb/server.rb
40
+ - spec/**/*
data/compose.yaml ADDED
@@ -0,0 +1,10 @@
1
+ services:
2
+ emrb:
3
+ image: ruby:3
4
+ volumes:
5
+ - ".:/app"
6
+ - gems:/usr/local/bundle
7
+ working_dir: "/app"
8
+
9
+ volumes:
10
+ gems:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- emrb (0.1.1)
4
+ emrb (0.1.3)
5
5
  prometheus-client (~> 4)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- emrb (0.1.1)
4
+ emrb (0.1.3)
5
5
  prometheus-client (~> 4)
6
6
 
7
7
  GEM
@@ -70,7 +70,7 @@ module Emrb
70
70
  # For a full list of options and functionalities for creating and utilizing a Gauge,
71
71
  # refer to the Prometheus client documentation:
72
72
  # https://github.com/prometheus/client_ruby?tab=readme-ov-file#gauge
73
- def gauge(identifier, docs, **, &)
73
+ def gauge(identifier, docs = "...", **, &)
74
74
  check_identifier!(identifier)
75
75
  opts = block_opts(**, &)
76
76
  State.gauge(id_for(identifier), docs, **opts).tap do |g|
@@ -108,7 +108,7 @@ module Emrb
108
108
  # For all available options and functionalities for creating and utilizing a Histogram,
109
109
  # refer to the Prometheus client documentation:
110
110
  # https://github.com/prometheus/client_ruby?tab=readme-ov-file#histogram
111
- def histogram(identifier, docs, **, &)
111
+ def histogram(identifier, docs = "...", **, &)
112
112
  check_identifier!(identifier)
113
113
  opts = block_opts(**, &)
114
114
  State.histogram(id_for(identifier), docs, **opts).tap do |h|
@@ -139,7 +139,7 @@ module Emrb
139
139
  # For a complete list of options and functionalities for creating and utilizing a Summary,
140
140
  # refer to the Prometheus client documentation:
141
141
  # https://github.com/prometheus/client_ruby?tab=readme-ov-file#summary
142
- def summary(identifier, docs, **, &)
142
+ def summary(identifier, docs = "...", **, &)
143
143
  check_identifier!(identifier)
144
144
  opts = block_opts(**, &)
145
145
  State.summary(id_for(identifier), docs, **opts).tap do |s|
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "sinatra/base"
5
+ rescue LoadError
6
+ raise(<<~MESSAGE)
7
+ ERROR: You attempted to use emrb/server, but sinatra is not available.
8
+ Add sinatra to your application's dependencies before using this feature.
9
+ MESSAGE
10
+ end
11
+
12
+ begin
13
+ require "puma"
14
+ rescue LoadError
15
+ raise(<<~MESSAGE)
16
+ ERROR: You attempted to use emrb/server, but puma is not available.
17
+ Add puma to your application's dependencies before using this feature.
18
+ MESSAGE
19
+ end
20
+
21
+ module Emrb
22
+ # expose_metrics starts a simple sinatra server on a given port and
23
+ # address that exposes a single /metrics endpoint for scrapers to access.
24
+ # It is a courtesy utility for applications not exposing an HTTP server
25
+ # by default.
26
+ #
27
+ # To use this method, the application calling it must bundle both sinatra
28
+ # and puma gems.
29
+ #
30
+ # port - Port to expose the server
31
+ # address - Address to expose the server. Defaults to `0.0.0.0`.
32
+ #
33
+ # Returns nothing.
34
+ def self.expose_metrics(port, address = "0.0.0.0")
35
+ return if @metrics_app
36
+
37
+ metrics_app = Class.new(Sinatra::Base) do
38
+ set :bind, address
39
+ set :port, port
40
+ use Emrb::Exporter
41
+ use Rack::Deflater
42
+ end
43
+
44
+ @metrics_app = metrics_app.new
45
+ puma_server = Puma::Server.new(metrics_app)
46
+ puma_server.add_tcp_listener(address, port)
47
+ @puma_server = puma_server
48
+ @metrics_thr = Thread.new { puma_server.run }
49
+ end
50
+
51
+ # Stops the metrics server previously started by #expose_metrics.
52
+ #
53
+ # Returns nothing.
54
+ def self.stop_exposing_metrics
55
+ return unless @metrics_app
56
+
57
+ @puma_server.stop(true)
58
+ @metrics_thr.join
59
+ end
60
+ end
data/lib/emrb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Emrb
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Mariotti
@@ -33,11 +33,13 @@ executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
+ - ".editorconfig"
36
37
  - ".rspec"
37
38
  - ".rubocop.yml"
38
39
  - CODE_OF_CONDUCT.md
39
40
  - README.md
40
41
  - Rakefile
42
+ - compose.yaml
41
43
  - example/http/Gemfile
42
44
  - example/http/Gemfile.lock
43
45
  - example/http/main.rb
@@ -52,6 +54,7 @@ files:
52
54
  - lib/emrb/instruments/exporters.rb
53
55
  - lib/emrb/instruments/instruments.rb
54
56
  - lib/emrb/instruments/state.rb
57
+ - lib/emrb/server.rb
55
58
  - lib/emrb/version.rb
56
59
  homepage: https://github.com/ofeefo/emrb
57
60
  licenses: