├── .gitignore ├── LICENSE ├── README.md ├── api.go ├── doc.go ├── examples ├── dummy.json ├── nginx.json └── seed.sh ├── main.go ├── marathon-drax.json └── metronome-drax.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | .idea 10 | 11 | # Architecture specific extensions/prefixes 12 | *.[568vq] 13 | [568vq].out 14 | 15 | *.cgo1.go 16 | *.cgo2.c 17 | _cgo_defun.c 18 | _cgo_gotypes.go 19 | _cgo_export.* 20 | 21 | _testmain.go 22 | 23 | *.exe 24 | *.test 25 | *.prof 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DRAX 2 | 3 | This is DRAX, the [DC/OS](https://dcos.io) Resilience Automated Xenodiagnosis tool. It helps to test DC/OS deployments by applying a [Chaos Monkey](http://techblog.netflix.com/2012/07/chaos-monkey-released-into-wild.html)-inspired, proactive and invasive testing approach. 4 | 5 | Well, actually DRAX is a reverse acronym inspired by the Guardians of the Galaxy character Drax the Destroyer. 6 | 7 | You might have heard of Netflix's [Chaos Monkey](http://techblog.netflix.com/2012/07/chaos-monkey-released-into-wild.html) or it's containerized [variant](https://medium.com/production-ready/chaos-monkey-for-fun-and-profit-87e2f343db31). Maybe you've seen a [gaming version](https://www.wehkamplabs.com/blog/2016/06/02/docker-and-zombies/) of it or stumbled upon a [lower-level species](http://probablyfine.co.uk/2016/05/30/announcing-byte-monkey/). In any case I assume you're somewhat familiar with chaos-based resilience testing. 8 | 9 | DRAX is a DC/OS-specific resilience testing tool that works mainly on the task-level. Future work may include node-level up to cluster-level. 10 | 11 | ## Installation and usage 12 | 13 | Note that DRAX assumes a running [DC/OS 1.9](https://dcos.io/) cluster. 14 | 15 | ### Production 16 | 17 | Launch DRAX using the DC/OS CLI via the Marathon app spec provided: 18 | 19 | $ dcos marathon app add marathon-drax.json 20 | 21 | Now you can (modulo the public node of your cluster) do the following: 22 | 23 | $ http http://ec2-52-38-188-110.us-west-2.compute.amazonaws.com:7777/stats 24 | HTTP/1.1 200 OK 25 | Content-Length: 10 26 | Content-Type: application/javascript 27 | Date: Mon, 13 Jun 2016 14:39:11 GMT 28 | 29 | {"gone":0} 30 | 31 | If you launched DRAX via Marathon, you can also trigger a POST to the /rampage continuously by deploying a DC/OS job. The example job is triggering the destruction every business hour from Monday till Friday: 32 | 33 | $ dcos job add metronome-drax.json 34 | 35 | ### Testing and development 36 | 37 | Get DRAX and build from source: 38 | 39 | $ go get github.com/dcos-labs/drax 40 | $ go build 41 | $ MARATHON_URL=http://localhost:8080 ./drax 42 | INFO[0000] This is DRAX in version 0.4.0 main=init 43 | INFO[0000] Listening on port 7777 main=init 44 | INFO[0000] On destruction level 0 main=init 45 | INFO[0000] Using Marathon at http://localhost:8080 main=init 46 | INFO[0000] I will destroy 2 tasks on a rampage main=init 47 | 48 | And in a different terminal session: 49 | 50 | $ http http://localhost:7777/stats 51 | HTTP/1.1 200 OK 52 | Content-Length: 10 53 | Content-Type: application/javascript 54 | Date: Mon, 13 Jun 2016 14:39:11 GMT 55 | 56 | {"gone":0} 57 | 58 | For Go development, be aware of the following dependencies (not using explicit vendoring ATM): 59 | 60 | - [github.com/gambol99/go-marathon](https://github.com/gambol99/go-marathon), an API library for working with Marathon. 61 | - [github.com/Sirupsen/logrus](https://github.com/Sirupsen/logrus), a logging library. 62 | 63 | ### Configuration 64 | 65 | Note that the following environment variables are pre-set in the [Marathon app spec](marathon-drax.json) and yours to overwrite. 66 | 67 | 68 | #### Number of target tasks 69 | 70 | To specify how many tasks DRAX is supposed to destroy in one rampage, use `NUM_TARGETS`. For example, `NUM_TARGETS=5 drax` means that (up to) 5 tasks will be destroyed, unless the overall number of tasks is less, of course. 71 | 72 | #### Log level 73 | 74 | To influence the log level, use the `LOG_LEVEL` env variable, for example `LOG_LEVEL=DEBUG drax` would give you fine-grained log messages (defaults to `INFO`). 75 | 76 | ## API 77 | 78 | ### /health [GET] 79 | 80 | Will return a HTTP 200 code and `I am Groot` if DRAX is healthy. 81 | 82 | ### /stats [GET] 83 | 84 | Will return runtime statistics, such as killed containers or apps and will report from the beginning of time (well, beginning of time for DRAX anyways). 85 | 86 | $ http http://localhost:7777/stats 87 | HTTP/1.1 200 OK 88 | Content-Length: 10 89 | Content-Type: application/javascript 90 | Date: Mon, 13 Jun 2016 14:39:11 GMT 91 | 92 | {"gone":2} 93 | 94 | ### /rampage [POST] 95 | 96 | Will trigger a destruction. Invoke with: 97 | 98 | $ http POST localhost:7777/rampage 99 | HTTP/1.1 200 OK 100 | Content-Length: 121 101 | Content-Type: application/javascript 102 | Date: Mon, 13 Jun 2016 12:15:19 GMT 103 | 104 | {"success":true,"goners":["webserver.0fde0035-315f-11e6-aad0-1e9bbbc1653f","dummy.11a7c3bb-315f-11e6-aad0-1e9bbbc1653f"]} 105 | -------------------------------------------------------------------------------- /api.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | "math/rand" 7 | "net/http" 8 | "strings" 9 | "sync/atomic" 10 | "time" 11 | 12 | log "github.com/Sirupsen/logrus" 13 | marathon "github.com/gambol99/go-marathon" 14 | ) 15 | 16 | // StatsResult JSON payload 17 | type StatsResult struct { 18 | KilledTasks uint64 `json:"gone"` 19 | } 20 | 21 | // RampageResult JSON payload 22 | type RampageResult struct { 23 | Success bool `json:"success"` 24 | KilledTasks []string `json:"goners"` 25 | } 26 | 27 | // Handles /health API calls (GET only) 28 | func getHealth(w http.ResponseWriter, r *http.Request) { 29 | log.WithFields(log.Fields{"handle": "/health"}).Info("health check") 30 | io.WriteString(w, "I am Groot") 31 | } 32 | 33 | // Handles /stats API calls (GET only) 34 | func getStats(w http.ResponseWriter, r *http.Request) { 35 | log.WithFields(log.Fields{"handle": "/stats"}).Info("Overall tasks killed: ", overallTasksKilled) 36 | 37 | sr := &StatsResult{ 38 | KilledTasks: overallTasksKilled} 39 | 40 | srJSON, _ := json.Marshal(sr) 41 | w.Header().Set("Content-Type", "application/json") 42 | io.WriteString(w, string(srJSON)) 43 | } 44 | 45 | // Handles /rampage API calls (POST only) 46 | func postRampage(w http.ResponseWriter, r *http.Request) { 47 | if r.Method == "POST" { 48 | log.WithFields(log.Fields{"handle": "/rampage"}).Info("Starting rampage on destruction level ", destructionLevel) 49 | 50 | switch destructionLevel { 51 | case DLBASIC: 52 | killTasks(w, r) 53 | case DLADVANCED: 54 | io.WriteString(w, "not yet implemented") 55 | case DLALL: 56 | io.WriteString(w, "not yet implemented") 57 | default: 58 | http.NotFound(w, r) 59 | } 60 | 61 | } else { 62 | log.WithFields(log.Fields{"handle": "/rampage"}).Error("Only POST method supported") 63 | http.NotFound(w, r) 64 | } 65 | 66 | } 67 | 68 | // killTasks will identify tasks of any apps (but not framework services) 69 | // and randomly kill off a few of them 70 | func killTasks(w http.ResponseWriter, r *http.Request) { 71 | if client, ok := getClient(); ok { 72 | apps, err := client.Applications(nil) 73 | if err != nil { 74 | log.WithFields(log.Fields{"handle": "/rampage"}).Info("Failed to list apps") 75 | http.Error(w, "Failed to list apps", 500) 76 | return 77 | } 78 | log.WithFields(log.Fields{"handle": "/rampage"}).Info("Found overall ", len(apps.Apps), " applications running") 79 | 80 | candidates := []string{} 81 | for _, app := range apps.Apps { 82 | log.WithFields(log.Fields{"handle": "/rampage"}).Debug("APP ", app.ID) 83 | details, _ := client.Application(app.ID) 84 | 85 | if !myself(details) && !isFramework(details) { 86 | if details.Tasks != nil && len(details.Tasks) > 0 { 87 | for _, task := range details.Tasks { 88 | log.WithFields(log.Fields{"handle": "/rampage"}).Debug("TASK ", task.ID) 89 | candidates = append(candidates, task.ID) 90 | } 91 | } 92 | } 93 | } 94 | 95 | if len(candidates) > 0 { 96 | log.WithFields(log.Fields{"handle": "/rampage"}).Info("Found ", len(candidates), " tasks to kill") 97 | rampage(w, client, candidates) 98 | } 99 | 100 | } else { 101 | http.Error(w, "Can't connect to Marathon", 500) 102 | } 103 | } 104 | 105 | // getClient tries to get a connection to the DC/OS System Marathon 106 | func getClient() (marathon.Marathon, bool) { 107 | config := marathon.NewDefaultConfig() 108 | config.URL = marathonURL 109 | client, err := marathon.NewClient(config) 110 | if err != nil { 111 | log.WithFields(log.Fields{"handle": "/rampage"}).Error("Failed to create Marathon client due to ", err) 112 | return nil, false 113 | } 114 | return client, true 115 | } 116 | 117 | // rampage kills random tasks from the candidates and returns a JSON result 118 | func rampage(w http.ResponseWriter, c marathon.Marathon, candidates []string) { 119 | var targets []int 120 | 121 | // generates a list of random, non-repeating indices into the candidates: 122 | if len(candidates) > numTargets { 123 | targets = rand.Perm(len(candidates))[:numTargets] 124 | } else { 125 | targets = rand.Perm(len(candidates)) 126 | } 127 | 128 | rr := &RampageResult{ 129 | Success: true, 130 | KilledTasks: []string{}} 131 | 132 | // kill the candidates 133 | for _, t := range targets { 134 | candidate := candidates[t] 135 | killTask(c, candidate) 136 | log.WithFields(log.Fields{"handle": "/rampage"}).Info("Killed tasks ", candidate) 137 | rr.KilledTasks = append(rr.KilledTasks, candidate) 138 | atomic.AddUint64(&overallTasksKilled, 1) 139 | log.WithFields(log.Fields{"handle": "/rampage"}).Info("Counter: ", overallTasksKilled) 140 | time.Sleep(time.Millisecond * time.Duration(sleepTime)) 141 | } 142 | 143 | rrJSON, _ := json.Marshal(rr) 144 | w.Header().Set("Content-Type", "application/json") 145 | io.WriteString(w, string(rrJSON)) 146 | } 147 | 148 | // killTask kills a certain task and increments overall count if successful 149 | func killTask(c marathon.Marathon, taskID string) bool { 150 | _, err := c.KillTask(taskID, nil) 151 | if err != nil { 152 | log.WithFields(log.Fields{"handle": "/rampage"}).Debug("Not able to kill task ", taskID) 153 | return false 154 | } 155 | 156 | log.WithFields(log.Fields{"handle": "/rampage"}).Debug("Killed task ", taskID) 157 | return true 158 | } 159 | 160 | // myself returns true if it is applied to DRAX Marathon app itself 161 | func myself(app *marathon.Application) bool { 162 | if strings.Contains(app.ID, "drax") { 163 | return true 164 | } 165 | return false 166 | } 167 | 168 | // isFramework returns true if the Marathon app is a service framework, 169 | // and false otherwise (determined via the DCOS_PACKAGE_IS_FRAMEWORK label key) 170 | func isFramework(app *marathon.Application) bool { 171 | for k, v := range *app.Labels { 172 | log.WithFields(log.Fields{"handle": "/rampage"}).Debug("LABEL ", k, ":", v) 173 | if k == "DCOS_PACKAGE_IS_FRAMEWORK" && v == "true" { 174 | return true 175 | } 176 | } 177 | return false 178 | } 179 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package DRAX (DC/OS Resilience Automated Xenodiagnosis) implements a 3 | chaosmonkey-like testing functionality for DC/OS clusters. 4 | 5 | To launch it locally use the following: 6 | 7 | $ MARATHON_URL=http://localhost:8080 drax 8 | 9 | To launch it into the cluster (via the DC/OS CLI) use: 10 | 11 | $ dcos marathon app add marathon-drax.json 12 | 13 | You can then use the API to destroy tasks and check stats, 14 | see https://github.com/dcos-labs/drax#api for details. 15 | 16 | */ 17 | package main 18 | -------------------------------------------------------------------------------- /examples/dummy.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "dummy", 3 | "instances": 20, 4 | "cpus": 0.01, 5 | "mem": 32, 6 | "cmd": "while [ true ] ; do echo \"I am a dummy\" ; sleep 20 ; done" 7 | } -------------------------------------------------------------------------------- /examples/nginx.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "webserver", 3 | "instances": 5, 4 | "cpus": 0.1, 5 | "mem": 80, 6 | "container": { 7 | "type": "DOCKER", 8 | "docker": { 9 | "image": "nginx:1.9", 10 | "network": "BRIDGE", 11 | "portMappings": [ 12 | { 13 | "containerPort": 80, 14 | "hostPort": 0 15 | } 16 | ] 17 | } 18 | }, 19 | "acceptedResourceRoles": [ 20 | "slave_public", 21 | "*" 22 | ] 23 | } -------------------------------------------------------------------------------- /examples/seed.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Launches all Marathon app specs in the directory. 4 | # These Marathon apps serve as a test bed for DRAX. 5 | 6 | set -o errexit 7 | set -o pipefail 8 | set -o nounset 9 | 10 | command -v dcos >/dev/null 2>&1 || { echo >&2 "Need the DC/OS CLI to carry out my work, but it seems it's not installed. See https://dcos.io/docs/latest/cli/install/ for how to get it ..."; exit 1; } 11 | 12 | for ma in *.json ; do 13 | echo "Trying to launching Marathon app defined in: $ma" 14 | dcos marathon app add $ma 15 | echo "$ma launched" 16 | done 17 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | "os" 6 | "strconv" 7 | "strings" 8 | 9 | log "github.com/Sirupsen/logrus" 10 | ) 11 | 12 | // DestructionLevel of type (0 .. 2) 13 | type DestructionLevel int 14 | 15 | const ( 16 | // VERSION of DRAX 17 | VERSION string = "0.4.0" 18 | // DEFAULTPORT is the port DRAX is listening on 19 | DEFAULTPORT string = "7777" 20 | // MARATHONURL for connection to DC/OS 21 | MARATHONURL string = "http://marathon.mesos:8080" 22 | // DEFAULTNUMTARGET is the number of tasks to kill 23 | DEFAULTNUMTARGET int = 2 24 | // DEFAULTSLEEPTIME is the time in ms to wait between the killing of tasks 25 | DEFAULTSLEEPTIME int = 100 26 | ) 27 | 28 | const ( 29 | // DLBASIC means destroy random tasks 30 | DLBASIC DestructionLevel = iota 31 | // DLADVANCED means destroy random apps 32 | DLADVANCED 33 | // DLALL means destroy random apps and services 34 | DLALL 35 | ) 36 | 37 | var ( 38 | port string 39 | marathonURL string 40 | destructionLevel = DestructionLevel(DLBASIC) 41 | numTargets = int(DEFAULTNUMTARGET) 42 | sleepTime = int(DEFAULTSLEEPTIME) 43 | overallTasksKilled uint64 44 | ) 45 | 46 | func init() { 47 | 48 | if ll := os.Getenv("LOG_LEVEL"); ll != "" { 49 | switch strings.ToUpper(ll) { 50 | case "DEBUG": 51 | log.SetLevel(log.DebugLevel) 52 | case "INFO": 53 | log.SetLevel(log.InfoLevel) 54 | default: 55 | log.SetLevel(log.ErrorLevel) 56 | } 57 | 58 | } 59 | 60 | log.WithFields(log.Fields{"main": "init"}).Info("This is DRAX in version ", VERSION) 61 | 62 | // set port for http server 63 | if port = os.Getenv("PORT"); len(port) == 0 { 64 | port = DEFAULTPORT 65 | } 66 | log.WithFields(log.Fields{"main": "init"}).Info("Listening on port ", port) 67 | 68 | // set destruction level 69 | if dl := os.Getenv("DESTRUCTION_LEVEL"); dl != "" { 70 | l, _ := strconv.Atoi(dl) 71 | destructionLevel = DestructionLevel(l) 72 | } 73 | log.WithFields(log.Fields{"main": "init"}).Info("On destruction level ", destructionLevel) 74 | 75 | // per default, use the cluster-internal, non-auth endpoint: 76 | if marathonURL = os.Getenv("MARATHON_URL"); marathonURL == "" { 77 | marathonURL = MARATHONURL 78 | } 79 | log.WithFields(log.Fields{"main": "init"}).Info("Using Marathon at ", marathonURL) 80 | 81 | if nt := os.Getenv("NUM_TARGETS"); nt != "" { 82 | n, _ := strconv.Atoi(nt) 83 | numTargets = n 84 | } 85 | log.WithFields(log.Fields{"main": "init"}).Info("I will destroy ", numTargets, " tasks on a rampage") 86 | 87 | if st := os.Getenv("SLEEP_TIME"); st != "" { 88 | s, _ := strconv.Atoi(st) 89 | sleepTime = s 90 | } 91 | log.WithFields(log.Fields{"main": "init"}).Info("I will wait ", sleepTime, "ms between the killing of tasks") 92 | 93 | } 94 | 95 | func main() { 96 | 97 | http.HandleFunc("/health", getHealth) 98 | http.HandleFunc("/stats", getStats) 99 | http.HandleFunc("/rampage", postRampage) 100 | 101 | err := http.ListenAndServe(":"+port, nil) 102 | if err != nil { 103 | log.Fatal(err) 104 | panic(err) 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /marathon-drax.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "/drax", 3 | "cmd": "chmod u+x drax && ./drax", 4 | "instances": 1, 5 | "cpus": 0.1, 6 | "mem": 200, 7 | "fetch": [ 8 | { 9 | "uri": "https://github.com/dcos-labs/drax/releases/download/0.4.0/drax" 10 | } 11 | ], 12 | "healthChecks": [ 13 | { 14 | "portIndex": 0, 15 | "path": "/health", 16 | "protocol": "MESOS_HTTP" 17 | } 18 | ], 19 | "acceptedResourceRoles": [ 20 | "slave_public" 21 | ], 22 | "portDefinitions": [ 23 | { 24 | "port": 7777, 25 | "protocol": "tcp", 26 | "name": "default", 27 | "labels": { 28 | "VIP_0": "/drax:7777" 29 | } 30 | } 31 | ], 32 | "requirePorts": true, 33 | "env": { 34 | "LOG_LEVEL": "DEBUG", 35 | "DESTRUCTION_LEVEL": "0", 36 | "NUM_TARGETS": "3" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /metronome-drax.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "rampage", 3 | "run": { 4 | "cpus": 0.1, 5 | "mem": 128, 6 | "disk": 0, 7 | "cmd": "http POST http://drax.marathon.l4lb.thisdcos.directory:7777/rampage", 8 | "docker": { 9 | "image": "alpine/httpie" 10 | } 11 | }, 12 | "schedules": [ 13 | { 14 | "id": "default", 15 | "enabled": true, 16 | "cron": "0 9-17 * * 1-5", 17 | "concurrencyPolicy": "ALLOW" 18 | } 19 | ] 20 | } 21 | --------------------------------------------------------------------------------