Skip to content

Commit 76206a7

Browse files
authored
TAF: Check errors in process files (#1460)
* Added new tests for checking errors in files * Revert to ci_prod branch
1 parent 7104277 commit 76206a7

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

test/ginkgo-e2e/containerstatus/containerstatus_suite_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package containerstatus_test
22

33
import (
4+
"os"
45
"testing"
56

67
"docker-provider/test/utils"
@@ -17,6 +18,7 @@ import (
1718
var K8sClient *kubernetes.Clientset
1819
var Cfg *rest.Config
1920
var ResourceOptimizationEnabled string
21+
var GenevaIntegrationEnabled string
2022

2123
func TestContainerStatus(t *testing.T) {
2224
RegisterFailHandler(Fail)
@@ -30,6 +32,7 @@ var _ = BeforeSuite(func() {
3032
Expect(err).NotTo(HaveOccurred())
3133
ResourceOptimizationEnabled, err = utils.IsResourceOptimizationEnabled(K8sClient, "kube-system", "component", "ama-logs-agent", "ama-logs")
3234
Expect(err).NotTo(HaveOccurred())
35+
GenevaIntegrationEnabled = os.Getenv("GENEVA_INTEGRATION")
3336
})
3437

3538
var _ = AfterSuite(func() {

test/ginkgo-e2e/containerstatus/containerstatus_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,28 @@ var _ = DescribeTable("The container logs should not contain errors",
117117
Entry("when checking the ama-logs daemonset pods", "kube-system", "component", "ama-logs-agent"),
118118
Entry("when checking the ama-logs-windows daemonset pods", "kube-system", "component", "ama-logs-agent-windows", Label(utils.WindowsLabel)),
119119
)
120+
121+
/*
122+
- The containers should not contain any errors for the running processes.
123+
*/
124+
var _ = DescribeTable("The ama-logs container should not contain errors in the running processes",
125+
func(namespace, labelName, labelValue, containerName, filePath string) {
126+
if GenevaIntegrationEnabled == "true" && filePath == "/var/opt/microsoft/docker-cimprov/log/fluent-bit.log" {
127+
Skip("Skipping fluent-bit log check for ama-logs container when Geneva integration is enabled")
128+
} else if GenevaIntegrationEnabled != "true" && filePath == "/var/opt/microsoft/docker-cimprov/log/fluent-bit-geneva.log" {
129+
Skip("Skipping fluent-bit-geneva log check for ama-logs container when Geneva integration is disabled")
130+
}
131+
err := utils.CheckFileForErrors(K8sClient, Cfg, namespace, labelName, labelValue, containerName, filePath)
132+
Expect(err).NotTo(HaveOccurred())
133+
},
134+
// fluentd logs
135+
Entry("when checking the ama-logs container for fluentd", "kube-system", "component", "ama-logs-agent", "ama-logs", "/var/opt/microsoft/docker-cimprov/log/fluentd.log"),
136+
// fluent-bit logs
137+
Entry("when checking the ama-logs container for fluentbit", "kube-system", "component", "ama-logs-agent", "ama-logs", "/var/opt/microsoft/docker-cimprov/log/fluent-bit.log"),
138+
Entry("when checking the ama-logs container for fluentbit", "kube-system", "component", "ama-logs-agent", "ama-logs", "/var/opt/microsoft/docker-cimprov/log/fluent-bit-geneva.log"),
139+
Entry("when checking the ama-logs container for fluent_forward_failed", "kube-system", "component", "ama-logs-agent", "ama-logs", "/var/opt/microsoft/docker-cimprov/log/fluent_forward_failed.log"),
140+
// telegraf logs
141+
Entry("when checking the ama-logs container for telegraf", "kube-system", "component", "ama-logs-agent", "ama-logs", "/var/opt/microsoft/docker-cimprov/log/telegraf_error.log"),
142+
// mdsd logs
143+
Entry("when checking the ama-logs container for mdsd", "kube-system", "component", "ama-logs-agent", "ama-logs", "/var/opt/microsoft/linuxmonagent/log/mdsd.err"),
144+
)

test/ginkgo-e2e/utils/kubernetes_api_utils.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,30 @@ func GetAllNodes(clientset *kubernetes.Clientset) ([]corev1.Node, error) {
492492

493493
return nodes.Items, nil
494494
}
495+
496+
// CheckFileForErrors checks if a specific file in a linux container contains errors.
497+
func CheckFileForErrors(clientset *kubernetes.Clientset, Cfg *rest.Config, namespace, labelName, labelValue, containerName, filePath string) error {
498+
pods, err := GetPodsWithLabel(clientset, namespace, labelName, labelValue)
499+
if err != nil {
500+
return fmt.Errorf("failed to get pods with label %s=%s: %v", labelName, labelValue, err)
501+
}
502+
503+
for _, pod := range pods {
504+
command := []string{"bash", "-c", fmt.Sprintf("grep -i error %s", filePath)}
505+
stdout, stderr, err := ExecCmd(clientset, Cfg, pod.Name, containerName, namespace, command)
506+
if err != nil {
507+
// If grep returns exit code 1, it means no matches were found, which is not an error for our use case
508+
if strings.Contains(err.Error(), "exit code 1") {
509+
// No errors found in the file, continue
510+
continue
511+
}
512+
return fmt.Errorf("error executing command in pod %s, container %s: %v, stderr: %s", pod.Name, containerName, err, stderr)
513+
}
514+
515+
if stdout != "" {
516+
return fmt.Errorf("errors found in file %s in pod %s, container %s: %s", filePath, pod.Name, containerName, stdout)
517+
}
518+
}
519+
520+
return nil
521+
}

test/testkube/testkube-test-crs.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ spec:
1616
branch: ci_prod
1717
path: test/ginkgo-e2e
1818
executionRequest:
19+
variables:
20+
GENEVA_INTEGRATION:
21+
name: GENEVA_INTEGRATION
22+
value: "$GENEVA_INTEGRATION"
23+
type: basic
1924
args:
2025
- "--label-filter"
2126
- "!(windows)"
@@ -40,6 +45,11 @@ spec:
4045
branch: ci_prod
4146
path: test/ginkgo-e2e
4247
executionRequest:
48+
variables:
49+
GENEVA_INTEGRATION:
50+
name: GENEVA_INTEGRATION
51+
value: "$GENEVA_INTEGRATION"
52+
type: basic
4353
args:
4454
- "--label-filter"
4555
- "windows"

0 commit comments

Comments
 (0)