Skip to content

Commit

Permalink
Removing DotNet from supported auto-instrumentation platforms (#1334)
Browse files Browse the repository at this point in the history
* Cutting DotNet from instrumentation platforms

* Fix validation pipeline

* Bug fix in validation pipeline

* Refactoring of validation pipeline

* Bug fix

* Validation pipeline fixes

* Cosmetic fixes to validation

* Bug fix

* Updating @kubernetes/client-node to 0.22.1

* Sample change

* Trigger re-checks
  • Loading branch information
tokaplan authored Oct 16, 2024
1 parent c99aafa commit 543ea0e
Show file tree
Hide file tree
Showing 16 changed files with 428 additions and 366 deletions.
11 changes: 2 additions & 9 deletions .pipelines/azure_pipeline_validation_appmonitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ jobs:
fullImageName: ${{ variables.repoImageName }}:$(imageTag)
javaTestAppImageName: 'aicommon.azurecr.io/demoaks-java-app:latest'
javaTestAppName: 'test-app-java'
dotnetTestAppImageName: 'aicommon.azurecr.io/demoaks-dotnet-app:latest'
dotnetTestAppName: 'test-app-dotnet'
nodeTestAppImageName: 'aicommon.azurecr.io/demoaks-nodejs-app:latest'
nodeTestAppName: 'test-app-nodejs'
testNamespace: 'test-ns'
Expand Down Expand Up @@ -205,16 +203,13 @@ jobs:
az aks get-credentials --resource-group ${{ variables.AKSResourceGroup }} --name ${{ variables.AKSResourceName }}
export JAVA_TEST_IMAGE_NAME=${{ variables.javaTestAppImageName }}
export DOTNET_TEST_IMAGE_NAME=${{ variables.dotnetTestAppImageName }}
export NODEJS_TEST_IMAGE_NAME=${{ variables.nodeTestAppImageName }}
export TEST_NS="${{ variables.testNamespace }}"
export AI_CONNECTION_STRING="${{ variables.aiConnectionString }}"
export DOTNET_TEST_APP_NAME="${{ variables.dotnetTestAppName }}"
export JAVA_TEST_APP_NAME="${{ variables.javaTestAppName }}"
export NODEJS_TEST_APP_NAME="${{ variables.nodeTestAppName }}"
cat java-test-app.yaml | envsubst | kubectl delete -f -
cat dotnet-test-app.yaml | envsubst | kubectl delete -f -
cat node-test-app.yaml | envsubst | kubectl delete -f -
cat appmonitoring-cr.yaml | envsubst | kubectl delete -f -
Expand All @@ -228,7 +223,6 @@ jobs:
sleep 10
cat java-test-app.yaml | envsubst | kubectl apply -f -
cat dotnet-test-app.yaml | envsubst | kubectl apply -f -
cat node-test-app.yaml | envsubst | kubectl apply -f -
echo "Wait for 60s for charts to be applied..."
Expand All @@ -247,7 +241,7 @@ jobs:
az aks get-credentials --resource-group ${{ variables.AKSResourceGroup }} --name ${{ variables.AKSResourceName }}
sudo chmod u+x ./validate-mutation.sh
./validate-mutation.sh "test-app-dotnet" "test-app-java" "test-app-nodejs" "test-ns"
./validate-mutation.sh "test-app-java" "test-app-nodejs" "test-ns"
- task: AzureCLI@2
displayName: "Check test apps are sending telemetry to AI"
Expand All @@ -260,15 +254,14 @@ jobs:
pwd
az account set --subscription ${{ variables.subscription }}
az aks get-credentials --resource-group ${{ variables.AKSResourceGroup }} --name ${{ variables.AKSResourceName }}
export DOTNET_TEST_APP_NAME="${{ variables.dotnetTestAppName }}"
export JAVA_TEST_APP_NAME="${{ variables.javaTestAppName }}"
export NODEJS_TEST_APP_NAME="${{ variables.nodeTestAppName }}"
echo "Wait for 3m for telemetry to flow..."
sleep 180
sudo chmod u+x ./validate_ai.sh
./validate_ai.sh "test-app-dotnet" "test-app-java" "test-app-nodejs" "${{ variables.aiResourceId }}" "test-ns"
./validate_ai.sh "test-app-java" "test-app-nodejs" "${{ variables.aiResourceId }}" "test-ns"
- task: AzureCLI@2
displayName: "Retag the image as ready to deploy"
Expand Down
17 changes: 7 additions & 10 deletions appmonitoring/scripts/validate-mutation.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
DEPLOYMENT_deployment#!/bin/bash
#!/bin/bash

# Define the pod name and namespace
DEPLOYMENT_DOTNET_NAME=$1
DEPLOYMENT_JAVA_NAME=$2
DEPLOYMENT_NODEJS_NAME=$3
NAMESPACE=$4
DEPLOYMENT_JAVA_NAME=$1
DEPLOYMENT_NODEJS_NAME=$2
NAMESPACE=$3

# Define the property to check for
PROPERTY="APPLICATIONINSIGHTS_CONNECTION_STRING"

DOTNET_DEPLOYMENT_NAME=$(kubectl get deployment -n "$NAMESPACE" -o custom-columns=NAME:.metadata.name | grep "$DEPLOYMENT_DOTNET_NAME")
JAVA_DEPLOYMENT_NAME=$(kubectl get deployment -n "$NAMESPACE" -o custom-columns=NAME:.metadata.name | grep "$DEPLOYMENT_JAVA_NAME")
NODEJS_DEPLOYMENT_NAME=$(kubectl get deployment -n "$NAMESPACE" -o custom-columns=NAME:.metadata.name | grep "$DEPLOYMENT_NODEJS_NAME")

checkit() {
checkMutation() {
local deploymentName="$1" # The first argument to the function is stored in 'name'
DEPLOYMENT_YAML=$(kubectl get deployment "$deploymentName" -n "$NAMESPACE" -o yaml)

Expand All @@ -26,6 +24,5 @@ checkit() {
fi
}

checkit "$DEPLOYMENT_DOTNET_NAME"
checkit "$DEPLOYMENT_JAVA_NAME"
checkit "$DEPLOYMENT_NODEJS_NAME"
checkMutation "$DEPLOYMENT_JAVA_NAME"
checkMutation "$DEPLOYMENT_NODEJS_NAME"
19 changes: 8 additions & 11 deletions appmonitoring/scripts/validate_ai.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#!/bin/bash

DEPLOYMENT_DOTNET_NAME=$1
DEPLOYMENT_JAVA_NAME=$2
DEPLOYMENT_NODEJS_NAME=$3
AI_RES_ID=$4
$NS=$5
DEPLOYMENT_JAVA_NAME=$1
DEPLOYMENT_NODEJS_NAME=$2
AI_RES_ID=$3
NAMESPACE=$4


POD_DOTNET_NAME=$(kubectl get pods -n test-ns -l app=$DEPLOYMENT_DOTNET_NAME --no-headers -o custom-columns=":metadata.name" | head -n 1)
POD_JAVA_NAME=$(kubectl get pods -n test-ns -l app=$DEPLOYMENT_JAVA_NAME --no-headers -o custom-columns=":metadata.name" | head -n 1)
POD_NODEJS_NAME=$(kubectl get pods -n test-ns -l app=$DEPLOYMENT_NODEJS_NAME --no-headers -o custom-columns=":metadata.name" | head -n 1)
POD_JAVA_NAME=$(kubectl get pods -n "$NAMESPACE" -l app=$DEPLOYMENT_JAVA_NAME --no-headers -o custom-columns=":metadata.name" | head -n 1)
POD_NODEJS_NAME=$(kubectl get pods -n "$NAMESPACE" -l app=$DEPLOYMENT_NODEJS_NAME --no-headers -o custom-columns=":metadata.name" | head -n 1)


# Get an access token
result_rsp=$(curl 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://api.applicationinsights.io&mi_res_id=/subscriptions/66010356-d8a5-42d3-8593-6aaa3aeb1c11/resourceGroups/rambhatt-rnd-v2/providers/Microsoft.ManagedIdentity/userAssignedIdentities/rambhatt-agentpool-es-identity' -H Metadata:true -s)
# echo "Result: $result_rsp"
access_token=$(echo $result_rsp | jq -r '.access_token')

echo $AI_RES_ID
echo "$AI_RES_ID"

# Define your variables
url="https://api.loganalytics.io/v1$AI_RES_ID/query"
Expand All @@ -35,7 +33,7 @@ verify_AI_telemetry() {
}
}";

echo $json_body
echo "$json_body"

# Make the POST request
response=$(curl -s -X POST $url \
Expand All @@ -55,7 +53,6 @@ verify_AI_telemetry() {
fi
}

verify_AI_telemetry "$POD_DOTNET_NAME" "dotnet"
verify_AI_telemetry "$POD_JAVA_NAME" "java"
verify_AI_telemetry "$POD_NODEJS_NAME" "nodejs"

95 changes: 0 additions & 95 deletions appmonitoring/ts/src/Mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
*/
export class Mutations {
// name of the init container
private static initContainerNameDotNet = "azure-monitor-auto-instrumentation-dotnet";
private static initContainerNameJava = "azure-monitor-auto-instrumentation-java";
private static initContainerNameNodeJs = "azure-monitor-auto-instrumentation-nodejs";

// agent image
private static agentImageCommonPrefix = "mcr.microsoft.com/applicationinsights";
private static agentImageDotNet = {
repositoryPath: "opentelemetry-auto-instrumentation/dotnet",
imageTag: "1.0.0-rc.3"
};
private static agentImageNodeJs = {
repositoryPath: "opentelemetry-auto-instrumentation/nodejs",
imageTag: "3.2.4"
Expand All @@ -25,17 +20,14 @@ export class Mutations {
};

// path on agent image to copy from
private static imagePathDotNet = "/dotnet-tracer-home/.";
private static imagePathJava = "/agents/java/.";
private static imagePathNodeJs = "/agents/nodejs/.";

// agent volume (where init containers copy agent binaries to)
private static agentVolumeDotNet = "azure-monitor-auto-instrumentation-volume-dotnet";
private static agentVolumeJava = "azure-monitor-auto-instrumentation-volume-java";
private static agentVolumeNodeJs = "azure-monitor-auto-instrumentation-volume-nodejs";

// agent volume mount path (where customer app's runtime loads agents from)
private static agentVolumeMountPathDotNet = "/azure-monitor-auto-instrumentation-dotnet";
private static agentVolumeMountPathJava = "/azure-monitor-auto-instrumentation-java";
private static agentVolumeMountPathNodeJs = "/azure-monitor-auto-instrumentation-nodejs";

Expand All @@ -53,29 +45,6 @@ export class Mutations {

for (let i = 0; i < platforms.length; i++) {
switch (platforms[i] as AutoInstrumentationPlatforms) {
case AutoInstrumentationPlatforms.DotNet:
containers.push({
name: Mutations.initContainerNameDotNet,
image: Mutations.generateImagePath(platforms[i], imageRepoPath),
command: ["cp"],
args: ["-a", Mutations.imagePathDotNet, Mutations.agentVolumeMountPathDotNet], // cp -a <source> <destination>
volumeMounts: [{
name: Mutations.agentVolumeDotNet,
mountPath: Mutations.agentVolumeMountPathDotNet
}],
resources: {
requests: {
cpu: "100m",
memory: "128Mi"
},
limits: {
cpu: "2",
memory: "1Gi"
}
}
});
break;

case AutoInstrumentationPlatforms.Java:
containers.push({
name: Mutations.initContainerNameJava,
Expand Down Expand Up @@ -202,52 +171,6 @@ ${ownerUidAttribute}`
// platform-specific environment variables
for (let i = 0; i < platforms.length; i++) {
switch (platforms[i] as AutoInstrumentationPlatforms) {
case AutoInstrumentationPlatforms.DotNet:
returnValue.push(...[
{
name: "OTEL_DOTNET_AUTO_LOG_DIRECTORY",
value: Mutations.agentLogsVolumeMountPath,
platformSpecific: platforms[i]
},
{
name: "DOTNET_STARTUP_HOOKS",
value: `${Mutations.agentVolumeMountPathDotNet}/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll`,
platformSpecific: platforms[i]
},
{
name: "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES",
value: "OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper",
platformSpecific: platforms[i]
},
{
name: "DOTNET_ADDITIONAL_DEPS",
value: `${Mutations.agentVolumeMountPathDotNet}/AdditionalDeps`,
platformSpecific: platforms[i]
},
{
name: "DOTNET_SHARED_STORE",
value: `${Mutations.agentVolumeMountPathDotNet}/store`,
platformSpecific: platforms[i]
},
{
name: "OTEL_DOTNET_AUTO_HOME",
value: `${Mutations.agentVolumeMountPathDotNet}/`,
platformSpecific: platforms[i]
},
{
name: "OTEL_DOTNET_AUTO_PLUGINS",
value: "Azure.Monitor.OpenTelemetry.AutoInstrumentation.AzureMonitorPlugin, Azure.Monitor.OpenTelemetry.AutoInstrumentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
platformSpecific: platforms[i]
},
{
name: "OTEL_DOTNET_AUTO_LOGS_ENABLED",
value: "false",
platformSpecific: platforms[i],
doNotSet: !disableAppLogs
}]
);
break;

case AutoInstrumentationPlatforms.Java:
{
returnValue.push(...[{
Expand Down Expand Up @@ -296,13 +219,6 @@ ${ownerUidAttribute}`

for (let i = 0; i < platforms.length; i++) {
switch (platforms[i] as AutoInstrumentationPlatforms) {
case AutoInstrumentationPlatforms.DotNet:
volumeMounts.push({
name: Mutations.agentVolumeDotNet,
mountPath: Mutations.agentVolumeMountPathDotNet
});
break;

case AutoInstrumentationPlatforms.Java:
volumeMounts.push({
name: Mutations.agentVolumeJava,
Expand All @@ -325,7 +241,6 @@ ${ownerUidAttribute}`
let logVolumeMounted = false;
for (let i = 0; i < platforms.length; i++) {
switch (platforms[i] as AutoInstrumentationPlatforms) {
case AutoInstrumentationPlatforms.DotNet:
case AutoInstrumentationPlatforms.Java:
case AutoInstrumentationPlatforms.NodeJs:
if(!logVolumeMounted) {
Expand All @@ -350,13 +265,6 @@ ${ownerUidAttribute}`

for (let i = 0; i < platforms.length; i++) {
switch (platforms[i] as AutoInstrumentationPlatforms) {
case AutoInstrumentationPlatforms.DotNet:
volumes.push({
name: Mutations.agentVolumeDotNet,
emptyDir: {}
});
break;

case AutoInstrumentationPlatforms.Java:
volumes.push({
name: Mutations.agentVolumeJava,
Expand All @@ -379,7 +287,6 @@ ${ownerUidAttribute}`
let logVolumeAdded = false;
for (let i = 0; i < platforms.length; i++) {
switch (platforms[i] as AutoInstrumentationPlatforms) {
case AutoInstrumentationPlatforms.DotNet:
case AutoInstrumentationPlatforms.Java:
case AutoInstrumentationPlatforms.NodeJs:
if(!logVolumeAdded) {
Expand All @@ -404,8 +311,6 @@ ${ownerUidAttribute}`
}

switch (platform as AutoInstrumentationPlatforms) {
case AutoInstrumentationPlatforms.DotNet:
return `${imagePath ?? Mutations.agentImageCommonPrefix}/${Mutations.agentImageDotNet.repositoryPath}:${Mutations.agentImageDotNet.imageTag}`;
case AutoInstrumentationPlatforms.Java:
return `${imagePath ?? Mutations.agentImageCommonPrefix}/${Mutations.agentImageJava.repositoryPath}:${Mutations.agentImageJava.imageTag}`;
case AutoInstrumentationPlatforms.NodeJs:
Expand Down
10 changes: 2 additions & 8 deletions appmonitoring/ts/src/Mutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,10 @@ export class Mutator {
* Based on the admission review's inject-* annotations and available CRs, picks a CR to be applied to the admission review
*/
private pickCR(): string {
const injectDotNetAnnotation: string = this.admissionReview.request.object.spec.template.metadata?.annotations?.["instrumentation.opentelemetry.io/inject-dotnet"];
const injectJavaAnnotation: string = this.admissionReview.request.object.spec.template.metadata?.annotations?.["instrumentation.opentelemetry.io/inject-java"];
const injectNodeJsAnnotation: string = this.admissionReview.request.object.spec.template.metadata?.annotations?.["instrumentation.opentelemetry.io/inject-nodejs"];

const injectAnnotationValues: string[] = [injectDotNetAnnotation, injectJavaAnnotation, injectNodeJsAnnotation];
const injectAnnotationValues: string[] = [injectJavaAnnotation, injectNodeJsAnnotation];

// if any of the annotations contain a value other than "true" or "false", that must be the same value for all annotations, we can't apply multiple CRs to the same pod
const specificCRNames: string[] = injectAnnotationValues.filter(value => value && value.toLowerCase() != "true" && value.toLowerCase() != "false", this);
Expand All @@ -171,11 +170,10 @@ export class Mutator {

// assuming annotation set is valid
// annotations are on the pod template spec
const injectDotNetAnnotation: string = this.admissionReview.request.object.spec.template.metadata?.annotations?.["instrumentation.opentelemetry.io/inject-dotnet"];
const injectJavaAnnotation: string = this.admissionReview.request.object.spec.template.metadata?.annotations?.["instrumentation.opentelemetry.io/inject-java"];
const injectNodeJsAnnotation: string = this.admissionReview.request.object.spec.template.metadata?.annotations?.["instrumentation.opentelemetry.io/inject-nodejs"];

const injectAnnotationValues: string[] = [injectDotNetAnnotation, injectJavaAnnotation, injectNodeJsAnnotation];
const injectAnnotationValues: string[] = [injectJavaAnnotation, injectNodeJsAnnotation];

if(injectAnnotationValues.filter(value => value).length == 0) {
// no annotations specified, use platform list from the CR
Expand All @@ -185,10 +183,6 @@ export class Mutator {

const platforms: AutoInstrumentationPlatforms[] = [];

if (injectDotNetAnnotation && injectDotNetAnnotation.toLowerCase() !== "false") {
platforms.push(AutoInstrumentationPlatforms.DotNet);
}

if (injectJavaAnnotation && injectJavaAnnotation.toLowerCase() !== "false") {
platforms.push(AutoInstrumentationPlatforms.Java);
}
Expand Down
10 changes: 10 additions & 0 deletions appmonitoring/ts/src/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# MutatingWebhook


# Making a change to the image
1. Prepare a change in a branch made off of _ai_prod_ branch. All work is confined within _appmonitoring/ts/src_.
2. Make sure the branch builds locally with _build.cmd_.
3. Build and push the image to a test ACR by running _dockerBuild.cmd v0_ where _v0_ is the image tag.
4. Create a standalone environment of AKS RP to test the change, or test it directly on an AKS cluster by plugging the modified image into a test workload.
5. Merge a PR into the _ai_prod_ branch.
6. Prepare a GitHub release following the _semver_ conventions.
7. Build and push the image to MCR by running the [ContainerInsights-MultiArch-MergedBranches-AppMonitoring](https://github-private.visualstudio.com/microsoft/_build?definitionId=539) pipeline.
8. Merge a PR into the AKS RP repo that updates the version of the image used.
9. Follow daily and weekly rollouts of AKS RP and watch change propagation on the dashboard.
2 changes: 0 additions & 2 deletions appmonitoring/ts/src/RequestDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface IInstrumentationState {
export const InstrumentationAnnotationName = "monitor.azure.com/instrumentation";
export const EnableApplicationLogsAnnotationName = "monitor.azure.com/enable-application-logs";
export interface IAnnotations {
"instrumentation.opentelemetry.io/inject-dotnet"?: string;
"instrumentation.opentelemetry.io/inject-java"?: string;
"instrumentation.opentelemetry.io/inject-nodejs"?: string;

Expand Down Expand Up @@ -176,7 +175,6 @@ export class PodInfo {
}

export enum AutoInstrumentationPlatforms {
DotNet = "DotNet",
Java = "Java",
NodeJs = "NodeJs"
}
Expand Down
Loading

0 comments on commit 543ea0e

Please sign in to comment.