gitlab-exporter 14.0.0 → 14.2.0

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: 6420230ed0ec27d530fa71e46c0776ea2cb21b036a198335229fc304dcdfe3e0
4
- data.tar.gz: 91205ee62a32b2e00f7978f9fc7ec063be203d593cade97ea481f85ee1388bbd
3
+ metadata.gz: b7f9898831930837f37459941f701115d678149f1e0ccdc4dfa896ed729066db
4
+ data.tar.gz: b7d4a3e5310b838cbefc49475eb7893749a4fc6b6e8574b6f7d03f080790ab8b
5
5
  SHA512:
6
- metadata.gz: 3be9966a1abe20b42169a4a85e20815649c87e46a31f853002dd5fb0eaff6437a692f5904334d42172fb1950627b0d3bba31a67c6992e5533051f367ed74144f
7
- data.tar.gz: 20aefc5c04ee63033feeb80e986e6f239a711d9d88197859c154fe4e429573344d52d5c58ca9d9e611dace90804da5fba8341ed45ed5f592e33a5df8c3c6cc7e
6
+ metadata.gz: 87701dd407f197bfe6e4927f66e494bfd63aafea8c49eef7d5e86996256853b671f2d8a891b709543f89aead3f3a0609b453c104b826cf0ea8aaf7b586d8d6b7
7
+ data.tar.gz: e6bcf77ffc7c6b14d6f472fcb0d7c386c676a217021200b75898dbac15e8586f852782ee3e71b3fa010811263b3b01e65417a3d24a01f089db3f931f167c76ec
data/.gitlab-ci.yml CHANGED
@@ -1,13 +1,10 @@
1
1
  include:
2
+ - component: gitlab.com/components/container-scanning/container-scanning@~latest
3
+ - component: gitlab.com/components/sast/sast@~latest
4
+ - component: gitlab.com/components/secret-detection/secret-detection@~latest
5
+ - component: gitlab.com/gitlab-org/components/gem-release/gem-release@~latest
2
6
  - template: Security/DAST.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml
3
- - 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
4
7
  - 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
5
- - 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
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
- - 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
- - project: 'gitlab-org/quality/pipeline-common'
9
- file:
10
- - '/ci/gem-release.yml'
11
8
 
12
9
  variables:
13
10
  RUBY_VERSION: "2.7"
@@ -65,9 +62,6 @@ rubocop:
65
62
  - bundle exec rubocop
66
63
  before_script: *before_scripts
67
64
 
68
- license_scanning:
69
- rules: *workflow_rules
70
-
71
65
  gemnasium-dependency_scanning:
72
66
  rules: *workflow_rules
73
67
 
data/.rubocop.yml CHANGED
@@ -33,4 +33,4 @@ Metrics/AbcSize:
33
33
  Enabled: false
34
34
 
35
35
  Metrics/ClassLength:
36
- Max: 150
36
+ Max: 155
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-exporter (14.0.0)
4
+ gitlab-exporter (14.2.0)
5
5
  connection_pool (= 2.2.5)
6
+ deep_merge (~> 1.2.2)
6
7
  faraday (~> 1.8.0)
7
8
  pg (= 1.5.3)
8
9
  puma (= 5.6.5)
@@ -18,6 +19,7 @@ GEM
18
19
  specs:
19
20
  ast (2.4.1)
20
21
  connection_pool (2.2.5)
22
+ deep_merge (1.2.2)
21
23
  diff-lcs (1.5.0)
22
24
  faraday (1.8.0)
23
25
  faraday-em_http (~> 1.0)
data/README.md CHANGED
@@ -95,6 +95,25 @@ Once running, you can point your browser or curl to the following URLs:
95
95
  * http://localhost:9168/sidekiq
96
96
  * http://localhost:9168/metrics (to get all of the above combined)
97
97
 
98
+ If it is undesirable to have secrets (e.g. Redis password or PostgreSQL credentials) in the config file,
99
+ then you can specify an external command (with the `--extra-config-command <command>` flag) that outputs
100
+ such credentials in a YAML form (same structure as the config file) and it will be merged with the file configuration.
101
+
102
+ For example:
103
+
104
+ ```
105
+ $ vault kv get -format=yaml secrets/gitlab/gitlab-exporter
106
+ probes:
107
+ sidekiq:
108
+ opts:
109
+ redis_url: redis://hunter1@localhost:9765
110
+ database:
111
+ opts:
112
+ connection_string: postgres://db-admin:hunter1@localhost:6543/main-db
113
+
114
+ $ bin/gitlab-exporter web -c config/gitlab-exporter.yml --extra-config-command "vault kv get -format=yaml secrets/gitlab/gitlab-exporter"
115
+ ```
116
+
98
117
  ### Database Bloat Metrics
99
118
 
100
119
  Database bloat is measured for indexes (`btree`) and/or tables
@@ -94,6 +94,9 @@ probes:
94
94
  - probe_retries
95
95
  opts:
96
96
  redis_url: "redis://localhost:6379"
97
+ # Uncomment if username or password is not part of the redis_url specified above
98
+ # redis_username: 'redis-username'
99
+ # redis_password: 'redis-password'
97
100
  redis_enable_client: true
98
101
 
99
102
  ruby: &ruby
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.license = "MIT"
22
22
 
23
23
  s.add_runtime_dependency "connection_pool", "2.2.5"
24
+ s.add_runtime_dependency "deep_merge", "~> 1.2.2"
24
25
  s.add_runtime_dependency "faraday", "~> 1.8.0"
25
26
  s.add_runtime_dependency "pg", "1.5.3"
26
27
  s.add_runtime_dependency "puma", "5.6.5"
@@ -1,4 +1,6 @@
1
1
  require "yaml"
2
+ require "deep_merge"
3
+ require "English"
2
4
 
3
5
  # TODO: Remove this once we're on Ruby 3
4
6
  # https://gitlab.com/gitlab-org/gitlab/-/issues/393651
@@ -188,6 +190,10 @@ module GitLab
188
190
  opts.on("-c config.yml", "Monitoring config") do |val|
189
191
  @config_file = val
190
192
  end
193
+ opts.on("--extra-config-command command", "Shell command that returns YAML config to be merged
194
+ with the config file") do |val|
195
+ @extra_config_command = val
196
+ end
191
197
  end
192
198
  end
193
199
 
@@ -195,12 +201,17 @@ module GitLab
195
201
  @options.help
196
202
  end
197
203
 
204
+ def merged_config
205
+ config_from_file = Utils.deep_symbolize_hash_keys(YAML.safe_load_file(@config_file, aliases: true))
206
+ config_from_command = extra_config_from_command
207
+
208
+ config_from_file.deep_merge!(config_from_command)
209
+ end
210
+
198
211
  def run
199
212
  validate!
200
213
 
201
- config = Utils.deep_symbolize_hash_keys(YAML.safe_load_file(@config_file, aliases: true))
202
-
203
- WebExporter.setup(config)
214
+ WebExporter.setup(merged_config)
204
215
  WebExporter.run!
205
216
  end
206
217
 
@@ -209,6 +220,22 @@ module GitLab
209
220
  def validate!
210
221
  fail InvalidCLICommand.new(help) unless @config_file
211
222
  end
223
+
224
+ def run_extra_config_command
225
+ puts "Using extra config by running command `#{@extra_config_command}`"
226
+
227
+ output = `#{@extra_config_command}`
228
+ return output if $CHILD_STATUS == 0
229
+
230
+ puts "ERROR: command `#{@extra_config_command}` returned a non-zero code."
231
+ exit(2)
232
+ end
233
+
234
+ def extra_config_from_command
235
+ return {} unless @extra_config_command
236
+
237
+ Utils.deep_symbolize_hash_keys(YAML.safe_load(run_extra_config_command))
238
+ end
212
239
  end
213
240
 
214
241
  # Process runner
@@ -199,6 +199,10 @@ module GitLab
199
199
  reconnect_attempts: 0
200
200
  }
201
201
 
202
+ %i[username password].each do |credential|
203
+ options[credential] = @opts[:"redis_#{credential}"] if @opts.key?(:"redis_#{credential}")
204
+ end
205
+
202
206
  options[:id] = nil unless redis_enable_client?
