atatus 1.3.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/Gemfile +72 -22
  4. data/LICENSE +1 -1
  5. data/atatus.gemspec +2 -2
  6. data/lib/atatus/agent.rb +78 -29
  7. data/lib/atatus/central_config/cache_control.rb +18 -1
  8. data/lib/atatus/central_config.rb +72 -27
  9. data/lib/atatus/child_durations.rb +64 -0
  10. data/lib/atatus/collector/base.rb +102 -43
  11. data/lib/atatus/collector/builder.rb +134 -4
  12. data/lib/atatus/collector/hist.rb +54 -0
  13. data/lib/atatus/collector/layer.rb +1 -0
  14. data/lib/atatus/collector/transport.rb +41 -11
  15. data/lib/atatus/config/bytes.rb +17 -0
  16. data/lib/atatus/config/duration.rb +17 -0
  17. data/lib/atatus/config/options.rb +29 -9
  18. data/lib/atatus/config/regexp_list.rb +17 -0
  19. data/lib/atatus/config/wildcard_pattern_list.rb +64 -0
  20. data/lib/atatus/config.rb +129 -28
  21. data/lib/atatus/context/request/socket.rb +18 -1
  22. data/lib/atatus/context/request/url.rb +17 -0
  23. data/lib/atatus/context/request.rb +17 -0
  24. data/lib/atatus/context/response.rb +27 -2
  25. data/lib/atatus/context/user.rb +17 -0
  26. data/lib/atatus/context.rb +32 -1
  27. data/lib/atatus/context_builder.rb +19 -4
  28. data/lib/atatus/deprecations.rb +17 -0
  29. data/lib/atatus/error/exception.rb +24 -0
  30. data/lib/atatus/error/log.rb +17 -0
  31. data/lib/atatus/error.rb +27 -0
  32. data/lib/atatus/error_builder.rb +21 -2
  33. data/lib/atatus/grape.rb +62 -0
  34. data/lib/atatus/graphql.rb +91 -0
  35. data/lib/atatus/grpc.rb +99 -0
  36. data/lib/atatus/instrumenter.rb +135 -30
  37. data/lib/atatus/internal_error.rb +17 -0
  38. data/lib/atatus/logging.rb +17 -2
  39. data/lib/atatus/metadata/process_info.rb +17 -0
  40. data/lib/atatus/metadata/service_info.rb +21 -6
  41. data/lib/atatus/metadata/system_info/container_info.rb +49 -10
  42. data/lib/atatus/metadata/system_info/hw_info.rb +1 -1
  43. data/lib/atatus/metadata/system_info.rb +22 -3
  44. data/lib/atatus/metadata.rb +17 -0
  45. data/lib/atatus/metrics/breakdown_set.rb +31 -0
  46. data/lib/atatus/metrics/{cpu_mem.rb → cpu_mem_set.rb} +110 -63
  47. data/lib/atatus/metrics/metric.rb +140 -0
  48. data/lib/atatus/metrics/set.rb +123 -0
  49. data/lib/atatus/metrics/span_scoped_set.rb +56 -0
  50. data/lib/atatus/metrics/transaction_set.rb +26 -0
  51. data/lib/atatus/metrics/vm_set.rb +58 -0
  52. data/lib/atatus/metrics.rb +69 -27
  53. data/lib/atatus/metricset.rb +48 -4
  54. data/lib/atatus/middleware.rb +28 -8
  55. data/lib/atatus/naively_hashable.rb +17 -0
  56. data/lib/atatus/normalizers/grape/endpoint_run.rb +65 -0
  57. data/lib/atatus/normalizers/grape.rb +22 -0
  58. data/lib/atatus/normalizers/rails/action_controller.rb +44 -0
  59. data/lib/atatus/normalizers/rails/action_mailer.rb +43 -0
  60. data/lib/atatus/normalizers/{action_view.rb → rails/action_view.rb} +17 -0
  61. data/lib/atatus/normalizers/rails/active_record.rb +80 -0
  62. data/lib/atatus/normalizers/rails.rb +27 -0
  63. data/lib/atatus/normalizers.rb +23 -9
  64. data/lib/atatus/opentracing.rb +75 -42
  65. data/lib/atatus/rails.rb +29 -13
  66. data/lib/atatus/railtie.rb +19 -6
  67. data/lib/atatus/resque.rb +29 -0
  68. data/lib/atatus/sinatra.rb +53 -0
  69. data/lib/atatus/span/context/db.rb +43 -0
  70. data/lib/atatus/span/context/destination.rb +77 -0
  71. data/lib/atatus/span/context/http.rb +43 -0
  72. data/lib/atatus/span/context.rb +43 -28
  73. data/lib/atatus/span.rb +44 -15
  74. data/lib/atatus/span_helpers.rb +18 -1
  75. data/lib/atatus/spies/action_dispatch.rb +27 -6
  76. data/lib/atatus/spies/delayed_job.rb +26 -5
  77. data/lib/atatus/spies/dynamo_db.rb +62 -0
  78. data/lib/atatus/spies/elasticsearch.rb +53 -7
  79. data/lib/atatus/spies/faraday.rb +54 -20
  80. data/lib/atatus/spies/http.rb +36 -6
  81. data/lib/atatus/spies/json.rb +18 -0
  82. data/lib/atatus/spies/mongo.rb +41 -10
  83. data/lib/atatus/spies/net_http.rb +52 -11
  84. data/lib/atatus/spies/rake.rb +42 -23
  85. data/lib/atatus/spies/redis.rb +17 -0
  86. data/lib/atatus/spies/resque.rb +57 -0
  87. data/lib/atatus/spies/sequel.rb +54 -17
  88. data/lib/atatus/spies/shoryuken.rb +69 -0
  89. data/lib/atatus/spies/sidekiq.rb +46 -25
  90. data/lib/atatus/spies/sinatra.rb +20 -4
  91. data/lib/atatus/spies/sneakers.rb +74 -0
  92. data/lib/atatus/spies/sucker_punch.rb +58 -0
  93. data/lib/atatus/spies/tilt.rb +20 -1
  94. data/lib/atatus/spies.rb +33 -15
  95. data/lib/atatus/sql/signature.rb +169 -0
  96. data/lib/atatus/sql/tokenizer.rb +264 -0
  97. data/lib/atatus/sql/tokens.rb +63 -0
  98. data/lib/atatus/sql.rb +36 -0
  99. data/lib/atatus/sql_summarizer.rb +24 -6
  100. data/lib/atatus/stacktrace/frame.rb +17 -3
  101. data/lib/atatus/stacktrace.rb +17 -0
  102. data/lib/atatus/stacktrace_builder.rb +23 -3
  103. data/lib/atatus/subscriber.rb +23 -4
  104. data/lib/atatus/trace_context/traceparent.rb +111 -0
  105. data/lib/atatus/trace_context/tracestate.rb +148 -0
  106. data/lib/atatus/trace_context.rb +84 -51
  107. data/lib/atatus/transaction.rb +74 -18
  108. data/lib/atatus/transport/base.rb +44 -27
  109. data/lib/atatus/transport/connection/http.rb +58 -35
  110. data/lib/atatus/transport/connection/proxy_pipe.rb +24 -5
  111. data/lib/atatus/transport/connection.rb +28 -72
  112. data/lib/atatus/transport/filters/hash_sanitizer.rb +77 -0
  113. data/lib/atatus/transport/filters/secrets_filter.rb +30 -55
  114. data/lib/atatus/transport/filters.rb +18 -1
  115. data/lib/atatus/transport/headers.rb +83 -0
  116. data/lib/atatus/transport/serializers/context_serializer.rb +30 -3
  117. data/lib/atatus/transport/serializers/error_serializer.rb +17 -2
  118. data/lib/atatus/transport/serializers/metadata_serializer.rb +44 -22
  119. data/lib/atatus/transport/serializers/metricset_serializer.rb +34 -6
  120. data/lib/atatus/transport/serializers/span_serializer.rb +47 -12
  121. data/lib/atatus/transport/serializers/transaction_serializer.rb +18 -2
  122. data/lib/atatus/transport/serializers.rb +17 -5
  123. data/lib/atatus/transport/user_agent.rb +48 -0
  124. data/lib/atatus/transport/worker.rb +31 -7
  125. data/lib/atatus/util/inflector.rb +17 -0
  126. data/lib/atatus/util/lru_cache.rb +17 -0
  127. data/lib/atatus/util/throttle.rb +17 -0
  128. data/lib/atatus/util.rb +18 -1
  129. data/lib/atatus/version.rb +19 -1
  130. data/lib/atatus.rb +84 -16
  131. metadata +46 -26
  132. data/Rakefile +0 -19
  133. data/bench/.gitignore +0 -2
  134. data/bench/app.rb +0 -53
  135. data/bench/benchmark.rb +0 -36
  136. data/bench/report.rb +0 -55
  137. data/bench/rubyprof.rb +0 -39
  138. data/bench/stackprof.rb +0 -23
  139. data/bin/build_docs +0 -5
  140. data/bin/console +0 -15
  141. data/bin/setup +0 -8
  142. data/bin/with_framework +0 -7
  143. data/lib/atatus/metrics/vm.rb +0 -60
  144. data/lib/atatus/normalizers/action_controller.rb +0 -27
  145. data/lib/atatus/normalizers/action_mailer.rb +0 -26
  146. data/lib/atatus/normalizers/active_record.rb +0 -45
  147. data/lib/atatus/util/prefixed_logger.rb +0 -18
  148. data/vendor/.gitkeep +0 -0
