Skip to content

Commit 71fab73

Browse files
authored
Add integration tests for JMX. (#250)
1 parent 73ea5d7 commit 71fab73

8 files changed

+221
-16
lines changed

.github/workflows/operator-integration-test.yml

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
kubectl wait --for=condition=Ready pod --all -n default
7979
kubectl get pods -A
8080
kubectl describe pods -n default
81-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/java/default_instrumentation_java_env_variables.json
81+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/java/default_instrumentation_java_env_variables.json app_signals
8282
8383
- name: Test for defined instrumentation resources for Java
8484
run: |
@@ -87,7 +87,7 @@ jobs:
8787
sleep 5
8888
kubectl wait --for=condition=Ready pod --all -n default
8989
90-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
90+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals
9191
kubectl delete instrumentation sample-instrumentation
9292
9393
- name: Test for default instrumentation resources for python
@@ -97,15 +97,15 @@ jobs:
9797
kubectl wait --for=condition=Ready pod --all -n default
9898
kubectl get pods -A
9999
kubectl describe pods -n default
100-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/python/default_instrumentation_python_env_variables.json
100+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/python/default_instrumentation_python_env_variables.json app_signals
101101
102102
- name: Test for defined instrumentation resources for python
103103
run: |
104104
kubectl apply -f integration-tests/manifests/sample-instrumentation.yaml
105105
kubectl delete pods --all -n default
106106
sleep 5
107107
kubectl wait --for=condition=Ready pod --all -n default
108-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
108+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals
109109
kubectl delete instrumentation sample-instrumentation
110110
111111
- name: Test for default instrumentation resources for dotnet
@@ -116,15 +116,15 @@ jobs:
116116
kubectl wait --for=condition=Available deployment/nginx -n default
117117
kubectl get pods -A
118118
kubectl describe pods -n default
119-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/dotnet/default_instrumentation_dotnet_env_variables.json
119+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/dotnet/default_instrumentation_dotnet_env_variables.json app_signals
120120
121121
- name: Test for defined instrumentation resources for dotnet
122122
run: |
123123
kubectl apply -f integration-tests/manifests/sample-instrumentation.yaml
124124
kubectl delete pods --all -n default
125125
sleep 5
126126
kubectl wait --for=condition=Ready pod --all -n default
127-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
127+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals
128128
kubectl delete instrumentation sample-instrumentation
129129
130130
- name: Test for default instrumentation resources for nodejs
@@ -137,7 +137,7 @@ jobs:
137137
kubectl wait --for=condition=Available deployment/nginx -n default
138138
kubectl get pods -A
139139
kubectl describe pods -n default
140-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/nodejs/default_instrumentation_nodejs_env_variables.json
140+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/nodejs/default_instrumentation_nodejs_env_variables.json app_signals
141141
142142
- name: Test for defined instrumentation resources for nodejs
143143
run: |
@@ -146,7 +146,7 @@ jobs:
146146
sleep 5
147147
kubectl wait --for=condition=Available deployment/nginx -n default
148148
sleep 5
149-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
149+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals
150150
kubectl delete instrumentation sample-instrumentation
151151
152152
- name: Test for default instrumentation resources for all languages
@@ -155,8 +155,7 @@ jobs:
155155
sleep 5
156156
kubectl wait --for=condition=Available deployment/nginx -n default
157157
sleep 5
158-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/all-languages/default_instrumentation_all-languages_env_variables.json
159-
158+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/all-languages/default_instrumentation_all-languages_env_variables.json app_signals
160159
161160
- name: Test for defined instrumentation resources for all languages
162161
run: |
@@ -165,9 +164,69 @@ jobs:
165164
sleep 5
166165
kubectl wait --for=condition=Available deployment/nginx -n default
167166
sleep 5
168-
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
167+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals
169168
kubectl delete instrumentation sample-instrumentation
170169
170+
- name: Test for default instrumentation resources for jmx
171+
run: |
172+
kubectl delete pods --all -n default
173+
sleep 5
174+
cat integration-tests/jmx/sample-deployment-jmx.yaml
175+
kubectl apply -f integration-tests/jmx/sample-deployment-jmx.yaml
176+
sleep 5
177+
kubectl wait --for=condition=Available deployment/nginx -n default
178+
kubectl get pods -A
179+
kubectl describe pods -n default
180+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/jmx/default_instrumentation_jmx_env_variables.json app_signals
181+
182+
- name: Test for defined instrumentation resources for jmx
183+
run: |
184+
kubectl apply -f integration-tests/manifests/sample-instrumentation.yaml
185+
kubectl delete pods --all -n default
186+
sleep 5
187+
kubectl wait --for=condition=Available deployment/nginx -n default
188+
sleep 5
189+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals
190+
kubectl delete instrumentation sample-instrumentation
191+
192+
- name: Test case for cloudwatch agent without app signals pod creation
193+
run: |
194+
kubectl delete daemonset cloudwatch-agent -n amazon-cloudwatch
195+
sleep 5
196+
kubectl apply -f integration-tests/manifests/cloudwatch-agent-daemonset-no-app-signals.yaml -n amazon-cloudwatch
197+
sleep 20
198+
kubectl wait --for=condition=Ready pod --all -n amazon-cloudwatch
199+
200+
pod_name="$(kubectl get pods -n amazon-cloudwatch -l app.kubernetes.io/component=amazon-cloudwatch-agent,app.kubernetes.io/instance=amazon-cloudwatch.cloudwatch-agent -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')"
201+
if [ -z "$pod_name" ]; then
202+
echo "Pod $pod_name is not created. Exiting with ERROR."
203+
echo "Pod is not created test case: FAIL"
204+
else
205+
echo "Pod $pod_name is created."
206+
echo "Pod is created test case: PASS"
207+
fi
208+
209+
- name: Test for default instrumentation resources for jmx without app signals
210+
run: |
211+
kubectl delete pods --all -n default
212+
sleep 5
213+
cat integration-tests/jmx/sample-deployment-jmx.yaml
214+
kubectl apply -f integration-tests/jmx/sample-deployment-jmx.yaml
215+
sleep 5
216+
kubectl wait --for=condition=Available deployment/nginx -n default
217+
kubectl get pods -A
218+
kubectl describe pods -n default
219+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/jmx/default_instrumentation_jmx_env_variables_no_app_signals.json no_app_signals
220+
221+
- name: Test for defined instrumentation resources for jmx without app signals
222+
run: |
223+
kubectl apply -f integration-tests/manifests/sample-instrumentation.yaml
224+
kubectl delete pods --all -n default
225+
sleep 5
226+
kubectl wait --for=condition=Available deployment/nginx -n default
227+
sleep 5
228+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals
229+
kubectl delete instrumentation sample-instrumentation
171230
172231
DeploymentAnnotationsTest:
173232
name: DeploymentAnnotationsTest

integration-tests/all-languages/default_instrumentation_all-languages_env_variables.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"DOTNET_ADDITIONAL_DEPS": "/otel-auto-instrumentation-dotnet/AdditionalDeps",
2121
"OTEL_DOTNET_AUTO_HOME": "/otel-auto-instrumentation-dotnet",
2222
"DOTNET_SHARED_STORE": "/otel-auto-instrumentation-dotnet/store",
23-
"CORECLR_ENABLE_PROFILING": "1"
24-
25-
}
23+
"CORECLR_ENABLE_PROFILING": "1",
24+
"OTEL_AWS_JMX_EXPORTER_METRICS_ENDPOINT": "http://cloudwatch-agent.amazon-cloudwatch:4314/v1/metrics",
25+
"OTEL_JMX_TARGET_SYSTEM": "jvm,tomcat,kafka,kafka-consumer,kafka-producer"
26+
}

integration-tests/all-languages/sample-deployment-all-languages.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ spec:
1414
instrumentation.opentelemetry.io/inject-python: "true"
1515
instrumentation.opentelemetry.io/inject-java: "true"
1616
instrumentation.opentelemetry.io/inject-dotnet: "true"
17+
instrumentation.opentelemetry.io/inject-nodejs: "true"
18+
cloudwatch.aws.amazon.com/inject-jmx-jvm: "true"
19+
cloudwatch.aws.amazon.com/inject-jmx-tomcat: "true"
20+
cloudwatch.aws.amazon.com/inject-jmx-kafka: "true"
21+
cloudwatch.aws.amazon.com/inject-jmx-kafka-consumer: "true"
22+
cloudwatch.aws.amazon.com/inject-jmx-kafka-producer: "true"
1723
spec:
1824
containers:
1925
- name: nginx
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
3+
"OTEL_METRICS_EXPORTER": "none",
4+
"OTEL_LOGS_EXPORTER": "none",
5+
"OTEL_AWS_APP_SIGNALS_ENABLED": "true",
6+
"OTEL_AWS_APPLICATION_SIGNALS_ENABLED": "true",
7+
"OTEL_TRACES_SAMPLER_ARG": "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000",
8+
"OTEL_TRACES_SAMPLER": "xray",
9+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces",
10+
"OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT": "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics",
11+
"OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT": "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics",
12+
"OTEL_AWS_JMX_EXPORTER_METRICS_ENDPOINT": "http://cloudwatch-agent.amazon-cloudwatch:4314/v1/metrics",
13+
"OTEL_JMX_TARGET_SYSTEM": "jvm,tomcat,kafka,kafka-consumer,kafka-producer",
14+
"JAVA_TOOL_OPTIONS": "-javaagent:/otel-auto-instrumentation-java/javaagent.jar"
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
3+
"OTEL_METRICS_EXPORTER": "none",
4+
"OTEL_LOGS_EXPORTER": "none",
5+
"OTEL_TRACES_EXPORTER": "none",
6+
"OTEL_AWS_JMX_EXPORTER_METRICS_ENDPOINT": "http://cloudwatch-agent.amazon-cloudwatch:4314/v1/metrics",
7+
"OTEL_JMX_TARGET_SYSTEM": "jvm,tomcat,kafka,kafka-consumer,kafka-producer",
8+
"JAVA_TOOL_OPTIONS": "-javaagent:/otel-auto-instrumentation-java/javaagent.jar"
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nginx
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: nginx
9+
template:
10+
metadata:
11+
labels:
12+
app: nginx
13+
annotations:
14+
instrumentation.opentelemetry.io/inject-java: "true"
15+
cloudwatch.aws.amazon.com/inject-jmx-jvm: "true"
16+
cloudwatch.aws.amazon.com/inject-jmx-tomcat: "true"
17+
cloudwatch.aws.amazon.com/inject-jmx-kafka: "true"
18+
cloudwatch.aws.amazon.com/inject-jmx-kafka-consumer: "true"
19+
cloudwatch.aws.amazon.com/inject-jmx-kafka-producer: "true"
20+
spec:
21+
containers:
22+
- name: nginx
23+
image: nginx:1.14.2
24+
restartPolicy: Always
25+
status: {}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
apiVersion: cloudwatch.aws.amazon.com/v1alpha1
2+
kind: AmazonCloudWatchAgent
3+
metadata:
4+
name: cloudwatch-agent
5+
namespace: amazon-cloudwatch
6+
spec:
7+
mode: daemonset
8+
serviceAccount: cloudwatch-agent
9+
image: public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest
10+
config: |
11+
{
12+
"agent": {
13+
"region": "${REGION}",
14+
"debug": true
15+
}
16+
}
17+
volumeMounts:
18+
- mountPath: /rootfs
19+
name: rootfs
20+
readOnly: true
21+
- mountPath: /var/run/docker.sock
22+
name: dockersock
23+
readOnly: true
24+
- mountPath: /run/containerd/containerd.sock
25+
name: containerdsock
26+
- mountPath: /var/lib/docker
27+
name: varlibdocker
28+
readOnly: true
29+
- mountPath: /sys
30+
name: sys
31+
readOnly: true
32+
- mountPath: /dev/disk
33+
name: devdisk
34+
readOnly: true
35+
volumes:
36+
- name: rootfs
37+
hostPath:
38+
path: /
39+
- hostPath:
40+
path: /var/run/docker.sock
41+
name: dockersock
42+
- hostPath:
43+
path: /var/lib/docker
44+
name: varlibdocker
45+
- hostPath:
46+
path: /run/containerd/containerd.sock
47+
name: containerdsock
48+
- hostPath:
49+
path: /sys
50+
name: sys
51+
- hostPath:
52+
path: /dev/disk/
53+
name: devdisk
54+
env:
55+
- name: K8S_NODE_NAME
56+
valueFrom:
57+
fieldRef:
58+
fieldPath: spec.nodeName
59+
- name: HOST_IP
60+
valueFrom:
61+
fieldRef:
62+
fieldPath: status.hostIP
63+
- name: HOST_NAME
64+
valueFrom:
65+
fieldRef:
66+
fieldPath: spec.nodeName
67+
- name: K8S_NAMESPACE
68+
valueFrom:
69+
fieldRef:
70+
fieldPath: metadata.namespace

integration-tests/manifests/cmd/validate_instrumentation_vars.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,21 @@ import (
1818
"k8s.io/client-go/kubernetes"
1919
)
2020

21+
var appSignalsEnvVarKeys = []string{
22+
"OTEL_AWS_APP_SIGNALS_ENABLED",
23+
"OTEL_AWS_APPLICATION_SIGNALS_ENABLED",
24+
"OTEL_TRACES_SAMPLER_ARG",
25+
"OTEL_TRACES_SAMPLER",
26+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
27+
"OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT",
28+
}
29+
2130
func main() {
2231

2332
args := os.Args
2433
namespace := args[1]
2534
jsonFilePath := args[2]
35+
appSignalsEnabled := args[3] == "app_signals"
2636

2737
userHomeDir, err := os.UserHomeDir()
2838
if err != nil {
@@ -42,7 +52,7 @@ func main() {
4252
fmt.Printf("error getting kubernetes config: %v\n\n", err)
4353
}
4454

45-
success := verifyInstrumentationEnvVariables(clientSet, namespace, jsonFilePath)
55+
success := verifyInstrumentationEnvVariables(clientSet, namespace, jsonFilePath, appSignalsEnabled)
4656
if !success {
4757
fmt.Println("Instrumentation Annotation Injection Test: FAIL")
4858
os.Exit(1)
@@ -51,7 +61,7 @@ func main() {
5161
}
5262
}
5363

54-
func verifyInstrumentationEnvVariables(clientset *kubernetes.Clientset, namespace, jsonPath string) bool {
64+
func verifyInstrumentationEnvVariables(clientset *kubernetes.Clientset, namespace, jsonPath string, appSignalsEnabled bool) bool {
5565
podList, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{
5666
LabelSelector: "app=nginx",
5767
FieldSelector: "status.phase!=Terminating",
@@ -89,6 +99,16 @@ func verifyInstrumentationEnvVariables(clientset *kubernetes.Clientset, namespac
8999
}
90100
fmt.Println("JSON data:", jsonData)
91101

102+
if !appSignalsEnabled {
103+
fmt.Println("Checking if app signals environment variables exist")
104+
for _, key := range appSignalsEnvVarKeys {
105+
if _, exists := jsonData[key]; exists {
106+
fmt.Printf("Error: Key '%s' should not exist in jsonData when app signals is not enabled\n", key)
107+
return false
108+
}
109+
}
110+
}
111+
92112
for key, value := range jsonData {
93113
if val, ok := envMap[key]; ok {
94114
if strings.ReplaceAll(val, " ", "") != strings.ReplaceAll(value, " ", "") {

0 commit comments

Comments
 (0)