203
207
  options
204
208
  end
@@ -1,5 +1,5 @@
1
1
  module GitLab
2
2
  module Exporter
3
- VERSION = "14.0.0".freeze
3
+ VERSION = "14.2.0".freeze
4
4
  end
5
5
  end
data/spec/cli_spec.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "spec_helper"
2
2
  require "gitlab_exporter/cli"
3
+ require "optparse"
3
4
 
4
5
  context "With valid pair of repositories" do
5
6
  let(:repos) { GitRepoBuilder.new }
@@ -29,3 +30,49 @@ context "With valid pair of repositories" do
29
30
  end
30
31
  end
31
32
  end
33
+
34
+ describe GitLab::Exporter::CLI::Server do
35
+ context "extra-config-command is passed" do
36
+ let(:argv) do
37
+ ["-c", "spec/fixtures/config.yml", "--extra-config-command", extra_config_command]
38
+ .extend(OptionParser::Arguable)
39
+ end
40
+ let(:extra_config_command) { "vault kv get top-secrets" }
41
+ let(:server_cmd) { described_class.new(argv) }
42
+
43
+ before do
44
+ allow(server_cmd).to receive(:run_extra_config_command).and_return(<<~YAML
45
+ probes:
46
+ sidekiq:
47
+ methods:
48
+ - probe_workers
49
+ opts:
50
+ redis_url: redis://hunter1@localhost:9765
51
+ database:
52
+ opts:
53
+ connection_string: postgres://db-admin:hunter1@localhost:6543/main-db
54
+ YAML
55
+ )
56
+ end
57
+
58
+ it "merges the returned YAML from the command with the passed config" do
59
+ expect(server_cmd.merged_config).to eq({
60
+ probes: {
61
+ sidekiq: {
62
+ methods: %w[probe_stats probe_workers],
63
+ opts: {
64
+ redis_url: "redis://hunter1@localhost:9765"
65
+ }
66
+ },
67
+ database: {
68
+ methods: ["probe_db"],
69
+ opts: {
70
+ connection_string:
71
+ "postgres://db-admin:hunter1@localhost:6543/main-db"
72
+ }
73
+ }
74
+ }
75
+ })
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,10 @@
1
+ probes:
2
+ sidekiq:
3
+ methods:
4
+ - probe_stats
5
+
6
+ database:
7
+ methods:
8
+ - probe_db
9
+ opts:
10
+ connection_string: to-be-overridden
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: 14.0.0
4
+ version: 14.2.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
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.2.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: deep_merge
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: faraday
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -229,6 +243,7 @@ files:
229
243
  - spec/database/ci_builds_spec.rb
230
244
  - spec/database/row_count_spec.rb
231
245
  - spec/elasticsearch_spec.rb
246
+ - spec/fixtures/config.yml
232
247
  - spec/fixtures/smaps/sample.txt
233
248
  - spec/git_process_proper_spec.rb
234
249
  - spec/git_spec.rb
@@ -242,7 +257,7 @@ homepage: https://gitlab.com/gitlab-org/ruby/gems/gitlab-exporter
242
257
  licenses:
243
258
  - MIT
244
259
  metadata: {}
245
- post_install_message:
260
+ post_install_message:
246
261
  rdoc_options: []
247
262
  require_paths:
248
263
  - lib
@@ -257,8 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
272
  - !ruby/object:Gem::Version
258
273
  version: '0'
259
274
  requirements: []
260
- rubygems_version: 3.1.6
261
- signing_key:
275
+ rubygems_version: 3.3.26
276
+ signing_key:
262
277
  specification_version: 4
263
278
  summary: GitLab metrics exporter
264
279
  test_files:
@@ -267,6 +282,7 @@ test_files:
267
282
  - spec/database/ci_builds_spec.rb
268
283
  - spec/database/row_count_spec.rb
269
284
  - spec/elasticsearch_spec.rb
285
+ - spec/fixtures/config.yml
270
286
  - spec/fixtures/smaps/sample.txt
271
287
  - spec/git_process_proper_spec.rb
272
288
  - spec/git_spec.rb