@@ -1,12 +1,29 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  require 'atatus/trace_context'
21
+ require 'atatus/child_durations'
4
22
  require 'atatus/span'
5
23
  require 'atatus/transaction'
6
24
  require 'atatus/span_helpers'
7
25
 
8
26
  module Atatus
9
- # rubocop:disable Metrics/ClassLength
10
27
  # @api private
11
28
  class Instrumenter
12
29
  TRANSACTION_KEY = :__atatus_instrumenter_transaction_key
@@ -39,18 +56,22 @@ module Atatus
39
56
  end
40
57
  end
41
58
 
42
- def initialize(config, stacktrace_builder:, &enqueue)
59
+ def initialize(config, metrics:, stacktrace_builder:, &enqueue)
43
60
  @config = config
44
61
  @stacktrace_builder = stacktrace_builder
45
62
  @enqueue = enqueue
63
+ @metrics = metrics
46
64
 
47
65
  @current = Current.new
48
66
  end
49
67
 
50
- attr_reader :config, :stacktrace_builder, :enqueue
68
+ attr_reader :stacktrace_builder, :enqueue
51
69
 
52
70
  def start
53
71
  debug 'Starting instrumenter'
72
+ # We call register! on @subscriber in case the
73
+ # instrumenter was stopped and started again
74
+ @subscriber&.register!
54
75
  end
