Skip to content

Commit

Permalink
Implement #73 integration tests for .NET (#83)
Browse files Browse the repository at this point in the history
* Implement #73 integration tests for .NET

This adds .NET auto attachment tests

* make sure we get the logs for dotnet-test-app not java-test-app

* ensure app logs at trace level

* enable stdout logging

* ensure we use /elastic/apm/ as mount path

* update agent_has_started grep for agent presence

* :grep => grep, trying out fleet but its VI bindings are still crap :)

* more info from agent_has_started.sh

* simpler grep
  • Loading branch information
Mpdreamz authored Jul 10, 2024
1 parent 88c21f6 commit 445b4ef
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 9 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ on:
- '**.asciidoc'

env:
AGENT_TESTS: java nodejs

permissions:
contents: read

AGENT_TESTS: dotnet java nodejs

jobs:
integration-test:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ main

.webhook
.vscode
.idea
bin

html_docs
html_docs
6 changes: 3 additions & 3 deletions charts/apm-attacher/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ webhookConfig:
environment:
CORECLR_ENABLE_PROFILING: "1"
CORECLR_PROFILER: "{FA65FE15-F085-4681-9B20-95E04F6C03CC}"
CORECLR_PROFILER_PATH: "/usr/agent/apm-dotnet-agent/libelastic_apm_profiler.so"
ELASTIC_APM_PROFILER_HOME: "/usr/agent/apm-dotnet-agent"
ELASTIC_APM_PROFILER_INTEGRATIONS: "/usr/agent/apm-dotnet-agent/integrations.yml"
CORECLR_PROFILER_PATH: "/elastic/apm/agent/apm-dotnet-agent/libelastic_apm_profiler.so"
ELASTIC_APM_PROFILER_HOME: "/elastic/apm/agent/apm-dotnet-agent"
ELASTIC_APM_PROFILER_INTEGRATIONS: "/elastic/apm/agent/apm-dotnet-agent/integrations.yml"
2 changes: 2 additions & 0 deletions test/dotnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
obj
19 changes: 19 additions & 0 deletions test/dotnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore

# copy everything else and build app
COPY . .
RUN dotnet publish -c release -o /app --no-restore

# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app ./
ENV ELASTIC_APM_PROFILER_LOG_TARGETS=stdout;file
ENV ELASTIC_APM_PROFILER_LOG=trace
ENTRYPOINT ["dotnet", "dotnetapp.dll"]
7 changes: 7 additions & 0 deletions test/dotnet/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var builder = WebApplication.CreateBuilder(args);
_ = builder.Logging.SetMinimumLevel(LogLevel.Trace);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();
12 changes: 12 additions & 0 deletions test/dotnet/agent_has_started.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
#initial 10 second delay for restricted CPUs making agent slow starting
sleep 10
START_MESSAGE=`kubectl logs dotnet-test-app | grep 'Elastic APM .NET Agent, version'`
if [ "x$START_MESSAGE" = "x" ]
then
echo "APM Agent appears to have not been started"
exit 1
else
echo "Found APM agent in the kubctl logs"
exit 0
fi
9 changes: 9 additions & 0 deletions test/dotnet/dotnetapp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
13 changes: 13 additions & 0 deletions test/dotnet/test-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: dotnet-test-app
annotations:
co.elastic.apm/attach: dotnet
labels:
app: dotnet-test-app
spec:
containers:
- image: localhost:5001/registry/dotnet-test-app
imagePullPolicy: Always
name: dotnet-test-app
5 changes: 5 additions & 0 deletions test/mock/test_values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ webhookConfig:
ELASTIC_APM_SERVER_URL: "http://mock-apm-server-service:8027"
ELASTIC_APM_ENVIRONMENT: "test"
ELASTIC_APM_LOG_LEVEL: "trace"
dotnet:
environment:
ELASTIC_APM_SERVER_URL: "http://mock-apm-server-service:8027"
ELASTIC_APM_ENVIRONMENT: "test"
ELASTIC_APM_LOG_LEVEL: "trace"

0 comments on commit 445b4ef

Please sign in to comment.