topological_inventory-providers-common 2.1.0 → 2.1.5

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: aad209b97efea9bb19ce488782adb1dabfa8d650c12f8637e2b348ed4ec95a15
4
- data.tar.gz: 69b9bbed6a2d725990206ab3bfc7b13ec25b10f7e0c1a979b48c61b67e53fd0d
3
+ metadata.gz: 75348e5abd6addefc5c90886fe1b31fc8405239998e030f6f740ebd2b034d726
4
+ data.tar.gz: 7b6c51b8299d5209587253954d41e8c7898c0f15fcab3fcdbcdfd631d8311aff
5
5
  SHA512:
6
- metadata.gz: 45722b70f009a764d8cd804424157cc98b1a225b72326b8b8971fecd093fa6260446777db76bc3502e487d27dc82b2b4325959302f4a1abe13fbbf8c015c1d54
7
- data.tar.gz: b1a6de8e2eb93b2b26d4b609f17a1a518cf4b318dbcf117c6225fe297bb3ec97f870b944e151786977ad90f42c16746eeeadf6a3d113b648921e278cb831aadd
6
+ metadata.gz: d2e5ed6d7135c0ace48bcd109c8b757c8b3f93633053bb8878cbcdc69ea13d69b18461db763ca97ad140d729078d15c1b05b59462fdfcc28a9b487fac0a73d24
7
+ data.tar.gz: 6967cf0f588c7fc477e308f1cc3d9ad9be1487cb8932506fb5cbd7604d372486a33eb3d503d77a21e7eb3a08e5a02dfeba056f1d04336b44b3037cd28a2f81d0
@@ -3,8 +3,25 @@ All notable changes to this project will be documented in this file.
3
3
 
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
+ ## [2.1.5] - 2021-01-07
7
+ Include x-rh-id header in Kafka Availability-Status message #73
6
8
 
7
- ## [2.1.0]
9
+ ## [2.1.4] - 2020-12-14
10
+ Common Counter metrics init #71
11
+
12
+ ## [2.1.3] - 2020-12-14
13
+ Update travis URL in README file #67
14
+ Kafka availability_checks fix #68
15
+
16
+ ## [2.1.2] - 2020-11-24
17
+ Custom Metrics for AsyncWorker #60
18
+ Change error metric name to errors_total #64
19
+
20
+ ## [2.1.1] - 2020-11-04
21
+ MessagingClient and Source fix #61
22
+ Fix availability_check in app check #62
23
+
24
+ ## [2.1.0] - 2020-11-02
8
25
  Add Availability checks for sources via Kafka #54
9
26
  Common Metrics exporter #57
10
27
  Rubocop rules from insights-api-common + yamllint #59
@@ -12,7 +29,7 @@ Rubocop rules from insights-api-common + yamllint #59
12
29
  ## [2.0.0] - 2020-10-20
13
30
  Operations/API clients refactoring
14
31
 
15
- ## [1.0.12] - 2020-10-01
32
+ ## [1.0.12] - 2020-10-05
16
33
  Add Operations Async Worker class #55
17
34
 
18
35
  ## [1.0.11] - 2020-09-04
@@ -67,7 +84,12 @@ manageiq-loggers to >= 0.4.2 #20
67
84
  ## [1.0.0] - 2020-03-19
68
85
  ### Initial release to rubygems.org
69
86
 
