Add Java agent injector feature#14
Conversation
Signed-off-by: dashanji <952129620@qq.com>
|
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 This is not a blocker of this PR but I hope we can simplify further the usage of our agent injector. |
|
@hanahmily PTAL. |
| @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 |
There was a problem hiding this comment.
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.
Signed-off-by: dashanji <952129620@qq.com>
Maybe we can add it in the future. |
Signed-off-by: dashanji <952129620@qq.com>
|
@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. |
|
@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 |
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. |
Yep, I'm writing the blog about how to use SWCK, when it is finished, I will change the doc related to it. |
|
I add an e2e test to ensure that all components can run normally after we build the image. |
| resource: service/rocket-bot | ||
| port: 8080 | ||
| timeout: 20m | ||
|
|
There was a problem hiding this comment.
Could you add verification at least checking the service list?
| 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 |
There was a problem hiding this comment.
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
| command: ["java"] | ||
| # @feature: java-agent-injector; we need to add $(AGENT_OPTS) to enable the injected configuration | ||
| args: ${JAVA_AGENT} |
There was a problem hiding this comment.
Why do we need this? Does swck requires users to modify these?
There was a problem hiding this comment.
Yep, the injector needs to add the AGENT_OPTS to JVM argument like ["$(AGENT_OPTS)","-jar","/app.jar"].
There was a problem hiding this comment.
Yep, the injector needs to add the
AGENT_OPTSto 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?
There was a problem hiding this comment.
Make sense to me, we can improve it in the next version.
There was a problem hiding this comment.
Make sense to me, we can improve it in the next version.
Nice 🎉
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I learn from it, thanks a lot.
|
Updated it. |
| push: | ||
| branches: | ||
| - main |
There was a problem hiding this comment.
I think we only need this in pull request, WDYT? @wu-sheng
| @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 - |
There was a problem hiding this comment.
| @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 - |
There was a problem hiding this comment.
ok, get it. By the way, the CI may be wrong as we don't push the image.
There was a problem hiding this comment.
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.
|
@dashanji any update? |
|
Any progress to update? |
|
Still testing, I have failed many times on the Github action, I am still looking for the reason. |
09bc229 to
2cd79f6
Compare
|
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. |
|
Running. |
| push: | ||
| branches: | ||
| - main |
There was a problem hiding this comment.
| push: | |
| branches: | |
| - main |
| 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 |
There was a problem hiding this comment.
| 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 |
There was a problem hiding this comment.
| # @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 |
There was a problem hiding this comment.
| # @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 |
| .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 |
There was a problem hiding this comment.
| $(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 |
| # @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 - |
There was a problem hiding this comment.
| @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 - |
|
|
||
|
No newline at end of file |
| docker build . -t $(HUB)/load-gen:$(TAG) | ||
| docker tag $(HUB)/load-gen:$(TAG) $(HUB)/load-gen:$(TAG)-agentless |
There was a problem hiding this comment.
| 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 |
| name: test-selfsigned | ||
| EOF | ||
|
|
||
| timeout $TIMEOUT bash -c -- "\ |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
I don't think this is a valid assignment, please also check other places
| $prepare_ok=false | |
| prepare_ok=false |
There was a problem hiding this comment.
Yep, the swck is the same, I will correct it, thanks a lot.
|
Updated it, thanks for the correction. @kezhenxu94 |
Signed-off-by: dashanji <952129620@qq.com>
|
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.
|
I added a readinessProbe, hope this can make the CI successful. |
|
@kezhenxu94 I run this CI twice, both passed but require 30+ minutes. |
kezhenxu94
left a comment
There was a problem hiding this comment.
@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
|
Thanks @dashanji for the work!! |
The PR is related to apache/skywalking#8195, and do two things: