stack-service-base 0.0.5 → 0.0.7
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: d0ffd5710f34312bd023c5f1ca82dc8398348707dbcd55671bee9c69dae7f065
|
4
|
+
data.tar.gz: 7ca510e9f8f852b3eadf02503347bae49f51d1b273ab73052abf6e20ed48555b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8102f0558f710f43c8cdbaa1f61f120921ba8053f31dcbc2bedaa93093c5e2473ecc5f50c847c65127be383ccc0081b9e23e6529446dc075e031c1f40347dcfe
|
7
|
+
data.tar.gz: 0530e3f4556889387ed229956b6f07a7dbb1fa7d117106b355e08c6e4c87421351efb80b830b1dff49f301ce0b1551993064ced07111eaa440a33a9e1508d520
|
@@ -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,6 +72,18 @@ module RackHelpers
|
|
72
72
|
[status, headers, body]
|
73
73
|
end
|
74
74
|
|
75
|
+
Rack.define_middleware :RequestsLimiter do |env, app, opts|
|
76
|
+
@sem ||= Async::Semaphore.new(opts[0][:limit] || 5 )
|
77
|
+
|
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
|
85
|
+
end
|
86
|
+
|
75
87
|
# PATCH: for the Grape
|
76
88
|
class Rack::Lint::Wrapper::InputWrapper
|
77
89
|
def rewind = @input.rewind
|
@@ -100,10 +112,12 @@ module RackHelpers
|
|
100
112
|
if status.to_i / 100 == 5
|
101
113
|
_body = body.to_s # each(&:to_s).join
|
102
114
|
LOGGER.error [status, headers, _body]
|
103
|
-
OpenTelemetry::Trace
|
104
|
-
|
105
|
-
|
106
|
-
|
115
|
+
if defined? OpenTelemetry::Trace
|
116
|
+
OpenTelemetry::Trace.current_span.tap do |span|
|
117
|
+
event_attributes = { 'exception.type' => "HTTP #{status.to_i}", 'exception.message' => _body, 'exception.stacktrace' => '' }
|
118
|
+
span.add_event('exception', attributes: event_attributes)
|
119
|
+
span.status = OpenTelemetry::Trace::Status.error("Request error: #{status.to_i}")
|
120
|
+
end
|
107
121
|
end
|
108
122
|
end
|
109
123
|
|
@@ -152,7 +166,7 @@ module RackHelpers
|
|
152
166
|
use OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware
|
153
167
|
end
|
154
168
|
app.use Rack::Deflater
|
155
|
-
app.use OTELTraceInfo
|
169
|
+
app.use OTELTraceInfo if defined? OpenTelemetry::Trace
|
156
170
|
|
157
171
|
unless defined?(PERFORMANCE) && PERFORMANCE
|
158
172
|
app.use RequestProfile
|
data/lib/stack-service-base.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stack-service-base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prometheus-client
|