Skip to content

Commit

Permalink
[operator] add tests for Python support (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Feb 3, 2025
1 parent 56f18c7 commit 0198bd5
Show file tree
Hide file tree
Showing 15 changed files with 2,409 additions and 1,615 deletions.
12 changes: 12 additions & 0 deletions .chloggen/python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement
# The name of the component, or a single word describing the area of concern, (e.g. agent, clusterReceiver, gateway, operator, chart, other)
component: operator
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add tests for Python support
# One or more tracking issues related to the change
issues: [1641]
# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ spec:
- name: OTEL_RESOURCE_ATTRIBUTES
value: splunk.zc.method=splunk-otel-js:v2.15.0
python:
image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:0.44b0
image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:0.50b0
env:
- name: OTEL_RESOURCE_ATTRIBUTES
value: splunk.zc.method=autoinstrumentation-python:0.44b0
value: splunk.zc.method=autoinstrumentation-python:0.50b0
# python auto-instrumentation uses http/proto by default, so data must be sent to 4318 instead of 4317.
# See: https://github.com/open-telemetry/opentelemetry-operator#opentelemetry-auto-instrumentation-injection
- name: OTEL_EXPORTER_OTLP_ENDPOINT
Expand Down
1 change: 1 addition & 0 deletions functional_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ kind load docker-image quay.io/splunko11ytest/dotnet_test:latest --name kind
kind load docker-image ghcr.io/signalfx/splunk-otel-dotnet/splunk-otel-dotnet:v1.8.0 --name kind
kind load docker-image ghcr.io/signalfx/splunk-otel-js/splunk-otel-js:v2.4.4 --name kind
kind load docker-image ghcr.io/signalfx/splunk-otel-java/splunk-otel-java:v1.30.0 --name kind
kind load docker-image ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:0.50b0 --name kind
```

## Config switches
Expand Down
86 changes: 86 additions & 0 deletions functional_tests/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ func deployChartsAndApps(t *testing.T) {
require.NoError(t, err)
}
}
// Python test app
stream, err = os.ReadFile(filepath.Join(testDir, "python", "deployment.yaml"))
require.NoError(t, err)
deployment, _, err = decode(stream, nil, nil)
require.NoError(t, err)
_, err = deployments.Create(context.Background(), deployment.(*appsv1.Deployment), metav1.CreateOptions{})
if err != nil {
_, err2 := deployments.Update(context.Background(), deployment.(*appsv1.Deployment), metav1.UpdateOptions{})
assert.NoError(t, err2)
if err2 != nil {
require.NoError(t, err)
}
}
// Prometheus annotation
stream, err = os.ReadFile(filepath.Join(testDir, manifestsDir, "deployment_with_prometheus_annotations.yaml"))
require.NoError(t, err)
Expand Down Expand Up @@ -433,6 +446,9 @@ func teardown(t *testing.T) {
_ = deployments.Delete(context.Background(), "java-test", metav1.DeleteOptions{
GracePeriodSeconds: &waitTime,
})
_ = deployments.Delete(context.Background(), "python-test", metav1.DeleteOptions{
GracePeriodSeconds: &waitTime,
})
_ = deployments.Delete(context.Background(), "dotnet-test", metav1.DeleteOptions{
GracePeriodSeconds: &waitTime,
})
Expand Down Expand Up @@ -541,6 +557,7 @@ func Test_Functions(t *testing.T) {
t.Run("node.js traces captured", testNodeJSTraces)
t.Run("java traces captured", testJavaTraces)
t.Run(".NET traces captured", testDotNetTraces)
t.Run("Python traces captured", testPythonTraces)
t.Run("kubernetes cluster metrics", testK8sClusterReceiverMetrics)
t.Run("agent logs", testAgentLogs)
t.Run("test HEC metrics", testHECMetrics)
Expand Down Expand Up @@ -616,6 +633,75 @@ func testNodeJSTraces(t *testing.T) {
require.NoError(t, err)
}

func testPythonTraces(t *testing.T) {
tracesConsumer := setupOnce(t).tracesConsumer

var expectedTraces ptrace.Traces
expectedTracesFile := filepath.Join(testDir, expectedValuesDir, "expected_python_traces.yaml")
expectedTraces, err := golden.ReadTraces(expectedTracesFile)
require.NoError(t, err)

waitForTraces(t, 10, tracesConsumer)

var selectedTrace *ptrace.Traces

read := 0
require.Eventually(t, func() bool {
for i := len(tracesConsumer.AllTraces()) - 1; i > read; i-- {
trace := tracesConsumer.AllTraces()[i]
if val, ok := trace.ResourceSpans().At(0).Resource().Attributes().Get("telemetry.sdk.language"); ok && strings.Contains(val.Str(), "python") {
if expectedTraces.SpanCount() == trace.SpanCount() && expectedTraces.ResourceSpans().Len() == trace.ResourceSpans().Len() {
selectedTrace = &trace
break
}
}
}
read = len(tracesConsumer.AllTraces()) - 1
return selectedTrace != nil
}, 1*time.Minute, 5*time.Second)
require.NotNil(t, selectedTrace)

maskScopeVersion(*selectedTrace)
maskScopeVersion(expectedTraces)

err = ptracetest.CompareTraces(expectedTraces, *selectedTrace,
ptracetest.IgnoreResourceAttributeValue("container.id"),
ptracetest.IgnoreResourceAttributeValue("host.arch"),
ptracetest.IgnoreResourceAttributeValue("k8s.deployment.name"),
ptracetest.IgnoreResourceAttributeValue("k8s.pod.ip"),
ptracetest.IgnoreResourceAttributeValue("k8s.pod.name"),
ptracetest.IgnoreResourceAttributeValue("k8s.pod.uid"),
ptracetest.IgnoreResourceAttributeValue("k8s.replicaset.name"),
ptracetest.IgnoreResourceAttributeValue("os.version"),
ptracetest.IgnoreResourceAttributeValue("process.pid"),
ptracetest.IgnoreResourceAttributeValue("splunk.distro.version"),
ptracetest.IgnoreResourceAttributeValue("process.runtime.version"),
ptracetest.IgnoreResourceAttributeValue("process.command"),
ptracetest.IgnoreResourceAttributeValue("process.command_args"),
ptracetest.IgnoreResourceAttributeValue("process.executable.path"),
ptracetest.IgnoreResourceAttributeValue("process.owner"),
ptracetest.IgnoreResourceAttributeValue("process.runtime.description"),
ptracetest.IgnoreResourceAttributeValue("splunk.zc.method"),
ptracetest.IgnoreResourceAttributeValue("telemetry.distro.version"),
ptracetest.IgnoreResourceAttributeValue("telemetry.sdk.version"),
ptracetest.IgnoreResourceAttributeValue("service.instance.id"),
ptracetest.IgnoreSpanAttributeValue("http.user_agent"),
ptracetest.IgnoreSpanAttributeValue("net.peer.port"),
ptracetest.IgnoreSpanAttributeValue("network.peer.port"),
ptracetest.IgnoreSpanAttributeValue("os.version"),
ptracetest.IgnoreTraceID(),
ptracetest.IgnoreSpanID(),
ptracetest.IgnoreStartTimestamp(),
ptracetest.IgnoreEndTimestamp(),
ptracetest.IgnoreResourceSpansOrder(),
ptracetest.IgnoreScopeSpansOrder(),
)
if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" {
writeNewExpectedTracesResult(t, expectedTracesFile, selectedTrace)
}
require.NoError(t, err)
}

func testJavaTraces(t *testing.T) {
tracesConsumer := setupOnce(t).tracesConsumer

Expand Down
Loading

0 comments on commit 0198bd5

Please sign in to comment.