Skip to content

Commit

Permalink
PHP agent extension injection Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-lozoya committed Jan 31, 2024
1 parent 00af38b commit 4d62edf
Show file tree
Hide file tree
Showing 47 changed files with 610 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
grep -v '\#' versions.txt | grep newrelic-instrumentation-nodejs | awk -F= '{print "NEWRELIC_INSTRUMENTATION_NODEJS_VERSION="$2}' >> $GITHUB_ENV
grep -v '\#' versions.txt | grep newrelic-instrumentation-python | awk -F= '{print "NEWRELIC_INSTRUMENTATION_PYTHON_VERSION="$2}' >> $GITHUB_ENV
grep -v '\#' versions.txt | grep newrelic-instrumentation-dotnet | awk -F= '{print "NEWRELIC_INSTRUMENTATION_DOTNET_VERSION="$2}' >> $GITHUB_ENV
grep -v '\#' versions.txt | grep newrelic-instrumentation-php | awk -F= '{print "NEWRELIC_INSTRUMENTATION_PHP_VERSION="$2}' >> $GITHUB_ENV
echo "VERSION_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
echo "VERSION=$(git describe --tags | sed 's/^v//')" >> $GITHUB_ENV
Expand Down Expand Up @@ -76,5 +77,6 @@ jobs:
NEWRELIC_INSTRUMENTATION_NODEJS_VERSION=${{ env.NEWRELIC_INSTRUMENTATION_NODEJS_VERSION }}
NEWRELIC_INSTRUMENTATION_PYTHON_VERSION=${{ env.NEWRELIC_INSTRUMENTATION_PYTHON_VERSION }}
NEWRELIC_INSTRUMENTATION_DOTNET_VERSION=${{ env.NEWRELIC_INSTRUMENTATION_DOTNET_VERSION }}
NEWRELIC_INSTRUMENTATION_PHP_VERSION=${{ env.NEWRELIC_INSTRUMENTATION_PHP_VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
65 changes: 65 additions & 0 deletions .github/workflows/publish-newrelic-instrumentation-php.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "Publish php Newrelic-Instrumentation"

on:
push:
paths:
- 'autoinstrumentation/php/**'
- '.github/workflows/publish-newrelic-instrumentation-php.yaml'
branches:
- main
pull_request:
paths:
- 'autoinstrumentation/php/**'
- '.github/workflows/publish-newrelic-instrumentation-php.yaml'
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- name: Read version
run: echo "VERSION=$(cat autoinstrumentation/php/version.txt)" >> $GITHUB_ENV

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository_owner }}/newrelic-agent-operator/instrumentation-php
tags: |
type=match,pattern=v(.*),group=1,value=v${{ env.VERSION }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Package Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: autoinstrumentation/php
platforms: linux/amd64,linux/arm64
push: true
build-args: version=${{ env.VERSION }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ ARG NEWRELIC_INSTRUMENTATION_JAVA_VERSION
ARG NEWRELIC_INSTRUMENTATION_NODEJS_VERSION
ARG NEWRELIC_INSTRUMENTATION_PYTHON_VERSION
ARG NEWRELIC_INSTRUMENTATION_DOTNET_VERSION
ARG NEWRELIC_INSTRUMENTATION_PHP_VERSION
ARG AUTO_INSTRUMENTATION_GO_VERSION
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION}" -a -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationPhp=${NEWRELIC_INSTRUMENTATION_PHP_VERSION}" -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ NEWRELIC_INSTRUMENTATION_JAVA_VERSION ?= "$(shell grep -v '\#' versions.txt | gr
NEWRELIC_INSTRUMENTATION_NODEJS_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-nodejs | awk -F= '{print $$2}')"
NEWRELIC_INSTRUMENTATION_PYTHON_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-python | awk -F= '{print $$2}')"
NEWRELIC_INSTRUMENTATION_DOTNET_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-dotnet | awk -F= '{print $$2}')"
NEWRELIC_INSTRUMENTATION_PHP_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-php | awk -F= '{print $$2}')"
AUTO_INSTRUMENTATION_GO_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-go | awk -F= '{print $$2}')"
LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationGo=${AUTO_INSTRUMENTATION_GO_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION}"
LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationGo=${AUTO_INSTRUMENTATION_GO_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationPhp=${NEWRELIC_INSTRUMENTATION_PHP_VERSION}"
ARCH ?= $(shell go env GOARCH)

# Image URL to use all building/pushing image targets
Expand Down Expand Up @@ -155,7 +156,7 @@ scorecard-tests: operator-sdk
# buildx is used to ensure same results for arm based systems (m1/2 chips)
.PHONY: container
container:
docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg NEWRELIC_INSTRUMENTATION_JAVA_VERSION=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_NODEJS_VERSION=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_PYTHON_VERSION=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_DOTNET_VERSION=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} .
docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg NEWRELIC_INSTRUMENTATION_JAVA_VERSION=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_NODEJS_VERSION=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_PYTHON_VERSION=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_DOTNET_VERSION=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_PHP_VERSION=${NEWRELIC_INSTRUMENTATION_PHP_VERSION} .

# Push the container image, used only for local dev purposes
.PHONY: container-push
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ spec:
image: ghcr.io/newrelic-experimental/newrelic-agent-operator/instrumentation-python:latest
dotnet:
image: ghcr.io/newrelic-experimental/newrelic-agent-operator/instrumentation-dotnet:latest
php:
image: ghcr.io/newrelic-experimental/newrelic-agent-operator/instrumentation-php:latest
go:
image: ghcr.io/open-telemetry/opentelemetry-go-instrumentation/autoinstrumentation-go:latest
```
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
17 changes: 16 additions & 1 deletion api/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,6 +67,10 @@ type InstrumentationSpec struct {
// +optional
DotNet DotNet `json:"dotnet,omitempty"`

// Php defines configuration for DotNet auto-instrumentation.
// +optional
Php Php `json:"php,omitempty"`

// Go defines configuration for Go auto-instrumentation.
// When using Go auto-instrumentation you must provide a value for the OTEL_GO_AUTO_TARGET_EXE env var via the
// Instrumentation env vars or via the instrumentation.opentelemetry.io/otel-go-auto-target-exe pod annotation.
Expand Down Expand Up @@ -156,6 +160,17 @@ type DotNet struct {
Env []corev1.EnvVar `json:"env,omitempty"`
}

type Php struct {
// Image is a container image with DotNet agent and auto-instrumentation.
// +optional
Image string `json:"image,omitempty"`

// Env defines DotNet specific env vars.
// If the former var had been defined, then the other vars would be ignored.
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`
}

type Go struct {
// Image is a container image with Go SDK and auto-instrumentation.
// +optional
Expand Down
11 changes: 10 additions & 1 deletion api/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,7 @@ const (
AnnotationDefaultAutoInstrumentationNodeJS = "instrumentation.newrelic.com/default-auto-instrumentation-nodejs-image"
AnnotationDefaultAutoInstrumentationPython = "instrumentation.newrelic.com/default-auto-instrumentation-python-image"
AnnotationDefaultAutoInstrumentationDotNet = "instrumentation.newrelic.com/default-auto-instrumentation-dotnet-image"
AnnotationDefaultAutoInstrumentationPhp = "instrumentation.newrelic.com/default-auto-instrumentation-php-image"
AnnotationDefaultAutoInstrumentationGo = "instrumentation.newrelic.com/default-auto-instrumentation-go-image"
envNewRelicPrefix = "NEW_RELIC_"
envOtelPrefix = "OTEL_"
Expand Down Expand Up @@ -80,6 +81,11 @@ func (r *Instrumentation) Default() {
r.Spec.DotNet.Image = val
}
}
if r.Spec.Php.Image == "" {
if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationPhp]; ok {
r.Spec.DotNet.Image = val
}
}
if r.Spec.Go.Image == "" {
if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationGo]; ok {
r.Spec.Go.Image = val
Expand Down Expand Up @@ -128,6 +134,9 @@ func (r *Instrumentation) validate() error {
if err := r.validateEnv(r.Spec.DotNet.Env); err != nil {
return err
}
if err := r.validateEnv(r.Spec.Php.Env); err != nil {
return err
}
if err := r.validateEnv(r.Spec.Go.Env); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/upgrade_strategy.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
25 changes: 24 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions autoinstrumentation/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# To build one auto-instrumentation image for PHP, please:
# - Download the newrelic php artefacts to `/instrumentation` directory. This is required as when instrumenting the pod,
# one init container will be created to copy the files to your app's container.
# - Grant the necessary access to the files in the `/instrumentation` directory.
FROM alpine:latest as build

RUN apk update && apk add ca-certificates

ARG version

WORKDIR /instrumentation

RUN wget -c "https://download.newrelic.com/php_agent/release/newrelic-php5-${version}-linux-musl.tar.gz" -O - | tar -xz --strip-components 1

FROM busybox

COPY --from=build /instrumentation /instrumentation

RUN chmod -R go+r /instrumentation
1 change: 1 addition & 0 deletions autoinstrumentation/php/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.16.0.5
Loading

0 comments on commit 4d62edf

Please sign in to comment.