gitlab-exporter 14.0.0 → 14.1.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: dd25ebf8533fde9c59b0db768540fcbdf338c961715617459c2a4aa2eb2cc912
4
+ data.tar.gz: 12e190d1ea1f1cf0a16aa68ab54995c4953555807c7e3c80ecf8a40072d811dd
5
5
  SHA512:
6
- metadata.gz: 3be9966a1abe20b42169a4a85e20815649c87e46a31f853002dd5fb0eaff6437a692f5904334d42172fb1950627b0d3bba31a67c6992e5533051f367ed74144f
7
- data.tar.gz: 20aefc5c04ee63033feeb80e986e6f239a711d9d88197859c154fe4e429573344d52d5c58ca9d9e611dace90804da5fba8341ed45ed5f592e33a5df8c3c6cc7e
6
+ metadata.gz: f482931b5c30361f7d9e2899c47de30e4fe296b02028818c83bf189defcd8e0dd6fa30f411c1a96e2abab809c1d45ea4c679479b61ac093c09d678154a8b6ce5
7
+ data.tar.gz: 5942a5b4b0ea8ecdccdab0de8a5bfdad2f7b1f125e200bfc94e64cf4328ca750cf866ccd394dbe14dfc91fe3dcc5915332e5519c9f9d37682f49251ac2a7b581
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.1.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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module GitLab
2
2
  module Exporter
3
- VERSION = "14.0.0".freeze
3
+ VERSION = "14.1.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,7 +1,7 @@
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.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Carranza
@@ -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
@@ -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