Skip to content

Commit 993b4ce

Browse files
authored
[chore] Add AKS Hosted Functional test (#2146)
* [chore] Add AKS Hosted Functional test Signed-off-by: Dani Louca <dlouca@splunk.com> * Switch to cmd.exe as powershell was slow and causing flakiness due to timeout Signed-off-by: Dani Louca <dlouca@splunk.com> --------- Signed-off-by: Dani Louca <dlouca@splunk.com>
1 parent bd9d0e6 commit 993b4ce

File tree

7 files changed

+196
-6
lines changed

7 files changed

+196
-6
lines changed

.github/workflows/functional_test_v2.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ jobs:
266266
(github.ref == 'refs/heads/main')
267267
env:
268268
KUBE_TEST_ENV: aks
269-
SKIP_TESTS: "true"
270269
runs-on: ubuntu-latest
271270
continue-on-error: ${{ contains(github.event.pull_request.labels.*.name, 'Ignore Tests') }}
272271
steps:

functional_tests/functional/functional_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ const (
5959
kindValuesDir = "expected_kind_values"
6060
eksValuesDir = "expected_eks_values"
6161
eksAutoModeValuesDir = "expected_eks_auto_mode_values"
62+
aksValuesDir = "expected_aks_values"
6263
agentLabelSelector = "component=otel-collector-agent"
6364
clusterReceiverLabelSelector = "component=otel-k8s-cluster-receiver"
65+
linuxPodMetricsPath = "/tmp/metrics.json"
66+
winPodMetricsPath = "C:\\metrics.json"
6467
)
6568

6669
var archRe = regexp.MustCompile("-amd64$|-arm64$|-ppc64le$")
@@ -546,7 +549,7 @@ func runHostedClusterTests(t *testing.T, kubeTestEnv string) {
546549
client, err := kubernetes.NewForConfig(kubeConfig)
547550
require.NoError(t, err)
548551
switch kubeTestEnv {
549-
case eksTestKubeEnv, eksAutoModeTestKubeEnv:
552+
case eksTestKubeEnv, eksAutoModeTestKubeEnv, aksTestKubeEnv:
550553
expectedValuesDir = selectExpectedValuesDir(kubeTestEnv)
551554
t.Run("agent resource attributes validation", func(t *testing.T) {
552555
validateResourceAttributes(t, client, kubeConfig, "agent")
@@ -560,10 +563,14 @@ func runHostedClusterTests(t *testing.T, kubeTestEnv string) {
560563
}
561564

562565
func selectExpectedValuesDir(kubeTestEnv string) string {
563-
if kubeTestEnv == eksAutoModeTestKubeEnv {
566+
switch kubeTestEnv {
567+
case eksAutoModeTestKubeEnv:
564568
return eksAutoModeValuesDir
569+
case aksTestKubeEnv:
570+
return aksValuesDir
571+
default:
572+
return eksValuesDir
565573
}
566-
return eksValuesDir
567574
}
568575

569576
func validateResourceAttributes(t *testing.T, clientset *kubernetes.Clientset, kubeConfig *rest.Config, collectorType string) {
@@ -584,11 +591,15 @@ func validateResourceAttributes(t *testing.T, clientset *kubernetes.Clientset, k
584591
require.NotEmpty(t, pods.Items, "no pods found for label %s", labelSelector)
585592

586593
podName := pods.Items[0].Name
594+
podPathFile := linuxPodMetricsPath
595+
if pods.Items[0].Labels["osType"] == "windows" {
596+
podPathFile = winPodMetricsPath
597+
}
587598

588599
tmpFile, err := os.CreateTemp(t.TempDir(), "actualResourceAttributes*.yaml")
589600
require.NoError(t, err)
590601

591-
internal.CopyFileFromPod(t, clientset, kubeConfig, internal.DefaultNamespace, podName, "otel-collector", "/tmp/metrics.json", tmpFile.Name())
602+
internal.CopyFileFromPod(t, clientset, kubeConfig, internal.DefaultNamespace, podName, "otel-collector", podPathFile, tmpFile.Name())
592603

593604
actualResourceAttributes := readAndNormalizeMetrics(t, tmpFile.Name(), "k8s.cluster.name").ResourceMetrics().At(0).Resource().Attributes()
594605
expectedResourceAttributes := readAndNormalizeMetrics(t, expectedResourceAttributesFile, "k8s.cluster.name").ResourceMetrics().At(0).Resource().Attributes()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
resourceMetrics:
2+
- resource:
3+
attributes:
4+
- key: cloud.account.id
5+
value:
6+
stringValue: abcd
7+
- key: cloud.platform
8+
value:
9+
stringValue: abcd
10+
- key: cloud.provider
11+
value:
12+
stringValue: abcd
13+
- key: cloud.region
14+
value:
15+
stringValue: abcd
16+
- key: azure.vm.name
17+
value:
18+
stringValue: abcd
19+
- key: host.id
20+
value:
21+
stringValue: abcd
22+
- key: host.name
23+
value:
24+
stringValue: abcd
25+
- key: k8s.cluster.name
26+
value:
27+
stringValue: test
28+
- key: k8s.namespace.name
29+
value:
30+
stringValue: abcd
31+
- key: k8s.node.name
32+
value:
33+
stringValue: abcd
34+
- key: k8s.pod.name
35+
value:
36+
stringValue: abcd
37+
- key: k8s.pod.uid
38+
value:
39+
stringValue: abcd
40+
- key: os.type
41+
value:
42+
stringValue: abcd
43+
- key: otelcol.service.mode
44+
value:
45+
stringValue: abcd
46+
- key: server.port
47+
value:
48+
stringValue: abcd
49+
- key: service.instance.id
50+
value:
51+
stringValue: abcd
52+
- key: service.name
53+
value:
54+
stringValue: abcd
55+
- key: service.version
56+
value:
57+
stringValue: abcd
58+
- key: splunk_otlp_histograms
59+
value:
60+
stringValue: abcd
61+
- key: url.scheme
62+
value:
63+
stringValue: abcd
64+
- key: azure.vm.size
65+
value:
66+
stringValue: abcd
67+
- key: azure.resourcegroup.name
68+
value:
69+
stringValue: abcd
70+
- key: azure.vm.scaleset.name
71+
value:
72+
stringValue: abcd
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
resourceMetrics:
2+
- resource:
3+
attributes:
4+
- key: cloud.account.id
5+
value:
6+
stringValue: abcd
7+
- key: cloud.platform
8+
value:
9+
stringValue: abcd
10+
- key: cloud.provider
11+
value:
12+
stringValue: abcd
13+
- key: cloud.region
14+
value:
15+
stringValue: abcd
16+
- key: cluster_name
17+
value:
18+
stringValue: abcd
19+
- key: customfield1
20+
value:
21+
stringValue: abcd
22+
- key: customfield2
23+
value:
24+
stringValue: abcd
25+
- key: host.id
26+
value:
27+
stringValue: abcd
28+
- key: host.name
29+
value:
30+
stringValue: abcd
31+
- key: k8s.cluster.name
32+
value:
33+
stringValue: test
34+
- key: k8s.namespace.name
35+
value:
36+
stringValue: abcd
37+
- key: k8s.node.name
38+
value:
39+
stringValue: abcd
40+
- key: k8s.pod.name
41+
value:
42+
stringValue: abcd
43+
- key: k8s.pod.uid
44+
value:
45+
stringValue: abcd
46+
- key: metric_source
47+
value:
48+
stringValue: abcd
49+
- key: os.type
50+
value:
51+
stringValue: abcd
52+
- key: otelcol.service.mode
53+
value:
54+
stringValue: abcd
55+
- key: server.port
56+
value:
57+
stringValue: abcd
58+
- key: service.instance.id
59+
value:
60+
stringValue: abcd
61+
- key: service.name
62+
value:
63+
stringValue: abcd
64+
- key: service.version
65+
value:
66+
stringValue: abcd
67+
- key: url.scheme
68+
value:
69+
stringValue: abcd
70+
- key: azure.vm.name
71+
value:
72+
stringValue: abcd
73+
- key: azure.vm.size
74+
value:
75+
stringValue: abcd
76+
- key: azure.vm.scaleset.name
77+
value:
78+
stringValue: abcd
79+
- key: azure.resourcegroup.name
80+
value:
81+
stringValue: abcd

functional_tests/functional/testdata/values/aks_test_linux_values.yaml.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ agent:
1919
memory: 1Gi
2020
config:
2121
exporters:
22+
file:
23+
path: /tmp/metrics.json
2224
otlp:
2325
endpoint: {{ .OtlpEndpoint }}
2426
tls:
@@ -28,6 +30,9 @@ agent:
2830
traces:
2931
exporters:
3032
- otlp
33+
metrics/agent:
34+
exporters:
35+
- file
3136

3237
clusterReceiver:
3338
enabled: false

functional_tests/functional/testdata/values/aks_test_win_values.yaml.tmpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ splunkPlatform:
1010
endpoint: {{ .LogHecEndpoint }}
1111

1212
agent:
13+
podLabels:
14+
osType: "windows"
1315
resources:
1416
requests:
1517
cpu: 100m
@@ -23,19 +25,33 @@ agent:
2325
endpoint: {{ .OtlpEndpoint }}
2426
tls:
2527
insecure: true
28+
file:
29+
path: C:\metrics.json
2630
service:
2731
pipelines:
2832
traces:
2933
exporters:
3034
- otlp
35+
metrics/agent:
36+
exporters:
37+
- file
3138
clusterReceiver:
39+
podLabels:
40+
osType: "windows"
3241
eventsEnabled: true
3342
config:
3443
exporters:
3544
signalfx:
3645
ingest_url: {{ .K8sClusterEndpoint }}
3746
tls:
3847
insecure: true
48+
file:
49+
path: C:\metrics.json
50+
service:
51+
pipelines:
52+
metrics/collector:
53+
exporters:
54+
- file
3955

4056
k8sObjects:
4157
- name: pods

functional_tests/internal/common.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,19 @@ func CopyFileToPod(t *testing.T, clientset *kubernetes.Clientset, config *rest.C
168168
func CopyFileFromPod(t *testing.T, clientset *kubernetes.Clientset, config *rest.Config,
169169
namespace, podName, containerName, podFilePath, localFilePath string,
170170
) {
171+
var command []string
172+
if strings.HasPrefix(podFilePath, "/") {
173+
command = []string{"cat", podFilePath}
174+
} else {
175+
command = []string{"cmd.exe", "/c", "type", podFilePath}
176+
}
171177
req := clientset.CoreV1().RESTClient().Post().
172178
Resource("pods").
173179
Name(podName).
174180
Namespace(namespace).
175181
SubResource("exec").
176182
VersionedParams(&v1.PodExecOptions{
177-
Command: []string{"cat", podFilePath},
183+
Command: command,
178184
Container: containerName,
179185
Stdin: false,
180186
Stdout: true,

0 commit comments

Comments
 (0)