From 285e83445ef9bbedebd22e9107522fa4f6b6e640 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Tue, 24 Sep 2024 16:59:52 +0100 Subject: [PATCH 1/3] refactor consul variable and add rule on default test --- spec/services/druid_coordinator_spec.rb | 27 ++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/spec/services/druid_coordinator_spec.rb b/spec/services/druid_coordinator_spec.rb index 51826c3..c5a1440 100644 --- a/spec/services/druid_coordinator_spec.rb +++ b/spec/services/druid_coordinator_spec.rb @@ -8,7 +8,7 @@ redborder-druid cookbook-druid druid ] service = 'druid-coordinator' -api_endpoint = 'http://localhost:8500/v1' +consul_api_endpoint = 'http://localhost:8500/v1' describe "Checking #{packages}" do packages.each do |package| @@ -27,9 +27,9 @@ end describe 'Registered in consul' do - service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'") + service_json_cluster = command("curl -s #{consul_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 = command("curl -s #{consul_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 |srv, health| @@ -39,4 +39,25 @@ end end end + + describe 'Druid should have at least one rule without forever duration' do + # Sample of wrong + # {"_default":[{"tieredReplicants":{"_default_tier":2},"type":"loadForever"}]} + # Sample of expected + # {"_default":[{"period":"P1M","tieredReplicants":{"_default_tier":1},"type":"loadByPeriod"},{"type":"dropForever"}]} + + # TODO: make to all work together in cluster??? + get_default_rules_cmd = "curl -X GET http://#{service}.service:8081/druid/coordinator/v1/rules/" + describe command(get_default_rules_cmd) do + its(:exit_status) { should eq 0 } + its(:stdout) { should_not be_empty } + it 'should have at least one rule without forever duration' do + rules = JSON.parse(subject.stdout)['_default'] + non_forever_rule = rules.any? do |rule| + rule['type'] != 'loadForever' && rule['type'] != 'dropForever' + end + expect(non_forever_rule).to be true + end + end + end end From 2c99fefd3f1e24f7c617f626820c55eb30afb036 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Tue, 24 Sep 2024 17:20:13 +0100 Subject: [PATCH 2/3] skip if the target host is not a druid coordinator for now --- spec/services/druid_coordinator_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/services/druid_coordinator_spec.rb b/spec/services/druid_coordinator_spec.rb index c5a1440..1c468f3 100644 --- a/spec/services/druid_coordinator_spec.rb +++ b/spec/services/druid_coordinator_spec.rb @@ -46,12 +46,12 @@ # Sample of expected # {"_default":[{"period":"P1M","tieredReplicants":{"_default_tier":1},"type":"loadByPeriod"},{"type":"dropForever"}]} - # TODO: make to all work together in cluster??? get_default_rules_cmd = "curl -X GET http://#{service}.service:8081/druid/coordinator/v1/rules/" describe command(get_default_rules_cmd) do its(:exit_status) { should eq 0 } - its(:stdout) { should_not be_empty } it 'should have at least one rule without forever duration' do + skip('Skipping test due to empty stdout') if subject.stdout.empty? + rules = JSON.parse(subject.stdout)['_default'] non_forever_rule = rules.any? do |rule| rule['type'] != 'loadForever' && rule['type'] != 'dropForever' From c407d75bb227c25a245d488ba20682f7bb5e9616 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Tue, 24 Sep 2024 17:53:18 +0100 Subject: [PATCH 3/3] LINT --- spec/services/druid_coordinator_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/services/druid_coordinator_spec.rb b/spec/services/druid_coordinator_spec.rb index 1c468f3..5a5f4a1 100644 --- a/spec/services/druid_coordinator_spec.rb +++ b/spec/services/druid_coordinator_spec.rb @@ -27,7 +27,8 @@ end describe 'Registered in consul' do - service_json_cluster = command("curl -s #{consul_api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'") + get_service_json_cmd = "curl -s #{consul_api_endpoint}/catalog/service/#{service} | jq -c 'group_by(.ID)[]'" + service_json_cluster = command(get_service_json_cmd) service_json_cluster = service_json_cluster.stdout.chomp.split("\n") health_cluster = command("curl -s #{consul_api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'") health_cluster = health_cluster.stdout.chomp.split("\n") @@ -44,7 +45,9 @@ # Sample of wrong # {"_default":[{"tieredReplicants":{"_default_tier":2},"type":"loadForever"}]} # Sample of expected - # {"_default":[{"period":"P1M","tieredReplicants":{"_default_tier":1},"type":"loadByPeriod"},{"type":"dropForever"}]} + # {"_default":[ + # {"period":"P1M","tieredReplicants":{"_default_tier":1},"type":"loadByPeriod"},{"type":"dropForever"} + # ]} get_default_rules_cmd = "curl -X GET http://#{service}.service:8081/druid/coordinator/v1/rules/" describe command(get_default_rules_cmd) do