Skip to content

Commit

Permalink
[DEX-2265] fix: replace / with - in metric tag name in last_stored_ev…
Browse files Browse the repository at this point in the history
…ent_id / created_counter
  • Loading branch information
ysatarov committed May 15, 2024
1 parent 6f97941 commit b7f66ff
Show file tree
Hide file tree
Showing 5 changed files with 32 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.3] - 2024-05-16

### Fixed

- replace `/` with `-` in label `name` in outbox_last_stored_event_id / outbox_created_counter

## [6.4.2] - 2024-05-07

### Fixed
Expand Down
6 changes: 4 additions & 2 deletions app/interactors/sbmt/outbox/base_create_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 BaseCreateItem < Outbox::DryInteractor
Expand Down Expand Up @@ -41,14 +43,14 @@ def track_last_stored_id(item_id, partition)
Yabeda
.outbox
.last_stored_event_id
.set({type: box_type, name: box_name, owner: owner, partition: partition}, item_id)
.set({type: box_type, name: Sbmt::Outbox::Metrics::Utils.metric_safe(box_name), owner: owner, partition: partition}, item_id)
end

def track_counter(partition)
Yabeda
.outbox
.created_counter
.increment({type: box_type, name: box_name, owner: owner, partition: partition}, by: 1)
.increment({type: box_type, name: Sbmt::Outbox::Metrics::Utils.metric_safe(box_name), owner: owner, partition: partition}, by: 1)
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.2"
VERSION = "6.4.3"
end
end
8 changes: 6 additions & 2 deletions spec/interactors/sbmt/outbox/create_inbox_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
end

it "tracks Yabeda metrics" do
expect { result }.to update_yabeda_gauge(Yabeda.outbox.last_stored_event_id)
expect { result }
.to update_yabeda_gauge(Yabeda.outbox.last_stored_event_id).with_tags(name: "inbox_item", type: :inbox, owner: nil, partition: 0)
.and increment_yabeda_counter(Yabeda.outbox.created_counter).with_tags(name: "inbox_item", type: :inbox, owner: nil, partition: 0)
end

context "when got errors" do
Expand All @@ -26,7 +28,9 @@
end

it "does not track Yabeda metrics" do
expect { result }.not_to update_yabeda_gauge(Yabeda.outbox.last_stored_event_id)
expect { result }
.to not_update_yabeda_gauge(Yabeda.outbox.last_stored_event_id)
.and not_increment_yabeda_counter(Yabeda.outbox.created_counter)
end

it "returns errors" do
Expand Down
25 changes: 15 additions & 10 deletions spec/interactors/sbmt/outbox/create_outbox_item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# frozen_string_literal: true

describe Sbmt::Outbox::CreateOutboxItem do
subject(:result) { described_class.call(OutboxItem, attributes: attributes) }
subject(:result) { described_class.call(Combined::OutboxItem, attributes: attributes) }

let(:attributes) do
{
payload: "test",
event_key: 10
event_key: 10,
event_name: "order_created"
}
end

it "creates a record" do
expect { result }.to change(OutboxItem, :count).by(1)
expect { result }.to change(Combined::OutboxItem, :count).by(1)
expect(result).to be_success
expect(result.value!).to have_attributes(bucket: 2)
expect(result.value!).to have_attributes(bucket: 1)
end

it "tracks Yabeda metrics" do
expect { result }.to update_yabeda_gauge(Yabeda.outbox.last_stored_event_id)
expect { result }
.to update_yabeda_gauge(Yabeda.outbox.last_stored_event_id).with_tags(name: "combined-outbox_item", type: :outbox, owner: nil, partition: 1)
.and increment_yabeda_counter(Yabeda.outbox.created_counter).with_tags(name: "combined-outbox_item", type: :outbox, owner: nil, partition: 1)
end

context "when got errors" do
Expand All @@ -26,24 +29,26 @@
end

it "does not track Yabeda metrics" do
expect { result }.not_to update_yabeda_gauge(Yabeda.outbox.last_stored_event_id)
expect { result }
.to not_update_yabeda_gauge(Yabeda.outbox.last_stored_event_id)
.and not_increment_yabeda_counter(Yabeda.outbox.created_counter)
end

it "returns errors" do
expect { result }.not_to change(OutboxItem, :count)
expect { result }.not_to change(Combined::OutboxItem, :count)
expect(result).not_to be_success
end
end

context "when partition by custom key" do
subject(:result) { described_class.call(InboxItem, attributes: attributes, partition_by: partition_by) }
subject(:result) { described_class.call(Combined::OutboxItem, attributes: attributes, partition_by: partition_by) }

let(:partition_by) { 9 }

it "creates a record" do
expect { result }.to change(InboxItem, :count).by(1)
expect { result }.to change(Combined::OutboxItem, :count).by(1)
expect(result).to be_success
expect(result.value!).to have_attributes(bucket: 1)
expect(result.value!).to have_attributes(bucket: 3)
end
end
end

0 comments on commit b7f66ff

Please sign in to comment.