emrb 0.1.2 → 0.1.4

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: f15f9f402475d30026e70a8cce75b215795571fce2f9dcd4136bf1dba606531c
4
- data.tar.gz: e067cdaeed6f55961b1575092eb568bda41ac599b076ae43f2e4d6dee6573ba6
3
+ metadata.gz: 28e29346fc4f54537087ca4b1ca4b179bc33f70266d4dc78de4cbdf5065dcd5a
4
+ data.tar.gz: eb0ef1dfb40da2d96604380880646b793837d8e5f1a8bd62146ff5ee1f24a3cf
5
5
  SHA512:
6
- metadata.gz: 7c1b89985d30211a1d78c1243ad8ca36cd20147230c93ee19140e2ad79dbff05655c1ca973f56936544ca9f446bb550e1036acebfdf12457831de7783ca2fe8d
7
- data.tar.gz: bb6f9946b27080c769f5a9d258e5385548d1a043aed15c1b4d1f97cf1bef95d271a75b9c95c5056a8196743ff3f9f9b7dee7e57f95de2f49db2cd81770b021a7
6
+ metadata.gz: 225ca18957ba3fc5cc5b26236a7fd0a38311a01bccae67ab3730ce053e8ef74e5fe7be1f589db9df1cc61833a051b5afdf6c179fab00872cdd88b3f51035cfa8
7
+ data.tar.gz: d999b2801431ba962d6ae0177f1d976b0568ce2c847248e2091f74c241f3645ff2c5fdfd68d7e3d4f7104e836bea988e6dc8d6aa6db197449449e8dcd1663e06
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.2)
4
+ emrb (0.1.4)
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.2)
4
+ emrb (0.1.4)
5
5
  prometheus-client (~> 4)
6
6
 
7
7
  GEM
@@ -176,6 +176,19 @@ module Emrb
176
176
  # end
177
177
  def push(job, **) = State.push(job, **)
178
178
 
179
+ # Periodically invokes #push in a given frequency.
180
+ #
181
+ # job - Job identifier
182
+ # frequency - Frequency, in seconds, in which #push will be called.
183
+ #
184
+ # Returns nothing.
185
+ def push_periodically(job, frequency = 10)
186
+ Thread.new do
187
+ sleep(frequency)
188
+ push(job)
189
+ end
190
+ end
191
+
179
192
  # Allows instruments to be declared with preset labels.
180
193
  #
181
194
  # labels - A hash containing the preset labels and values
@@ -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.2"
4
+ VERSION = "0.1.4"
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.2
4
+ version: 0.1.4
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: