gitlab-exporter 7.0.2 → 7.1.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: bd49abef867540a7fcfb667672ddef699d7bf883ddf4a3fc3856b1097959386b
4
- data.tar.gz: e959328537cd1b32003a9d1d7f006dc4812bf52bf82e71dab9a972f4ee86e4d5
3
+ metadata.gz: 2590101193dd650767c1f39170beb0b54661c188b7c1222fa7d01d59ee1f442a
4
+ data.tar.gz: 9237f257766fefe33cf0e398a86d44ecae609a393c046c7e5203b07a74adaca4
5
5
  SHA512:
6
- metadata.gz: 6c6a2a358ae1f30483f35cad1e26e5d074772d30522cb9bfea85436481f59f160170c90a309012f8def286808ebc334d3b0f1c451045a99fc7a7048505b7efc9
7
- data.tar.gz: 2df79f4b275b371846160f3d552a14254a21dcad1ba2e3650c92383384d17671b325d4e5daf7235b89f83c16eb7a825ca60b38be8a5f145df1c0ca8be73bdeaa
6
+ metadata.gz: 4109296df37f483e64b5c3f9c9da8ce6359a8b36cbb8b2bc7a40c3147ee0401fafee78829b6e67e43167b1a859d771669e6f94e85f7ebf8529a7bbea45be6431
7
+ data.tar.gz: e4d05c4fad006d5a27f693887320b6f2a633f96b1109e97f7e89f5b990d695528b72ef2e7b876901d520df3f4be6c6b24850208228923c227443e06b70b81988
@@ -26,3 +26,11 @@ rspec:
26
26
  rubocop:
27
27
  script:
28
28
  - bundle exec rubocop
29
+
30
+ include:
31
+ - template: Security/DAST.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml
32
+ - template: Security/Container-Scanning.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml
33
+ - template: Security/Dependency-Scanning.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml
34
+ - template: Security/License-Scanning.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/License-Scanning.gitlab-ci.yml
35
+ - template: Security/SAST.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml
36
+
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-exporter (7.0.2)
4
+ gitlab-exporter (7.1.0)
5
5
  connection_pool (~> 2.2.1)
6
6
  pg (~> 1.1)
7
7
  quantile (~> 0.2.0)
@@ -14,19 +14,20 @@ GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
16
  ast (2.4.0)
17
- connection_pool (2.2.2)
17
+ connection_pool (2.2.3)
18
18
  diff-lcs (1.3)
19
- mustermann (1.0.3)
19
+ mustermann (1.1.1)
20
+ ruby2_keywords (~> 0.0.1)
20
21
  parser (2.5.1.0)
21
22
  ast (~> 2.4.0)
22
- pg (1.2.2)
23
+ pg (1.2.3)
23
24
  powerpack (0.1.1)
24
25
  quantile (0.2.1)
25
- rack (2.0.7)
26
- rack-protection (2.0.7)
26
+ rack (2.2.3)
27
+ rack-protection (2.0.8.1)
27
28
  rack
28
29
  rainbow (2.1.0)
29
- redis (4.1.3)
30
+ redis (4.1.4)
30
31
  redis-namespace (1.6.0)
31
32
  redis (>= 3.0.4)
32
33
  rspec (3.7.0)
@@ -49,17 +50,18 @@ GEM
49
50
  ruby-progressbar (~> 1.7)
50
51
  unicode-display_width (~> 1.0, >= 1.0.1)
51
52
  ruby-progressbar (1.8.1)
52
- sidekiq (5.2.7)
53
+ ruby2_keywords (0.0.2)
54
+ sidekiq (5.2.9)
53
55
  connection_pool (~> 2.2, >= 2.2.2)
54
- rack (>= 1.5.0)
56
+ rack (~> 2.0)
55
57
  rack-protection (>= 1.5.0)
56
- redis (>= 3.3.5, < 5)
57
- sinatra (2.0.7)
58
+ redis (>= 3.3.5, < 4.2)
59
+ sinatra (2.0.8.1)
58
60
  mustermann (~> 1.0)
