topological_inventory-providers-common 2.1.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -1
- data/README.md +1 -1
- data/lib/topological_inventory/providers/common/clowder_config.rb +68 -0
- data/lib/topological_inventory/providers/common/messaging_client.rb +3 -2
- data/lib/topological_inventory/providers/common/metrics.rb +27 -2
- data/lib/topological_inventory/providers/common/operations/async_worker.rb +12 -7
- data/lib/topological_inventory/providers/common/operations/source.rb +7 -6
- data/lib/topological_inventory/providers/common/version.rb +1 -1
- data/spec/support/shared/availability_check.rb +18 -15
- data/spec/topological_inventory/providers/common/operations/async_worker_spec.rb +14 -5
- data/topological_inventory-providers-common.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3292228e7688ff8aa1d33e40d3a50a6e30928cc4b8e950166e9d7d82df61ee53
|
4
|
+
data.tar.gz: a1f98d554c706ff3dc37ea9659ac88ddf9b7e7801958a68fbf6b1824e74f32d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d44938aa30f1002deb30d15f61f6c89d80da94f6387e3985468ca76ac219d64ad3b57a91d7638480c14d32a17610545dae82abe3044a1328b2ef10ea6f5c9773
|
7
|
+
data.tar.gz: fb858ce78c5a5123e78fb55cb69fe01d7d682baa4c83661ed7ab3e665da95cab283992356a89cd73da1e1cd6580e5b18c8b2e480c70b2a8c9b9cf604b06dbefb
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,22 @@ 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
|
+
## [3.0.0] - 2021-03-08
|
7
|
+
Clowder migration #75
|
8
|
+
|
9
|
+
## [2.1.5] - 2021-01-07
|
10
|
+
Include x-rh-id header in Kafka Availability-Status message #73
|
11
|
+
|
12
|
+
## [2.1.4] - 2020-12-14
|
13
|
+
Common Counter metrics init #71
|
14
|
+
|
15
|
+
## [2.1.3] - 2020-12-14
|
16
|
+
Update travis URL in README file #67
|
17
|
+
Kafka availability_checks fix #68
|
18
|
+
|
19
|
+
## [2.1.2] - 2020-11-24
|
20
|
+
Custom Metrics for AsyncWorker #60
|
21
|
+
Change error metric name to errors_total #64
|
6
22
|
|
7
23
|
## [2.1.1] - 2020-11-04
|
8
24
|
MessagingClient and Source fix #61
|
@@ -71,7 +87,14 @@ manageiq-loggers to >= 0.4.2 #20
|
|
71
87
|
## [1.0.0] - 2020-03-19
|
72
88
|
### Initial release to rubygems.org
|
73
89
|
|
74
|
-
[Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/
|
90
|
+
[Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v3.0.0...HEAD
|
91
|
+
[3.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.5...v3.0.0
|
92
|
+
[2.1.5]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.4...v2.1.5
|
93
|
+
[2.1.5]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.4...v2.1.5
|
94
|
+
[2.1.4]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.3...v2.1.4
|
95
|
+
[2.1.3]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.2...v2.1.3
|
96
|
+
[2.1.2]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.1...v2.1.2
|
97
|
+
[2.1.1]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.0...v2.1.1
|
75
98
|
[2.1.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.0.0...v2.1.0
|
76
99
|
[2.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.12...v2.0.0
|
77
100
|
[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.
|
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)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'clowder-common-ruby'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module TopologicalInventory
|
5
|
+
module Providers
|
6
|
+
module Common
|
7
|
+
class ClowderConfig
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def self.clowder_enabled?
|
11
|
+
::ClowderCommonRuby::Config.clowder_enabled?
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.instance
|
15
|
+
@instance ||= {}.tap do |options|
|
16
|
+
if clowder_enabled?
|
17
|
+
config = ::ClowderCommonRuby::Config.load
|
18
|
+
options["awsAccessKeyId"] = config.logging.cloudwatch.accessKeyId
|
19
|
+
options["awsRegion"] = config.logging.cloudwatch.region
|
20
|
+
options["awsSecretAccessKey"] = config.logging.cloudwatch.secretAccessKey
|
21
|
+
broker = config.kafka.brokers.first
|
22
|
+
options["kafkaHost"] = broker.hostname
|
23
|
+
options["kafkaPort"] = broker.port
|
24
|
+
|
25
|
+
options["kafkaTopics"] = {}.tap do |topics|
|
26
|
+
config.kafka.topics.each do |topic|
|
27
|
+
topics[topic.requestedName.to_s] = topic.name.to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
options["logGroup"] = config.logging.cloudwatch.logGroup
|
31
|
+
options["metricsPort"] = config.metricsPort
|
32
|
+
options["metricsPath"] = config.metricsPath # not supported by PrometheusExporter
|
33
|
+
else
|
34
|
+
options["awsAccessKeyId"] = ENV['CW_AWS_ACCESS_KEY_ID']
|
35
|
+
options["awsRegion"] = 'us-east-1'
|
36
|
+
options["awsSecretAccessKey"] = ENV['CW_AWS_SECRET_ACCESS_KEY']
|
37
|
+
options["kafkaBrokers"] = ["#{ENV['QUEUE_HOST']}:#{ENV['QUEUE_PORT']}"]
|
38
|
+
options["kafkaHost"] = ENV['QUEUE_HOST'] || 'localhost'
|
39
|
+
options["kafkaPort"] = (ENV['QUEUE_PORT'] || '9092').to_i
|
40
|
+
options["kafkaTopics"] = {}
|
41
|
+
options["logGroup"] = 'platform-dev'
|
42
|
+
options["metricsPort"] = (ENV['METRICS_PORT'] || 9394).to_i
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.fill_args_operations(args)
|
48
|
+
args[:metrics_port] = instance['metricsPort']
|
49
|
+
args[:queue_host] = instance['kafkaHost']
|
50
|
+
args[:queue_port] = instance['kafkaPort']
|
51
|
+
args
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.kafka_topic(name)
|
55
|
+
instance["kafkaTopics"][name] || name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# ManageIQ Message Client depends on these variables
|
63
|
+
ENV["QUEUE_HOST"] = TopologicalInventory::Providers::Common::ClowderConfig.instance["kafkaHost"]
|
64
|
+
ENV["QUEUE_PORT"] = TopologicalInventory::Providers::Common::ClowderConfig.instance["kafkaPort"].to_s
|
65
|
+
|
66
|
+
# ManageIQ Logger depends on these variables
|
67
|
+
ENV['CW_AWS_ACCESS_KEY_ID'] = TopologicalInventory::Providers::Common::ClowderConfig.instance["awsAccessKeyId"]
|
68
|
+
ENV['CW_AWS_SECRET_ACCESS_KEY'] = TopologicalInventory::Providers::Common::ClowderConfig.instance["awsSecretAccessKey"]
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "more_core_extensions/core_ext/module/cache_with_timeout"
|
2
2
|
require "manageiq-messaging"
|
3
|
+
require "topological_inventory/providers/common/clowder_config"
|
3
4
|
|
4
5
|
module TopologicalInventory
|
5
6
|
module Providers
|
@@ -11,8 +12,8 @@ module TopologicalInventory
|
|
11
12
|
attr_accessor :queue_port
|
12
13
|
|
13
14
|
def initialize
|
14
|
-
self.queue_host =
|
15
|
-
self.queue_port =
|
15
|
+
self.queue_host = TopologicalInventory::Providers::Common::ClowderConfig.instance["kafkaHost"]
|
16
|
+
self.queue_port = TopologicalInventory::Providers::Common::ClowderConfig.instance["kafkaPort"].to_i
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.default
|
@@ -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
|
-
@
|
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
|
13
|
+
def initialize(processor, queue: nil, metrics: nil)
|
12
14
|
@processor = processor
|
13
|
-
@queue
|
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(
|
43
|
-
processor.process!(
|
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 =
|
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
|
-
|
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
|
@@ -17,7 +17,7 @@ module TopologicalInventory
|
|
17
17
|
|
18
18
|
STATUS_AVAILABLE, STATUS_UNAVAILABLE = %w[available unavailable].freeze
|
19
19
|
EVENT_AVAILABILITY_STATUS = "availability_status".freeze
|
20
|
-
|
20
|
+
KAFKA_TOPIC_NAME = "platform.sources.status".freeze
|
21
21
|
|
22
22
|
ERROR_MESSAGES = {
|
23
23
|
:authentication_not_found => "Authentication not found in Sources API",
|
@@ -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
|
33
|
+
self.metrics = metrics
|
34
34
|
self.operation = 'Source'
|
35
35
|
self.params = params
|
36
36
|
self.request_context = request_context
|
@@ -208,10 +208,11 @@ module TopologicalInventory
|
|
208
208
|
end
|
209
209
|
|
210
210
|
def availability_status_message(payload)
|
211
|
-
messaging_client.
|
212
|
-
:service =>
|
213
|
-
:
|
214
|
-
:payload => payload.to_json
|
211
|
+
messaging_client.publish_topic(
|
212
|
+
:service => TopologicalInventory::Providers::Common::ClowderConfig.kafka_topic(KAFKA_TOPIC_NAME),
|
213
|
+
:event => EVENT_AVAILABILITY_STATUS,
|
214
|
+
:payload => payload.to_json,
|
215
|
+
:headers => identity
|
215
216
|
)
|
216
217
|
rescue => err
|
217
218
|
logger.availability_check("Failed to update #{payload[:resource_type]} id: #{payload[:resource_id]} - #{err.message}", :error)
|
@@ -38,12 +38,15 @@ RSpec.shared_examples "availability_check" do
|
|
38
38
|
|
39
39
|
def kafka_message(resource_type, resource_id, status, error_message = nil)
|
40
40
|
res = {
|
41
|
-
:service => described_class::
|
42
|
-
:
|
41
|
+
:service => described_class::KAFKA_TOPIC_NAME,
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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
|
-
|
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(
|
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
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
26
|
spec.add_runtime_dependency 'activesupport', '~> 5.2.4.3'
|
27
|
+
spec.add_runtime_dependency 'clowder-common-ruby', '~> 0.2.1'
|
27
28
|
spec.add_runtime_dependency 'config', '~> 1.7', '>= 1.7.2'
|
28
29
|
spec.add_runtime_dependency 'json', '~> 2.3'
|
29
30
|
spec.add_runtime_dependency 'manageiq-loggers', '>= 0.4.2'
|
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:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Slemr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 5.2.4.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: clowder-common-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: config
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -304,6 +318,7 @@ files:
|
|
304
318
|
- bin/console
|
305
319
|
- bin/setup
|
306
320
|
- lib/topological_inventory/providers/common.rb
|
321
|
+
- lib/topological_inventory/providers/common/clowder_config.rb
|
307
322
|
- lib/topological_inventory/providers/common/collector.rb
|
308
323
|
- lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb
|
309
324
|
- lib/topological_inventory/providers/common/collector/inventory_collection_wrapper.rb
|