Skip to content

Commit

Permalink
[DEX-2265] feat: replace / with - in metric tag name
Browse files Browse the repository at this point in the history
  • Loading branch information
ysatarov committed May 7, 2024
1 parent b9e40a8 commit 2ecb8da
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/interactors/sbmt/outbox/process_item.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "sbmt/outbox/metrics/utils"

module Sbmt
module Outbox
class ProcessItem < Sbmt::Outbox::DryInteractor
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lib/sbmt/outbox/metrics/utils.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion lib/sbmt/outbox/v1/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "redlock"
require "sbmt/outbox/v1/thread_pool"
require "sbmt/outbox/metrics/utils"

module Sbmt
module Outbox
Expand Down Expand Up @@ -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
},
Expand Down
10 changes: 3 additions & 7 deletions lib/sbmt/outbox/v2/tasks/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "sbmt/outbox/metrics/utils"

module Sbmt
module Outbox
module V2
Expand All @@ -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
Expand All @@ -38,12 +40,6 @@ def to_h
end
result
end

private

def metric_safe(str)
str.tr("/", "-")
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sbmt/outbox/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Sbmt
module Outbox
VERSION = "6.4.1"
VERSION = "6.4.2"
end
end
11 changes: 11 additions & 0 deletions spec/interactors/sbmt/outbox/process_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
16 changes: 11 additions & 5 deletions spec/lib/sbmt/outbox/v1/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,13 +34,16 @@
@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
@outbox_item_1.destroy!
@outbox_item_2.destroy!
@inbox_item_3.destroy!
@inbox_item_4.destroy!
@outbox_item_5.destroy!
end
# rubocop:enable RSpec/BeforeAfterAll

Expand All @@ -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
Expand All @@ -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}
Expand All @@ -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
Expand Down

0 comments on commit 2ecb8da

Please sign in to comment.