diff --git a/.rubocop.yml b/.rubocop.yml index 17c7f88..8ce1aff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,3 +12,7 @@ Discourse/Plugins/NoMonkeyPatching: Discourse/Plugins/NamespaceMethods: Exclude: - bin/prometheus_exporter + +Style/InvertibleUnlessCondition: + Exclude: + - '*.gemspec' diff --git a/prometheus_exporter.gemspec b/prometheus_exporter.gemspec index dffec66..e1ee544 100644 --- a/prometheus_exporter.gemspec +++ b/prometheus_exporter.gemspec @@ -27,12 +27,12 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rubocop", ">= 0.69" spec.add_development_dependency "bundler", ">= 2.1.4" spec.add_development_dependency "rake", "~> 13.0" - spec.add_development_dependency "minitest", "~> 5.15.0" # https://github.com/qrush/m/issues/93 + spec.add_development_dependency "minitest", "~> 5.23.0" spec.add_development_dependency "guard", "~> 2.0" - spec.add_development_dependency "mini_racer", "~> 0.5.0" + spec.add_development_dependency "mini_racer", "~> 0.12.0" spec.add_development_dependency "guard-minitest", "~> 2.0" spec.add_development_dependency "oj", "~> 3.0" - spec.add_development_dependency "rack-test", "~> 0.8.3" + spec.add_development_dependency "rack-test", "~> 2.1.0" spec.add_development_dependency "minitest-stub-const", "~> 0.6" spec.add_development_dependency "rubocop-discourse", ">= 3" spec.add_development_dependency "appraisal", "~> 2.3" diff --git a/test/middleware_test.rb b/test/middleware_test.rb index 2d37714..c764cf5 100644 --- a/test/middleware_test.rb +++ b/test/middleware_test.rb @@ -133,7 +133,7 @@ def test_patch_called_with_prepend_instrument Object.stub_const(:Redis, Module) do ::Redis.stub_const(:Client) do mock = Minitest::Mock.new - mock.expect :call, nil, [Redis::Client, Array, :redis, { instrument: :prepend }] + mock.expect :call, nil, [Redis::Client, Array, :redis], instrument: :prepend ::PrometheusExporter::Instrumentation::MethodProfiler.stub(:patch, mock) do configure_middleware(instrument: :prepend) end @@ -144,7 +144,7 @@ def test_patch_called_with_prepend_instrument Object.stub_const(:PG, Module) do ::PG.stub_const(:Connection) do mock = Minitest::Mock.new - mock.expect :call, nil, [PG::Connection, Array, :sql, { instrument: :prepend }] + mock.expect :call, nil, [PG::Connection, Array, :sql], instrument: :prepend ::PrometheusExporter::Instrumentation::MethodProfiler.stub(:patch, mock) do configure_middleware(instrument: :prepend) end @@ -155,9 +155,9 @@ def test_patch_called_with_prepend_instrument Object.stub_const(:Mysql2, Module) do ::Mysql2.stub_consts({ Client: nil, Statement: nil, Result: nil }) do mock = Minitest::Mock.new - mock.expect :call, nil, [Mysql2::Client, Array, :sql, { instrument: :prepend }] - mock.expect :call, nil, [Mysql2::Statement, Array, :sql, { instrument: :prepend }] - mock.expect :call, nil, [Mysql2::Result, Array, :sql, { instrument: :prepend }] + mock.expect :call, nil, [Mysql2::Client, Array, :sql], instrument: :prepend + mock.expect :call, nil, [Mysql2::Statement, Array, :sql], instrument: :prepend + mock.expect :call, nil, [Mysql2::Result, Array, :sql], instrument: :prepend ::PrometheusExporter::Instrumentation::MethodProfiler.stub(:patch, mock) do configure_middleware(instrument: :prepend) end @@ -172,7 +172,7 @@ def test_patch_called_with_alias_method_instrument ::Redis.stub_const(:VERSION, '4.0.4') do ::Redis.stub_const(:Client) do mock = Minitest::Mock.new - mock.expect :call, nil, [Redis::Client, Array, :redis, { instrument: :alias_method }] + mock.expect :call, nil, [Redis::Client, Array, :redis], instrument: :alias_method ::PrometheusExporter::Instrumentation::MethodProfiler.stub(:patch, mock) do configure_middleware end @@ -184,7 +184,7 @@ def test_patch_called_with_alias_method_instrument Object.stub_const(:PG, Module) do ::PG.stub_const(:Connection) do mock = Minitest::Mock.new - mock.expect :call, nil, [PG::Connection, Array, :sql, { instrument: :alias_method }] + mock.expect :call, nil, [PG::Connection, Array, :sql], instrument: :alias_method ::PrometheusExporter::Instrumentation::MethodProfiler.stub(:patch, mock) do configure_middleware end @@ -195,9 +195,9 @@ def test_patch_called_with_alias_method_instrument Object.stub_const(:Mysql2, Module) do ::Mysql2.stub_consts({ Client: nil, Statement: nil, Result: nil }) do mock = Minitest::Mock.new - mock.expect :call, nil, [Mysql2::Client, Array, :sql, { instrument: :alias_method }] - mock.expect :call, nil, [Mysql2::Statement, Array, :sql, { instrument: :alias_method }] - mock.expect :call, nil, [Mysql2::Result, Array, :sql, { instrument: :alias_method }] + mock.expect :call, nil, [Mysql2::Client, Array, :sql], instrument: :alias_method + mock.expect :call, nil, [Mysql2::Statement, Array, :sql], instrument: :alias_method + mock.expect :call, nil, [Mysql2::Result, Array, :sql], instrument: :alias_method ::PrometheusExporter::Instrumentation::MethodProfiler.stub(:patch, mock) do configure_middleware end diff --git a/test/server/collector_test.rb b/test/server/collector_test.rb index 1bfd52c..45dc4f7 100644 --- a/test/server/collector_test.rb +++ b/test/server/collector_test.rb @@ -360,7 +360,7 @@ def test_it_can_collect_sidekiq_metrics_with_custom_labels_from_worker_class queue = "default" client = Minitest::Mock.new - client.expect(:send_json, '', [{ + client.expect(:send_json, '', [], type: "sidekiq", name: "PrometheusCollectorTest::#{worker_class}", queue: queue, @@ -368,7 +368,7 @@ def test_it_can_collect_sidekiq_metrics_with_custom_labels_from_worker_class shutdown: false, duration: 0, custom_labels: WorkerWithCustomLabels.custom_labels - }]) + ) ::Process.stub(:clock_gettime, 1, ::Process::CLOCK_MONOTONIC) do instrument = PrometheusExporter::Instrumentation::Sidekiq.new(client: client) @@ -386,7 +386,7 @@ def test_it_can_collect_sidekiq_metrics_with_custom_labels_from_job queue = "default" client = Minitest::Mock.new - client.expect(:send_json, '', [{ + client.expect(:send_json, '', [], type: "sidekiq", name: "PrometheusCollectorTest::#{worker_class}", queue: queue, @@ -394,7 +394,7 @@ def test_it_can_collect_sidekiq_metrics_with_custom_labels_from_job shutdown: false, duration: 0, custom_labels: { first_job_arg: 'arg_one' } - }]) + ) ::Process.stub(:clock_gettime, 1, ::Process::CLOCK_MONOTONIC) do instrument = PrometheusExporter::Instrumentation::Sidekiq.new(client: client) @@ -416,12 +416,12 @@ def test_it_can_collect_sidekiq_metrics_on_job_death worker = Minitest::Mock.new client = Minitest::Mock.new - client.expect(:send_json, '', [{ + client.expect(:send_json, '', [], type: "sidekiq", name: job["class"], dead: true, custom_labels: {} - }]) + ) Object.stub(:const_get, worker, [job['class']]) do PrometheusExporter::Client.stub(:default, client) do @@ -444,12 +444,12 @@ def test_it_can_collect_sidekiq_metrics_on_job_death_for_delayed worker = Minitest::Mock.new client = Minitest::Mock.new - client.expect(:send_json, '', [{ + client.expect(:send_json, '', [], type: "sidekiq", name: "DelayedAction#foo", dead: true, custom_labels: {} - }]) + ) Object.stub(:const_get, worker, [job['class']]) do PrometheusExporter::Client.stub(:default, client) do @@ -469,12 +469,12 @@ def test_it_can_collect_sidekiq_metrics_on_job_death_with_custom_labels_from_wor } client = Minitest::Mock.new - client.expect(:send_json, '', [{ + client.expect(:send_json, '', [], type: "sidekiq", name: job["class"], dead: true, custom_labels: WorkerWithCustomLabels.custom_labels - }]) + ) Object.stub(:const_get, WorkerWithCustomLabels, [job['class']]) do PrometheusExporter::Client.stub(:default, client) do diff --git a/test/test_helper.rb b/test/test_helper.rb index 6eb72e0..027c65e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,12 +4,12 @@ require "prometheus_exporter" require "minitest/autorun" - +require "ostruct" require "redis" module TestingMod class FakeConnection - def call_pipelined(_, _) + def call_pipelined(_, _, _) end def call(_, _)