gitlab-exporter 10.0.0 → 10.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f7115d7a7e8604d15ad7734afd3280c22edf9f6911af159f9386f2a9d495701
4
- data.tar.gz: 7b050b23851b8073da229a5347b0c22afd641a1420859f37f0a0b8a7a4113244
3
+ metadata.gz: 4c392268186f090b025d290c818f821120f5160a9a59f2e3ba228f26da0b8505
4
+ data.tar.gz: 3771d5912cb2a310183a1f78a8e24d191eb502d20c2beab3c327994243ae7077
5
5
  SHA512:
6
- metadata.gz: 848007d860313f8d62239b3f97a9024944aec9ddbfe6ea97472eaae64ddfc6e03cc056fe9466ce719209a6fad2b5a88947ff085f25ed6cf4ecf6421c1db576d7
7
- data.tar.gz: f751e8af1eea6d30eb00dae65ec41681b50e9481a392b6521fde15c07934d8550dd2c3e3b65ea13ae6cbc0adadfe30986bad418c88172699b3172d20f9f62a75
6
+ metadata.gz: c9ee25b554e51484e4cba96070677c90e3cbad17da49eef2e2f649ad4d4ff125e8e2982cfb6e952444436d7ead6f603f6173ba1270b7112b3de75126cb57b318
7
+ data.tar.gz: e6038eff74531eb7c0561437cb676336853d9a597b588d07a9561a4561ef165a3ad2f528711b3a2f5d61ebfc8df341ef93ec4d15274fb7efcc88859abc1bc6c3
data/.gitlab-ci.yml CHANGED
@@ -6,6 +6,10 @@ include:
6
6
  - template: Security/SAST.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml
7
7
  - template: Security/Secret-Detection.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/lib/gitlab/ci/templates/Security/Secret-Detection.gitlab-ci.yml
8
8
 
9
+ stages:
10
+ - test
11
+ - dast
12
+
9
13
  default:
10
14
  image: ruby:2.7
11
15
  cache:
data/Gemfile.lock CHANGED
@@ -1,30 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-exporter (10.0.0)
5
- connection_pool (~> 2.2.1)
6
- pg (~> 1.1)
7
- puma (~> 5.1.1)
8
- quantile (~> 0.2.0)
9
- redis (~> 4.1.2)
10
- redis-namespace (~> 1.6.0)
11
- sidekiq (~> 5.2.1)
12
- sinatra (~> 2.0.4)
4
+ gitlab-exporter (10.5.0)
5
+ connection_pool (= 2.2.5)
6
+ pg (= 1.2.3)
7
+ puma (= 5.3.2)
8
+ quantile (= 0.2.1)
9
+ redis (= 4.1.4)
10
+ redis-namespace (= 1.6.0)
11
+ sidekiq (= 5.2.9)
12
+ sinatra (= 2.0.8.1)
13
13
 
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
17
  ast (2.4.1)
18
- connection_pool (2.2.3)
18
+ connection_pool (2.2.5)
19
19
  diff-lcs (1.3)
20
20
  mustermann (1.1.1)
21
21
  ruby2_keywords (~> 0.0.1)
22
- nio4r (2.5.4)
22
+ nio4r (2.5.7)
23
23
  parallel (1.20.1)
24
24
  parser (3.0.0.0)
25
25
  ast (~> 2.4.1)
26
26
  pg (1.2.3)
27
- puma (5.1.1)
27
+ puma (5.3.2)
28
28
  nio4r (~> 2.0)
29
29
  quantile (0.2.1)
30
30
  rack (2.2.3)
data/README.md CHANGED
@@ -33,23 +33,6 @@ metrics.
33
33
  * [git pull/push timings](lib/gitlab_exporter/git.rb) --
34
34
  `git_pull_time_milliseconds`, `git_push_time_milliseconds`
35
35
  * git processes stats (see Process below)
36
- 1. [Process](lib/gitlab_exporter/process.rb)
37
- * CPU time -- `process_cpu_seconds_total`
38
- * Start time -- `process_start_time_seconds`
39
- * Count -- `process_count`
40
- * Memory usage
41
- * Data from /proc/<pid>/cmdline:
42
- * `process_resident_memory_bytes`
43
- * `process_virtual_memory_bytes`
44
- * Data from /proc/<pid>/smaps -- `probe_smaps` (off by default):
45
- * `process_smaps_size_bytes`
46
- * `process_smaps_rss_bytes`
47
- * `process_smaps_shared_clean_bytes`
48
- * `process_smaps_shared_dirty_bytes`
49
- * `process_smaps_private_clean_bytes`
50
- * `process_smaps_private_dirty_bytes`
51
- * `process_smaps_swap_bytes`
52
- * `process_smaps_pss_bytes`
53
36
  1. [Sidekiq](lib/gitlab_exporter/sidekiq.rb)
54
37
  * Stats
55
38
  * `sidekiq_jobs_processed_total`
data/bin/gitlab-exporter CHANGED
@@ -3,6 +3,7 @@
3
3
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
4
 
5
5
  require "rubygems"
6
+ require "bundler"
6
7
  require "bundler/setup"
7
8
  require "optparse"
8
9
  require "gitlab_exporter"
@@ -46,7 +46,6 @@ probes:
46
46
  <<: *db_common
47
47
  opts:
48
48
  <<: *db_common_opts
49
- allowed_repeated_commands_count: 2
50
49
  created_builds_counting_disabled: true
51
50
  unarchived_traces_offset_minutes: 1440
52
51
  tuple_stats:
@@ -79,8 +78,6 @@ probes:
79
78
  opts:
80
79
  - pid_or_pattern: "sidekiq .* \\[.*?\\]"
81
80
  name: sidekiq
82
- - pid_or_pattern: "unicorn.* worker\\[.*?\\]"
83
- name: unicorn
84
81
  - pid_or_pattern: "git-upload-pack --stateless-rpc"
85
82
  name: git_upload_pack
86
83
  quantiles: true
@@ -20,14 +20,14 @@ Gem::Specification.new do |s|
20
20
  s.homepage = "http://gitlab.com"
21
21
  s.license = "MIT"
22
22
 
23
- s.add_runtime_dependency "connection_pool", "~> 2.2.1"
24
- s.add_runtime_dependency "pg", "~> 1.1"
25
- s.add_runtime_dependency "puma", "~> 5.1.1"
26
- s.add_runtime_dependency "quantile", "~> 0.2.0"
27
- s.add_runtime_dependency "redis", "~> 4.1.2"
28
- s.add_runtime_dependency "redis-namespace", "~> 1.6.0"
29
- s.add_runtime_dependency "sidekiq", "~> 5.2.1"
30
- s.add_runtime_dependency "sinatra", "~> 2.0.4"
23
+ s.add_runtime_dependency "connection_pool", "2.2.5"
24
+ s.add_runtime_dependency "pg", "1.2.3"
25
+ s.add_runtime_dependency "puma", "5.3.2"
26
+ s.add_runtime_dependency "quantile", "0.2.1"
27
+ s.add_runtime_dependency "redis", "4.1.4"
28
+ s.add_runtime_dependency "redis-namespace", "1.6.0"
29
+ s.add_runtime_dependency "sidekiq", "5.2.9"
30
+ s.add_runtime_dependency "sinatra", "2.0.8.1"
31
31
 
32
32
  s.add_development_dependency "rspec", "~> 3.7.0"
33
33
  s.add_development_dependency "rspec-expectations", "~> 3.7.0"
@@ -217,7 +217,7 @@ module GitLab
217
217
  opts.on("--pid=123", "Process ID") do |val|
218
218
  @pid = val
219
219
  end
220
- opts.on("--pattern=unicorn", "Process command pattern") do |val|
220
+ opts.on("--pattern=worker", "Process command pattern") do |val|
221
221
  @pattern = val
222
222
  end
223
223
  opts.on("--name=NAME", "Process name to be used in metrics") do |val|
@@ -147,100 +147,6 @@ module GitLab
147
147
  SELECT COUNT(*) FROM licenses
148
148
  SQL
149
149
 
150
- REPEATED_COMMANDS_QUERY_EE =
151
- <<~SQL.freeze
152
- SELECT
153
- subquery.namespace_id,
154
- subquery.shared_runners_enabled,
155
- subquery.project_id,
156
- subquery.status,
157
- subquery.has_minutes,
158
- MAX(subquery.count) as count
159
- FROM (
160
- SELECT
161
- projects.namespace_id,
162
- projects.shared_runners_enabled,
163
- ci_builds.project_id,
164
- ci_builds.commit_id,
165
- ci_builds.status,
166
- (COALESCE(namespaces.shared_runners_minutes_limit, application_settings.shared_runners_minutes, 0) = 0 OR
167
- COALESCE(namespace_statistics.shared_runners_seconds, 0) < COALESCE(namespaces.shared_runners_minutes_limit, application_settings.shared_runners_minutes, 0) * 60) as has_minutes,
168
- COUNT(*) AS count
169
- FROM ci_builds
170
- JOIN projects
171
- ON projects.id = ci_builds.project_id
172
- JOIN namespaces
173
- ON namespaces.id = projects.namespace_id
174
- LEFT JOIN namespace_statistics
175
- ON namespace_statistics.namespace_id = namespaces.id
176
- JOIN application_settings ON (TRUE)
177
- WHERE ci_builds.type = 'Ci::Build'
178
- AND ci_builds.status IN ('running', 'pending')
179
- -- The created_at filter has been introduced for performance reasons only
180
- AND ci_builds.created_at > NOW() - INTERVAL '7 days'
181
- GROUP BY
182
- projects.namespace_id,
183
- projects.shared_runners_enabled,
184
- ci_builds.project_id,
185
- ci_builds.commit_id,
186
- ci_builds.status,
187
- ci_builds.commands,
188
- namespaces.shared_runners_minutes_limit,
189
- namespace_statistics.shared_runners_seconds,
190
- application_settings.shared_runners_minutes
191
- HAVING COUNT(*) > %d
192
- ) AS subquery
193
- GROUP BY
194
- subquery.namespace_id,
195
- subquery.shared_runners_enabled,
196
- subquery.project_id,
197
- subquery.commit_id,
198
- subquery.status,
199
- subquery.has_minutes
200
- SQL
201
-
202
- REPEATED_COMMANDS_QUERY_CE =
203
- <<~SQL.freeze
204
- SELECT
205
- subquery.namespace_id,
206
- subquery.shared_runners_enabled,
207
- subquery.project_id,
208
- subquery.status,
209
- MAX(subquery.count) as count
210
- FROM (
211
- SELECT
212
- projects.namespace_id,
213
- projects.shared_runners_enabled,
214
- ci_builds.project_id,
215
- ci_builds.commit_id,
216
- ci_builds.status,
217
- COUNT(*) AS count
218
- FROM ci_builds
219
- JOIN projects
220
- ON projects.id = ci_builds.project_id
221
- JOIN namespaces
222
- ON namespaces.id = projects.namespace_id
223
- WHERE ci_builds.type = 'Ci::Build'
224
- AND ci_builds.status IN ('running', 'pending')
225
- -- The created_at filter has been introduced for performance reasons only
226
- AND ci_builds.created_at > NOW() - INTERVAL '7 days'
227
- GROUP BY
228
- projects.namespace_id,
229
- projects.shared_runners_enabled,
230
- ci_builds.project_id,
231
- ci_builds.commit_id,
232
- ci_builds.status,
233
- ci_builds.commands
234
- HAVING COUNT(*) > %d
235
- ) AS subquery
236
- GROUP BY
237
- subquery.namespace_id,
238
- subquery.shared_runners_enabled,
239
- subquery.project_id,
240
- subquery.commit_id,
241
- subquery.status
242
- SQL
243
-
244
150
  UNARCHIVED_TRACES_QUERY =
245
151
  <<~SQL.freeze
246
152
  SELECT
@@ -265,7 +171,6 @@ module GitLab
265
171
  def initialize(opts, logger: nil)
266
172
  super(opts, logger: logger)
267
173
 
268
- @allowed_repeated_commands_count = opts[:allowed_repeated_commands_count]
269
174
  @created_builds_counting_disabled = opts[:created_builds_counting_disabled]
270
175
  @unarchived_traces_offset_minutes = opts[:unarchived_traces_offset_minutes]
271
176
  end
@@ -276,7 +181,6 @@ module GitLab
276
181
  results[:pending_builds] = builds(STATUS_PENDING)
277
182
  results[:stale_builds] = stale_builds
278
183
  results[:per_runner] = per_runner_builds
279
- results[:repeated_commands] = repeated_commands
280
184
  results[:unarchived_traces] = unarchived_traces
281
185
  results
282
186
  end
@@ -335,34 +239,6 @@ module GitLab
335
239
  include_ee_fields(values, row)
336
240
  end
337
241
 
338
- def repeated_commands
339
- results = []
340
-
341
- query = ee? ? REPEATED_COMMANDS_QUERY_EE : REPEATED_COMMANDS_QUERY_CE
342
- query = query % [allowed_repeated_commands_count] # rubocop:disable Style/FormatString
343
- exec_query_with_custom_random_page_cost(query).each do |row|
344
- results << transform_repeated_commands_row_to_values(row)
345
- end
346
-
347
- results
348
- rescue PG::UndefinedTable, PG::UndefinedColumn
349
- []
350
- end
351
-
352
- def allowed_repeated_commands_count
353
- @allowed_repeated_commands_count ||= 2
354
- end
355
-
356
- def transform_repeated_commands_row_to_values(row)
357
- values = { namespace: row["namespace_id"].to_s,
358
- project: row["project_id"].to_s,
359
- shared_runners: row["shared_runners_enabled"] == "t" ? "yes" : "no",
360
- status: row["status"].to_s,
361
- value: row["count"].to_i }
362
-
363
- include_has_minutes_field(values, row)
364
- end
365
-
366
242
  def unarchived_traces
367
243
  time = Time.now - (unarchived_traces_offset_minutes * 60)
368
244
  query = UNARCHIVED_TRACES_QUERY % [time.strftime("%F %T")] # rubocop:disable Style/FormatString
@@ -422,7 +298,6 @@ module GitLab
422
298
  @metrics = metrics
423
299
 
424
300
  collector_opts = { connection_string: opts[:connection_string],
425
- allowed_repeated_commands_count: opts[:allowed_repeated_commands_count],
426
301
  created_builds_counting_disabled: opts[:created_builds_counting_disabled],
427
302
  unarchived_traces_offset_minutes: opts[:unarchived_traces_offset_minutes] }
428
303
  @collector = CiBuildsCollector.new(collector_opts, logger: logger)
@@ -435,7 +310,6 @@ module GitLab
435
310
  ci_builds_metrics(@results[:pending_builds], "ci_pending_builds")
436
311
  ci_stale_builds_metrics
437
312
  metrics_per_runner
438
- repeated_commands_metrics
439
313
  unarchived_traces_metrics
440
314
 
441
315
  self
@@ -520,14 +394,6 @@ module GitLab
520
394
  @metrics.add(metric_name, value.to_f, selected_labels)
521
395
  end
522
396
 
523
- def repeated_commands_metrics
524
- @results[:repeated_commands].each do |metric|
525
- value = metric.delete(:value)
526
-
527
- @metrics.add("ci_repeated_commands_builds", value.to_f, metric)
528
- end
529
- end
530
-
531
397
  def unarchived_traces_metrics
532
398
  @metrics.add("ci_unarchived_traces", @results[:unarchived_traces].to_f)
533
399
  end
@@ -15,6 +15,21 @@ module GitLab
15
15
  @include_timestamp = include_timestamp
16
16
  end
17
17
 
18
+ class << self
19
+ def describe(name, description)
20
+ @metric_descriptions ||= {}
21
+ @metric_descriptions[name] = description
22
+ end
23
+
24
+ def description(name)
25
+ @metric_descriptions && @metric_descriptions[name]
26
+ end
27
+
28
+ def clear_descriptions
29
+ @metric_descriptions = {}
30
+ end
31
+ end
32
+
18
33
  def add(name, value, quantile = false, **labels)
19
34
  fail "value '#{value}' must be a number" unless value.is_a?(Numeric)
20
35
 
@@ -32,6 +47,8 @@ module GitLab
32
47
 
33
48
  buffer = ""
34
49
  @metrics.each do |name, measurements|
50
+ buffer << "# HELP #{name} #{self.class.description(name)}\n" if self.class.description(name)
51
+
35
52
  measurements.each do |measurement|
36
53
  buffer << name.to_s
37
54
  labels = (measurement[:labels] || {}).map { |label, value| "#{label}=\"#{value}\"" }.join(",")
@@ -10,6 +10,13 @@ module GitLab
10
10
  QUEUE_JOB_STATS_SCRIPT = File.read(File.expand_path("#{__FILE__}/../sidekiq_queue_job_stats.lua")).freeze
11
11
  QUEUE_JOB_STATS_SHA = Digest::SHA1.hexdigest(QUEUE_JOB_STATS_SCRIPT).freeze
12
12
 
13
+ # The maximum depth (from the head) of each queue to probe. Probing the
14
+ # entirety of a very large queue will take longer and run the risk of
15
+ # timing out. But when we have a very large queue, we are most in need of
16
+ # reliable metrics. This trades off completeness for predictability by
17
+ # only taking a limited amount of items from the head of the queue.
18
+ PROBE_JOBS_LIMIT = 1_000
19
+
13
20
  POOL_SIZE = 3
14
21
 
15
22
  # This timeout is configured to higher interval than scrapping
@@ -17,6 +24,9 @@ module GitLab
17
24
  # needed to be re-initialized
18
25
  POOL_TIMEOUT = 90
19
26
 
27
+ PrometheusMetrics.describe("sidekiq_enqueued_jobs",
28
+ "Total number of jobs enqueued by class name. Only inspects the first #{PROBE_JOBS_LIMIT} jobs per queue.") # rubocop:disable Layout/LineLength
29
+
20
30
  def self.connection_pool
21
31
  @@connection_pool ||= Hash.new do |h, connection_hash| # rubocop:disable Style/ClassVars
22
32
  config = connection_hash.merge(pool_timeout: POOL_TIMEOUT, size: POOL_SIZE)
@@ -62,6 +72,13 @@ module GitLab
62
72
  self
63
73
  end
64
74
 
75
+ # Count worker classes present in Sidekiq queues. This uses a Lua
76
+ # script to find all jobs in all queues. That script will block
77
+ # all other Redis commands:
78
+ # https://redis.io/commands/eval#atomicity-of-scripts
79
+ #
80
+ # The script is generally fast, but may be slower with very large
81
+ # queues, which is why this is not enabled by default.
65
82
  def probe_jobs
66
83
  with_sidekiq do
67
84
  job_stats = {}
@@ -84,6 +101,38 @@ module GitLab
84
101
  self
85
102
  end
86
103
 
104
+ # This does the same as #probe_jobs, but only looks at the first
105
+ # PROBE_JOBS_LIMIT jobs in each queue. This means that we run a
106
+ # single LRANGE command for each queue, which does not block other
107
+ # commands. For queues over PROBE_JOBS_LIMIT in size, this means
108
+ # that we will not have completely accurate statistics, but the
109
+ # probe performance will also not degrade as the queue gets
110
+ # larger.
111
+ #
112
+ # DO NOT USE this and probe_jobs together, as they export the same
113
+ # metric (sidekiq_enqueued_jobs).
114
+ def probe_jobs_limit
115
+ with_sidekiq do
116
+ job_stats = Hash.new(0)
117
+
118
+ Sidekiq::Queue.all.each do |queue|
119
+ Sidekiq.redis do |conn|
120
+ conn.lrange("queue:#{queue.name}", 0, PROBE_JOBS_LIMIT).each do |job|
121
+ job_class = Sidekiq.load_json(job)["class"]
122
+
123
+ job_stats[job_class] += 1
124
+ end
125
+ end
126
+ end
127
+
128
+ job_stats.each do |class_name, count|
129
+ @metrics.add("sidekiq_enqueued_jobs", count, name: class_name)
130
+ end
131
+ end
132
+
133
+ self
134
+ end
135
+
87
136
  def probe_workers
88
137
  with_sidekiq do
89
138
  worker_stats = Hash.new(0)
@@ -1,5 +1,5 @@
1
1
  module GitLab
2
2
  module Exporter
3
- VERSION = "10.0.0".freeze
3
+ VERSION = "10.5.0".freeze
4
4
  end
5
5
  end
@@ -10,12 +10,9 @@ describe GitLab::Exporter::Database do
10
10
  let(:per_runner_query_ee) { "SELECT ALL RUNNING PER RUNNER EE" }
11
11
  let(:per_runner_query_ce) { "SELECT ALL RUNNING PER RUNNER CE" }
12
12
  let(:ee_check_query) { "SELECT COUNT(*) FROM licenses" }
13
- let(:repeated_commands_query_ee) { "SELECT EE REPEATED COMNANDS %d" }
14
- let(:repeated_commands_query_ce) { "SELECT CE REPEATED COMNANDS %d" }
15
13
  let(:unarchived_traces_query) { "SELECT UNARCHIVED TRACES %s LIST" }
16
14
  let(:connection_pool) { double("connection pool") }
17
15
  let(:connection) { double("connection") }
18
- let(:allowed_repeated_commands_count) { 5 }
19
16
  let(:created_builds_counting_disabled) { true }
20
17
  let(:time_now) { Time.new(2019, 4, 9, 6, 30, 0) }
21
18
  let(:unarchived_traces_query_time) { "2019-04-09 05:30:00" }
@@ -63,22 +60,6 @@ describe GitLab::Exporter::Database do
63
60
  end
64
61
  # rubocop:enable Metrics/ParameterLists
65
62
 
66
- # rubocop:disable Metrics/ParameterLists
67
- def repeated_commands_query_row_ee(namespace_id, shared_runners_enabled, project_id, status, has_minutes, count)
68
- row = repeated_commands_query_row_ce(namespace_id, shared_runners_enabled, project_id, status, count)
69
- row["has_minutes"] = has_minutes
70
- row
71
- end
72
- # rubocop:enable Metrics/ParameterLists
73
-
74
- def repeated_commands_query_row_ce(namespace_id, shared_runners_enabled, project_id, status, count)
75
- { "namespace_id" => namespace_id,
76
- "shared_runners_enabled" => shared_runners_enabled,
77
- "project_id" => project_id,
78
- "status" => status,
79
- "count" => count }
80
- end
81
-
82
63
  before do
83
64
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::SET_RANDOM_PAGE_COST", set_random_page_cost_query)
84
65
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::BUILDS_QUERY_EE", builds_query_ee)
@@ -87,8 +68,6 @@ describe GitLab::Exporter::Database do
87
68
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::PER_RUNNER_QUERY_EE", per_runner_query_ee)
88
69
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::PER_RUNNER_QUERY_CE", per_runner_query_ce)
89
70
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::EE_CHECK_QUERY", ee_check_query)
90
- stub_const("GitLab::Exporter::Database::CiBuildsCollector::REPEATED_COMMANDS_QUERY_EE", repeated_commands_query_ee)
91
- stub_const("GitLab::Exporter::Database::CiBuildsCollector::REPEATED_COMMANDS_QUERY_CE", repeated_commands_query_ce)
92
71
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::UNARCHIVED_TRACES_QUERY", unarchived_traces_query)
93
72
 
94
73
  allow_any_instance_of(GitLab::Exporter::Database::CiBuildsCollector).to receive(:connection_pool).and_return(connection_pool)
@@ -130,24 +109,6 @@ describe GitLab::Exporter::Database do
130
109
  per_runner_query_row_ce(2, "project_type", 3, nil, 3, 5),
131
110
  per_runner_query_row_ce(3, "project_type", 4, nil, 3, 5)])
132
111
 
133
- # rubocop:disable Style/FormatString
134
- repeated_commands_query_ee_with_limit = repeated_commands_query_ee % [allowed_repeated_commands_count]
135
- repeated_commands_query_ce_with_limit = repeated_commands_query_ce % [allowed_repeated_commands_count]
136
- # rubocop:enable Style/FormatString
137
-
138
- allow(connection).to receive(:exec)
139
- .with(repeated_commands_query_ee_with_limit)
140
- .and_return([repeated_commands_query_row_ee(1, "t", 1, "pending", "t", 10),
141
- repeated_commands_query_row_ee(2, "f", 2, "running", "f", 20),
142
- repeated_commands_query_row_ee(1, "f", 3, "pending", "t", 30),
143
- repeated_commands_query_row_ee(2, "t", 4, "running", "f", 40)])
144
- allow(connection).to receive(:exec)
145
- .with(repeated_commands_query_ce_with_limit)
146
- .and_return([repeated_commands_query_row_ce(1, "t", 1, "pending", 10),
147
- repeated_commands_query_row_ce(2, "f", 2, "running", 20),
148
- repeated_commands_query_row_ce(1, "f", 3, "pending", 30),
149
- repeated_commands_query_row_ce(2, "t", 4, "running", 40)])
150
-
151
112
  unarchived_traces_query_with_time = unarchived_traces_query % [unarchived_traces_query_time] # rubocop:disable Style/FormatString
152
113
 
153
114
  allow(connection).to receive(:exec).with(unarchived_traces_query_with_time).and_return([{ "count" => 10 }])
@@ -156,7 +117,6 @@ describe GitLab::Exporter::Database do
156
117
  describe GitLab::Exporter::Database::CiBuildsCollector do
157
118
  let(:collector) do
158
119
  described_class.new(connection_string: "host=localhost",
159
- allowed_repeated_commands_count: allowed_repeated_commands_count,
160
120
  created_builds_counting_disabled: created_builds_counting_disabled,
161
121
  unarchived_traces_offset_minutes: unarchived_traces_offset_minutes)
162
122
  end
@@ -195,10 +155,6 @@ describe GitLab::Exporter::Database do
195
155
  expect(subject[:stale_builds]).to eq(expected_stale_builds)
196
156
  end
197
157
 
198
- it "returns raw repeated_commands data" do
199
- expect(subject[:repeated_commands]).to include(*expected_repeated_commands)
200
- end
201
-
202
158
  it "returns raw unarchived_traces data" do
203
159
  expect(subject[:unarchived_traces]).to eq(expected_unarchived_traces)
204
160
  end
@@ -222,12 +178,6 @@ describe GitLab::Exporter::Database do
222
178
  { runner: "2", runner_type: "project_type", namespace: "3", mirror: "yes", mirror_trigger_builds: "yes", scheduled: "no", triggered: "yes", has_minutes: "yes", value: 5.0 },
223
179
  { runner: "3", runner_type: "project_type", namespace: "4", mirror: "yes", mirror_trigger_builds: "yes", scheduled: "no", triggered: "yes", has_minutes: "no", value: 5.0 }]
224
180
  end
225
- let(:expected_repeated_commands) do
226
- [{ namespace: "1", project: "1", shared_runners: "yes", status: "pending", has_minutes: "yes", value: 10.0 },
227
- { namespace: "2", project: "2", shared_runners: "no", status: "running", has_minutes: "no", value: 20.0 },
228
- { namespace: "1", project: "3", shared_runners: "no", status: "pending", has_minutes: "yes", value: 30.0 },
229
- { namespace: "2", project: "4", shared_runners: "yes", status: "running", has_minutes: "no", value: 40.0 }]
230
- end
231
181
 
232
182
  before do
233
183
  stub_ee
@@ -254,12 +204,6 @@ describe GitLab::Exporter::Database do
254
204
  { runner: "2", runner_type: "project_type", namespace: "3", scheduled: "no", triggered: "yes", value: 5 },
255
205
  { runner: "3", runner_type: "project_type", namespace: "4", scheduled: "no", triggered: "yes", value: 5 }]
256
206
  end
257
- let(:expected_repeated_commands) do
258
- [{ namespace: "1", project: "1", shared_runners: "yes", status: "pending", value: 10 },
259
- { namespace: "2", project: "2", shared_runners: "no", status: "running", value: 20 },
260
- { namespace: "1", project: "3", shared_runners: "no", status: "pending", value: 30 },
261
- { namespace: "2", project: "4", shared_runners: "yes", status: "running", value: 40 }]
262
- end
263
207
 
264
208
  before do
265
209
  stub_ce
@@ -273,7 +217,6 @@ describe GitLab::Exporter::Database do
273
217
  let(:writer) { StringIO.new }
274
218
  let(:prober) do
275
219
  opts = { connection_string: "host=localhost",
276
- allowed_repeated_commands_count: allowed_repeated_commands_count,
277
220
  created_builds_counting_disabled: created_builds_counting_disabled,
278
221
  unarchived_traces_offset_minutes: unarchived_traces_offset_minutes }
279
222
  described_class.new(opts,
@@ -324,12 +267,6 @@ describe GitLab::Exporter::Database do
324
267
  end
325
268
  end
326
269
 
327
- it "responds with repeated commands Prometheus metrics" do
328
- ci_repeated_commands_builds_lines.each do |expected_line|
329
- expect(subject).to match(Regexp.new("^#{expected_line}$", Regexp::MULTILINE))
330
- end
331
- end
332
-
333
270
  it "responds with stale builds Prometheus metrics" do
334
271
  expect(subject).to match(/^ci_stale_builds 2.0$/m)
335
272
  end
@@ -372,12 +309,6 @@ describe GitLab::Exporter::Database do
372
309
  'ci_running_builds\{has_minutes="yes",mirror="yes",mirror_trigger_builds="yes",namespace="",runner="2",runner_type="project_type",scheduled="no",triggered="yes"\} 5.0',
373
310
  'ci_running_builds\{has_minutes="no",mirror="yes",mirror_trigger_builds="yes",namespace="",runner="3",runner_type="project_type",scheduled="no",triggered="yes"\} 5.0']
374
311
  end
375
- let(:ci_repeated_commands_builds_lines) do
376
- ['ci_repeated_commands_builds\{namespace="1",project="1",shared_runners="yes",status="pending",has_minutes="yes"\} 10.0',
377
- 'ci_repeated_commands_builds\{namespace="2",project="2",shared_runners="no",status="running",has_minutes="no"\} 20.0',
378
- 'ci_repeated_commands_builds\{namespace="1",project="3",shared_runners="no",status="pending",has_minutes="yes"\} 30.0',
379
- 'ci_repeated_commands_builds\{namespace="2",project="4",shared_runners="yes",status="running",has_minutes="no"\} 40.0']
380
- end
381
312
  let(:namespace_out_of_limit) { 2 }
382
313
 
383
314
  before do
@@ -403,12 +334,6 @@ describe GitLab::Exporter::Database do
403
334
  'ci_running_builds\{namespace="",runner="2",runner_type="project_type",scheduled="no",triggered="yes"\} 10.0',
404
335
  'ci_running_builds\{namespace="",runner="3",runner_type="project_type",scheduled="no",triggered="yes"\} 5.0']
405
336
  end
406
- let(:ci_repeated_commands_builds_lines) do
407
- ['ci_repeated_commands_builds\{namespace="1",project="1",shared_runners="yes",status="pending"\} 10.0',
408
- 'ci_repeated_commands_builds\{namespace="2",project="2",shared_runners="no",status="running"\} 20.0',
409
- 'ci_repeated_commands_builds\{namespace="1",project="3",shared_runners="no",status="pending"\} 30.0',
410
- 'ci_repeated_commands_builds\{namespace="2",project="4",shared_runners="yes",status="running"\} 40.0']
411
- end
412
337
  let(:namespace_out_of_limit) { 0 }
413
338
 
414
339
  before do
@@ -23,4 +23,21 @@ describe GitLab::Exporter::PrometheusMetrics do
23
23
  subject.add("mymetric", "invalid", mylabel: "x", myotherlabel: "y").to_s
24
24
  }.to raise_error(RuntimeError)
25
25
  end
26
+
27
+ it "supports described metrics" do
28
+ time = Time.now
29
+
30
+ allow(Time).to receive(:now).and_return(time)
31
+
32
+ described_class.describe("mymetric", "description")
33
+ described_class.describe("missingmetric", "otherdescription")
34
+ subject.add("mymetric", 1.3, mylabel: "x", myotherlabel: "y")
35
+
36
+ expect(subject.to_s).to eq(<<~METRICS)
37
+ # HELP mymetric description
38
+ mymetric{mylabel="x",myotherlabel="y"} 1.3 #{(time.to_f * 1000).to_i}
39
+ METRICS
40
+
41
+ described_class.clear_descriptions
42
+ end
26
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0
4
+ version: 10.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Carranza
@@ -14,114 +14,114 @@ dependencies:
14
14
  name: connection_pool
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.1
19
+ version: 2.2.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.1
26
+ version: 2.2.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: 1.2.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: 1.2.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: puma
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 5.1.1
47
+ version: 5.3.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 5.1.1
54
+ version: 5.3.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: quantile
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.0
61
+ version: 0.2.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.0
68
+ version: 0.2.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: redis
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 4.1.2
75
+ version: 4.1.4
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 4.1.2
82
+ version: 4.1.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: redis-namespace
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - '='
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.6.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - '='
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.6.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sidekiq
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 5.2.1
103
+ version: 5.2.9
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 5.2.1
110
+ version: 5.2.9
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: sinatra
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 2.0.4
117
+ version: 2.0.8.1
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 2.0.4
124
+ version: 2.0.8.1
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement