stack-service-base 0.0.6 → 0.0.8

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: 7fc2da143ab2622432f7fce2f36bf7e99e4679ffcb110f7b2a0f4b44d762b26b
4
- data.tar.gz: 0da55dfcbe8f1ea8cd89ea6625238e99ad607729a914aa0bbe3b45197a5615a3
3
+ metadata.gz: 4839f4b0eec912672fc27a3fbf17dbc7b36f852986eba8bff0acc75dee87f73f
4
+ data.tar.gz: b2b15094f726d025b4033a8e306607ebd0284e232c6e247fbe2b1be56169cd21
5
5
  SHA512:
6
- metadata.gz: e6a8a2321eef07de698ef008bc3f8cfe834484dda97692e2efa10a8d80fb1ad03c7b7f6906246545d0af9da444723ea49b8d910276393f2efb48b0fc82a9a9a0
7
- data.tar.gz: 0c9b6ea5c45abd03e06b9ec132e02abc7746019722b9fbebb30f8f56bb70e24e48944c0597b8a8b1fa42ee937ce02ddad22dd9bc1742f2ae195ed926b7cce113
6
+ metadata.gz: b126d88b6a70b01df38e889812aff8f04b17b360daa8a0872ad41d8ed233de803a3cadb00d48c9f93becbccbd01ad9dd0f57b96440fd641d0988509a835e5e5c
7
+ data.tar.gz: 3d37821195e25c093588496391c57738eb688538b303c01fe76eb3c87986eb18ed9c0ff6c13b21c8afcfecb9b6034500d4a7187f152e5bfd79290a3fb7900981
@@ -52,7 +52,7 @@ if defined? LOGGER and OTEL_ENABLED
52
52
  OpenTelemetry.logger = LOGGER
53
53
  end
54
54
 
55
- def otel_initialize(app)
55
+ def otel_initialize
56
56
  $stdout.puts "otl_configure: OTEL_ENABLED: #{OTEL_ENABLED}"
57
57
  return unless OTEL_ENABLED
58
58
 
@@ -88,8 +88,6 @@ def otel_initialize(app)
88
88
  }.transform_keys(&:to_s) )
89
89
  # span.status = OpenTelemetry::Trace::Status.error("error message here!")
90
90
  end
91
-
92
- app.use OTELTraceInfo
93
91
  end
94
92
 
95
93
  if defined? Sequel and OTEL_ENABLED
@@ -40,54 +40,56 @@ module PrometheusParser
40
40
  end
41
41
  end
42
42
 
43
- metrics_text = <<~METRICS
44
- # TYPE http_server_requests_total counter
45
- # HELP http_server_requests_total The total number of HTTP requests handled by the Rack application.
46
- http_server_requests_total{code="200",method="get",path="/"} 5.0
47
- http_server_requests_total{code="200",method="get",path="/metrics"} 18.0
48
- # TYPE http_server_request_duration_seconds histogram
49
- # HELP http_server_request_duration_seconds The HTTP response duration of the Rack application.
50
- http_server_request_duration_seconds_bucket{method="get",path="/",le="0.005"} 0.0
51
- http_server_request_duration_seconds_bucket{method="get",path="/",le="0.01"} 0.0
52
- http_server_request_duration_seconds_bucket{method="get",path="/",le="0.025"} 0.0
53
- http_server_request_duration_seconds_bucket{method="get",path="/",le="0.05"} 4.0
54
- http_server_request_duration_seconds_bucket{method="get",path="/",le="0.1"} 5.0
55
- http_server_request_duration_seconds_bucket{method="get",path="/",le="0.25"} 5.0
56
- http_server_request_duration_seconds_bucket{method="get",path="/",le="0.5"} 5.0
57
- http_server_request_duration_seconds_bucket{method="get",path="/",le="1"} 5.0
58
- http_server_request_duration_seconds_bucket{method="get",path="/",le="2.5"} 5.0
59
- http_server_request_duration_seconds_bucket{method="get",path="/",le="5"} 5.0
60
- http_server_request_duration_seconds_bucket{method="get",path="/",le="10"} 5.0
61
- http_server_request_duration_seconds_bucket{method="get",path="/",le="+Inf"} 5.0
62
- http_server_request_duration_seconds_sum{method="get",path="/"} 0.1885649065952748
63
- http_server_request_duration_seconds_count{method="get",path="/"} 5.0
64
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.005"} 18.0
65
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.01"} 18.0
66
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.025"} 18.0
67
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.05"} 18.0
68
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.1"} 18.0
69
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.25"} 18.0
70
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.5"} 18.0
71
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="1"} 18.0
72
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="2.5"} 18.0
73
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="5"} 18.0
74
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="10"} 18.0
75
- http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="+Inf"} 18.0
76
- http_server_request_duration_seconds_sum{method="get",path="/metrics"} 0.012181486235931516
77
- http_server_request_duration_seconds_count{method="get",path="/metrics"} 18.0
78
- # TYPE http_server_exceptions_total counter
79
- # HELP http_server_exceptions_total The total number of exceptions raised by the Rack application.
80
- METRICS
43
+ if __FILE__ == $0
44
+ metrics_text = <<~METRICS
45
+ # TYPE http_server_requests_total counter
46
+ # HELP http_server_requests_total The total number of HTTP requests handled by the Rack application.
47
+ http_server_requests_total{code="200",method="get",path="/"} 5.0
48
+ http_server_requests_total{code="200",method="get",path="/metrics"} 18.0
49
+ # TYPE http_server_request_duration_seconds histogram
50
+ # HELP http_server_request_duration_seconds The HTTP response duration of the Rack application.
51
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="0.005"} 0.0
52
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="0.01"} 0.0
53
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="0.025"} 0.0
54
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="0.05"} 4.0
55
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="0.1"} 5.0
56
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="0.25"} 5.0
57
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="0.5"} 5.0
58
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="1"} 5.0
59
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="2.5"} 5.0
60
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="5"} 5.0
61
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="10"} 5.0
62
+ http_server_request_duration_seconds_bucket{method="get",path="/",le="+Inf"} 5.0
63
+ http_server_request_duration_seconds_sum{method="get",path="/"} 0.1885649065952748
64
+ http_server_request_duration_seconds_count{method="get",path="/"} 5.0
65
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.005"} 18.0
66
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.01"} 18.0
67
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.025"} 18.0
68
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.05"} 18.0
69
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.1"} 18.0
70
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.25"} 18.0
71
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="0.5"} 18.0
72
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="1"} 18.0
73
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="2.5"} 18.0
74
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="5"} 18.0
75
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="10"} 18.0
76
+ http_server_request_duration_seconds_bucket{method="get",path="/metrics",le="+Inf"} 18.0
77
+ http_server_request_duration_seconds_sum{method="get",path="/metrics"} 0.012181486235931516
78
+ http_server_request_duration_seconds_count{method="get",path="/metrics"} 18.0
79
+ # TYPE http_server_exceptions_total counter
80
+ # HELP http_server_exceptions_total The total number of exceptions raised by the Rack application.
81
+ METRICS
81
82
 
