diff --git a/CHANGELOG.md b/CHANGELOG.md index d0139bc..f81fe26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - yyyy-mm-dd +## [6.4.2] - 2024-05-07 + +### Fixed + +- replace `/` with `-` in label `name` in box metrics + ## [6.4.1] - 2024-05-06 ### Fixed diff --git a/app/interactors/sbmt/outbox/process_item.rb b/app/interactors/sbmt/outbox/process_item.rb index 8c47efd..9418c2f 100644 --- a/app/interactors/sbmt/outbox/process_item.rb +++ b/app/interactors/sbmt/outbox/process_item.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "sbmt/outbox/metrics/utils" + module Sbmt module Outbox class ProcessItem < Sbmt::Outbox::DryInteractor @@ -255,7 +257,7 @@ def report_metrics(item) end def labels_for(item) - {worker_version: worker_version, type: box_type, name: box_name, owner: owner, partition: item&.partition} + {worker_version: worker_version, type: box_type, name: Sbmt::Outbox::Metrics::Utils.metric_safe(box_name), owner: owner, partition: item&.partition} end def counters diff --git a/lib/sbmt/outbox/metrics/utils.rb b/lib/sbmt/outbox/metrics/utils.rb new file mode 100644 index 0000000..2bfc24f --- /dev/null +++ b/lib/sbmt/outbox/metrics/utils.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Sbmt + module Outbox + module Metrics + module Utils + extend self + + def metric_safe(str) + str.tr("/", "-") + end + end + end + end +end diff --git a/lib/sbmt/outbox/v1/worker.rb b/lib/sbmt/outbox/v1/worker.rb index c9dacd9..1da513e 100644 --- a/lib/sbmt/outbox/v1/worker.rb +++ b/lib/sbmt/outbox/v1/worker.rb @@ -2,6 +2,7 @@ require "redlock" require "sbmt/outbox/v1/thread_pool" +require "sbmt/outbox/metrics/utils" module Sbmt module Outbox @@ -126,7 +127,7 @@ def build_jobs(boxes) }, yabeda_labels: { type: item_class.box_type, - name: item_class.box_name, + name: Sbmt::Outbox::Metrics::Utils.metric_safe(item_class.box_name), partition: partition, owner: item_class.owner }, diff --git a/lib/sbmt/outbox/v2/tasks/base.rb b/lib/sbmt/outbox/v2/tasks/base.rb index 9a895da..d26ae4a 100644 --- a/lib/sbmt/outbox/v2/tasks/base.rb +++ b/lib/sbmt/outbox/v2/tasks/base.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "sbmt/outbox/metrics/utils" + module Sbmt module Outbox module V2 @@ -23,7 +25,7 @@ def initialize(item_class:, worker_name:, worker_version: 2) @yabeda_labels = { type: item_class.box_type, - name: metric_safe(item_class.box_name), + name: Sbmt::Outbox::Metrics::Utils.metric_safe(item_class.box_name), owner: owner, worker_version: 2, worker_name: worker_name @@ -38,12 +40,6 @@ def to_h end result end - - private - - def metric_safe(str) - str.tr("/", "-") - end end end end diff --git a/lib/sbmt/outbox/version.rb b/lib/sbmt/outbox/version.rb index f05092e..2d2482e 100644 --- a/lib/sbmt/outbox/version.rb +++ b/lib/sbmt/outbox/version.rb @@ -2,6 +2,6 @@ module Sbmt module Outbox - VERSION = "6.4.1" + VERSION = "6.4.2" end end diff --git a/spec/interactors/sbmt/outbox/process_item_spec.rb b/spec/interactors/sbmt/outbox/process_item_spec.rb index 4421bbd..2c94494 100644 --- a/spec/interactors/sbmt/outbox/process_item_spec.rb +++ b/spec/interactors/sbmt/outbox/process_item_spec.rb @@ -104,6 +104,17 @@ end end + context "when combined outbox item produce to transport successfully" do + let!(:outbox_item) { create(:combined_outbox_item) } + + it "tracks Yabeda sent counter and last_sent_event_id and process_latency with proper box name" do + expect { described_class.call(Combined::OutboxItem, outbox_item.id) } + .to increment_yabeda_counter(Yabeda.outbox.sent_counter).with_tags(name: "combined-outbox_item", owner: nil, partition: 0, type: :outbox, worker_version: 1).by(1) + .and update_yabeda_gauge(Yabeda.outbox.last_sent_event_id).with_tags(name: "combined-outbox_item", owner: nil, partition: 0, type: :outbox, worker_version: 1) + .and measure_yabeda_histogram(Yabeda.outbox.process_latency).with_tags(name: "combined-outbox_item", owner: nil, partition: 0, type: :outbox, worker_version: 1) + end + end + context "when outbox item produce to transport unsuccessfully" do let!(:outbox_item) { create(:outbox_item) } diff --git a/spec/lib/sbmt/outbox/v1/worker_spec.rb b/spec/lib/sbmt/outbox/v1/worker_spec.rb index 47ceb07..96a3868 100644 --- a/spec/lib/sbmt/outbox/v1/worker_spec.rb +++ b/spec/lib/sbmt/outbox/v1/worker_spec.rb @@ -24,7 +24,7 @@ end describe "threads concurrency" do - let(:boxes) { [OutboxItem, InboxItem] } + let(:boxes) { [OutboxItem, InboxItem, Combined::OutboxItem] } let(:concurrency) { 2 } # TODO: [Rails 5.1] Database transactions are shared between test threads @@ -34,6 +34,8 @@ @outbox_item_2 = create(:outbox_item, event_key: 2, bucket: 1) @inbox_item_3 = create(:inbox_item, event_key: 3, bucket: 0) @inbox_item_4 = create(:inbox_item, event_key: 4, bucket: 1) + + @outbox_item_5 = create(:combined_outbox_item, event_key: 5, bucket: 0) end after(:context) do @@ -41,6 +43,7 @@ @outbox_item_2.destroy! @inbox_item_3.destroy! @inbox_item_4.destroy! + @outbox_item_5.destroy! end # rubocop:enable RSpec/BeforeAfterAll @@ -50,7 +53,7 @@ thread_1 = nil thread_2 = nil - expect(worker).to receive(:process_job).exactly(4).times.and_call_original + expect(worker).to receive(:process_job).exactly(5).times.and_call_original expect_to_process_item(@outbox_item_1, sleep_time: 3) do thread_1 = thread_pool.worker_number @@ -59,7 +62,8 @@ thread_2 = thread_pool.worker_number end expect_to_process_item(@inbox_item_3) - expect_to_process_item(@inbox_item_4) do + expect_to_process_item(@inbox_item_4) + expect_to_process_item(@outbox_item_5) do worker.stop end yabeda_labels = {owner: nil, worker_name: "worker", worker_version: 1} @@ -73,9 +77,11 @@ .with_tags(name: "inbox_item", state: "processed", partition: 0, type: :inbox, **yabeda_labels).by(1) .and increment_yabeda_counter(Yabeda.box_worker.job_counter) .with_tags(name: "inbox_item", state: "processed", partition: 1, type: :inbox, **yabeda_labels).by(1) + .and increment_yabeda_counter(Yabeda.box_worker.job_counter) + .with_tags(name: "combined-outbox_item", state: "processed", partition: 0, type: :outbox, **yabeda_labels).by(1) - expect(processed_info[:processed]).to eq [1, 3, 4, 2] - expect(processed_info[:processed_by_thread][thread_1]).to eq [1, 3, 4] + expect(processed_info[:processed]).to eq [1, 3, 4, 5, 2] + expect(processed_info[:processed_by_thread][thread_1]).to eq [1, 3, 4, 5] expect(processed_info[:processed_by_thread][thread_2]).to eq [2] end end