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

Add integration tests for DotNet #199

Merged
merged 17 commits into from
Jul 24, 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
75 changes: 47 additions & 28 deletions .github/workflows/operator-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ jobs:
make deploy
kubectl wait --for=condition=Ready pod --all -n amazon-cloudwatch


- name: Test case for cloudwatch agent pod creation
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
run: |
kubectl apply -f integration-tests/manifests/cloudwatch-agent-daemonset.yaml -n amazon-cloudwatch
sleep 5
sleep 20
kubectl wait --for=condition=Ready pod --all -n amazon-cloudwatch

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}')"
Expand All @@ -75,7 +76,8 @@ jobs:
kubectl apply -f integration-tests/java/sample-deployment-java.yaml
sleep 5
kubectl wait --for=condition=Ready pod --all -n default

kubectl get pods -A
kubectl describe pods -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/java/default_instrumentation_java_env_variables.json

- name: Test for defined instrumentation resources for Java
Expand All @@ -85,17 +87,16 @@ jobs:
sleep 5
kubectl wait --for=condition=Ready pod --all -n default

cd integration-tests/manifests/cmd
go run validate_instrumentation_vars.go default ns_instrumentation_env_variables.json
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
kubectl delete instrumentation sample-instrumentation

- name: Test for default instrumentation resources for python
run: |
kubectl apply -f integration-tests/python/sample-deployment-python.yaml
kubectl delete pods --all -n default
sleep 5
kubectl wait --for=condition=Ready pod --all -n default

kubectl get pods -A
kubectl describe pods -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/python/default_instrumentation_python_env_variables.json

- name: Test for defined instrumentation resources for python
Expand All @@ -104,31 +105,48 @@ jobs:
kubectl delete pods --all -n default
sleep 5
kubectl wait --for=condition=Ready pod --all -n default

cd integration-tests/manifests/cmd
go run validate_instrumentation_vars.go default ns_instrumentation_env_variables.json
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
kubectl delete instrumentation sample-instrumentation

- name: Test for default instrumentation resources for python and java
- name: Test for default instrumentation resources for dotnet
run: |
kubectl apply -f integration-tests/python-java/sample-deployment-python-java.yaml
cat integration-tests/dotnet/sample-deployment-dotnet.yaml
kubectl apply -f integration-tests/dotnet/sample-deployment-dotnet.yaml
sleep 5
kubectl wait --for=condition=Available deployment/nginx -n default
kubectl get pods -A
kubectl describe pods -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/dotnet/default_instrumentation_dotnet_env_variables.json

- name: Test for defined instrumentation resources for dotnet
run: |
kubectl apply -f integration-tests/manifests/sample-instrumentation.yaml
kubectl delete pods --all -n default
sleep 5
kubectl wait --for=condition=Ready pod --all -n default

go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/python-java/default_instrumentation_python-java_env_variables.json
kubectl wait --for=condition=Ready pod --all -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
kubectl delete instrumentation sample-instrumentation

- name: Test for defined instrumentation resources for python and java

- name: Test for default instrumentation resources for all languages
run: |
kubectl apply -f integration-tests/all-languages/sample-deployment-all-languages.yaml
sleep 5
kubectl wait --for=condition=Available deployment/nginx -n default
sleep 5
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/all-languages/default_instrumentation_all-languages_env_variables.json


- name: Test for defined instrumentation resources for all languages
run: |
kubectl apply -f integration-tests/manifests/sample-instrumentation.yaml
kubectl delete pods --all -n default
sleep 5
kubectl wait --for=condition=Ready pod --all -n default

cd integration-tests/manifests/cmd
go run validate_instrumentation_vars.go default ns_instrumentation_env_variables.json
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
kubectl delete instrumentation sample-instrumentation


DeploymentAnnotationsTest:
name: DeploymentAnnotationsTest
runs-on: ubuntu-latest
Expand Down Expand Up @@ -169,16 +187,15 @@ jobs:
kubectl get pods -A
kubectl describe pods -n default
sleep 5
go test -v -run TestJavaAndPythonDeployment ./integration-tests/manifests/annotations -timeout 30m
go test -v -run TestAllLanguagesDeployment ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestJavaOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestPythonOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestDotNetOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestAnnotationsOnMultipleResources ./integration-tests/manifests/annotations -timeout 30m




DaemonsetAnnotationsTest:
name: DaemonsetAnnotationsTest
Expand Down Expand Up @@ -220,15 +237,15 @@ jobs:
sleep 5
kubectl get pods -A
kubectl describe pods -n default
go test -v -run TestJavaAndPythonDaemonSet ./integration-tests/manifests/annotations -timeout 30m
go test -v -run TestAllLanguagesDaemonSet ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestJavaOnlyDaemonSet ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestPythonOnlyDaemonSet ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestDotNetOnlyDaemonSet ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestAutoAnnotationForManualAnnotationRemoval ./integration-tests/manifests/annotations -timeout 30m



StatefulsetAnnotationsTest:
name: StatefulsetAnnotationsTest
Expand Down Expand Up @@ -270,7 +287,7 @@ jobs:
sleep 5
kubectl get pods -A
kubectl describe pods -n default
go test -v -run TestJavaAndPythonStatefulSet ./integration-tests/manifests/annotations -timeout 30m
go test -v -run TestAllLanguagesStatefulSet ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestJavaOnlyStatefulSet ./integration-tests/manifests/annotations -timeout 30m
sleep 5
Expand Down Expand Up @@ -317,10 +334,12 @@ jobs:
run: |
kubectl get pods -A
kubectl describe pods -n default
go test -v -run TestJavaAndPythonNamespace ./integration-tests/manifests/annotations -timeout 30m
go test -v -run TestAllLanguagesNamespace ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestJavaOnlyNamespace ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestPythonOnlyNamespace ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestAlreadyAutoAnnotatedResourceShouldNotRestart ./integration-tests/manifests/annotations -timeout 30m
go test -v -run TestDotNetOnlyNamespace ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestAlreadyAutoAnnotatedResourceShouldNotRestart ./integration-tests/manifests/annotations -timeout 30m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
"OTEL_METRICS_EXPORTER": "none",
"OTEL_PYTHON_DISTRO": "aws_distro",
"OTEL_PYTHON_CONFIGURATOR": "aws_configurator",
"OTEL_DOTNET_DISTRO": "aws_distro",
"OTEL_LOGS_EXPORTER": "none",
"OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT": "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics",
"JAVA_TOOL_OPTIONS": "-javaagent:/otel-auto-instrumentation-java/javaagent.jar"
"JAVA_TOOL_OPTIONS": "-javaagent:/otel-auto-instrumentation-java/javaagent.jar",
"CORECLR_PROFILER_PATH": "/otel-auto-instrumentation-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so",
"DOTNET_STARTUP_HOOKS": "/otel-auto-instrumentation-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll",
"DOTNET_ADDITIONAL_DEPS": "/otel-auto-instrumentation-dotnet/AdditionalDeps",
"OTEL_DOTNET_AUTO_HOME": "/otel-auto-instrumentation-dotnet",
"DOTNET_SHARED_STORE": "/otel-auto-instrumentation-dotnet/store",
"CORECLR_ENABLE_PROFILING": "1"

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
annotations:
instrumentation.opentelemetry.io/inject-python: "true"
instrumentation.opentelemetry.io/inject-java: "true"
instrumentation.opentelemetry.io/inject-dotnet: "true"
spec:
containers:
- name: nginx
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"OTEL_TRACES_SAMPLER_ARG": "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000",
"OTEL_TRACES_SAMPLER" : "xray",
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces",
"OTEL_METRICS_EXPORTER": "none",
"OTEL_DOTNET_DISTRO": "aws_distro",
"OTEL_LOGS_EXPORTER": "none",
"CORECLR_PROFILER_PATH": "/otel-auto-instrumentation-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so",
"DOTNET_STARTUP_HOOKS": "/otel-auto-instrumentation-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll",
"DOTNET_ADDITIONAL_DEPS": "/otel-auto-instrumentation-dotnet/AdditionalDeps",
"OTEL_DOTNET_AUTO_HOME": "/otel-auto-instrumentation-dotnet",
"DOTNET_SHARED_STORE": "/otel-auto-instrumentation-dotnet/store",
"CORECLR_ENABLE_PROFILING": "1"

}
22 changes: 22 additions & 0 deletions integration-tests/dotnet/sample-deployment-dotnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
annotations:
instrumentation.opentelemetry.io/inject-dotnet: "true"
spec:
containers:
- name: nginx
image: nginx:1.14.2
restartPolicy: Always
status: {}


Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/aws/amazon-cloudwatch-agent-operator/pkg/instrumentation/auto"
)

func TestJavaAndPythonDaemonSet(t *testing.T) {
func TestAllLanguagesDaemonSet(t *testing.T) {
clientSet := setupTest(t)
randomNumber, err := rand.Int(rand.Reader, big.NewInt(9000))
if err != nil {
panic(err)
}
randomNumber.Add(randomNumber, big.NewInt(1000)) //adding a hash to namespace
uniqueNamespace := fmt.Sprintf("daemonset-namespace-java-python-%d", randomNumber)
uniqueNamespace := fmt.Sprintf("daemonset-namespace-all-languages-%d", randomNumber)

annotationConfig := auto.AnnotationConfig{
Java: auto.AnnotationResources{
Expand All @@ -36,6 +36,12 @@ func TestJavaAndPythonDaemonSet(t *testing.T) {
Deployments: []string{""},
StatefulSets: []string{""},
},
DotNet: auto.AnnotationResources{
Namespaces: []string{""},
DaemonSets: []string{filepath.Join(uniqueNamespace, daemonSetName)},
Deployments: []string{""},
StatefulSets: []string{""},
},
}
jsonStr, err := json.Marshal(annotationConfig)
if err != nil {
Expand All @@ -45,7 +51,7 @@ func TestJavaAndPythonDaemonSet(t *testing.T) {
startTime := time.Now()
updateTheOperator(t, clientSet, string(jsonStr))

if err := checkResourceAnnotations(t, clientSet, "daemonset", uniqueNamespace, daemonSetName, sampleDaemonsetYamlRelPath, startTime, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation, injectPythonAnnotation, autoAnnotatePythonAnnotation}, false); err != nil {
if err := checkResourceAnnotations(t, clientSet, "daemonset", uniqueNamespace, daemonSetName, sampleDaemonsetYamlRelPath, startTime, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation, injectPythonAnnotation, autoAnnotatePythonAnnotation, injectDotNetAnnotation, autoAnnotateDotNetAnnotation}, false); err != nil {
t.Fatalf("Failed annotation check: %s", err.Error())
}

Expand Down Expand Up @@ -121,3 +127,32 @@ func TestPythonOnlyDaemonSet(t *testing.T) {
}

}

func TestDotNetOnlyDaemonSet(t *testing.T) {
clientSet := setupTest(t)
randomNumber, err := rand.Int(rand.Reader, big.NewInt(9000))
if err != nil {
panic(err)
}
randomNumber.Add(randomNumber, big.NewInt(1000)) //adding a hash to namespace
uniqueNamespace := fmt.Sprintf("daemonset-namespace-dotnet-only-%d", randomNumber)
annotationConfig := auto.AnnotationConfig{
DotNet: auto.AnnotationResources{
Namespaces: []string{""},
DaemonSets: []string{filepath.Join(uniqueNamespace, daemonSetName)},
Deployments: []string{""},
StatefulSets: []string{""},
},
}
jsonStr, err := json.Marshal(annotationConfig)
if err != nil {
t.Error("Error:", err)
}
startTime := time.Now()
updateTheOperator(t, clientSet, string(jsonStr))

if err := checkResourceAnnotations(t, clientSet, "daemonset", uniqueNamespace, daemonSetName, sampleDaemonsetYamlRelPath, startTime, []string{injectDotNetAnnotation, autoAnnotateDotNetAnnotation}, false); err != nil {
t.Fatalf("Failed annotation check: %s", err.Error())
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ const (
autoAnnotateJavaAnnotation = "cloudwatch.aws.amazon.com/auto-annotate-java"
injectPythonAnnotation = "instrumentation.opentelemetry.io/inject-python"
autoAnnotatePythonAnnotation = "cloudwatch.aws.amazon.com/auto-annotate-python"
deploymentName = "sample-deployment"
nginxDeploymentName = "nginx"
statefulSetName = "sample-statefulset"
amazonCloudwatchNamespace = "amazon-cloudwatch"
injectDotNetAnnotation = "instrumentation.opentelemetry.io/inject-dotnet"
autoAnnotateDotNetAnnotation = "cloudwatch.aws.amazon.com/auto-annotate-dotnet"

deploymentName = "sample-deployment"
nginxDeploymentName = "nginx"
statefulSetName = "sample-statefulset"
amazonCloudwatchNamespace = "amazon-cloudwatch"

daemonSetName = "sample-daemonset"

Expand Down
Loading
Loading