Skip to content

Commit

Permalink
Merge branch 'feat/DEX-2069/add-owner-to-missing-activity-alert' into…
Browse files Browse the repository at this point in the history
… 'master'

[DEX-2069] feat: add owner to job_counter metric

Closes DEX-2069

See merge request nstmrt/rubygems/outbox!86
  • Loading branch information
bibendi committed Apr 17, 2024
2 parents 4c97021 + 6fc7fd6 commit d9becba
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased] - yyyy-mm-dd

## [6.1.0] - 2024-04-15

### Added
- Add `owner` label to `job_counter` metric

## [6.0.1] - 2024-03-28

### Added
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/yabeda.rb
Expand Up @@ -50,7 +50,7 @@
default_tag(:worker_name, "worker")

counter :job_counter,
tags: %i[type name partition state],
tags: %i[type name partition state owner],
comment: "The total number of processed jobs"

counter :job_timeout_counter,
Expand Down
3 changes: 2 additions & 1 deletion lib/sbmt/outbox/v1/worker.rb
Expand Up @@ -127,7 +127,8 @@ def build_jobs(boxes)
yabeda_labels: {
type: item_class.box_type,
name: item_class.box_name,
partition: partition
partition: partition,
owner: item_class.owner
},
resource_key: resource_key,
resource_path: "sbmt/outbox/worker/#{resource_key}"
Expand Down
3 changes: 3 additions & 0 deletions lib/sbmt/outbox/v2/tasks/base.rb
Expand Up @@ -7,6 +7,8 @@ module Tasks
class Base
attr_reader :item_class, :worker_name, :worker_version, :log_tags, :yabeda_labels

delegate :owner, to: :item_class

def initialize(item_class:, worker_name:, worker_version: 2)
@item_class = item_class
@worker_name = worker_name
Expand All @@ -22,6 +24,7 @@ def initialize(item_class:, worker_name:, worker_version: 2)
@yabeda_labels = {
type: item_class.box_type,
name: metric_safe(item_class.box_name),
owner: owner,
worker_version: 2,
worker_name: worker_name
}
Expand Down
2 changes: 1 addition & 1 deletion lib/sbmt/outbox/version.rb
Expand Up @@ -2,6 +2,6 @@

module Sbmt
module Outbox
VERSION = "6.0.1"
VERSION = "6.1.0"
end
end
2 changes: 2 additions & 0 deletions spec/interactors/sbmt/outbox/process_item_spec.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "ostruct"

describe Sbmt::Outbox::ProcessItem do
describe "#call" do
subject(:result) { described_class.call(OutboxItem, outbox_item.id) }
Expand Down
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "ostruct"

describe Sbmt::Outbox::Middleware::Sentry::TracingBatchProcessMiddleware do
let(:job) { OpenStruct.new(log_tags: {}) }
let(:scope) { double("scope") } # rubocop:disable RSpec/VerifiedDoubles
Expand Down
13 changes: 11 additions & 2 deletions spec/lib/sbmt/outbox/v1/worker_spec.rb
Expand Up @@ -62,8 +62,17 @@
expect_to_process_item(@inbox_item_4) do
worker.stop
end

worker.start
yabeda_labels = {owner: nil, worker_name: "worker", worker_version: 1}

expect { worker.start }
.to increment_yabeda_counter(Yabeda.box_worker.job_counter)
.with_tags(name: "outbox_item", state: "processed", partition: 0, type: :outbox, **yabeda_labels).by(1)
.and increment_yabeda_counter(Yabeda.box_worker.job_counter)
.with_tags(name: "outbox_item", state: "processed", partition: 1, type: :outbox, **yabeda_labels).by(1)
.and increment_yabeda_counter(Yabeda.box_worker.job_counter)
.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)

expect(processed_info[:processed]).to eq [1, 3, 4, 2]
expect(processed_info[:processed_by_thread][thread_1]).to eq [1, 3, 4]
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/sbmt/outbox/v2/box_processor_spec.rb
Expand Up @@ -49,7 +49,7 @@ def process_task(worker_number, task)
expect(Sbmt::Outbox.logger).to receive(:with_tags).with(**task.log_tags)

expect { processor.start }
.to increment_yabeda_counter(Yabeda.box_worker.job_counter).with_tags(name: "inbox_item", state: "processed", type: :inbox, worker_name: "abstract_worker", worker_version: 2).by(1)
.to increment_yabeda_counter(Yabeda.box_worker.job_counter).with_tags(name: "inbox_item", state: "processed", type: :inbox, owner: nil, worker_name: "abstract_worker", worker_version: 2).by(1)
.and measure_yabeda_histogram(Yabeda.box_worker.job_execution_runtime).with_tags(name: "inbox_item", type: :inbox, worker_name: "abstract_worker", worker_version: 2)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/sbmt/outbox/v2/tasks/base_spec.rb
Expand Up @@ -12,8 +12,8 @@
end

it "properly formats yabeda labels" do
expect(described_class.new(item_class: InboxItem, worker_name: worker_name).yabeda_labels).to eq(name: "inbox_item", type: :inbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: OutboxItem, worker_name: worker_name).yabeda_labels).to eq(name: "outbox_item", type: :outbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: Combined::OutboxItem, worker_name: worker_name).yabeda_labels).to eq(name: "combined-outbox_item", type: :outbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: InboxItem, worker_name: worker_name).yabeda_labels).to eq(name: "inbox_item", owner: nil, type: :inbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: OutboxItem, worker_name: worker_name).yabeda_labels).to eq(name: "outbox_item", owner: nil, type: :outbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: Combined::OutboxItem, worker_name: worker_name).yabeda_labels).to eq(name: "combined-outbox_item", owner: nil, type: :outbox, worker_name: "worker", worker_version: 2)
end
end
8 changes: 4 additions & 4 deletions spec/lib/sbmt/outbox/v2/tasks/poll_spec.rb
Expand Up @@ -14,9 +14,9 @@
end

it "properly formats yabeda labels" do
expect(described_class.new(item_class: InboxItem, worker_name: worker_name, partition: partition, buckets: buckets).yabeda_labels).to eq(name: "inbox_item", type: :inbox, worker_name: "worker", worker_version: 2, partition: 0)
expect(described_class.new(item_class: OutboxItem, worker_name: worker_name, partition: partition, buckets: buckets).yabeda_labels).to eq(name: "outbox_item", type: :outbox, worker_name: "worker", worker_version: 2, partition: 0)
expect(described_class.new(item_class: Combined::OutboxItem, worker_name: worker_name, partition: partition, buckets: buckets).yabeda_labels).to eq(name: "combined-outbox_item", type: :outbox, worker_name: "worker", worker_version: 2, partition: 0)
expect(described_class.new(item_class: InboxItem, worker_name: worker_name, partition: partition, buckets: buckets).yabeda_labels).to eq(name: "inbox_item", owner: nil, type: :inbox, worker_name: "worker", worker_version: 2, partition: 0)
expect(described_class.new(item_class: OutboxItem, worker_name: worker_name, partition: partition, buckets: buckets).yabeda_labels).to eq(name: "outbox_item", owner: nil, type: :outbox, worker_name: "worker", worker_version: 2, partition: 0)
expect(described_class.new(item_class: Combined::OutboxItem, worker_name: worker_name, partition: partition, buckets: buckets).yabeda_labels).to eq(name: "combined-outbox_item", owner: nil, type: :outbox, worker_name: "worker", worker_version: 2, partition: 0)
end

it "properly converts to hash" do
Expand All @@ -25,7 +25,7 @@
item_class: InboxItem, worker_name: "worker", worker_version: 2, partition: 0, buckets: [0, 1],
resource_key: "inbox_item:0", resource_path: "sbmt:outbox:worker:inbox_item:0", redis_queue: "inbox_item:job_queue",
log_tags: {box_name: "inbox_item", box_partition: 0, box_type: :inbox, worker_name: "worker", worker_version: 2},
yabeda_labels: {name: "inbox_item", type: :inbox, partition: 0, worker_name: "worker", worker_version: 2}
yabeda_labels: {name: "inbox_item", owner: nil, type: :inbox, partition: 0, worker_name: "worker", worker_version: 2}
)
end
end
8 changes: 4 additions & 4 deletions spec/lib/sbmt/outbox/v2/tasks/process_spec.rb
Expand Up @@ -14,9 +14,9 @@
end

it "properly formats yabeda labels" do
expect(described_class.new(item_class: InboxItem, worker_name: worker_name, bucket: bucket, ids: ids).yabeda_labels).to eq(name: "inbox_item", type: :inbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: OutboxItem, worker_name: worker_name, bucket: bucket, ids: ids).yabeda_labels).to eq(name: "outbox_item", type: :outbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: Combined::OutboxItem, worker_name: worker_name, bucket: bucket, ids: ids).yabeda_labels).to eq(name: "combined-outbox_item", type: :outbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: InboxItem, worker_name: worker_name, bucket: bucket, ids: ids).yabeda_labels).to eq(name: "inbox_item", owner: nil, type: :inbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: OutboxItem, worker_name: worker_name, bucket: bucket, ids: ids).yabeda_labels).to eq(name: "outbox_item", owner: nil, type: :outbox, worker_name: "worker", worker_version: 2)
expect(described_class.new(item_class: Combined::OutboxItem, worker_name: worker_name, bucket: bucket, ids: ids).yabeda_labels).to eq(name: "combined-outbox_item", owner: nil, type: :outbox, worker_name: "worker", worker_version: 2)
end

it "properly converts to hash" do
Expand All @@ -25,7 +25,7 @@
item_class: InboxItem, worker_name: "worker", worker_version: 2, bucket: 0, ids: [0, 1],
resource_key: "inbox_item:0", resource_path: "sbmt:outbox:worker:inbox_item:0",
log_tags: {box_name: "inbox_item", bucket: 0, box_type: :inbox, worker_name: "worker", worker_version: 2},
yabeda_labels: {name: "inbox_item", type: :inbox, worker_name: "worker", worker_version: 2}
yabeda_labels: {name: "inbox_item", owner: nil, type: :inbox, worker_name: "worker", worker_version: 2}
)
end
end

0 comments on commit d9becba

Please sign in to comment.