59
61
  rack (~> 2.0)
60
- rack-protection (= 2.0.7)
62
+ rack-protection (= 2.0.8.1)
61
63
  tilt (~> 2.0)
62
- tilt (2.0.9)
64
+ tilt (2.0.10)
63
65
  unicode-display_width (1.6.0)
64
66
 
65
67
  PLATFORMS
@@ -16,8 +16,9 @@ module GitLab
16
16
  end
17
17
  end
18
18
 
19
- def initialize(args)
19
+ def initialize(args, logger: nil)
20
20
  @connection_string = args[:connection_string]
21
+ @logger = logger
21
22
  end
22
23
 
23
24
  def run
@@ -33,10 +34,14 @@ module GitLab
33
34
  begin
34
35
  yield conn
35
36
  rescue PG::UnableToSend => e
37
+ @logger.warn "Error sending to the database: #{e}" if @logger
36
38
  conn.reset
37
39
  raise e
38
40
  end
39
41
  end
42
+ rescue PG::Error => e
43
+ @logger.error "Error connecting to the database: #{e}" if @logger
44
+ raise e
40
45
  end
41
46
  end
42
47
  end
@@ -21,8 +21,7 @@ module GitLab
21
21
  ON namespaces.id = projects.namespace_id
22
22
  LEFT JOIN namespace_statistics
23
23
  ON namespace_statistics.namespace_id = namespaces.id
24
- JOIN application_settings
25
- ON application_settings.id = 1
24
+ JOIN application_settings ON (TRUE)
26
25
  WHERE ci_builds.type = 'Ci::Build'
27
26
  AND ci_builds.status = '%s'
28
27
  -- The created_at filter has been introduced for performance reasons only
@@ -95,8 +94,7 @@ module GitLab
95
94
  ON namespaces.id = projects.namespace_id
96
95
  LEFT JOIN namespace_statistics
97
96
  ON namespace_statistics.namespace_id = namespaces.id
98
- JOIN application_settings
99
- ON application_settings.id = 1
97
+ JOIN application_settings ON (TRUE)
100
98
  WHERE ci_builds.type = 'Ci::Build'
101
99
  AND ci_builds.status = 'running'
102
100
  -- The created_at filter has been introduced for performance reasons only
@@ -144,9 +142,9 @@ module GitLab
144
142
  ci_builds.trigger_request_id
145
143
  SQL
146
144
 
147
- MIRROR_COLUMN_QUERY =
145
+ EE_CHECK_QUERY =
148
146
  <<~SQL.freeze
149
- SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='projects' AND column_name='mirror')
147
+ SELECT COUNT(*) FROM licenses
150
148
  SQL
151
149
 
152
150
  REPEATED_COMMANDS_QUERY_EE =
@@ -175,8 +173,7 @@ module GitLab
175
173
  ON namespaces.id = projects.namespace_id
176
174
  LEFT JOIN namespace_statistics
177
175
  ON namespace_statistics.namespace_id = namespaces.id
178
- JOIN application_settings
179
- ON application_settings.id = 1
176
+ JOIN application_settings ON (TRUE)
180
177
  WHERE ci_builds.type = 'Ci::Build'
181
178
  AND ci_builds.status IN ('running', 'pending')
182
179
  -- The created_at filter has been introduced for performance reasons only
@@ -265,8 +262,8 @@ module GitLab
265
262
 
266
263
  DEFAULT_UNARCHIVED_TRACES_OFFSET_MINUTES = 1440
267
264
 
268
- def initialize(opts)
269
- super(opts)
265
+ def initialize(opts, logger: nil)
266
+ super(opts, logger: logger)
270
267
 
271
268
  @allowed_repeated_commands_count = opts[:allowed_repeated_commands_count]
272
269
  @created_builds_counting_disabled = opts[:created_builds_counting_disabled]
