Skip to content

Commit

Permalink
Fix: Routed logs test now correctly checks if CNF is being tailed (#2034
Browse files Browse the repository at this point in the history
)

* Fix: Routed logs test now correctly checks if CNF is being tailed
Ref: #2025 #2016
- The issue explained in #2025 where fluent was tailing itself
instead of the CNF has been resolved.
- The dead helm repo mentioned in #2016 has been replace by link to bitnami repo,
there was a similar occurence in the spec test.
- The family of fluentd functions and files have been refactored into configurable
files (allows for future additions/checking of elastic, aws fluent, etc.).
- The routed_logs test was also modified to conform to the new functions (also shortened).
- Other files have been edited for completion/conformance with naming conventions.
Signed-off-by: svteb <slavo.valko@tietoevry.com>

* Fix: Corrected a require command in observability_spec.cr
Refs: #2025

Signed-off-by: svteb <slavo.valko@tietoevry.com>

* Refactor: better abstraction of fluent flavors
Refs: #2025
- Reworked the config dictionary into classes that inherit
from a base abstract class.
- Renamed FluentManagement module to FluentManager
- Interfaces changed to adhere to the new abstraction

Signed-off-by: svteb <slavo.valko@tietoevry.com>

---------

Signed-off-by: svteb <slavo.valko@tietoevry.com>
  • Loading branch information
svteb authored Jun 10, 2024
1 parent e55f633 commit 310e9c7
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 243 deletions.
File renamed without changes.
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 @@ -39,6 +39,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

0 comments on commit 310e9c7

Please sign in to comment.