55
76
 
56
77
  def stop
@@ -59,7 +80,12 @@ module Atatus
59
80
  self.current_transaction = nil
60
81
  current_spans.pop until current_spans.empty?
61
82
 
62
- @subscriber.unregister! if @subscriber
83
+ @subscriber&.unregister!
84
+ end
85
+
86
+ def handle_forking!
87
+ stop
88
+ start
63
89
  end
64
90
 
65
91
  def subscriber=(subscriber)
@@ -78,10 +104,10 @@ module Atatus
78
104
  @current.transaction = transaction
79
105
  end
80
106
 
81
- # rubocop:disable Metrics/MethodLength
82
107
  def start_transaction(
83
108
  name = nil,
84
109
  type = nil,
110
+ config:,
85
111
  context: nil,
86
112
  trace_context: nil
87
113
  )
@@ -89,10 +115,17 @@ module Atatus
89
115
 
90
116
  if (transaction = current_transaction)
91
117
  raise ExistingTransactionError,
92
- "Transactions may not be nested.\nAlready inside #{transaction}"
118
+ "Transactions may not be nested.\n" \
119
+ "Already inside #{transaction.inspect}"
93
120
  end
94
121
 
95
- sampled = trace_context ? trace_context.recorded? : random_sample?
122
+ if trace_context
123
+ samled = trace_context.recorded?
124
+ sample_rate = trace_context.tracestate.sample_rate
125
+ else
126
+ sampled = random_sample?(config)
127
+ sample_rate = config.transaction_sample_rate
128
+ end
96
129
 
97
130
  transaction =
98
131
  Transaction.new(
@@ -101,14 +134,14 @@ module Atatus
101
134
  context: context,
102
135
  trace_context: trace_context,
103
136
  sampled: sampled,
104
- labels: config.default_labels
137
+ sample_rate: sample_rate,
138
+ config: config
105
139
  )