82
- metrics = PrometheusParser::parse_metrics metrics_text
83
+ metrics = PrometheusParser::parse_metrics metrics_text
83
84
 
84
- # Print the parsed metrics
85
- metrics.each do |name, data|
86
- puts "Metric: #{name}"
87
- puts "Description: #{data[:help]}"
88
- puts "Type: #{data[:type]}"
89
- data[:series].each do |series|
90
- puts " #{series} "
85
+ # Print the parsed metrics
86
+ metrics.each do |name, data|
87
+ puts "Metric: #{name}"
88
+ puts "Description: #{data[:help]}"
89
+ puts "Type: #{data[:type]}"
90
+ data[:series].each do |series|
91
+ puts " #{series} "
92
+ end
93
+ puts
91
94
  end
92
- puts
93
95
  end
@@ -7,7 +7,7 @@ module RackHelpers
7
7
  end
8
8
 
9
9
  def Rack.define_middleware(name, &block)
10
- Object.const_set name, Rack.middleware_klass(&block)
10
+ RackHelpers.const_set name, Rack.middleware_klass(&block)
11
11
  end
12
12
 
13
13
  Rack.define_middleware :Authentication do |env, app|
@@ -72,16 +72,15 @@ module RackHelpers
72
72
  [status, headers, body]
73
73
  end
74
74
 
75
+ # use RackHelpers::RequestsLimiter, limit: 1, path_regex: %r{^(?!.*healthcheck)}
75
76
  Rack.define_middleware :RequestsLimiter do |env, app, opts|
77
+ @path_regex ||= opts[0][:path_regex] || %r{.*}
76
78
  @sem ||= Async::Semaphore.new(opts[0][:limit] || 5 )
77
79
 
78
- if @sem.blocking?
79
- [429, { 'Content-Type' => 'text/plain', 'Retry-After' => '1' }, ['Too Many Requests']]
80
- else
81
- @sem.acquire {
82
- app.call(env)
83
- }
84
- end
80
+ next app.call(env) unless env['PATH_INFO'] =~ @path_regex
81
+ next [429, { 'Content-Type' => 'text/plain', 'Retry-After' => '1' }, ['Too Many Requests']] if @sem.blocking?
82
+
83
+ @sem.acquire { app.call env }
85
84
  end
86
85
 
87
86
  # PATCH: for the Grape
@@ -166,7 +165,7 @@ module RackHelpers
166
165
  use OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware
167
166
  end
168
167
  app.use Rack::Deflater
169
- app.use OTELTraceInfo
168
+ app.use OTELTraceInfo if defined? OpenTelemetry::Trace
170
169
 
171
170
  unless defined?(PERFORMANCE) && PERFORMANCE
172
171
  app.use RequestProfile
@@ -20,7 +20,7 @@ module StackServiceBase
20
20
  end
21
21
 
22
22
  if OTEL_ENABLED
23
- otel_initialize app
23
+ otel_initialize
24
24
  end
25
25
 
26
26
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module StackServiceBase
2
2
  class Base
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.8'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack-service-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
OSZAR »