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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4839f4b0eec912672fc27a3fbf17dbc7b36f852986eba8bff0acc75dee87f73f
|
4
|
+
data.tar.gz: b2b15094f726d025b4033a8e306607ebd0284e232c6e247fbe2b1be56169cd21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
data/lib/stack-service-base.rb
CHANGED
data/lib/version.rb
CHANGED