106
140
 
107
141
  transaction.start
108
142
 
109
143
  self.current_transaction = transaction
110
144
  end
111
- # rubocop:enable Metrics/MethodLength
112
145
 
113
146
  def end_transaction(result = nil)
114
147
  return nil unless (transaction = current_transaction)
@@ -119,6 +152,8 @@ module Atatus
119
152
 
120
153
  enqueue.call transaction
121
154
 
155
+ update_transaction_metrics(transaction)
156
+
122
157
  transaction
123
158
  end
124
159
 
@@ -132,8 +167,8 @@ module Atatus
132
167
  current_spans.last
133
168
  end
134
169
 
135
- # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
136
- # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
170
+ # rubocop:disable Metrics/CyclomaticComplexity
171
+ # rubocop:disable Metrics/PerceivedComplexity
137
172
  # rubocop:disable Metrics/ParameterLists
138
173
  def start_span(
139
174
  name,
@@ -142,32 +177,40 @@ module Atatus
142
177
  action: nil,
143
178
  backtrace: nil,
144
179
  context: nil,
145
- trace_context: nil
180
+ trace_context: nil,
181
+ parent: nil,
182
+ sync: nil
146
183
  )
147
- return unless (transaction = current_transaction)
148
- return unless transaction.sampled?
149
-
150
- transaction.inc_started_spans!
151
184
 
152
- if transaction.max_spans_reached?(config)
153
- transaction.inc_dropped_spans!
154
- return
155
- end
185
+ transaction =
186
+ case parent
187
+ when Span
188
+ parent.transaction
189
+ when Transaction
190
+ parent
191
+ else
192
+ current_transaction
193
+ end
194
+ return unless transaction
195
+ return unless transaction.sampled?
196
+ return unless transaction.inc_started_spans!
156
197
 
157
- parent = current_span || transaction
198
+ parent ||= (current_span || current_transaction)
158
199
 
159
200
  span = Span.new(
160
201
  name: name,
161
202
  subtype: subtype,
162
203
  action: action,
163
- transaction_id: transaction.id,
164
- trace_context: trace_context || parent.trace_context.child,
204
+ transaction: transaction,
205
+ parent: parent,
206
+ trace_context: trace_context,
165
207
  type: type,
166
208
  context: context,
167
- stacktrace_builder: stacktrace_builder
209
+ stacktrace_builder: stacktrace_builder,
210
+ sync: sync
168
211
  )
169
212
 
170
- if backtrace && config.span_frames_min_duration?
213
+ if backtrace && transaction.span_frames_min_duration
171
214
  span.original_backtrace = backtrace
172
215
  end
173
216
 
@@ -176,8 +219,8 @@ module Atatus
176
219
  span.start
177
220
  end
178
221
  # rubocop:enable Metrics/ParameterLists
179
- # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
180
- # rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
222
+ # rubocop:enable Metrics/CyclomaticComplexity
223
+ # rubocop:enable Metrics/PerceivedComplexity
181
224
 
182
225
  def end_span
183
226
  return unless (span = current_spans.pop)
@@ -186,6 +229,8 @@ module Atatus
186
229
 
187
230
  enqueue.call span
188
231
 
232
+ update_span_metrics(span)
233
+
189
234
  span
190
235
  end
191
236
 
@@ -205,7 +250,7 @@ module Atatus
205
250
 
206
251
  def set_user(user)
207
252
  return unless current_transaction
208
- current_transaction.context.user = Context::User.infer(config, user)
253
+ current_transaction.set_user(user)
209
254
  end
210
255
 
211
256
  def inspect
@@ -216,9 +261,69 @@ module Atatus
216
261
 
217
262
  private
218
263
 
219
- def random_sample?
264
+ def random_sample?(config)
220
265
  rand <= config.transaction_sample_rate
221
266
  end
267
+
268
+ def update_transaction_metrics(transaction)
269
+ return unless transaction.collect_metrics?
270
+
271
+ tags = {
272
+ 'transaction.name': transaction.name,
273
+ 'transaction.type': transaction.type
274
+ }
275
+
276
+ @metrics.get(:transaction).timer(
277
+ :'transaction.duration.sum.us',
278
+ tags: tags, reset_on_collect: true
279
+ ).update(transaction.duration)
280
+
281
+ @metrics.get(:transaction).counter(
282
+ :'transaction.duration.count',
283
+ tags: tags, reset_on_collect: true
284
+ ).inc!
285
+
286
+ return unless transaction.sampled?
287
+ return unless transaction.breakdown_metrics
288
+
289
+ @metrics.get(:breakdown).counter(
290
+ :'transaction.breakdown.count',
291
+ tags: tags, reset_on_collect: true
292
+ ).inc!
293
+
294
+ span_tags = tags.merge('span.type': 'app')
295
+
296
+ @metrics.get(:breakdown).timer(
297
+ :'span.self_time.sum.us',
298
+ tags: span_tags, reset_on_collect: true
299
+ ).update(transaction.self_time)
300
+
301
+ @metrics.get(:breakdown).counter(
302
+ :'span.self_time.count',
303
+ tags: span_tags, reset_on_collect: true
304
+ ).inc!
305
+ end
306
+
307
+ def update_span_metrics(span)
308
+ return unless span.transaction.collect_metrics?
309
+
310
+ tags = {
311
+ 'span.type': span.type,
312
+ 'transaction.name': span.transaction.name,
313
+ 'transaction.type': span.transaction.type
314
+ }
315
+
316
+ tags[:'span.subtype'] = span.subtype if span.subtype
317
+
318
+ @metrics.get(:breakdown).timer(
319
+ :'span.self_time.sum.us',
320
+ tags: tags, reset_on_collect: true
321
+ ).update(span.self_time)
322
+
323
+ @metrics.get(:breakdown).counter(
324
+ :'span.self_time.count',
325
+ tags: tags, reset_on_collect: true
326
+ ).inc!
327
+ end
222
328
  end
223
- # rubocop:enable Metrics/ClassLength
224
329
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -1,6 +1,21 @@
1
- # frozen_string_literal: true
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
2
17
 
3
- require 'logger'
18
+ # frozen_string_literal: true
4
19
 
5
20
  module Atatus
6
21
  # @api private
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -13,16 +30,17 @@ module Atatus
13
30
 
14
31
  attr_reader :name, :version
15
32
  end
33
+
16
34
  class Agent < Versioned; end
17
35
  class Framework < Versioned; end
18
36
  class Language < Versioned; end
19
37
  class Runtime < Versioned; end
20
38
 
21
- # rubocop:disable Metrics/MethodLength
22
39
  def initialize(config)
23
40
  @config = config
24
41
 
25
42
  @name = @config.service_name
43
+ @node_name = @config.service_node_name
26
44
  @environment = @config.environment
27
45
  @agent = Agent.new(name: 'ruby', version: VERSION)
28
46
  @framework = Framework.new(
@@ -33,14 +51,12 @@ module Atatus
33
51
  @runtime = lookup_runtime
34
52
  @version = @config.service_version || Util.git_sha
35
53
  end
36
- # rubocop:enable Metrics/MethodLength
37
54
 
38
- attr_reader :name, :environment, :agent, :framework, :language, :runtime,
39
- :version
55
+ attr_reader :name, :node_name, :environment, :agent, :framework, :language,
56
+ :runtime, :version
40
57
 
41
58
  private
42
59
 
43
- # rubocop:disable Metrics/MethodLength
44
60
  def lookup_runtime
45
61
  case RUBY_ENGINE
46
62
  when 'ruby'
@@ -55,7 +71,6 @@ module Atatus
55
71
  )
56
72
  end
57
73
  end
58
- # rubocop:enable Metrics/MethodLength
59
74
  end
60
75
  end
61
76
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -34,7 +51,6 @@ module Atatus
34
51
  end
35
52
  end
36
53
 
37
- # rubocop:disable Metrics/MethodLength
38
54
  def kubernetes
39
55
  @kubernetes =
40
56
  begin
@@ -51,7 +67,6 @@ module Atatus
51
67
  kubernetes
52
68
  end
53
69
  end
54
- # rubocop:enable Metrics/MethodLength
55
70
 
56
71
  private
57
72
 
@@ -66,12 +81,18 @@ module Atatus
66
81
  ENV.fetch('KUBERNETES_POD_UID', kubernetes_pod_uid)
67
82
  end
68
83
 
69
- CONTAINER_ID_REGEX = /^[0-9A-Fa-f]{64}$/.freeze
70
- KUBEPODS_REGEX = %r{(?:^/kubepods/[^/]+/pod([^/]+)$)|(?:^/kubepods\.slice/kubepods-[^/]+\.slice/kubepods-[^/]+-pod([^/]+)\.slice$)}.freeze # rubocop:disable Metrics/LineLength
84
+ CONTAINER_ID_REGEXES = [
85
+ %r{^[[:xdigit:]]{64}$},
86
+ %r{^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4,}$}
87
+ ]
88
+ KUBEPODS_REGEXES = [
89
+ %r{(?:^/kubepods[^\s]*/pod([^/]+)$)},
90
+ %r{(?:^/kubepods\.slice/kubepods-[^/]+\.slice/kubepods-[^/]+-pod([^/]+)\.slice$)}
91
+ ]
71
92
  SYSTEMD_SCOPE_SUFFIX = '.scope'
72
93
 
73
- # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
74
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize
94
+ # rubocop:disable Metrics/PerceivedComplexity
95
+ # rubocop:disable Metrics/CyclomaticComplexity
75
96
  def read_from_cgroup!
76
97
  return unless File.exist?(cgroup_path)
77
98
  IO.readlines(cgroup_path).each do |line|
@@ -103,18 +124,36 @@ module Atatus
103
124
  end
104
125
  end
105
126
 
106
- if (kubepods_match = KUBEPODS_REGEX.match(directory))
127
+ if (kubepods_match = match_kubepods(directory))
107
128
  pod_id = kubepods_match[1] || kubepods_match[2]
108
129
 
109
130
  self.container_id = container_id
110
131
  self.kubernetes_pod_uid = pod_id
111
- elsif CONTAINER_ID_REGEX.match(container_id)
132
+ elsif match_container(container_id)
112
133
  self.container_id = container_id
113
134
  end
114
135
  end
115
136
  end
116
- # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
117
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize
137
+ # rubocop:enable Metrics/PerceivedComplexity
138
+ # rubocop:enable Metrics/CyclomaticComplexity
139
+
140
+ def match_kubepods(directory)
141
+ KUBEPODS_REGEXES.each do |r|
142
+ next unless (match = r.match(directory))
143
+ return match
144
+ end
145
+
146
+ nil
147
+ end
148
+
149
+ def match_container(container_id)
150
+ CONTAINER_ID_REGEXES.each do |r|
151
+ next unless (match = r.match(container_id))
152
+ return match
153
+ end
154
+
155
+ nil
156
+ end
118
157
  end
119
158
  end
120
159
  end
@@ -66,7 +66,7 @@ module Atatus
66
66
  end
67
67
 
68
68
  LINUX_CPUINFO_PATH = '/proc/cpuinfo'.freeze
69
- PROCESSOR_COUNT_REGEX = /^processor\s*:/.freeze
69
+ PROCESSOR_COUNT_REGEX = /processor\s+:\s+([0-9.]+)/.freeze
70
70
  MODEL_NAME_REGEX = /model name.+:(.+)/.freeze
71
71
  CPU_MHZ_REGEX = /cpu MHz\s+:\s+([0-9.]+)/.freeze
72
72
 
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -7,7 +24,7 @@ module Atatus
7
24
  def initialize(config)
8
25
  @config = config
9
26
 
10
- @hostname = @config.hostname || `hostname`.chomp
27
+ @hostname = @config.hostname || self.class.system_hostname
11
28
  @architecture = gem_platform.cpu
12
29
  @platform = gem_platform.os
13
30
 
@@ -21,11 +38,13 @@ module Atatus
21
38
 
22
39
  attr_reader :hostname, :architecture, :platform, :container, :kubernetes, :hwinfo, :osinfo
23
40
 
24
- private
25
-
26
41
  def gem_platform
27
42
  @gem_platform ||= Gem::Platform.local
28
43
  end
44
+
45
+ def self.system_hostname
46
+ @system_hostname ||= `hostname`.chomp
47
+ end
29
48
  end
30
49
  end
31
50
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -0,0 +1,31 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ module Atatus
21
+ module Metrics
22
+ # @api private
23
+ class BreakdownSet < SpanScopedSet
24
+ def initialize(config)
25
+ super
26
+
27
+ disable! unless config.breakdown_metrics?
28
+ end
29
+ end
30
+ end
31
+ end