@@ -289,7 +286,7 @@ module GitLab
289
286
  def builds(status)
290
287
  results = []
291
288
 
292
- query = mirror_column? ? BUILDS_QUERY_EE : BUILDS_QUERY_CE
289
+ query = ee? ? BUILDS_QUERY_EE : BUILDS_QUERY_CE
293
290
  query = query % [status] # rubocop:disable Style/FormatString
294
291
  exec_query_with_custom_random_page_cost(query).each do |row|
295
292
  results << transform_builds_row_to_values(row)
@@ -318,7 +315,7 @@ module GitLab
318
315
  def per_runner_builds
319
316
  results = []
320
317
 
321
- query = mirror_column? ? PER_RUNNER_QUERY_EE : PER_RUNNER_QUERY_CE
318
+ query = ee? ? PER_RUNNER_QUERY_EE : PER_RUNNER_QUERY_CE
322
319
  exec_query_with_custom_random_page_cost(query).each do |row|
323
320
  results << transform_per_runners_builds_row_to_values(row)
324
321
  end
@@ -341,7 +338,7 @@ module GitLab
341
338
  def repeated_commands
342
339
  results = []
343
340
 
344
- query = mirror_column? ? REPEATED_COMMANDS_QUERY_EE : REPEATED_COMMANDS_QUERY_CE
341
+ query = ee? ? REPEATED_COMMANDS_QUERY_EE : REPEATED_COMMANDS_QUERY_CE
345
342
  query = query % [allowed_repeated_commands_count] # rubocop:disable Style/FormatString
346
343
  exec_query_with_custom_random_page_cost(query).each do |row|
347
344
  results << transform_repeated_commands_row_to_values(row)
@@ -406,11 +403,11 @@ module GitLab
406
403
  end
407
404
  end
408
405
 
409
- def mirror_column?
410
- @mirror_column ||=
406
+ def ee?
407
+ @ee ||=
411
408
  begin
412
409
  with_connection_pool do |conn|
413
- conn.exec(MIRROR_COLUMN_QUERY)[0]["exists"] == "t"
410
+ conn.exec(EE_CHECK_QUERY)[0]["count"].to_i > 0 # rubocop:disable Style/NumericPredicate
414
411
  end
415
412
  rescue PG::UndefinedColumn
416
413
  false
@@ -420,14 +417,14 @@ module GitLab
420
417
 
421
418
  # The prober which is called when gathering metrics
422
419
  class CiBuildsProber
423
- def initialize(opts, metrics: PrometheusMetrics.new)
420
+ def initialize(opts, metrics: PrometheusMetrics.new, logger: nil)
424
421
  @metrics = metrics
425
422
 
426
423
  collector_opts = { connection_string: opts[:connection_string],
427
424
  allowed_repeated_commands_count: opts[:allowed_repeated_commands_count],
428
425
  created_builds_counting_disabled: opts[:created_builds_counting_disabled],
429
426
  unarchived_traces_offset_minutes: opts[:unarchived_traces_offset_minutes] }
430
- @collector = CiBuildsCollector.new(collector_opts)
427
+ @collector = CiBuildsCollector.new(collector_opts, logger: logger)
431
428
  end
432
429
 
433
430
  def probe_db
@@ -35,7 +35,7 @@ module GitLab
35
35
 
36
36
  # The prober which is called when gathering metrics
37
37
  class RemoteMirrorsProber
38
- def initialize(opts, metrics: PrometheusMetrics.new)
38
+ def initialize(opts, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
39
39
  @metrics = metrics
40
40
  @collector = RemoteMirrorsCollector.new(
41
41
  connection_string: opts[:connection_string],
@@ -110,7 +110,7 @@ module GitLab
110
110
  GROUP BY members.user_id
111
111
  ) AS u
112
112
  ON users.id = u.user_id",
113
- where: "ghost IS NULL AND bot_type IS NULL",
113
+ where: "user_type IS NULL",
114
114
  fields: {
115
115
  admin: {},
116
116
  external: {},
@@ -212,7 +212,7 @@ module GitLab
212
212
 
213
213
  # The prober which is called when gathering metrics
214
214
  class RowCountProber
215
- def initialize(opts, metrics: PrometheusMetrics.new)
215
+ def initialize(opts, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
216
216
  @metrics = metrics
217
217
  @collector = RowCountCollector.new(
218
218
  connection_string: opts[:connection_string],
@@ -25,9 +25,9 @@ module GitLab
25
25
 
26
26
  # Probes the DB specified by opts[:connection_string] for tuple stats, then converts them to metrics
27
27
  class TuplesProber
28
- def initialize(opts, metrics: PrometheusMetrics.new)
28
+ def initialize(opts, metrics: PrometheusMetrics.new, logger: nil)
29
29
  @metrics = metrics
30
- @collector = TupleStatsCollector.new(connection_string: opts[:connection_string])
30
+ @collector = TupleStatsCollector.new(connection_string: opts[:connection_string], logger: logger)
31
31
  end
32
32
 
33
33
  def probe_db
@@ -62,7 +62,7 @@ module GitLab
62
62
  # Optionally takes a metrics object which by default is a PrometheusMetrics, useful to change the
63
63
  # metrics writer to something else.
64
64
  class GitProber
65
- def initialize(opts, metrics: PrometheusMetrics.new)
65
+ def initialize(opts, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
66
66
  @metrics = metrics
67
67
  @labels = opts[:labels] || {}
68
68
  @git = Git.new(opts[:source])
@@ -85,7 +85,7 @@ module GitLab
85
85
 
86
86
  # A special prober for git processes
87
87
  class GitProcessProber
88
- def initialize(opts, metrics: PrometheusMetrics.new)
88
+ def initialize(opts, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
89
89
  @opts = opts
90
90
  @metrics = metrics
91
91
  end
@@ -2,9 +2,10 @@ module GitLab
2
2
  module Exporter
3
3
  # A class to combine multiple probers into one
4
4
  class Prober
5
- def initialize(prober_opts, metrics: PrometheusMetrics.new)
5
+ def initialize(prober_opts, metrics: PrometheusMetrics.new, logger: nil)
6
6
  @prober_opts = prober_opts
7
7
  @metrics = metrics
8
+ @logger = logger
8
9
 
9
10
  resolve_prober_classes
10
11
  end
@@ -12,7 +13,7 @@ module GitLab
12
13
  def probe_all
13
14
  @prober_opts.each do |_probe_name, params|
14
15
  Utils.wrap_in_array(params[:opts]).each do |opts|
15
- prober = params[:class].new(opts, metrics: @metrics)
16
+ prober = params[:class].new(opts, metrics: @metrics, logger: @logger)
16
17
  params[:methods].each do |meth|
17
18
  prober.send(meth)
18
19
  end
@@ -59,7 +59,7 @@ module GitLab
59
59
 
60
60
  # Probes a process for info then writes metrics to a target
61
61
  class ProcessProber
62
- def initialize(options, metrics: PrometheusMetrics.new)
62
+ def initialize(options, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
63
63
  @metrics = metrics
64
64
  @name = options[:name]
65
65
  @pids = if options[:pid_or_pattern] =~ /^\d+$/
@@ -10,9 +10,10 @@ 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
- def initialize(opts, metrics: PrometheusMetrics.new)
13
+ def initialize(opts, metrics: PrometheusMetrics.new, logger: nil)
14
14
  @opts = opts
15
15
  @metrics = metrics
16
+ @logger = logger
16
17
 
17
18
  Sidekiq.configure_client do |config|
18
19
  config.redis = redis_options
@@ -1,5 +1,5 @@
1
1
  module GitLab
2
2
  module Exporter
3
- VERSION = "7.0.2".freeze
3
+ VERSION = "7.1.0".freeze
4
4
  end
5
5
  end
@@ -42,6 +42,11 @@ module GitLab
42
42
 
43
43
  memory_threshold = (config[:server] && config[:server][:memory_threshold]) || 1024
44
44
  use MemoryKillerMiddleware, memory_threshold
45
+ use Rack::Logger
46
+ end
47
+
48
+ def logger
49
+ request.logger
45
50
  end
46
51
 
47
52
  def setup_server(config)
@@ -62,7 +67,7 @@ module GitLab
62
67
 
63
68
  get "/#{probe_name}" do
64
69
  content_type "text/plain; version=0.0.4"
65
- prober = Prober.new(opts, metrics: PrometheusMetrics.new(include_timestamp: false))
70
+ prober = Prober.new(opts, metrics: PrometheusMetrics.new(include_timestamp: false), logger: logger)
66
71
 
67
72
  prober.probe_all
68
73
  prober.write_to(response)
@@ -9,7 +9,7 @@ describe GitLab::Exporter::Database do
9
9
  let(:stale_builds_query) { "SELECT NOT UPDATED RUNNING" }
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
- let(:mirror_column_query) { "SELECT DOES MIRROR COLUMN EXISTS" }
12
+ let(:ee_check_query) { "SELECT COUNT(*) FROM licenses" }
13
13
  let(:repeated_commands_query_ee) { "SELECT EE REPEATED COMNANDS %d" }
14
14
  let(:repeated_commands_query_ce) { "SELECT CE REPEATED COMNANDS %d" }
15
15
  let(:unarchived_traces_query) { "SELECT UNARCHIVED TRACES %s LIST" }
@@ -22,11 +22,11 @@ describe GitLab::Exporter::Database do
22
22
  let(:unarchived_traces_offset_minutes) { 60 }
23
23
 
24
24
  def stub_ee
25
- allow(connection).to receive(:exec).with(mirror_column_query).and_return([{ "exists" => "t" }])
25
+ allow(connection).to receive(:exec).with(ee_check_query).and_return([{ "count" => 1 }])
26
26
  end
27
27
 
28
28
  def stub_ce
29
- allow(connection).to receive(:exec).with(mirror_column_query).and_return([{ "exists" => "f" }])
29
+ allow(connection).to receive(:exec).with(ee_check_query).and_return([{ "count" => 0 }])
30
30
  end
31
31
 
32
32
  def builds_query_row_ee(shared_runners_enabled, status, namespace_id, has_minutes, count)
@@ -86,7 +86,7 @@ describe GitLab::Exporter::Database do
86
86
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::STALE_BUILDS_QUERY", stale_builds_query)
87
87
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::PER_RUNNER_QUERY_EE", per_runner_query_ee)
88
88
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::PER_RUNNER_QUERY_CE", per_runner_query_ce)
89
- stub_const("GitLab::Exporter::Database::CiBuildsCollector::MIRROR_COLUMN_QUERY", mirror_column_query)
89
+ stub_const("GitLab::Exporter::Database::CiBuildsCollector::EE_CHECK_QUERY", ee_check_query)
90
90
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::REPEATED_COMMANDS_QUERY_EE", repeated_commands_query_ee)
91
91
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::REPEATED_COMMANDS_QUERY_CE", repeated_commands_query_ce)
92
92
  stub_const("GitLab::Exporter::Database::CiBuildsCollector::UNARCHIVED_TRACES_QUERY", unarchived_traces_query)
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.2
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Carranza
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-07-27 00:00:00.000000000 Z
@@ -191,7 +191,7 @@ homepage: http://gitlab.com
191
191
  licenses:
192
192
  - MIT
193
193
  metadata: {}
194
- post_install_message:
194
+ post_install_message:
195
195
  rdoc_options: []
196
196
  require_paths:
197
197
  - lib
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  version: '0'
208
208
  requirements: []
209
209
  rubygems_version: 3.0.3
210
- signing_key:
210
+ signing_key:
211
211
  specification_version: 4
212
212
  summary: GitLab metrics exporter
213
213
  test_files: