topological_inventory-providers-common 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faf7ab98d098c6dfed7cac60aa40dca8e84a26721eac35ed8a487c84c57d4375
4
- data.tar.gz: 122a119549a916b7d908c7655a94ed855af4ddb49220e05cedd11e89972abcd3
3
+ metadata.gz: 661072299fccb0117c3dcbe1fba36e4836a82ac1a6d98abbaab1808ea437e6d7
4
+ data.tar.gz: a1a45e527dc14cb4b09004d2df98f075818fb35d616d84d954839c289dac5c8a
5
5
  SHA512:
6
- metadata.gz: 90d69186763762d8d62c41282f27b926b6aee15fbd2b916d2f911eab519f586650e97e804ea07e3c2c1121b953a305f949912648e05ffe016ef27cd4273b0747
7
- data.tar.gz: f8864ca924b2e5b494d3e0fe2403bcd0f1c03450fe9ce755fb6bf80c832e8a1dafa0c788a9998ae50c2e63eb414852bdeadd593ca2ebfd8389ae1858e6517129
6
+ metadata.gz: ba101d97cca75814a073eb70f8528e3debb0f4270fb4cfb98cc9db55f53ff790efcd99380158e8c808b317603a9ce1a7a30d13f791e03741b699e06f0556965e
7
+ data.tar.gz: 3e4340ad6743693f104d0c847995bb866860ef2911c57865ce042389cb3872badf05f2b46119664650214285f509495f656dc5cf82f77cec9cf5e2a253a0f2cc
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.1.2] - 2020-11-24
8
+ Custom Metrics for AsyncWorker #60
9
+ Change error metric name to errors_total #64
10
+
7
11
  ## [2.1.1] - 2020-11-04
8
12
  MessagingClient and Source fix #61
9
13
  Fix availability_check in app check #62
@@ -71,7 +75,9 @@ manageiq-loggers to >= 0.4.2 #20
71
75
  ## [1.0.0] - 2020-03-19
72
76
  ### Initial release to rubygems.org
73
77
 
74
- [Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.0...HEAD
78
+ [Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.2...HEAD
79
+ [2.1.2]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.1...v2.1.2
80
+ [2.1.1]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.0...v2.1.1
75
81
  [2.1.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.0.0...v2.1.0
76
82
  [2.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.12...v2.0.0
77
83
  [1.0.12]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.11...v1.0.12
@@ -67,7 +67,7 @@ module TopologicalInventory
67
67
  PrometheusExporter::Metric::Base.default_prefix = default_prefix
68
68
 
69
69
  @duration_seconds = PrometheusExporter::Metric::Histogram.new('duration_seconds', 'Duration of processed operation')
70
- @error_counter = PrometheusExporter::Metric::Counter.new("error", ERROR_COUNTER_MESSAGE)
70
+ @error_counter = PrometheusExporter::Metric::Counter.new('errors_total', ERROR_COUNTER_MESSAGE)
71
71
  @status_counter = PrometheusExporter::Metric::Counter.new('status_counter', 'number of processed operations')
72
72
 
73
73
  [@duration_seconds, @error_counter, @status_counter].each do |metric|
@@ -1,4 +1,5 @@
1
1
  require "topological_inventory/providers/common/logging"
2
+ require "topological_inventory/providers/common/mixins/statuses"
2
3
  require "topological_inventory/providers/common/operations/health_check"
3
4
 
4
5
  module TopologicalInventory
@@ -7,10 +8,12 @@ module TopologicalInventory
7
8
  module Operations
8
9
  class AsyncWorker
9
10
  include Logging
11
+ include TopologicalInventory::Providers::Common::Mixins::Statuses
10
12
 
11
- def initialize(processor, queue = nil)
13
+ def initialize(processor, queue: nil, metrics: nil)
12
14
  @processor = processor
13
- @queue = queue || Queue.new
15
+ @queue = queue || Queue.new
16
+ @metrics = metrics
14
17
  end
15
18
 
16
19
  def start
@@ -37,15 +40,17 @@ module TopologicalInventory
37
40
 
38
41
  private
39
42
 
40
- attr_reader :thread, :queue, :processor
43
+ attr_reader :thread, :queue, :processor, :metrics
41
44
 
42
- def process_message(msg)
43
- processor.process!(msg)
45
+ def process_message(message)
46
+ result = processor.process!(message, metrics)
47
+ metrics&.record_operation(message.message, :status => result)
44
48
  rescue => err
45
- model, method = msg.message.to_s.split(".")
49
+ model, method = message.message.to_s.split(".")
46
50
  logger.error("#{model}##{method}: async worker failure: #{err.cause}\n#{err}\n#{err.backtrace.join("\n")}")
51
+ metrics&.record_operation(message.message, :status => operation_status[:error])
47
52
  ensure
48
- msg.ack
53
+ message.ack
49
54
  TopologicalInventory::Providers::Common::Operations::HealthCheck.touch_file
50
55
  logger.debug("Operations::AsyncWorker queue length: #{queue.length}") if queue.length >= 20 && queue.length % 5 == 0
51
56
  end
@@ -30,7 +30,7 @@ module TopologicalInventory
30
30
  attr_accessor :identity, :operation, :params, :request_context, :source_id, :account_number
31
31
 
32
32
  def initialize(params = {}, request_context = nil, metrics = nil)
33
- self.metrics = metrics
33
+ self.metrics = metrics
34
34
  self.operation = 'Source'
35
35
  self.params = params
36
36
  self.request_context = request_context
@@ -1,7 +1,7 @@
1
1
  module TopologicalInventory
2
2
  module Providers
3
3
  module Common
4
- VERSION = "2.1.1".freeze
4
+ VERSION = "2.1.2".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -3,33 +3,42 @@ require "topological_inventory/providers/common/operations/async_worker"
3
3
  describe TopologicalInventory::Providers::Common::Operations::AsyncWorker do
4
4
  let(:queue) { double }
5
5
  let(:impl) { double }
6
+ let(:metrics) { double('metrics') }
6
7
  let(:msg) { double }
7
- subject { described_class.new(impl, queue) }
8
+ let(:operation) { "Source.availability_check" }
9
+
10
+ subject { described_class.new(impl, :queue => queue, :metrics => metrics) }
8
11
 
9
12
  before do
10
13
  allow(queue).to receive(:length).and_return(0)
11
- allow(msg).to receive(:message).and_return("Source.availability_check")
14
+ allow(msg).to receive(:message).and_return(operation)
12
15
  end
13
16
 
14
17
  context "when the message is able to be processed" do
18
+ let(:result) { subject.operation_status[:success] }
15
19
  before do
16
- allow(impl).to receive(:process!).with(msg)
20
+ allow(impl).to receive(:process!).with(msg, metrics).and_return(result)
17
21
  allow(msg).to receive(:ack)
18
22
  end
19
23
 
20
24
  it "drains messages that are added to the queue" do
21
- expect(impl).to receive(:process!).with(msg).once
25
+ expect(impl).to receive(:process!).with(msg, metrics).once
26
+ expect(metrics).to receive(:record_operation).with(operation, :status => result)
22
27
  subject.send(:process_message, msg)
23
28
  end
24
29
  end
25
30
 
26
31
  context "when the message results in an error" do
32
+ let(:result) { subject.operation_status[:error] }
27
33
  before do
28
- allow(impl).to receive(:process!).with(msg).and_raise(StandardError.new("boom!"))
34
+ allow(impl).to receive(:process!).with(msg, metrics).and_raise(StandardError.new("boom!"))
29
35
  end
30
36
 
31
37
  it "ack's the message on failure" do
38
+ allow(subject).to receive(:logger).and_return(double.as_null_object)
39
+
32
40
  expect(msg).to receive(:ack).once
41
+ expect(metrics).to receive(:record_operation).with(operation, :status => result)
33
42
  subject.send(:process_message, msg)
34
43
  end
35
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topological_inventory-providers-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Slemr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-04 00:00:00.000000000 Z
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport