Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Routed logs test now correctly checks if CNF is being tailed #2034

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions embedded_files/fluentd-bitnami-values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aggregator:
enabled: false
16 changes: 8 additions & 8 deletions spec/workload/observability_spec.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "../spec_helper"
require "colorize"
require "../../src/tasks/utils/utils.cr"
require "../../src/tasks/utils/fluentbit.cr"
require "../../src/tasks/utils/fluent_manager.cr"
require "../../src/tasks/jaeger_setup.cr"

describe "Observability" do
Expand Down Expand Up @@ -125,7 +125,7 @@ describe "Observability" do
result = ShellCmd.run_testsuite("cnf_setup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml")
result = ShellCmd.run_testsuite("install_fluentdbitnami")
result = ShellCmd.run_testsuite("routed_logs")
(/(PASSED).*(Your cnf's logs are being captured)/ =~ result[:output]).should_not be_nil
(/(PASSED).*(Your CNF's logs are being captured)/ =~ result[:output]).should_not be_nil
ensure
result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml")
result = ShellCmd.run_testsuite("uninstall_fluentdbitnami")
Expand All @@ -134,26 +134,26 @@ describe "Observability" do

it "'routed_logs' should pass if cnfs logs are captured by fluentbit", tags: ["observability"] do
result = ShellCmd.run_testsuite("cnf_setup cnf-config=sample-cnfs/sample-fluentbit")
FluentBit.install
result = ShellCmd.run_testsuite("install_fluentbit")
result = ShellCmd.run_testsuite("routed_logs")
(/(PASSED).*(Your cnf's logs are being captured)/ =~ result[:output]).should_not be_nil
(/(PASSED).*(Your CNF's logs are being captured)/ =~ result[:output]).should_not be_nil
ensure
result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-fluentbit")
FluentBit.uninstall
result = ShellCmd.run_testsuite("uninstall_fluentbit")
result[:status].success?.should be_true
end

it "'routed_logs' should fail if cnfs logs are not captured", tags: ["observability"] do

result = ShellCmd.run_testsuite("cnf_setup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml")
Helm.helm_repo_add("bitnami","oci://registry-1.docker.io/bitnamicharts")
Helm.helm_repo_add("bitnami","https://charts.bitnami.com/bitnami")
#todo #helm install --values ./override.yml fluentd ./fluentd
Helm.install("--values ./spec/fixtures/fluentd-values-bad.yml -n #{TESTSUITE_NAMESPACE} fluentd bitnami/fluentd")
Log.info { "Installing FluentD daemonset " }
Log.info { "Installing FluentD daemonset" }
KubectlClient::Get.resource_wait_for_install("Daemonset", "fluentd", namespace: TESTSUITE_NAMESPACE)

result = ShellCmd.run_testsuite("routed_logs")
(/(FAILED).*(Your cnf's logs are not being captured)/ =~ result[:output]).should_not be_nil
(/(FAILED).*(Your CNF's logs are not being captured)/ =~ result[:output]).should_not be_nil
ensure
result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml")
result = ShellCmd.run_testsuite("uninstall_fluentd")
Expand Down
1 change: 1 addition & 0 deletions src/tasks/constants.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ EmbeddedFileManager.constraint_template
EmbeddedFileManager.disable_cni
EmbeddedFileManager.fluentd_values
EmbeddedFileManager.fluentbit_values
EmbeddedFileManager.fluentd_bitnami_values
EmbeddedFileManager.ueransim_helmconfig

EXCLUDE_NAMESPACES = [
Expand Down
34 changes: 34 additions & 0 deletions src/tasks/fluent_setup.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require "sam"
require "file_utils"
require "colorize"
require "totem"

desc "Install FluentD"
task "install_fluentd" do |_, args|
FluentManager::FluentD.new.install
end

desc "Uninstall FluentD"
task "uninstall_fluentd" do |_, args|
FluentManager::FluentD.new.uninstall
end

desc "Install FluentDBitnami"
task "install_fluentdbitnami" do |_, args|
FluentManager::FluentDBitnami.new.install
end

desc "Uninstall FluentDBitnami"
task "uninstall_fluentdbitnami" do |_, args|
FluentManager::FluentDBitnami.new.uninstall
end

desc "Install FluentBit"
task "install_fluentbit" do |_, args|
FluentManager::FluentBit.new.install
end

desc "Uninstall FluentBit"
task "uninstall_fluentbit" do |_, args|
FluentManager::FluentBit.new.uninstall
end
14 changes: 0 additions & 14 deletions src/tasks/fluentbit_setup.cr

This file was deleted.

14 changes: 0 additions & 14 deletions src/tasks/fluentd_setup.cr

This file was deleted.

14 changes: 0 additions & 14 deletions src/tasks/fluentdbitnami_setup.cr

This file was deleted.

5 changes: 4 additions & 1 deletion src/tasks/utils/embedded_file_manager.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ module EmbeddedFileManager
FLUENTD_VALUES = Base64.decode_string("{{ `cat ./embedded_files/fluentd-values.yml | base64`}}")
end
macro fluentbit_values
FLUENTBIT_VALUES = Base64.decode_string("{{ `cat ./embedded_files/fluentbit-config.yml | base64`}}")
FLUENTBIT_VALUES = Base64.decode_string("{{ `cat ./embedded_files/fluentbit-values.yml | base64`}}")
end
macro fluentd_bitnami_values
FLUENTD_BITNAMI_VALUES = Base64.decode_string("{{ `cat ./embedded_files/fluentd-bitnami-values.yml | base64`}}")
end
macro ueransim_helmconfig
UERANSIM_HELMCONFIG = Base64.decode_string("{{ `cat ./embedded_files/ue.yaml | base64`}}")
Expand Down
100 changes: 100 additions & 0 deletions src/tasks/utils/fluent_manager.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module FluentManager
abstract class FluentBase
getter flavor_name : String
getter repo_url : String
getter values_file : String
getter values_macro : String
getter image_name : String
getter chart : String

def initialize(flavor_name : String, repo_url : String, values_file : String, values_macro : String, image_name : String, chart : String)
@flavor_name = flavor_name
@repo_url = repo_url
@values_file = values_file
@values_macro = values_macro
@image_name = image_name
@chart = chart
end

def install
Log.info { "Installing #{flavor_name} daemonset using #{values_file}" }
Helm.helm_repo_add(flavor_name, repo_url)
File.write(values_file, values_macro)
begin
Helm.install("--values #{values_file} -n #{TESTSUITE_NAMESPACE} #{flavor_name} #{chart}")
KubectlClient::Get.resource_wait_for_install("Daemonset", flavor_name, namespace: TESTSUITE_NAMESPACE)
rescue Helm::CannotReuseReleaseNameError
Log.info { "Release #{flavor_name} already installed" }
end
end

def uninstall
Log.info { "Uninstalling #{flavor_name} in #{TESTSUITE_NAMESPACE}" }
Helm.delete("#{flavor_name} -n #{TESTSUITE_NAMESPACE}")
end

def installed?
KubectlClient::Get.resource_wait_for_install("Daemonset", flavor_name, namespace: TESTSUITE_NAMESPACE)
end
end

class FluentD < FluentBase
def initialize
super("fluentd",
"https://fluent.github.io/helm-charts",
"fluentd-values.yml",
FLUENTD_VALUES,
"fluent/fluentd-kubernetes-daemonset",
"fluent/fluentd")
end
end

class FluentDBitnami < FluentBase
def initialize
super("fluentdbitnami",
"https://charts.bitnami.com/bitnami",
"fluentd-bitnami-values.yml",
FLUENTD_BITNAMI_VALUES,
"bitnami/fluentd",
"bitnami/fluentd")
end
end

class FluentBit < FluentBase
def initialize
super("fluent-bit",
"https://fluent.github.io/helm-charts",
"fluentbit-values.yml",
FLUENTBIT_VALUES,
"fluent/fluent-bit",
"fluent/fluent-bit")
end
end

def self.find_active_match
all_flavors.each do |flavor|
match = ClusterTools.local_match_by_image_name(flavor.image_name)
return match if match[:found]
end
nil
end

def self.pod_tailed?(pod_name, match)
return false unless match

fluent_pods = KubectlClient::Get.pods_by_digest(match[:digest])
fluent_pods.each do |fluent_pod|
fluent_pod_name = fluent_pod.dig("metadata", "name").as_s
logs = KubectlClient.logs(fluent_pod_name, namespace: TESTSUITE_NAMESPACE)
Log.info { "Searching logs of #{fluent_pod_name} for string #{pod_name}" }
Log.debug { "Fluent logs: #{logs}" }
return true if logs[:output].to_s.includes?(pod_name)
end

false
end

def self.all_flavors : Array(FluentBase)
[FluentD.new, FluentDBitnami.new, FluentBit.new]
end
end
54 changes: 0 additions & 54 deletions src/tasks/utils/fluentbit.cr

This file was deleted.

50 changes: 0 additions & 50 deletions src/tasks/utils/fluentd.cr

This file was deleted.

Loading
Loading