Skip to content

Commit

Permalink
Merge pull request #56 from redBorder/integrate_solution_to_consul_re…
Browse files Browse the repository at this point in the history
…gistering

Integrate solution to consul registering
  • Loading branch information
manegron authored Dec 14, 2023
2 parents 8f59348 + e3beba1 commit 03558f8
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 110 deletions.
18 changes: 11 additions & 7 deletions spec/services/consul_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

service = 'consul'
port = 8300
api_endpoint = 'http://localhost:8500/v1'

describe "Checking packages for #{service}..." do
packages.each do |package|
Expand Down Expand Up @@ -40,13 +41,16 @@
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
Expand Down
19 changes: 12 additions & 7 deletions spec/services/druid_broker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# frozen_string_literal: true

require 'spec_helper'
require 'json'
set :os, family: 'redhat', release: '9', arch: 'x86_64'

packages = %w[
redborder-druid cookbook-druid druid
]
service = 'druid-broker'
port = 8084
api_endpoint = 'http://localhost:8500/v1'

describe "Checking packages for #{service}..." do
packages.each do |package|
Expand Down Expand Up @@ -38,13 +40,16 @@
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
Expand Down
27 changes: 17 additions & 10 deletions spec/services/druid_coordinator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
# frozen_string_literal: true

require 'spec_helper'
require 'json'
set :os, family: 'redhat', release: '9', arch: 'x86_64'

packages = %w[
redborder-druid cookbook-druid druid
]
service = 'druid-coordinator'
describe "Checking #{service}" do
outer_service = 'druid-coordinator'
api_endpoint = 'http://localhost:8500/v1'

describe "Checking #{service_in_consul}" do
packages.each do |package|
describe package(package) do
it { should be_installed }
end
end

describe service(service) do
describe service(service_in_consul) do
it { should be_enabled }
it { should be_running }
end

describe port(8084) do
it { should be_listening }
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{outer_ervice} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{outer_service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
15 changes: 11 additions & 4 deletions spec/services/druid_historical_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
service = 'druid-historical'
port = 8083

def service_registered_and_healthy?(service)
def services_registered_and_healthy?(service)
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout.strip
JSON.parse(service_json).any? && health == 'passing'
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)

service_and_health.all? do |service_json, health|
registered = JSON.parse(service_json)[0].key?('Address') && health == 'passing'
registered # return the result of the check for this service/health pair
end
end

service_status = command("systemctl is-enabled #{service}").stdout.strip
Expand Down
18 changes: 11 additions & 7 deletions spec/services/druid_realtime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

service = 'druid-realtime'
port = 8084
api_endpoint = 'http://localhost:8500/v1'

describe "Checking packages for #{service}..." do
packages.each do |package|
Expand Down Expand Up @@ -40,13 +41,16 @@
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
Expand Down
17 changes: 11 additions & 6 deletions spec/services/f2k_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
service = 'f2k'
port = 2055
service_status = command("systemctl is-enabled #{service}").stdout.strip
api_endpoint = 'http://localhost:8500/v1'

packages = %w[cookbook-f2k f2k]

Expand Down Expand Up @@ -36,12 +37,16 @@
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
Expand Down
18 changes: 12 additions & 6 deletions spec/services/http2k_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require 'spec_helper'
require 'json'
set :os, family: 'redhat', release: '9', arch: 'x86_64'

service = 'http2k'
port = 7980
service_status = command("systemctl is-enabled #{service}").stdout.strip
api_endpoint = 'http://localhost:8500/v1'

packages = %w[cookbook-http2k redborder-http2k]

Expand Down Expand Up @@ -35,12 +37,16 @@
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
Expand Down
17 changes: 11 additions & 6 deletions spec/services/kafka_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
service = 'kafka'
port = 9092
service_status = command("systemctl is-enabled #{service}").stdout.strip
api_endpoint = 'http://localhost:8500/v1'

packages = %w[cookbook-kafka confluent-kafka redborder-kafka librdkafka n2kafka rsyslog-kafka]

Expand Down Expand Up @@ -36,12 +37,16 @@
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
Expand Down
18 changes: 11 additions & 7 deletions spec/services/memcached_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'spec_helper'
require 'json'
api_endpoint = 'http://localhost:8500/v1'
set :os, family: 'redhat', release: '9', arch: 'x86_64'

service = 'memcached'
Expand Down Expand Up @@ -29,13 +30,16 @@

# Check if Memcached is registered and healthy in Consul
describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout.strip
registered = JSON.parse(service_json).any? && health == 'passing'

it 'Should be registered and healthy' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
Expand Down
19 changes: 12 additions & 7 deletions spec/services/mongodb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# frozen_string_literal: true

require 'spec_helper'
require 'json'
set :os, family: 'redhat', release: '9', arch: 'x86_64'

packages = %w[
cookbook-mongodb
]
service = 'mongodb'
port = 27_017
api_endpoint = 'http://localhost:8500/v1'

describe "Checking packages for #{service}..." do
packages.each do |package|
Expand Down Expand Up @@ -38,13 +40,16 @@
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
Expand Down
18 changes: 11 additions & 7 deletions spec/services/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

service = 'nginx'
port = 443
api_endpoint = 'http://localhost:8500/v1'

describe "Checking packages for #{service}..." do
packages.each do |package|
Expand Down Expand Up @@ -40,13 +41,16 @@
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
Expand Down
Loading

0 comments on commit 03558f8

Please sign in to comment.