Skip to content

Add Java agent injector feature#14

Merged
kezhenxu94 merged 10 commits into
apache:mainfrom
dashanji:add-java-agent-injector
Jan 19, 2022
Merged

Add Java agent injector feature#14
kezhenxu94 merged 10 commits into
apache:mainfrom
dashanji:add-java-agent-injector

Conversation

@dashanji

Copy link
Copy Markdown
Member

The PR is related to apache/skywalking#8195, and do two things:

  • Add the java agent injector to replace the original method (injected when building the image) so that we can inject the java agent more natively.
  • Update the doc.

Signed-off-by: dashanji <952129620@qq.com>
@kezhenxu94

Copy link
Copy Markdown
Member

Do we have a more recommended way to use swck, like via CLI?

@wu-sheng

Copy link
Copy Markdown
Member

Do we have a more recommended way to use swck, like via CLI?

Could you be more specific? CLI(current) is not responsible for deployment AFAIK

@kezhenxu94

Copy link
Copy Markdown
Member

Do we have a more recommended way to use swck, like via CLI?

Could you be more specific? CLI(current) is not responsible for deployment AFAIK

I remember there is swctl install to install OAP and UI, it's better we can install or generate agent manifest there too, the current usage in this pr looks kindof complex. For example, user provides their original yaml of the application, and pass them into our command, then our command populates the necessary part like annotations, etc., swctl inject java -f deployments/java-app.yaml | kubectl apply -f -

This is not a blocker of this PR but I hope we can simplify further the usage of our agent injector.

@wu-sheng

Copy link
Copy Markdown
Member

@hanahmily PTAL.

Comment thread deploy/platform/kubernetes/features.mk Outdated
@kubectl delete --ignore-not-found -f https://raw.githubusercontent.com/kubernetes/kube-state-metrics/v2.2.4/examples/standard/service.yaml
@kubectl delete --ignore-not-found -f https://raw.githubusercontent.com/kubernetes/kube-state-metrics/v2.2.4/examples/standard/deployment.yaml

# @feature: java agent injector

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you use this comment pattern: # @feature: <feature-name>; <what and why we need this step in this feature>. The same for other comments added in this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK, updated it.

Signed-off-by: dashanji <952129620@qq.com>
@dashanji

Copy link
Copy Markdown
Member Author

Do we have a more recommended way to use swck, like via CLI?

Could you be more specific? CLI(current) is not responsible for deployment AFAIK

I remember there is swctl install to install OAP and UI, it's better we can install or generate agent manifest there too, the current usage in this pr looks kindof complex. For example, user provides their original yaml of the application, and pass them into our command, then our command populates the necessary part like annotations, etc., swctl inject java -f deployments/java-app.yaml | kubectl apply -f -

This is not a blocker of this PR but I hope we can simplify further the usage of our agent injector.

Maybe we can add it in the future.

Comment thread deploy/platform/kubernetes/features.mk Outdated
@wu-sheng
wu-sheng requested a review from hanahmily December 25, 2021 12:42
Signed-off-by: dashanji <952129620@qq.com>
@wu-sheng wu-sheng added the enhancement New feature or request label Dec 25, 2021
@wu-sheng

Copy link
Copy Markdown
Member

@kezhenxu94 We seems don't have any verification in CI process. Should we add some?

@wu-sheng

Copy link
Copy Markdown
Member

@kezhenxu94 We seems don't have any verification in CI process. Should we add some?

I think we don't need functionality testing here, but we should make sure k8s and docker-compose deploying successfully, with at least one metric verified.

@wu-sheng

Copy link
Copy Markdown
Member

@dashanji I think we need a new doc at here, https://skywalking.apache.org/docs/skywalking-java/latest/en/setup/service-agent/java-agent/containerization/#kubernetes

Besides initContainers of a sidecar, SWCK provides another way to deploy agent.

Comment thread deploy/platform/kubernetes/feature-agent/resources.yaml
@hanahmily

Copy link
Copy Markdown
Contributor

I remember there is swctl install to install OAP and UI, it's better we can install or generate agent manifest there too, the current usage in this pr looks kindof complex. For example, user provides their original yaml of the application, and pass them into our command, then our command populates the necessary part like annotations, etc., swctl inject java -f deployments/java-app.yaml | kubectl apply -f -

The recommended path to onboard java agent injection is to install all SW backends through the SWCK operator. The operator provided several CRDs to manage OAP, UI, and other critical components. This model should be our canonical way.

We could provide a manual-style injection to swctl to help users don't want to inject init container by webhooks automatically. But from experiences of istio, vault, and other projects who have similar injection workflows, the manual way is not widely used, because this style brings a steep learning curve to users since the operator reduced it.

@dashanji

Copy link
Copy Markdown
Member Author

@dashanji I think we need a new doc at here, https://skywalking.apache.org/docs/skywalking-java/latest/en/setup/service-agent/java-agent/containerization/#kubernetes

Besides initContainers of a sidecar, SWCK provides another way to deploy agent.

Yep, I'm writing the blog about how to use SWCK, when it is finished, I will change the doc related to it.

@dashanji

Copy link
Copy Markdown
Member Author

I add an e2e test to ensure that all components can run normally after we build the image.

Comment thread test/e2e/e2e.yaml
resource: service/rocket-bot
port: 8080
timeout: 20m

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add verification at least checking the service list?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok

Comment thread .github/workflows/publish-images.yaml Outdated
Comment on lines +47 to +61
e2e-tests:
name: e2e tests(kubenretes platform)
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Run E2E Test
uses: apache/skywalking-infra-e2e@996ed8902e941e2883fcf0ac5b3090364942d205
with:
e2e-file: test/e2e/e2e.yaml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Put this job to a separate file, this file is only for publishing images and it's only executed on main branch, not pull requests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok, get it.

Comment on lines +114 to +116
command: ["java"]
# @feature: java-agent-injector; we need to add $(AGENT_OPTS) to enable the injected configuration
args: ${JAVA_AGENT}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need this? Does swck requires users to modify these?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, the injector needs to add the AGENT_OPTS to JVM argument like ["$(AGENT_OPTS)","-jar","/app.jar"].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yep, the injector needs to add the AGENT_OPTS to JVM argument like ["$(AGENT_OPTS)","-jar","/app.jar"].

Sorry I didn't follow the related pull request in swck repo, but why don't we use environment name JAVA_TOOL_OPTIONS so that JVM can automatically pick this up and users don't need to modify their command?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Make sense to me, we can improve it in the next version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make sense to me, we can improve it in the next version.

Nice 🎉

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Now the injector is using the way to inject. I don't know much about java, can it be used as an environment variable? if possible, then we don’t need to add it to the startup parameters.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now the injector is using the way to inject. I don't know much about java, can it be used as an environment variable? if possible, then we don’t need to add it to the startup parameters.

@dashanji yes, take a look at this https://github.com/apache/skywalking-java/blob/96ea77cf8f1fa922ed4f1e8c4bf9796e33790bdf/Dockerfile#L31 , this env var is automatically picked up by JVM and it's the same effect as java $JAVA_TOOL_OPTIONS /app.jar for all Java applications in that container

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I learn from it, thanks a lot.

@dashanji

Copy link
Copy Markdown
Member Author

Updated it.

Comment thread .github/workflows/go.yml Outdated
Comment on lines +21 to +23
push:
branches:
- main

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we only need this in pull request, WDYT? @wu-sheng

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes.

Comment thread deploy/platform/kubernetes/features.mk Outdated
@curl -Ls https://dlcdn.apache.org/skywalking/swck/${SWCK_OPERATOR_VERSION}/skywalking-swck-${SWCK_OPERATOR_VERSION}-bin.tgz | tar -zxf - -O ./config/operator-bundle.yaml | kubectl apply -f -
@kubectl label namespace --overwrite $(NAMESPACE) swck-injection=enabled
# @feature: java-agent-injector; we can update the agent's backend address in a single-node cluster firstly so that we don't need to add the same backend env for every java agent
@kubectl get configmap skywalking-swck-java-agent-configmap -n skywalking-swck-system -oyaml | sed 's/127.0.0.1/default-oap.default/' | kubectl apply -f -

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
@kubectl get configmap skywalking-swck-java-agent-configmap -n skywalking-swck-system -oyaml | sed 's/127.0.0.1/default-oap.default/' | kubectl apply -f -
@kubectl get configmap skywalking-swck-java-agent-configmap -n skywalking-swck-system -oyaml | sed "s/127.0.0.1/default-oap.$(NAMESPACE)/" | kubectl apply -f -

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok, get it. By the way, the CI may be wrong as we don't push the image.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh yes. Then in CI you need to build the images first (make docker -j 5), and then load them into the KinD using infra-e2e.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK,thanks a lot.

@hanahmily

Copy link
Copy Markdown
Contributor

@dashanji any update?

@wu-sheng

wu-sheng commented Jan 6, 2022

Copy link
Copy Markdown
Member

Any progress to update?

@dashanji

dashanji commented Jan 6, 2022

Copy link
Copy Markdown
Member Author

Still testing, I have failed many times on the Github action, I am still looking for the reason.

Signed-off-by: dashanji <952129620@qq.com>
@dashanji
dashanji force-pushed the add-java-agent-injector branch from 09bc229 to 2cd79f6 Compare January 17, 2022 17:02
@dashanji

Copy link
Copy Markdown
Member Author

Could you please re-run the CI job? I feel very strange that the CI running results are different from my personal repository and the test results in my personal repository are good.

@wu-sheng

Copy link
Copy Markdown
Member

Running.

@wu-sheng
wu-sheng requested a review from kezhenxu94 January 18, 2022 07:32
Comment thread .github/workflows/go.yml Outdated
Comment on lines +21 to +23
push:
branches:
- main

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
push:
branches:
- main

Comment thread .github/workflows/go.yml Outdated
Comment on lines +25 to +43
env:
IMAGE_HUB: ghcr.io/apache/skywalking-showcase

jobs:
e2e-tests:
name: e2e tests(kubenretes platform)
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: set image_tag to env
shell: bash
run: |
echo "IMAGE_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
env:
IMAGE_HUB: ghcr.io/apache/skywalking-showcase
jobs:
e2e-tests:
name: e2e tests(kubenretes platform)
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: set image_tag to env
shell: bash
run: |
echo "IMAGE_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
env:
IMAGE_HUB: ghcr.io/apache/skywalking-showcase
IMAGE_TAG: ${{ github.sha }}
jobs:
e2e-tests:
name: e2e tests(kubenretes platform)
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Check out source code
uses: actions/checkout@v2

imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
# @feature: als; set env to configure java agent, If we use injector, we don't need to set env, only to configure java gent through annotation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# @feature: als; set env to configure java agent, If we use injector, we don't need to set env, only to configure java gent through annotation
# @feature: agent; set env to configure java agent, If we use injector, we don't need to set env, only to configure java gent through annotation

imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
# @feature: als; set env to configure java agent, If we use injector, we don't need to set env, only to configure java gent through annotation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# @feature: als; set env to configure java agent, If we use injector, we don't need to set env, only to configure java gent through annotation
# @feature: agent; set env to configure java agent, If we use injector, we don't need to set env, only to configure java gent through annotation

Comment thread deploy/platform/kubernetes/features.mk Outdated
.PHONY: deploy.feature-als
deploy.feature-als: prerequisites
$(MAKE) deploy FEATURE_FLAGS=agent TAG=$(TAG)-agentless NAMESPACE=$(NAMESPACE)-agentless AGENTLESS=true SHOW_TIPS=false
$(MAKE) deploy FEATURE_FLAGS=agent TAG=$(TAG)-agentless NAMESPACE=$(NAMESPACE)-agentless AGENTLESS=true JAVA_AGENT=$(JAVA_AGENT_OPTS_AGENTLESS) SHOW_TIPS=false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
$(MAKE) deploy FEATURE_FLAGS=agent TAG=$(TAG)-agentless NAMESPACE=$(NAMESPACE)-agentless AGENTLESS=true JAVA_AGENT=$(JAVA_AGENT_OPTS_AGENTLESS) SHOW_TIPS=false
$(MAKE) deploy FEATURE_FLAGS=agent TAG=$(TAG)-agentless NAMESPACE=$(NAMESPACE)-agentless AGENTLESS=true SHOW_TIPS=false

Comment thread deploy/platform/kubernetes/features.mk Outdated
# @feature: java-agent-injector; uninstall the swck operator and cert-manager
.PHONY: undeploy.feature-java-agent-injector
undeploy.feature-java-agent-injector:
@curl -Ls https://dlcdn.apache.org/skywalking/swck/${SWCK_OPERATOR_VERSION}/skywalking-swck-${SWCK_OPERATOR_VERSION}-bin.tgz | tar -zxf - -O ./config/operator-bundle.yaml | kubectl delete -f -

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
@curl -Ls https://dlcdn.apache.org/skywalking/swck/${SWCK_OPERATOR_VERSION}/skywalking-swck-${SWCK_OPERATOR_VERSION}-bin.tgz | tar -zxf - -O ./config/operator-bundle.yaml | kubectl delete -f -
@curl -Ls https://archive.apache.org/dist/skywalking/swck/${SWCK_OPERATOR_VERSION}/skywalking-swck-${SWCK_OPERATOR_VERSION}-bin.tgz | tar -zxf - -O ./config/operator-bundle.yaml | kubectl delete -f -

Comment thread deploy/platform/kubernetes/features.mk Outdated
Comment on lines +110 to +111


No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change

Comment thread services/load-gen/Makefile Outdated
Comment on lines +29 to +30
docker build . -t $(HUB)/load-gen:$(TAG)
docker tag $(HUB)/load-gen:$(TAG) $(HUB)/load-gen:$(TAG)-agentless

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
docker build . -t $(HUB)/load-gen:$(TAG)
docker tag $(HUB)/load-gen:$(TAG) $(HUB)/load-gen:$(TAG)-agentless
docker build . -t $(HUB)/load-gen:$(TAG) -t $(HUB)/load-gen:$(TAG)-agentless

Comment thread scripts/wait-cert-manager-ready.sh Outdated
name: test-selfsigned
EOF

timeout $TIMEOUT bash -c -- "\

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

timeout command is not available in my MacOS, please try to use other means that are generally available, I don't want (myself or others) to struggle for installing this just for testing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK, I will change it.

Comment thread scripts/prepare-e2e.sh Outdated
tar xz && cd skywalking-cli-${SWCTL_VERSION} && make ${OS} && mv bin/swctl-*-${OS}-amd64 ${INSTALL_DIR}/swctl
if [ $? -ne 0 ]; then
echo "install swctl error, please check"
$prepare_ok=false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is a valid assignment, please also check other places

Suggested change
$prepare_ok=false
prepare_ok=false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, the swck is the same, I will correct it, thanks a lot.

Signed-off-by: dashanji <952129620@qq.com>
@dashanji

Copy link
Copy Markdown
Member Author

Updated it, thanks for the correction. @kezhenxu94

@wu-sheng
wu-sheng requested a review from kezhenxu94 January 18, 2022 15:21
dashanji and others added 3 commits January 19, 2022 00:06
Signed-off-by: dashanji <952129620@qq.com>
@kezhenxu94

Copy link
Copy Markdown
Member

Hi @dashanji , I updated something and the codes LGTM, can you please check why the tests failed? Once the tests passed we can merge this

@dashanji

Copy link
Copy Markdown
Member Author

Hi @dashanji , I updated something and the codes LGTM, can you please check why the tests failed? Once the tests passed we can merge this

OK

Add a readinessProbe to make sure the UI has something listening on port 8080.
@dashanji

Copy link
Copy Markdown
Member Author

I added a readinessProbe, hope this can make the CI successful.

@wu-sheng

Copy link
Copy Markdown
Member

@kezhenxu94 I run this CI twice, both passed but require 30+ minutes.

@kezhenxu94 kezhenxu94 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kezhenxu94 I run this CI twice, both passed but require 30+ minutes.

It's reasonable to me it takes so long as long as the tests passed

@kezhenxu94 kezhenxu94 changed the title add java agent injector Add Java agent injector feature Jan 19, 2022
@kezhenxu94
kezhenxu94 merged commit 95e9576 into apache:main Jan 19, 2022
@kezhenxu94

Copy link
Copy Markdown
Member

Thanks @dashanji for the work!!

@dashanji
dashanji deleted the add-java-agent-injector branch January 19, 2022 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants