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

Implement the JVM chaos controller #1264

Merged
merged 21 commits into from
Jan 26, 2021

Conversation

Gallardot
Copy link
Member

@Gallardot Gallardot commented Dec 9, 2020

What problem does this PR solve?

#650

What is changed and how does it work?

We use chaosblade-exec-jvm to implement JVM chaos. We use admission-webhook to inject the required files and associated configurations. We use JAVA_TOOL_OPTIONS to start a java agent with application.

ps: It is currently only a technical preview, and we need to do more for the documentation and E2E test. 😂

Here are the steps to perform JVM chaos. Have fun.🚀

# create app namespace
kubectl create namespace app

// enable chaos mesh admission-webhook
kubectl label namespace app admission-webhook=enabled

// add the required sidecar profile
kubectl apply -f  examples/jvm/sidecar.yaml  
kubectl apply -f  examples/jvm/sidecar-template.yaml 

Preparation done
At this point, we need to prepare a Java application pod, adding the following information to the annotations of pod

admission-webhook.chaos-mesh.org/request: jvmchaos-sidecar

As an example, you can use our demo program.

// deploy a demo app
kubectl apply -f examples/jvm/app.yaml

// wait until the pod is running
kubectl get pods -n app


JVM Agent injection validation

// Open two new terminals to perform the local service
kubectl port-forward -n app deployment/springboot-jvmchaos-demo 12345:8080
kubectl port-forward -n app deployment/springboot-jvmchaos-demo 10086:10086

// Check that the JVM Agent has been injected
curl -N -s http://127.0.0.1:10086/sandbox/default/module/http/sandbox-module-mgr/list

// response information is as follows
sandbox-info        	ACTIVE  	LOADED  	0    	0    	0.0.4          	luanjia@taobao.com
sandbox-module-mgr  	ACTIVE  	LOADED  	0    	0    	0.0.2          	luanjia@taobao.com
chaosblade          	FROZEN  	LOADED  	0    	0    	0.9.0          	Changjun Xiao
sandbox-control     	ACTIVE  	LOADED  	0    	0    	0.0.3          	luanjia@taobao.com
total=4

make a delayed fault injection test

// Very fast response
curl -w "time_total:%{time_total}s" http://127.0.0.1:12345/hello

// Starts a delayed fault injection for all path in the servlet
kubectl apply -f examples/jvm/jvm-delay4servlet-example.yaml 

// about 10s delay
curl -w "time_total:%{time_total}s" http://127.0.0.1:12345/hello

// clean 
 kubectl delete -f examples/jvm/jvm-delay4servlet-example.yaml 

// Very fast response
curl -w "time_total:%{time_total}s" http://127.0.0.1:12345/hello

Do a test to modify the method's return value

// return `hello world!`
curl http://127.0.0.1:12345/hello

// change the return value to 'hello chaos mesh!'
kubectl apply -f examples/jvm/jvm-return-example.yaml 

// return `hello chaos mesh!`
curl http://127.0.0.1:12345/hello

// clean 
kubectl delete -f examples/jvm/jvm-return-example.yaml 

// return `hello world!`
curl http://127.0.0.1:12345/hello

Checklist

Tests

  • Unit test
  • E2E test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Breaking backward compatibility

Related changes

  • Need to update the documentation

Does this PR introduce a user-facing change?

NONE

Signed-off-by: Gallardot <tttick@163.com>
Signed-off-by: Gallardot <tttick@163.com>
@codecov-io
Copy link

codecov-io commented Dec 11, 2020

Codecov Report

Merging #1264 (092141d) into master (7e9ff3f) will decrease coverage by 4.40%.
The diff coverage is 54.34%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1264      +/-   ##
==========================================
- Coverage   55.78%   51.37%   -4.41%     
==========================================
  Files          68       79      +11     
  Lines        4383     5014     +631     
==========================================
+ Hits         2445     2576     +131     
- Misses       1768     2174     +406     
- Partials      170      264      +94     
Impacted Files Coverage Δ
api/v1alpha1/common_types.go 0.00% <0.00%> (ø)
api/v1alpha1/common_webhook.go 100.00% <ø> (ø)
api/v1alpha1/dnschaos_type.go 0.00% <0.00%> (ø)
api/v1alpha1/dnschaos_webhook.go 0.00% <0.00%> (ø)
api/v1alpha1/httpchaos_types.go 0.00% <0.00%> (ø)
api/v1alpha1/iochaos_types.go 0.00% <ø> (-40.00%) ⬇️
api/v1alpha1/jvmchaos_webhook.go 0.00% <0.00%> (ø)
api/v1alpha1/kernelchaos_types.go 0.00% <ø> (-20.00%) ⬇️
api/v1alpha1/kernelchaos_webhook.go 100.00% <ø> (+14.81%) ⬆️
api/v1alpha1/kinds.go 27.27% <ø> (+0.60%) ⬆️
... and 128 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4852fb...092141d. Read the comment docs.

Signed-off-by: Gallardot <tttick@163.com>
Signed-off-by: Gallardot <tttick@163.com>
Signed-off-by: Gallardot <tttick@163.com>
@STRRL
Copy link
Member

STRRL commented Dec 21, 2020

Hi @Gallardot, is there any documents about the web API http://%s:%d/sandbox/default/module/http/chaosblade/create and docker image gallardot/chaos-jvm?😁

@Gallardot
Copy link
Member Author

Hi @Gallardot, is there any documents about the web API http://%s:%d/sandbox/default/module/http/chaosblade/create and docker image gallardot/chaos-jvm?😁

Sorry, the web API has no documentation. But we can find the implementation code.

The docker image gallardot/chaos-jvm is our demo program.

Signed-off-by: Gallardot <tttick@163.com>
@STRRL
Copy link
Member

STRRL commented Jan 11, 2021

Hi @Gallardot , sorry for my late reply, as you mentioned before, copy "jvm-sandbox" then attach JVM in the container works well.

I think injecting chaos at runtime is better than manually changing workload spec, although the first one is more complex.

How about making JAVA_HOME and USER (and other necessary things) as fields in the JVMChaosSpec? As we have "chaos-daemon", we could implement "copy file" and "change user" without kubernetes API.

Multi-container and more than one java process should also be considered, we should enrich out chaos spec.

@Gallardot
Copy link
Member Author

As we discussed, executing JVM Chaos by Chaos-daemon is desirable, but difficult to handle all cases. With Sidecar we can handle most cases.
Therefore, we plan to implement both ways, and the user can choose one or the other depending on the actual situation. @STRRL is going to help us implement the Chaos-daemon way. Thanks to @STRRL .❤️

We want to merge the current PR first, and then we create other PR to implement the Chaos-daemon way and supplement the E2E use cases and documentation.

ps: I will fix the conflicting files later.

@cwen0 @YangKeao PTAL

@Gallardot Gallardot requested a review from STRRL January 14, 2021 09:38
STRRL
STRRL previously approved these changes Jan 19, 2021
Copy link
Member

@STRRL STRRL left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@cwen0 cwen0 left a comment

Choose a reason for hiding this comment

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

Rest LGTM

r.Log.Info("Try to apply jvm chaos", "namespace",
pod.Namespace, "name", pod.Name)

err := jvm.ActiveSandbox(pod.Status.PodIP, 10086)
Copy link
Member

Choose a reason for hiding this comment

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

Use a const to defein 10086?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! PTAL!

Signed-off-by: Gallardot <tttick@163.com>
@Gallardot Gallardot requested review from STRRL and cwen0 January 20, 2021 08:38
STRRL
STRRL previously approved these changes Jan 20, 2021
Copy link
Member

@STRRL STRRL left a comment

Choose a reason for hiding this comment

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

LGTM

cwen0
cwen0 previously approved these changes Jan 26, 2021
Copy link
Member

@cwen0 cwen0 left a comment

Choose a reason for hiding this comment

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

LGTM

@cwen0
Copy link
Member

cwen0 commented Jan 26, 2021

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@Gallardot merge failed.

Signed-off-by: Gallardot <tttick@163.com>
@Gallardot Gallardot dismissed stale reviews from cwen0 and STRRL via ce2aba5 January 26, 2021 10:03
@cwen0 cwen0 requested review from STRRL and cwen0 January 26, 2021 10:19
@STRRL
Copy link
Member

STRRL commented Jan 26, 2021

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 65b7d25 into chaos-mesh:master Jan 26, 2021
@Gallardot Gallardot deleted the jvm-chaos-controller branch January 26, 2021 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants