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

pause and start experiment by API #542

Merged
merged 8 commits into from
May 24, 2020

Conversation

cwen0
Copy link
Member

@cwen0 cwen0 commented May 22, 2020

Signed-off-by: cwen0 [email protected]

What problem does this PR solve?

#370

We need to support pause and start chaos experiment by API.

@codecov-commenter
Copy link

codecov-commenter commented May 22, 2020

Codecov Report

Merging #542 into master will decrease coverage by 5.10%.
The diff coverage is 41.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #542      +/-   ##
==========================================
- Coverage   61.39%   56.28%   -5.11%     
==========================================
  Files          64       67       +3     
  Lines        4069     4301     +232     
==========================================
- Hits         2498     2421      -77     
- Misses       1383     1710     +327     
+ Partials      188      170      -18     
Impacted Files Coverage Δ
controllers/kernelchaos_controller.go 0.00% <0.00%> (ø)
controllers/podchaos/types.go 65.95% <0.00%> (ø)
controllers/stresschaos_controller.go 0.00% <0.00%> (ø)
pkg/chaosdaemon/netem_linux.go 26.66% <0.00%> (ø)
pkg/chaosdaemon/netlink_linux.go 0.00% <ø> (ø)
pkg/chaosdaemon/stress_server_linux.go 0.00% <0.00%> (ø)
pkg/utils/chaosdaemon.go 51.21% <ø> (ø)
pkg/webhook/config/config.go 17.14% <ø> (-72.86%) ⬇️
pkg/webhook/config/watcher/config.go 41.66% <ø> (-58.34%) ⬇️
pkg/webhook/config/watcher/util.go 75.00% <ø> (ø)
... and 50 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 fb2cf1e...134158b. Read the comment docs.

Signed-off-by: cwen0 <[email protected]>
@cwen0 cwen0 marked this pull request as ready for review May 22, 2020 12:17
cwen0 added 3 commits May 22, 2020 21:25
Signed-off-by: cwen0 <[email protected]>
Signed-off-by: cwen0 <[email protected]>
Signed-off-by: cwen0 <[email protected]>
@cwen0 cwen0 requested review from fewdan and yeya24 May 22, 2020 15:54
Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

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

Looks good. Just some small nits.

BTW, do you mind updating the deleteExperiment swagger in this PR? Seems I forgot to include the failure 404

// @Success 200 "delete ok"
// @Router /api/experiments/{kind}/{namespace}/{name} [delete]
// @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError
func (s *Service) deleteExperiment(c *gin.Context) {


// ChaosKindMap defines a map including all chaos kinds.
type chaosKindMap struct {
sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a map, so I think it is necessary

for key, kind := range c.kinds {
out[key] = &ChaosKind{
Chaos: kind.Chaos.DeepCopyObject(),
ChaosList: kind.ChaosList,
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure whether DeepCopyObject() is necessary or not. If it is, ChaosList also supports this method. kind.ChaosList.DeepCopyObject()

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, DeepCopyObject() is not necessary and I have removed it.

// @Param name path string true "name"
// @Success 200 "start ok"
// @Failure 500 {object} utils.APIError
// @Failure 404 {object} utils.APIError
Copy link
Contributor

Choose a reason for hiding this comment

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

400 Failure

// @Success 200 "start ok"
// @Failure 500 {object} utils.APIError
// @Failure 404 {object} utils.APIError
// @Router /api/experiments/start/{kind}/{ns}/{name} [put]
Copy link
Contributor

Choose a reason for hiding this comment

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

// @Router /api/experiments/start/{kind}/{namespace}/{name} [put]

// @Param name path string true "name"
// @Success 200 "pause ok"
// @Failure 500 {object} utils.APIError
// @Failure 404 {object} utils.APIError
Copy link
Contributor

Choose a reason for hiding this comment

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

400 Failure is also needed


// ExperimentBase is used to identify the unique experiment from API request.
type ExperimentBase struct {
Kind string `uri:"kind" binding:"required,oneof=PodChaos NetworkChaos IoChaos StressChaos TimeChaos"`
Copy link
Contributor

Choose a reason for hiding this comment

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

KernelChaos :D

endpoint.GET("/detail/:namespace/:name", s.getExperimentDetail)
endpoint.DELETE("/:kind/:namespace/:name", s.deleteExperiment)
endpoint.GET("/detail/:kind/:namespace/:name", s.getExperimentDetail)
endpoint.DELETE("/delete/:kind/:namespace/:name", s.deleteExperiment)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO /delete/:kind/:namespace/:name is not needed, do you mind changing this to /:kind/:namespace/:name? We are already using the DELETE verb here.

@cwen0
Copy link
Member Author

cwen0 commented May 23, 2020

/run-e2e-test

1 similar comment
@cwen0
Copy link
Member Author

cwen0 commented May 23, 2020

/run-e2e-test

Copy link
Member

@fewdan fewdan left a comment

Choose a reason for hiding this comment

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

LGTM

@yeya24
Copy link
Contributor

yeya24 commented May 23, 2020

/run-e2e-test

@zhouqiang-cl
Copy link
Contributor

/merge

@@ -600,3 +609,111 @@ func (s *Service) state(c *gin.Context) {

c.JSON(http.StatusOK, data)
}

// ExperimentBase is used to identify the unique experiment from API request.
type ExperimentBase struct {
Copy link

Choose a reason for hiding this comment

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

type name will be used as experiment.ExperimentBase by other packages, and that stutters; consider calling this Base

@sre-bot
Copy link
Contributor

sre-bot commented May 24, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented May 24, 2020

@cwen0 merge failed.

@zhouqiang-cl
Copy link
Contributor

/run-e2e-tests

@cwen0 cwen0 merged commit b53fde0 into chaos-mesh:master May 24, 2020
@cwen0 cwen0 deleted the pause_experiment_api branch May 24, 2020 15:01
huangwei2013 added a commit to huangwei2013/chaos-mesh that referenced this pull request May 24, 2020
pause and start experiment by API (chaos-mesh#542)
sjwsl pushed a commit to sjwsl/chaos-mesh that referenced this pull request May 6, 2021
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.

6 participants