70
- [Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.0...HEAD
87
+ [Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.5...HEAD
88
+ [2.1.5]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.4...v2.1.5
89
+ [2.1.4]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.3...v2.1.4
90
+ [2.1.3]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.2...v2.1.3
91
+ [2.1.2]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.1...v2.1.2
92
+ [2.1.1]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.0...v2.1.1
71
93
  [2.1.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.0.0...v2.1.0
72
94
  [2.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.12...v2.0.0
73
95
  [1.0.12]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.11...v1.0.12
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TopologicalInventory::Providers::Common
2
2
 
3
- [![Build Status](https://travis-ci.org/RedHatInsights/topological_inventory-providers-common.svg?branch=master)](https://travis-ci.org/RedHatInsights/topological_inventory-providers-common)
3
+ [![Build Status](https://travis-ci.com/RedHatInsights/topological_inventory-providers-common.svg?branch=master)](https://travis-ci.com/RedHatInsights/topological_inventory-providers-common)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/df747492b802bfea3c83/maintainability)](https://codeclimate.com/github/RedHatInsights/topological_inventory-providers-common/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/df747492b802bfea3c83/test_coverage)](https://codeclimate.com/github/RedHatInsights/topological_inventory-providers-common/test_coverage)
6
6
  [![security](https://hakiri.io/github/RedHatInsights/topological_inventory-providers-common/master.svg)](https://hakiri.io/github/RedHatInsights/topological_inventory-providers-common/master)
@@ -11,8 +11,8 @@ module TopologicalInventory
11
11
  attr_accessor :queue_port
12
12
 
13
13
  def initialize
14
- @queue_host = ENV['QUEUE_HOST'] || 'localhost'
15
- @queue_port = (ENV['QUEUE_PORT'] || 9092).to_i
14
+ self.queue_host = ENV['QUEUE_HOST'] || 'localhost'
15
+ self.queue_port = (ENV['QUEUE_PORT'] || 9092).to_i
16
16
  end
17
17
 
18
18
  def self.default
@@ -28,7 +28,7 @@ module TopologicalInventory
28
28
  end
29
29
 
30
30
  cache_with_timeout(:client) do
31
- ManageIQ::Messaging::Client.open(:protocol => :Kafka, :host => @queue_host, :port => @queue_port)
31
+ ManageIQ::Messaging::Client.open(:protocol => :Kafka, :host => default.queue_host, :port => default.queue_port)
32
32
  end
33
33
 
34
34
  def client
@@ -3,18 +3,25 @@ require "prometheus_exporter"
3
3
  require "prometheus_exporter/server"
4
4
  require "prometheus_exporter/client"
5
5
  require "prometheus_exporter/instrumentation"
6
+ require "topological_inventory/providers/common/mixins/statuses"
6
7
 
7
8
  module TopologicalInventory
8
9
  module Providers
9
10
  module Common
10
11
  class Metrics
12
+ include TopologicalInventory::Providers::Common::Mixins::Statuses
13
+
11
14
  ERROR_COUNTER_MESSAGE = "total number of errors".freeze
15
+ ERROR_TYPES = %i[general].freeze
16
+ OPERATIONS = %w[].freeze
12
17
 
13
18
  def initialize(port = 9394)
14
19
  return if port == 0
15
20
 
16
21
  configure_server(port)
17
22
  configure_metrics
23
+
24
+ init_counters
18
25
  end
19
26
 
20
27
  def stop_server
@@ -25,6 +32,10 @@ module TopologicalInventory
25
32
  @error_counter&.observe(1, :type => type.to_s)
26
33
  end
27
34
 
35
+ def record_refresh_timing(labels = {}, &block)
36
+ record_time(@refresh_timer, labels, &block)
37
+ end
38
+
28
39
  def record_operation(name, labels = {})
29
40
  @status_counter&.observe(1, (labels || {}).merge(:name => name))
30
41
  end
@@ -55,6 +66,19 @@ module TopologicalInventory
55
66
 
56
67
  private
57
68
 
69
+ # Set all values to 0 (otherwise the counter is undefined)
70
+ def init_counters
71
+ self.class::ERROR_TYPES.each do |err_type|
72
+ @error_counter&.observe(0, :type => err_type)
73
+ end
74
+
75
+ self.class::OPERATIONS.each do |op|
76
+ operation_status.each_key do |status|
77
+ @status_counter&.observe(0, :name => op, :status => status.to_s)
78
+ end
79
+ end
80
+ end
81
+
58
82
  def configure_server(port)
59
83
  @server = PrometheusExporter::Server::WebServer.new(:port => port)
60
84
  @server.start
@@ -67,10 +91,11 @@ module TopologicalInventory
67
91
  PrometheusExporter::Metric::Base.default_prefix = default_prefix
68
92
 
69
93
  @duration_seconds = PrometheusExporter::Metric::Histogram.new('duration_seconds', 'Duration of processed operation')
70
- @error_counter = PrometheusExporter::Metric::Counter.new("error", ERROR_COUNTER_MESSAGE)
94
+ @refresh_timer = PrometheusExporter::Metric::Histogram.new('refresh_time', 'Duration of full refresh')
95
+ @error_counter = PrometheusExporter::Metric::Counter.new('errors_total', ERROR_COUNTER_MESSAGE)
71
96
  @status_counter = PrometheusExporter::Metric::Counter.new('status_counter', 'number of processed operations')
72
97
 
73
- [@duration_seconds, @error_counter, @status_counter].each do |metric|
98
+ [@duration_seconds, @refresh_timer, @error_counter, @status_counter].each do |metric|
74
99
  @server.collector.register_metric(metric)
75
100
  end
76
101
  end
@@ -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
@@ -83,7 +83,7 @@ module TopologicalInventory
83
83
  application.last_checked_at.present? && application.last_checked_at >= LAST_CHECKED_AT_THRESHOLD.ago
84
84
  end
85
85
 
86
- logger.availability_check("Skipping, last check at #{endpoint.last_checked_at || application.last_checked_at} [Source ID: #{source_id}] ") if checked_recently
86
+ logger.availability_check("Skipping, last check at #{endpoint&.last_checked_at || application&.last_checked_at} [Source ID: #{source_id}] ") if checked_recently
87
87
 
88
88
  checked_recently
89
89
  end
@@ -208,13 +208,14 @@ module TopologicalInventory
208
208
  end
209
209
 
210
210
  def availability_status_message(payload)
211
- messaging_client.publish_message(
211
+ messaging_client.publish_topic(
212
212
  :service => SERVICE_NAME,
213
- :message => EVENT_AVAILABILITY_STATUS,
214
- :payload => payload.to_json
213
+ :event => EVENT_AVAILABILITY_STATUS,
214
+ :payload => payload.to_json,
215
+ :headers => identity
215
216
  )
216
217
  rescue => err
217
- logger.availability_check("Failed to update Application id: #{application.id} - #{err.message}", :error)
218
+ logger.availability_check("Failed to update #{payload[:resource_type]} id: #{payload[:resource_id]} - #{err.message}", :error)
218
219
  ensure
219
220
  messaging_client&.close
220
221
  end
@@ -1,7 +1,7 @@
1
1
  module TopologicalInventory
2
2
  module Providers
3
3
  module Common
4
- VERSION = "2.1.0".freeze
4
+ VERSION = "2.1.5".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -39,11 +39,14 @@ RSpec.shared_examples "availability_check" do
39
39
  def kafka_message(resource_type, resource_id, status, error_message = nil)
40
40
  res = {
41
41
  :service => described_class::SERVICE_NAME,
42
- :message => described_class::EVENT_AVAILABILITY_STATUS,
42
+ :event => described_class::EVENT_AVAILABILITY_STATUS,
43
43
  :payload => {
44
44
  :resource_type => resource_type,
45
45
  :resource_id => resource_id,
46
46
  :status => status
47
+ },
48
+ :headers => {
49
+ "x-rh-identity" => "eyJpZGVudGl0eSI6eyJhY2NvdW50X251bWJlciI6IjExMDAxIiwidXNlciI6eyJpc19vcmdfYWRtaW4iOnRydWV9fX0="
47
50
  }
48
51
  }
49
52
  res[:payload][:error] = error_message if error_message
@@ -67,15 +70,15 @@ RSpec.shared_examples "availability_check" do
67
70
 
68
71
  expect(subject).to receive(:connection_status).and_return([status_available, ''])
69
72
 
70
- expect(kafka_client).to receive(:publish_message).with(
73
+ expect(kafka_client).to receive(:publish_topic).with(
71
74
  kafka_message("Source", source_id, status_available)
72
75
  )
73
76
 
74
- expect(kafka_client).to receive(:publish_message).with(
77
+ expect(kafka_client).to receive(:publish_topic).with(
75
78
  kafka_message("Endpoint", endpoint_id, status_available, '')
76
79
  )
77
80
 
78
- expect(kafka_client).to receive(:publish_message).with(
81
+ expect(kafka_client).to receive(:publish_topic).with(
79
82
  kafka_message("Application", application_id, status_available)
80
83
  )
81
84
 
@@ -89,15 +92,15 @@ RSpec.shared_examples "availability_check" do
89
92
 
90
93
  expect(subject).to receive(:connection_status).and_return([status_unavailable, error_message])
91
94
 
92
- expect(kafka_client).to receive(:publish_message).with(
95
+ expect(kafka_client).to receive(:publish_topic).with(
93
96
  kafka_message("Source", source_id, status_unavailable)
94
97
  )
95
98
 
96
- expect(kafka_client).to receive(:publish_message).with(
99
+ expect(kafka_client).to receive(:publish_topic).with(
97
100
  kafka_message("Endpoint", endpoint_id, status_unavailable, error_message)
98
101
  )
99
102
 
100
- expect(kafka_client).to receive(:publish_message).with(
103
+ expect(kafka_client).to receive(:publish_topic).with(
101
104
  kafka_message("Application", application_id, status_unavailable)
102
105
  )
103
106
 
@@ -110,7 +113,7 @@ RSpec.shared_examples "availability_check" do
110
113
 
111
114
  expect(subject).to receive(:connection_status).and_return([status_unavailable, error_message])
112
115
 
113
- expect(kafka_client).to receive(:publish_message).with(
116
+ expect(kafka_client).to receive(:publish_topic).with(
114
117
  kafka_message("Source", source_id, status_unavailable)
115
118
  )
116
119
 
@@ -126,11 +129,11 @@ RSpec.shared_examples "availability_check" do
126
129
 
127
130
  expect(subject).to receive(:connection_status).and_return([status_unavailable, error_message])
128
131
 
129
- expect(kafka_client).to receive(:publish_message).with(
132
+ expect(kafka_client).to receive(:publish_topic).with(
130
133
  kafka_message("Source", source_id, status_unavailable)
131
134
  )
132
135
 
133
- expect(kafka_client).to receive(:publish_message).with(
136
+ expect(kafka_client).to receive(:publish_topic).with(
134
137
  kafka_message("Endpoint", endpoint_id, status_unavailable, error_message)
135
138
  )
136
139
 
@@ -258,11 +261,11 @@ RSpec.shared_examples "availability_check" do
258
261
 
259
262
  expect(subject).to receive(:connection_status).and_return([status_available, ''])
260
263
 
261
- expect(kafka_client).to receive(:publish_message).with(
264
+ expect(kafka_client).to receive(:publish_topic).with(
262
265
  kafka_message("Source", source_id, status_available)
263
266
  )
264
267
 
265
- expect(kafka_client).to receive(:publish_message).with(
268
+ expect(kafka_client).to receive(:publish_topic).with(
266
269
  kafka_message("Application", application_id, status_available)
267
270
  )
268
271
 
@@ -307,11 +310,11 @@ RSpec.shared_examples "availability_check" do
307
310
 
308
311
  expect(subject).to receive(:connection_status).and_return([status_unavailable, error_message])
309
312
 
310
- expect(kafka_client).to receive(:publish_message).with(
313
+ expect(kafka_client).to receive(:publish_topic).with(
311
314
  kafka_message("Source", source_id, status_unavailable)
312
315
  )
313
316
 
314
- expect(kafka_client).to receive(:publish_message).with(
317
+ expect(kafka_client).to receive(:publish_topic).with(
315
318
  kafka_message("Application", application_id, status_unavailable)
316
319
  )
317
320
 
@@ -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.0
4
+ version: 2.1.5
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-02 00:00:00.000000000 Z
11
+ date: 2021-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport