Commit 5807ffe3 authored by Ahmad Sherif's avatar Ahmad Sherif
Browse files

Merge branch '84-ruby3-build' into 'master'

Add Ruby 3 build

Closes #84

See merge request gitlab-org/gitlab-exporter!148
parents 60d6c720 7ceea4e2
Pipeline #205792 passed with stage
in 1 minute and 48 seconds
......@@ -6,12 +6,15 @@ include:
- template: Security/SAST.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml
- 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
variables:
RUBY_VERSION: "2.7"
stages:
- test
- dast
default:
image: ruby:2.7
image: ruby:${RUBY_VERSION}
cache:
paths:
- vendor
......@@ -36,6 +39,10 @@ rspec:
script:
- bundle exec rspec spec -f d -c
before_script: *before_scripts
parallel:
matrix:
- RUBY_VERSION: "2.7"
- RUBY_VERSION: "3.0"
rubocop:
script:
......
......@@ -2,6 +2,8 @@ source "https://rubygems.org"
gemspec
gem "webrick", "~> 1.7"
group :test do
gem "rspec", "~>3.5"
gem "rubocop", "~>0.42"
......
PATH
remote: .
specs:
gitlab-exporter (11.1.0)
gitlab-exporter (11.2.0)
connection_pool (= 2.2.5)
pg (= 1.2.3)
puma (= 5.3.2)
......@@ -9,7 +9,7 @@ PATH
redis (= 4.1.4)
redis-namespace (= 1.6.0)
sidekiq (= 5.2.9)
sinatra (= 2.0.8.1)
sinatra (~> 2.1.0)
GEM
remote: https://rubygems.org/
......@@ -28,7 +28,7 @@ GEM
nio4r (~> 2.0)
quantile (0.2.1)
rack (2.2.3)
rack-protection (2.0.8.1)
rack-protection (2.1.0)
rack
rainbow (3.0.0)
redis (4.1.4)
......@@ -67,13 +67,14 @@ GEM
rack (~> 2.0)
rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 4.2)
sinatra (2.0.8.1)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.8.1)
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
tilt (2.0.10)
unicode-display_width (1.7.0)
webrick (1.7.0)
PLATFORMS
ruby
......@@ -83,6 +84,7 @@ DEPENDENCIES
rspec (~> 3.5)
rspec-expectations (~> 3.7.0)
rubocop (~> 0.42)
webrick (~> 1.7)
BUNDLED WITH
2.1.4
2.2.22
......@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "redis", "4.1.4"
s.add_runtime_dependency "redis-namespace", "1.6.0"
s.add_runtime_dependency "sidekiq", "5.2.9"
s.add_runtime_dependency "sinatra", "2.0.8.1"
s.add_runtime_dependency "sinatra", "~> 2.1.0"
s.add_development_dependency "rspec", "~> 3.7.0"
s.add_development_dependency "rspec-expectations", "~> 3.7.0"
......
......@@ -41,8 +41,8 @@ module GitLab
conn.type_map_for_results = tm
end
def initialize(args, logger: nil)
@connection_string = args[:connection_string]
def initialize(connection_string:, logger: nil, **opts) # rubocop:disable Lint/UnusedMethodArgument
@connection_string = connection_string
@logger = logger
end
......
......@@ -39,12 +39,11 @@ module GitLab
attr_reader :metrics, :collector, :bloat_types
def initialize(opts,
metrics: PrometheusMetrics.new,
collector: BloatCollector.new(connection_string: opts[:connection_string]),
logger: nil)
def initialize(metrics: PrometheusMetrics.new,
logger: nil,
**opts)
@metrics = metrics
@collector = collector
@collector = opts[:collector] || BloatCollector.new(**opts)
@collector.logger = logger
@bloat_types = opts[:bloat_types] || %i[btree table]
end
......
......@@ -168,8 +168,8 @@ module GitLab
DEFAULT_UNARCHIVED_TRACES_OFFSET_MINUTES = 1440
def initialize(opts, logger: nil)
super(opts, logger: logger)
def initialize(**opts)
super
@created_builds_counting_disabled = opts[:created_builds_counting_disabled]
@unarchived_traces_offset_minutes = opts[:unarchived_traces_offset_minutes]
......@@ -294,13 +294,9 @@ module GitLab
# The prober which is called when gathering metrics
class CiBuildsProber
def initialize(opts, metrics: PrometheusMetrics.new, logger: nil)
def initialize(metrics: PrometheusMetrics.new, **opts)
@metrics = metrics
collector_opts = { connection_string: opts[:connection_string],
created_builds_counting_disabled: opts[:created_builds_counting_disabled],
unarchived_traces_offset_minutes: opts[:unarchived_traces_offset_minutes] }
@collector = CiBuildsCollector.new(collector_opts, logger: logger)
@collector = CiBuildsCollector.new(**opts)
end
def probe_db
......@@ -391,7 +387,7 @@ module GitLab
labels[:namespace] = "" unless labels[:namespace]
selected_labels = labels.select { |k, _| allowed_labels.include?(k) }.sort.to_h
@metrics.add(metric_name, value.to_f, selected_labels)
@metrics.add(metric_name, value.to_f, **selected_labels)
end
def unarchived_traces_metrics
......
......@@ -10,8 +10,8 @@ module GitLab
FROM remote_mirrors WHERE project_id IN (%s) AND enabled = 't'
SQL
def initialize(args)
super(args)
def initialize(**args)
super(**args)
@project_ids = args[:project_ids]
end
......@@ -35,7 +35,7 @@ module GitLab
# The prober which is called when gathering metrics
class RemoteMirrorsProber
def initialize(opts, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
def initialize(metrics: PrometheusMetrics.new, **opts)
@metrics = metrics
@collector = RemoteMirrorsCollector.new(
connection_string: opts[:connection_string],
......
......@@ -134,10 +134,10 @@ module GitLab
}
}.freeze
def initialize(args)
super(args)
def initialize(selected_queries: nil, **args)
super(**args)
@selected_queries = Set.new(args[:selected_queries].map(&:to_sym)) unless args[:selected_queries].nil?
@selected_queries = Set.new(selected_queries.map(&:to_sym)) unless selected_queries.nil?
end
def run
......@@ -200,12 +200,9 @@ module GitLab
# The prober which is called when gathering metrics
class RowCountProber
def initialize(opts, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
def initialize(metrics: PrometheusMetrics.new, **opts)
@metrics = metrics
@collector = RowCountCollector.new(
connection_string: opts[:connection_string],
selected_queries: opts[:selected_queries]
)
@collector = RowCountCollector.new(**opts)
end
def probe_db
......
......@@ -25,9 +25,9 @@ module GitLab
# Probes the DB specified by opts[:connection_string] for tuple stats, then converts them to metrics
class TuplesProber
def initialize(opts, metrics: PrometheusMetrics.new, logger: nil)
def initialize(metrics: PrometheusMetrics.new, **opts)
@metrics = metrics
@collector = TupleStatsCollector.new(connection_string: opts[:connection_string], logger: logger)
@collector = TupleStatsCollector.new(**opts)
end
def probe_db
......
......@@ -64,10 +64,10 @@ module GitLab
# Optionally takes a metrics object which by default is a PrometheusMetrics, useful to change the
# metrics writer to something else.
class GitProber
def initialize(opts, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
def initialize(source:, metrics: PrometheusMetrics.new, labels: {}, **opts) # rubocop:disable Lint/UnusedMethodArgument
@metrics = metrics
@labels = opts[:labels] || {}
@git = Git.new(opts[:source])
@labels = labels
@git = Git.new(source)
end
def probe_pull
......@@ -87,9 +87,9 @@ module GitLab
# A special prober for git processes
class GitProcessProber
def initialize(opts, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
@opts = opts
def initialize(metrics: PrometheusMetrics.new, quantiles: nil, **opts) # rubocop:disable Lint/UnusedMethodArgument
@metrics = metrics
@quantiles = quantiles
end
def probe_git # rubocop:disable Metrics/MethodLength
......@@ -115,7 +115,7 @@ module GitLab
{
name: name,
pid_or_pattern: pid,
quantiles: @opts[:quantiles]
quantiles: @quantiles
},
metrics: @metrics
)
......
......@@ -2,7 +2,7 @@ module GitLab
module Exporter
# A class to combine multiple probers into one
class Prober
def initialize(prober_opts, metrics: PrometheusMetrics.new, logger: nil)
def initialize(metrics: PrometheusMetrics.new, logger: nil, **prober_opts)
@prober_opts = prober_opts
@metrics = metrics
@logger = logger
......@@ -13,7 +13,7 @@ module GitLab
def probe_all
@prober_opts.each do |_probe_name, params|
Utils.wrap_in_array(params[:opts]).each do |opts|
prober = params[:class].new(opts, metrics: @metrics, logger: @logger)
prober = params[:class].new(metrics: @metrics, logger: @logger, **opts)
params[:methods].each do |meth|
prober.send(meth)
end
......
......@@ -59,15 +59,15 @@ module GitLab
# Probes a process for info then writes metrics to a target
class ProcessProber
def initialize(options, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
def initialize(name:, metrics: PrometheusMetrics.new, quantiles: false, **options)
@metrics = metrics
@name = options[:name]
@name = name
@pids = if options[:pid_or_pattern] =~ /^\d+$/
[options[:pid_or_pattern]]
else
Utils.pgrep(options[:pid_or_pattern])
end
@use_quantiles = options.fetch(:quantiles, false)
@use_quantiles = quantiles
end
def probe_stat
......
......@@ -4,9 +4,9 @@ module GitLab
module Exporter
# Probes a current process GC for info then writes metrics to a target
class RubyProber
def initialize(options, metrics: PrometheusMetrics.new, logger: nil) # rubocop:disable Lint/UnusedMethodArgument
def initialize(metrics: PrometheusMetrics.new, quantiles: false, **opts) # rubocop:disable Lint/UnusedMethodArgument
@metrics = metrics
@use_quantiles = options.fetch(:quantiles, false)
@use_quantiles = quantiles
end
def probe_gc
......
......@@ -33,7 +33,7 @@ module GitLab
end
end
def initialize(opts, metrics: PrometheusMetrics.new, logger: nil)
def initialize(metrics: PrometheusMetrics.new, logger: nil, **opts)
@opts = opts
@metrics = metrics
@logger = logger
......
module GitLab
module Exporter
VERSION = "11.1.0".freeze
VERSION = "11.2.0".freeze
end
end
......@@ -89,7 +89,7 @@ module GitLab
get "/#{probe_name}" do
content_type "text/plain; version=0.0.4"
prober = Prober.new(opts, metrics: PrometheusMetrics.new(include_timestamp: false), logger: logger)
prober = Prober.new(metrics: PrometheusMetrics.new(include_timestamp: false), logger: logger, **opts)
prober.probe_all
prober.write_to(response)
......
......@@ -26,7 +26,7 @@ describe GitLab::Exporter::Database::BloatCollector do
end
describe GitLab::Exporter::Database::BloatProber do
let(:opts) { { bloat_types: %i[btree table] } }
let(:opts) { { bloat_types: %i[btree table], connection_string: "" } }
let(:metrics) { double("PrometheusMetrics", add: nil) }
let(:collector) { double("BloatCollector", run: data) }
......@@ -43,7 +43,7 @@ describe GitLab::Exporter::Database::BloatProber do
end
describe "#probe_db" do
subject { described_class.new(opts, metrics: metrics, collector: collector, logger: STDOUT).probe_db }
subject { described_class.new(metrics: metrics, collector: collector, logger: STDOUT, **opts).probe_db }
before do
expect(collector).to receive(:logger=).with(STDOUT)
......@@ -92,7 +92,7 @@ describe GitLab::Exporter::Database::BloatProber do
describe "#write_to" do
let(:target) { double }
let(:metrics) { double("PrometheusMetrics", to_s: double) }
subject { described_class.new(opts, metrics: metrics).write_to(target) }
subject { described_class.new(metrics: metrics, **opts).write_to(target) }
it "writes to given target" do
expect(target).to receive(:write).with(metrics.to_s)
......
......@@ -216,11 +216,12 @@ describe GitLab::Exporter::Database do
describe GitLab::Exporter::Database::CiBuildsProber do
let(:writer) { StringIO.new }
let(:prober) do
opts = { connection_string: "host=localhost",
created_builds_counting_disabled: created_builds_counting_disabled,
unarchived_traces_offset_minutes: unarchived_traces_offset_minutes }
described_class.new(opts,
metrics: GitLab::Exporter::PrometheusMetrics.new(include_timestamp: false))
described_class.new(
connection_string: "host=localhost",
created_builds_counting_disabled: created_builds_counting_disabled,
unarchived_traces_offset_minutes: unarchived_traces_offset_minutes,
metrics: GitLab::Exporter::PrometheusMetrics.new(include_timestamp: false)
)
end
before do
......
......@@ -34,17 +34,17 @@ context "With valid pair of repositories" do
end
describe GitLab::Exporter::GitProber do
let(:options) { GitProberOptions.new(repos.cloned_repo, {}) }
let(:options) { { source: repos.cloned_repo, labels: {} } }
let(:output) { StringIO.new }
it "probes and monitors a pull" do
prober = GitLab::Exporter::GitProber.new(options)
prober = GitLab::Exporter::GitProber.new(**options)
prober.probe_pull.write_to(output)
expect(output.string).to match(/git_pull_time_milliseconds \d+ \d+/)
end
it "probes and monitors a push" do
prober = GitLab::Exporter::GitProber.new(options)
prober = GitLab::Exporter::GitProber.new(**options)
prober.probe_push.write_to(output)
expect(output.string).to match(/git_push_time_milliseconds \d+ \d+/)
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment