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

ELASTIC_APM_ACTIVATION_METHOD=K8S_ATTACH, prefer ELASTIC_APM_SERVER_URL; integration.yml workflow tweak #87

Merged
merged 7 commits into from
Jan 12, 2024

Conversation

trentm
Copy link
Member

@trentm trentm commented Jan 8, 2024

Set ELASTIC_APM_ACTIVATION_METHOD=K8S_ATTACH in code rather than values.yaml
This means that custom 'webhookConfig.agent.*' names do not need to repeat this
envvar. It does mean that newer Node.js and .NET APM agents that use the
newer value (used to be 'K8S') will be required for the 'activation_method' to
get set correctly.

Also:

  • Use singular ELASTIC_APM_SERVER_URL, because the plural only works with the java agent. The use cases in the tests were probably fine, but there was one case in docs where the plural was being suggested for possible Node.js APM agent use.
  • drop redundant kind cluster creation in integration.yml workflow

Closes: #91

@trentm trentm requested a review from jackshirazi January 8, 2024 23:43
@trentm trentm self-assigned this Jan 8, 2024
@github-actions github-actions bot added the apm-k8s-attacher Mutating Webhook to attach apm agents on k8s label Jan 8, 2024
@trentm trentm requested a review from estolfo January 10, 2024 01:02
@trentm trentm marked this pull request as ready for review January 10, 2024 01:02
estolfo
estolfo previously approved these changes Jan 10, 2024
@trentm trentm changed the title test: drop redundant kind cluster creation in integration.yml workflow docs: prefer singular ELASTIC_APM_SERVER_URL; integration.yml workflow tweak Jan 10, 2024
…es.yaml

This means that custom 'webhookConfig.agent.*' names do not need to repeat this
envvar. It *does* mean that newer Node.js and .NET APM agents that use the
newer value (used to be 'K8S') will be required for the 'activation_method' to
get set correctly.

Closes: #91
@trentm trentm changed the title docs: prefer singular ELASTIC_APM_SERVER_URL; integration.yml workflow tweak ELASTIC_APM_ACTIVATION_METHOD=K8S_ATTACH, prefer ELASTIC_APM_SERVER_URL; integration.yml workflow tweak Jan 11, 2024
@trentm
Copy link
Member Author

trentm commented Jan 11, 2024

How I tested the ELASTIC_APM_ACTIVATION_METHOD change

  1. Follow the first section of https://github.com/elastic/apm-nodejs-dev/mockapmserver/share/k8s/README.md to create a local Docker registry and kind Kubernetes cluster. This also deploys a mockapmserver service in the cluster that we'll use. (TODO: make this doc public? Just happens to be in internal dev repo.) The local Docker registry is at localhost:5001/.
git clone [email protected]:elastic/apm-nodejs-dev.git
cd apm-nodejs-dev/mockapmserver/share/k8s
./create-kind-cluster-with-registry.sh

# Build and publish the Docker image for mockapmserver.
docker build -t mockapmserver ../..
docker tag mockapmserver localhost:5001/mockapmserver
docker push localhost:5001/mockapmserver

# Deploy the mockapmserver service.
kubectl create -f ./mockapmserver-service.yaml
kubectl create -f ./mockapmserver-deployment.yaml
  1. Create and publish a new apm-agent-nodejs image that supports the new ELASTIC_APM_ACTIVATION_METHOD=K8S_ATTACH value.
git clone [email protected]:elastic/apm-agent-nodejs.git
cd apm-agent-nodejs
git checkout trentm/activation-method-new-envvar-val
./dev-utils/make-distribution.sh
docker build -t localhost:5001/apm-agent-nodejs:t1 --build-arg AGENT_DIR=build/dist/nodejs .
docker push localhost:5001/apm-agent-nodejs:t1

We'll be using this image later.

  1. Build and publish a new apm-attacher image with the change to set ELASTIC_APM_ACTIVATION_METHOD.
git clone [email protected]:elastic/apm-k8s-attacher.git
cd apm-k8s-attacher
git checkout trentm/tweaks-to-integration-test
make .webhook  # this builds "apm/apm-attacher:latest"
docker tag apm/apm-attacher localhost:5001/apm-attacher
docker push localhost:5001/apm-attacher
  1. Install the Helm chart (modified to no longer have ELASTIC_APM_ACTIVATION_METHOD in values.yaml). We will use these custom values to use our mockapmserver and the custom images we just built:
# apm-attacher-config.yaml
image:
  repository: localhost:5001/apm-attacher

webhookConfig:
  agents:
    nodejs:
      image: localhost:5001/apm-agent-nodejs:t1
      environment:
        ELASTIC_APM_SERVER_URL: "http://mockapmserver:8200"

Run this to install the chart:

cd apm-k8s-attacher
vi apm-attacher-config.yaml # see above
helm install apm-attacher ./charts/apm-attacher \
    --namespace=elastic-apm --create-namespace \
    --values ./apm-attacher-config.yaml
  1. Run a small Node.js app. There is a small Express Node.js app documented at https://github.com/elastic/apm-nodejs-dev/tree/main/mockapmserver/share/k8s/#use-the-apm-k8s-attacher-to-automatically-trace
cd .../apm-nodejs-dev/mockapmserver/share/k8s/example-app-auto
npm install

# Build the Docker image.
docker build -t example-app-auto .
docker tag example-app-auto localhost:5001/example-app-auto
docker push localhost:5001/example-app-auto

# Deploy a single container of this app, configuring the APM agent to use
# "http://mockapmserver:8200".
kubectl create -f ./deployment.yaml
  1. Look at the APM server log to verify that it is getting tracing data and the correct activation_method
kubectl logs service/mockapmserver -f

For example:

...
[2024-01-11T07:26:46.004Z]  INFO: mockapmserver/22 on mockapmserver-deployment-845f7d8489-5svsg: request (req.remoteAddress=10.244.0.14, req.remotePort=50234, req.bodyLength=4638, res.bodyLength=2)
    POST /intake/v2/events HTTP/1.1
    accept: application/json
    user-agent: apm-agent-nodejs/4.3.0 (example-app-auto 1.0.0)
    content-type: application/x-ndjson
    content-encoding: gzip
    host: mockapmserver:8200
    connection: keep-alive
    transfer-encoding: chunked

    {
        "metadata": {
            "service": {
                "name": "example-app-auto",
                "environment": "development",
                "runtime": {
                    "name": "node",
                    "version": "18.19.0"
                },
                "language": {
                    "name": "javascript"
                },
                "agent": {
                    "name": "nodejs",
                    "version": "4.3.0",
                    "activation_method": "k8s-attach"
                },
                "framework": {
                    "name": "express",
                    "version": "4.18.2"
                },
                "version": "1.0.0"
            },
...

@trentm trentm requested a review from estolfo January 11, 2024 07:33
@trentm
Copy link
Member Author

trentm commented Jan 11, 2024

@jackshirazi Please take a look

Copy link
Contributor

@jackshirazi jackshirazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely, thanks!

@jackshirazi jackshirazi merged commit 7e30998 into main Jan 12, 2024
10 checks passed
@trentm trentm deleted the trentm/tweaks-to-integration-test branch January 12, 2024 21:19
@trentm
Copy link
Member Author

trentm commented Jan 12, 2024

FYI: for the ELASTIC_APM_ACTIVATION_METHOD=K8S_ATTACH to work with Node.js apps will require using at least v4.4.0 or v3.51.0 of the Node.js APM agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm-k8s-attacher Mutating Webhook to attach apm agents on k8s
Projects
None yet
3 participants