topological_inventory-providers-common 2.1.2 → 3.0.1

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: 661072299fccb0117c3dcbe1fba36e4836a82ac1a6d98abbaab1808ea437e6d7
4
- data.tar.gz: a1a45e527dc14cb4b09004d2df98f075818fb35d616d84d954839c289dac5c8a
3
+ metadata.gz: b0d5e54970be70204d7ac119fdd23e0a68bbc01a3e1d3c64520ce3fc6129cfe7
4
+ data.tar.gz: 624c68af0b57940bc5436099f1a4238eb5405a9e9b87706911278b5c3fcf44e0
5
5
  SHA512:
6
- metadata.gz: ba101d97cca75814a073eb70f8528e3debb0f4270fb4cfb98cc9db55f53ff790efcd99380158e8c808b317603a9ce1a7a30d13f791e03741b699e06f0556965e
7
- data.tar.gz: 3e4340ad6743693f104d0c847995bb866860ef2911c57865ce042389cb3872badf05f2b46119664650214285f509495f656dc5cf82f77cec9cf5e2a253a0f2cc
6
+ metadata.gz: ac55e0263630b78533d49b061d972beab29e249911f785f536a8acbb3cada1d88e3935849d089791f9be001b87a0f3100b4e44bc3595527d169107ef14a5e9b0
7
+ data.tar.gz: df3b8288f73292d647a77629d5f5ae78a21dad4eeb206e6b1e4e2d077ffd475c60c705f0365311b374fd88544a81943403484089f829aa3611919e95d2ee734f
data/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@ 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.1] - 2021-04-30
7
+ More generic activesupport dependency #77
8
+
9
+ ## [3.0.0] - 2021-03-08
10
+ Clowder migration #75
11
+
12
+ ## [2.1.5] - 2021-01-07
13
+ Include x-rh-id header in Kafka Availability-Status message #73
14
+
15
+ ## [2.1.4] - 2020-12-14
16
+ Common Counter metrics init #71
17
+
18
+ ## [2.1.3] - 2020-12-14
19
+ Update travis URL in README file #67
20
+ Kafka availability_checks fix #68
6
21
 
7
22
  ## [2.1.2] - 2020-11-24
8
23
  Custom Metrics for AsyncWorker #60
@@ -75,11 +90,17 @@ manageiq-loggers to >= 0.4.2 #20
75
90
  ## [1.0.0] - 2020-03-19
76
91
  ### Initial release to rubygems.org
77
92
 
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
81
- [2.1.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.0.0...v2.1.0
82
- [2.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.12...v2.0.0
93
+ [Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v3.0.1.freeze...HEAD
94
+ [3.0.1]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v3.0.0.freeze...v3.0.1.freeze
95
+ [3.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.5.freeze...v3.0.0.freeze
96
+ [2.1.5]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.4.freeze...v2.1.5.freeze
97
+ [2.1.5]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.4.freeze...v2.1.5.freeze
98
+ [2.1.4]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.3.freeze...v2.1.4.freeze
99
+ [2.1.3]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.2.freeze...v2.1.3.freeze
100
+ [2.1.2]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.1.freeze...v2.1.2.freeze
101
+ [2.1.1]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.0.freeze...v2.1.1.freeze
102
+ [2.1.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.0.0.freeze...v2.1.0.freeze
103
+ [2.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.12...v2.0.0.freeze
83
104
  [1.0.12]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.11...v1.0.12
84
105
  [1.0.11]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.10...v1.0.11
85
106
  [1.0.10]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.9...v1.0.10
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)
@@ -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 = ENV['QUEUE_HOST'] || 'localhost'
15
- self.queue_port = (ENV['QUEUE_PORT'] || 9092).to_i
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')
94
+ @refresh_timer = PrometheusExporter::Metric::Histogram.new('refresh_time', 'Duration of full refresh')
70
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
@@ -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
- SERVICE_NAME = "platform.sources.status".freeze
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",
@@ -208,10 +208,11 @@ module TopologicalInventory
208
208
  end
209
209
 
210
210
  def availability_status_message(payload)
211
- messaging_client.publish_message(
212
- :service => SERVICE_NAME,
213
- :message => EVENT_AVAILABILITY_STATUS,
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)
@@ -1,7 +1,7 @@
1
1
  module TopologicalInventory
2
2
  module Providers
3
3
  module Common
4
- VERSION = "2.1.2".freeze
4
+ VERSION = "3.0.1".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -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::SERVICE_NAME,
42
- :message => described_class::EVENT_AVAILABILITY_STATUS,
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(: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
 
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_runtime_dependency 'activesupport', '~> 5.2.4.3'
26
+ spec.add_runtime_dependency 'activesupport', '~> 5.2', '>= 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,20 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topological_inventory-providers-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 3.0.1
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-24 00:00:00.000000000 Z
11
+ date: 2021-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 5.2.4.3
20
23
  type: :runtime
@@ -22,8 +25,25 @@ dependencies:
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.2'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 5.2.4.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: clowder-common-ruby
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.2.1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.1
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: config
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -304,6 +324,7 @@ files:
304
324
  - bin/console
305
325
  - bin/setup
306
326
  - lib/topological_inventory/providers/common.rb
327
+ - lib/topological_inventory/providers/common/clowder_config.rb
307
328
  - lib/topological_inventory/providers/common/collector.rb
308
329
  - lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb
309
330
  - lib/topological_inventory/providers/common/collector/inventory_collection_wrapper.rb
@@ -358,7 +379,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
358
379
  - !ruby/object:Gem::Version
359
380
  version: '0'
360
381
  requirements: []
361
- rubygems_version: 3.0.3
382
+ rubygems_version: 3.0.3.1
362
383
  signing_key:
363
384
  specification_version: 4
364
385
  summary: Common classes for topological-inventory collectors/operations