diff --git a/chaos/backend/api/stressvo.go b/chaos/backend/api/stressvo.go new file mode 100644 index 0000000000000000000000000000000000000000..13ff3d68e5afb9f60d5bf9c851daf017516bb601 --- /dev/null +++ b/chaos/backend/api/stressvo.go @@ -0,0 +1,19 @@ +package api + +type StressReport struct { + MeanLatency float64 `json:"meanLatency"` + RequestNum int `json:"requestNum"` + RequestRate float64 `json:"requestRate"` + Throughput float64 `json:"throughput"` + SuccessRate float64 `json:"successRate"` +} + +type StressStatus struct { + Tps + IsStressed bool `json:"isStressed"` +} + +type Tps struct { + TravelServiceTps int `json:"travelServiceTps"` + TravelPlanServiceTps int `json:"travelPlanServiceTps"` +} diff --git a/chaos/backend/chaos-backend-deploy.yaml b/chaos/backend/chaos-backend-deploy.yaml index e44e00fab5e65e6227799237803dd020894cf6b0..e6b391f65168fad952c7684f482e67e0730fac2d 100644 --- a/chaos/backend/chaos-backend-deploy.yaml +++ b/chaos/backend/chaos-backend-deploy.yaml @@ -25,32 +25,33 @@ spec: app: chaos-backend spec: volumes: - - name: chaos-backend-config - configMap: - name: chaos-backend-config - defaultMode: 420 + - name: chaos-backend-config + configMap: + name: chaos-backend-config + defaultMode: 420 containers: - - name: chaos-backend - command: - - /app/chaos-backend - - --authType=serviceAccount - - --skywalkingUIAddr=http://skywalking.train-ticket:12800/graphql - - --prometheusUIAddr=http://prometheus-k8s.monitoring:9090 - - --metricSource=skywalking - image: chaos-backend:latest - imagePullPolicy: IfNotPresent - ports: - - name: http - containerPort: 8080 - protocol: TCP - resources: - limits: - cpu: 200m - memory: 256Mi - volumeMounts: - - name: chaos-backend-config - mountPath: /app/config/chaos_template.yaml - subPath: chaos_template.yaml + - name: chaos-backend + command: + - /app/chaos-backend + - --authType=serviceAccount + - --skywalkingUIAddr=http://skywalking.train-ticket:12800/graphql + - --prometheusUIAddr=http://prometheus-k8s.monitoring:9090 + - --trainTicketUIAddr=http://ts-gateway-service.train-ticket:18888 + - --metricSource=skywalking + image: chaos-backend:latest + imagePullPolicy: IfNotPresent + ports: + - name: http + containerPort: 8080 + protocol: TCP + resources: + limits: + cpu: 200m + memory: 256Mi + volumeMounts: + - name: chaos-backend-config + mountPath: /app/config/chaos_template.yaml + subPath: chaos_template.yaml --- apiVersion: v1 kind: Service @@ -64,43 +65,43 @@ spec: selector: app: chaos-backend ports: - - name: http - port: 8080 - protocol: TCP - targetPort: 8080 + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: chaos-backend-cluster-role rules: - - apiGroups: - - chaos-mesh.org - resources: - - awschaos - - azurechaos - - blockchaos - - dnschaos - - gcpchaos - - httpchaos - - iochaos - - jvmchaos - - kernelchaos - - networkchaos - - physicalmachinechaos - - physicalmachines - - podchaos - - podhttpchaos - - podiochaos - - podnetworkchaos - - remoteclusters - - schedules - - statuschecks - - stresschaos - - timechaos - - workflownodes - - workflows - verbs: ["get", "list", "watch", "create", "update", "delete"] +- apiGroups: + - chaos-mesh.org + resources: + - awschaos + - azurechaos + - blockchaos + - dnschaos + - gcpchaos + - httpchaos + - iochaos + - jvmchaos + - kernelchaos + - networkchaos + - physicalmachinechaos + - physicalmachines + - podchaos + - podhttpchaos + - podiochaos + - podnetworkchaos + - remoteclusters + - schedules + - statuschecks + - stresschaos + - timechaos + - workflownodes + - workflows + verbs: ["get", "list", "watch", "create", "update", "delete"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding @@ -111,9 +112,9 @@ roleRef: kind: ClusterRole name: chaos-backend-cluster-role subjects: - - kind: ServiceAccount - name: chaos-backend - namespace: chaos-injection +- kind: ServiceAccount + name: chaos-backend + namespace: chaos-injection --- apiVersion: v1 diff --git a/chaos/backend/configs/server_config.go b/chaos/backend/configs/server_config.go index c14773fb886b498b44135d72b2595a29f7539961..0f9d12241d97d1d5898d2882deff59b56d9bf6d3 100644 --- a/chaos/backend/configs/server_config.go +++ b/chaos/backend/configs/server_config.go @@ -6,7 +6,8 @@ type Config struct { UnstructuredChaosFilePath string `json:"unstructured_chaos_file_path"` // Third Party Dependence - MetricSource string `json:"metric_source"` - SkywalkingUIAddr string `json:"skywalking_ui_config"` - PrometheusUIAddr string `json:"prometheus_ui_config"` + MetricSource string `json:"metric_source"` + SkywalkingUIAddr string `json:"skywalking_ui_config"` + PrometheusUIAddr string `json:"prometheus_ui_config"` + TrainTicketUIAddr string `json:"train_ticket_ui_config"` } diff --git a/chaos/backend/go.mod b/chaos/backend/go.mod index 59863852f8c5a6f3aef3bffb547ce6cdc3bd7388..af049893b83bc8c6b1413632be1a7216e5603607 100644 --- a/chaos/backend/go.mod +++ b/chaos/backend/go.mod @@ -23,6 +23,7 @@ require ( github.com/gomodule/redigo v1.8.9 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/influxdata/tdigest v0.0.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mailru/easyjson v0.7.7 // indirect @@ -30,6 +31,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/robfig/go-cache v0.0.0-20130306151617-9fc39e0dbf62 // indirect + github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 // indirect github.com/sagikazarmark/locafero v0.3.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect @@ -38,6 +40,7 @@ require ( github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/sync v0.3.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect ) @@ -80,10 +83,11 @@ require ( github.com/prometheus/client_golang v1.16.0 github.com/prometheus/client_model v0.4.0 // indirect github.com/prometheus/common v0.44.0 - github.com/prometheus/procfs v0.10.1 // indirect + github.com/prometheus/procfs v0.11.0 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.17.0 + github.com/tsenart/vegeta/v12 v12.11.1 github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect golang.org/x/arch v0.3.0 // indirect diff --git a/chaos/backend/go.sum b/chaos/backend/go.sum index 6b3d85c7d473c0295f71e7b7b4a87f5f5c7cbabe..5fbdb6a88a37d26f39a7454751b0c383e9555fc9 100644 --- a/chaos/backend/go.sum +++ b/chaos/backend/go.sum @@ -42,6 +42,7 @@ github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAu github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bmizerany/perks v0.0.0-20230307044200-03f9df79da1e h1:mWOqoK5jV13ChKf/aF3plwQ96laasTJgZi4f1aSOu+M= github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d h1:pVrfxiGfwelyab6n21ZBkbkmbevaf+WvMIiR7sr97hw= github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40Nwln+M/+faA= @@ -68,6 +69,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-gk v0.0.0-20200319235926-a69029f61654 h1:XOPLOMn/zT4jIgxfxSsoXPxkrzz0FaCHwp33x5POJ+Q= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ= @@ -230,6 +232,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= +github.com/influxdata/tdigest v0.0.1 h1:XpFptwYmnEKUqmkcDjrzffswZ3nvNeevbUSLPP/ZzIY= +github.com/influxdata/tdigest v0.0.1/go.mod h1:Z0kXnxzbTC2qrx4NaIzYkE1k66+6oEDQTvL95hQFh5Y= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= @@ -303,8 +307,8 @@ github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUo github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= -github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= -github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= +github.com/prometheus/procfs v0.11.0 h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk= +github.com/prometheus/procfs v0.11.0/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/robfig/go-cache v0.0.0-20130306151617-9fc39e0dbf62 h1:pyecQtsPmlkCsMkYhT5iZ+sUXuwee+OvfuJjinEA3ko= @@ -313,6 +317,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 h1:Lt9DzQALzHoDwMBGJ6v8ObDPR0dzr2a6sXTB1Fq7IHs= +github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417/go.mod h1:qe5TWALJ8/a1Lqznoc5BDHpYX/8HU60Hm2AwRmqzxqA= github.com/sagikazarmark/locafero v0.3.0 h1:zT7VEGWC2DTflmccN/5T1etyKvxSxpHsjb9cJvm4SvQ= github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= @@ -327,6 +333,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI= github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI= +github.com/streadway/quantile v0.0.0-20220407130108-4246515d968d h1:X4+kt6zM/OVO6gbJdAfJR60MGPsqCzbtXNnjoGqdfAs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -343,6 +350,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/tsenart/vegeta/v12 v12.11.1 h1:Rbwe7Zxr7sJ+BDTReemeQalYPvKiSV+O7nwmUs20B3E= +github.com/tsenart/vegeta/v12 v12.11.1/go.mod h1:swiFmrgpqj2llHURgHYFRFN0tfrIrlnspg01HjwOnSQ= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= @@ -380,6 +389,7 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -470,6 +480,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -531,6 +543,7 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -587,6 +600,9 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= +gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca h1:PupagGYwj8+I4ubCxcmcBRk3VlUWtTg5huQpZR9flmE= +gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= +gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -724,6 +740,7 @@ k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrC k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= +pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/chaos/backend/internal/app/engine.go b/chaos/backend/internal/app/engine.go index 44e5af2b69594f5f5f4a52a646e99be150a583e6..c89d61a6edbfb1df4b51431302155d62067afbc9 100644 --- a/chaos/backend/internal/app/engine.go +++ b/chaos/backend/internal/app/engine.go @@ -20,6 +20,7 @@ func SetupApplication( kubeConfigPath string, skywalkingUIAddr string, prometheusUIAddr string, + trainTicketUIAddr string, chaosTemplateFilePath string, unstructuredChaosFilePath string, metricSource string, @@ -42,6 +43,7 @@ func SetupApplication( UnstructuredChaosFilePath: unstructuredChaosFilePath, SkywalkingUIAddr: skywalkingUIAddr, PrometheusUIAddr: prometheusUIAddr, + TrainTicketUIAddr: trainTicketUIAddr, MetricSource: metricSource, } @@ -49,6 +51,7 @@ func SetupApplication( SetupRouter(DefaultEngine) SetupKubeAuthConfig(cfg) SetupThirdPartyDataSource(cfg) + SetupTrainTicketAddr(cfg) SetupChaosTemplate(cfg) // TODO logger @@ -84,3 +87,7 @@ func SetupThirdPartyDataSource(cfg configs.Config) { service.SetDatasource(cfg.MetricSource) } + +func SetupTrainTicketAddr(cfg configs.Config) { + service.SetupTrainTicketAddr(cfg.TrainTicketUIAddr) +} diff --git a/chaos/backend/internal/app/route.go b/chaos/backend/internal/app/route.go index f3f91a5988b0c940fac17a2392870185d9828fd8..9cfad49830078b887ceee38e95afeb9f2c7e2352 100644 --- a/chaos/backend/internal/app/route.go +++ b/chaos/backend/internal/app/route.go @@ -14,6 +14,7 @@ func SetupRouter(e *gin.Engine) { apiRoute := e.Group("api") service.RegisterChaos(apiRoute) service.RegisterSceneChaos(apiRoute) + service.RegisterStress(apiRoute) } func Cors() gin.HandlerFunc { diff --git a/chaos/backend/internal/service/stress_service.go b/chaos/backend/internal/service/stress_service.go new file mode 100644 index 0000000000000000000000000000000000000000..ff9cf438b3a8593dceff579edab8f781578d3f22 --- /dev/null +++ b/chaos/backend/internal/service/stress_service.go @@ -0,0 +1,153 @@ +package service + +import ( + "log" + "net/http" + "time" + + "github.com/Kindling-project/chaos-backend/api" + "github.com/gin-gonic/gin" + vegeta "github.com/tsenart/vegeta/v12/lib" +) + +var StressStatus = api.StressStatus{ + Tps: api.Tps{ + TravelServiceTps: 0, + TravelPlanServiceTps: 0, + }, + IsStressed: false, +} +var Attacker = vegeta.NewAttacker() +var TravelServiceMetrics vegeta.Metrics +var TravelPlanServiceMetrics vegeta.Metrics +var trainTicketAddr string + +func RegisterStress(router *gin.RouterGroup) { + chaosRouter := router.Group("tps") + { + chaosRouter.POST("/start", StartStress) + chaosRouter.GET("/stop", EndStress) + chaosRouter.GET("/status", GetStressStatus) + } +} + +func SetupTrainTicketAddr(addr string) { + trainTicketAddr = addr +} + +func StartStress(c *gin.Context) { + + if StressStatus.IsStressed { + log.Printf("Please end this stress test first") + api.Response(c, http.StatusInternalServerError, 500, "please end this stress test first", nil) + return + } + + tps := api.Tps{} + if err := c.BindJSON(&tps); err != nil { + log.Println("request body is illegal: ", err) + api.Response(c, http.StatusInternalServerError, 500, "request body is illegal", nil) + return + } + + if tps.TravelServiceTps <= 0 && tps.TravelPlanServiceTps <= 0 { + log.Printf("At least one Tps should be a positive integer") + api.Response(c, http.StatusInternalServerError, 500, + "failed to run stress tests, at least one Tps should be a positive integer", nil) + return + } + + header := http.Header{} + header.Add("Accept", "application/json, text/javascript, */*; q=0.01") + header.Add("Content-Type", "application/json") + date := time.Now().Format("2006-01-02") + body := []byte(`{"startPlace":"Shang Hai","endPlace":"Su Zhou","departureTime":"` + date + ` 00:00:00"}`) + travelServiceTargeter := vegeta.NewStaticTargeter(vegeta.Target{ + Method: "POST", + Header: header, + Body: body, + URL: trainTicketAddr + "/api/v1/travelservice/trips/left", + }) + travelPlanServiceTargeter := vegeta.NewStaticTargeter(vegeta.Target{ + Method: "POST", + Header: header, + Body: body, + URL: trainTicketAddr + "/api/v1/travelplanservice/travelPlan/cheapest", + }) + StressStatus.TravelServiceTps = tps.TravelServiceTps + StressStatus.TravelPlanServiceTps = tps.TravelPlanServiceTps + + duration := 0 * time.Second // duration=0时持续压测 + + StressStatus.IsStressed = true + + if tps.TravelServiceTps > 0 { + if tps.TravelServiceTps > 200 { + tps.TravelServiceTps = 200 + } + travelServiceRate := vegeta.Rate{Freq: StressStatus.TravelServiceTps, Per: time.Second} + go func() { + for res := range Attacker.Attack(travelServiceTargeter, travelServiceRate, duration, "stress on travel-service") { + TravelServiceMetrics.Add(res) + } + }() + } + + if tps.TravelPlanServiceTps > 0 { + if tps.TravelPlanServiceTps > 200 { + tps.TravelPlanServiceTps = 200 + } + travelPlanServiceRate := vegeta.Rate{Freq: StressStatus.TravelPlanServiceTps, Per: time.Second} + go func() { + for res := range Attacker.Attack(travelPlanServiceTargeter, travelPlanServiceRate, duration, "stress on travel-plan-service") { + TravelPlanServiceMetrics.Add(res) + } + }() + } + + api.ResponseOK(c, "", nil) +} + +func EndStress(c *gin.Context) { + + if !StressStatus.IsStressed { + log.Printf("Stress testing has not started yet") + api.Response(c, http.StatusInternalServerError, 500, "stress testing has not yet started", nil) + return + } + + Attacker.Stop() + TravelServiceMetrics.Close() + TravelPlanServiceMetrics.Close() + StressStatus.IsStressed = false + StressStatus.TravelPlanServiceTps = 0 + StressStatus.TravelServiceTps = 0 + + Attacker = vegeta.NewAttacker() + + api.ResponseOK(c, "", api.Data{ + "travel-service-report": api.StressReport{ + MeanLatency: float64(TravelServiceMetrics.Latencies.Mean) / 1000000000, + RequestNum: int(TravelServiceMetrics.Requests), + RequestRate: TravelServiceMetrics.Rate, + Throughput: TravelServiceMetrics.Throughput, + SuccessRate: TravelServiceMetrics.Success, + }, + "travel-plan-service-report": api.StressReport{ + MeanLatency: float64(TravelPlanServiceMetrics.Latencies.Mean) / 1000000000, + RequestNum: int(TravelPlanServiceMetrics.Requests), + RequestRate: TravelPlanServiceMetrics.Rate, + Throughput: TravelPlanServiceMetrics.Throughput, + SuccessRate: TravelPlanServiceMetrics.Success, + }, + }) + + TravelServiceMetrics = vegeta.Metrics{} + TravelPlanServiceMetrics = vegeta.Metrics{} +} + +func GetStressStatus(c *gin.Context) { + api.ResponseOK(c, "", api.Data{ + "stressStatus": StressStatus, + }) +} diff --git a/chaos/backend/internal/service/stress_service_test.go b/chaos/backend/internal/service/stress_service_test.go new file mode 100644 index 0000000000000000000000000000000000000000..2353e141ab0d643118cc975b520694ffffbdcd0f --- /dev/null +++ b/chaos/backend/internal/service/stress_service_test.go @@ -0,0 +1,61 @@ +package service + +import ( + "fmt" + "net/http" + "testing" + "time" + + vegeta "github.com/tsenart/vegeta/v12/lib" +) + +var TestMetrics vegeta.Metrics +var testAddr = "http://192.168.1.6:32677" + +func TestStartAttack(t *testing.T) { + var TestAttacker = vegeta.NewAttacker() + + header := http.Header{} + header.Add("Accept", "application/json, text/javascript, */*; q=0.01") + header.Add("Content-Type", "application/json") + date := time.Now().Format("2006-01-02") + body := []byte(`{"startPlace":"Shang Hai","endPlace":"Su Zhou","departureTime":"` + date + ` 00:00:00"}`) + travelServiceUrl := testAddr + "/api/v1/travelservice/trips/left" + testTargeter := vegeta.NewStaticTargeter(vegeta.Target{ + Method: "POST", + Header: header, + Body: body, + URL: travelServiceUrl, + }) + + rate := vegeta.Rate{Freq: 1, Per: time.Second} + duration := 3 * time.Second // duration=0时持续压测 + fmt.Println("start attack") + for res := range TestAttacker.Attack(testTargeter, rate, duration, "Big Bang!") { + TestMetrics.Add(res) + } + TestMetrics.Close() + fmt.Printf("1st metrics: %+v\n\n", TestMetrics) + + var tmpMetrics vegeta.Metrics + TestMetrics = tmpMetrics + fmt.Printf("reset metrics: %+v\n\n", TestMetrics) + + TestAttacker = vegeta.NewAttacker() + rate2 := vegeta.Rate{Freq: 10, Per: time.Second} + travelPlanServiceUrl := testAddr + "/api/v1/travelservice/travelPlan/cheapest" + testTargeter2 := vegeta.NewStaticTargeter(vegeta.Target{ + Method: "POST", + Header: header, + Body: body, + URL: travelPlanServiceUrl, + }) + duration2 := 3 * time.Second // duration=0时持续压测 + fmt.Println("start attack 2") + for res := range TestAttacker.Attack(testTargeter2, rate2, duration2, "Big Bang!") { + TestMetrics.Add(res) + } + TestMetrics.Close() + fmt.Printf("2nd metrics: %+v\n\n", TestMetrics) + +} diff --git a/chaos/backend/main.go b/chaos/backend/main.go index f81d2d545795576f2f15ef44458f39b82aec75e5..4c82679588971ae8217553e4a758e08badd95b46 100644 --- a/chaos/backend/main.go +++ b/chaos/backend/main.go @@ -18,6 +18,7 @@ func main() { unstructuredChaosFilePath := flag.String("unstructured_chaos_file_path", "config/unstructured_chaos.gotmpl", "set unstructured chaos_template file path") skywalkingUIAddr := flag.String("skywalkingUIAddr", "http://skywalking.train-ticket:12800/graphql", "skywalkingUIAddr describe the address of your skywalking UI") prometheusUIAddr := flag.String("prometheusUIAddr", "http://prometheus-k8s.monitoring:9090/", "prometheusUIAddr describe the address of your prometheus UI") + trainTicketUIAddr := flag.String("trainTicketUIAddr", "http://ts-gateway-service.train-ticket:18888", "trainTicketUIAddr describe the address of your train-ticket UI") metricSource := flag.String("metricSource", "skywalking", "use skywalking or prometheus to show request latency and cpm metric, default skywalking") enableDebug := flag.Bool("debug", false, "enable debug log") flag.Parse() @@ -27,6 +28,7 @@ func main() { *kubeConfigPath, *skywalkingUIAddr, *prometheusUIAddr, + *trainTicketUIAddr, *chaosTemplateFilePath, *unstructuredChaosFilePath, *metricSource, diff --git a/chaos/front/Dockerfile b/chaos/front/Dockerfile index 2b9649be26a3a9a2594b36417102239aa1023353..7271f09c4d18207615b3f81e4d0b8f10b9d345d6 100644 --- a/chaos/front/Dockerfile +++ b/chaos/front/Dockerfile @@ -1,5 +1,6 @@ FROM node:lts-alpine as build-stage WORKDIR /app/ +RUN npm config set registry https://registry.npmmirror.com/ COPY package*.json ./ RUN npm install COPY . . diff --git a/chaos/front/components.d.ts b/chaos/front/components.d.ts index f8bd205c883a58aab281322a5217516737134ba5..ea5099f1cbce528f5f7d758a296cfde5a9e2746f 100644 --- a/chaos/front/components.d.ts +++ b/chaos/front/components.d.ts @@ -7,6 +7,7 @@ export {} declare module 'vue' { export interface GlobalComponents { + AFormItemRest: typeof import('ant-design-vue/es')['FormItemRest'] HelloWorld: typeof import('./src/components/HelloWorld.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] diff --git a/chaos/front/src/api/tps/index.ts b/chaos/front/src/api/tps/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..8a689470f93fc68fff302f742c363df1452e9c16 --- /dev/null +++ b/chaos/front/src/api/tps/index.ts @@ -0,0 +1,33 @@ + + +import request from "@/utils/axios"; + + +enum Api { + START_TPS = '/tps/start', + GET_TPS_STATUS = '/tps/status', + STOP_STATUS = '/tps/stop', +} + +// 启动压测 +export function startTpsApi(params: any) { + return request({ + url: Api.START_TPS, + method: 'post', + data:params + }); +} +// 查看当前压测状态 +export function getTpsStatusApi() { + return request({ + url: Api.GET_TPS_STATUS, + method: 'get', + }); +} +// 暂停压测 +export function stopTpsApi() { + return request({ + url: Api.STOP_STATUS, + method: 'get', + }); +} diff --git a/chaos/front/src/store/tps/index.ts b/chaos/front/src/store/tps/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..0ddb4e814a3e6cbaca2e8b1d6608d5a05e750849 --- /dev/null +++ b/chaos/front/src/store/tps/index.ts @@ -0,0 +1,30 @@ +// InstanceModule.ts +import { defineStore } from "pinia"; +interface TpsState { + isStressed: boolean | null; + travelServiceTps: any | null; + travelPlanServiceTps: any | null; +} +interface TpsModuleState { + tps: TpsState; +} +export const useTpsModuleStore = defineStore({ + id: "tps-module", + state: (): TpsModuleState => ({ + tps: { + isStressed: null, + travelServiceTps: null, + travelPlanServiceTps: null, + }, + }), + getters: { + getTps(state): any { + return state.tps; + }, + }, + actions: { + setTps(value: any) { + this.tps = value; + }, + }, +}); diff --git a/chaos/front/src/view/fault-injection/Index.vue b/chaos/front/src/view/fault-injection/Index.vue index 6aa68ec0d73240905aa8e39039721221d64427f9..279cf53a93bb2a8454307741e22cd7b6f661f539 100644 --- a/chaos/front/src/view/fault-injection/Index.vue +++ b/chaos/front/src/view/fault-injection/Index.vue @@ -1,45 +1,86 @@ - - - + + + - - + + + \ No newline at end of file + diff --git a/chaos/front/src/view/fault-injection/components/Dagre.vue b/chaos/front/src/view/fault-injection/components/Dagre.vue index a661391d920a0818a07caddbd994fb6e9f0a87c3..66df47006ad8f7a274147d46eb1ebda9bfdbe827 100644 --- a/chaos/front/src/view/fault-injection/components/Dagre.vue +++ b/chaos/front/src/view/fault-injection/components/Dagre.vue @@ -38,7 +38,7 @@ import injectedNodeSvg from "../../../assets/topology-node/injectedNode.svg"; import injectingNodeSvg from "../../../assets/topology-node/injectingNode.svg"; import runningNodeSvg from "../../../assets/topology-node/runningNode.svg"; import { selectOptions, getData, remainingData } from "./dataJson"; -import { Card, Select, Button } from "ant-design-vue"; +import { Card, Select, Button, notification } from "ant-design-vue"; import { ref } from "vue"; import _ from "lodash"; import { InstanceItem } from "@/type/instances"; @@ -250,8 +250,8 @@ export default { .style("stroke", "none"); inner.selectAll("g.node tspan").style("fill", "#555555"); - var svgWidth = +svg.node().getBoundingClientRect().width; - var svgHeight = +svg.node().getBoundingClientRect().height; + var svgWidth = +svg.node()?.getBoundingClientRect().width; + var svgHeight = +svg.node()?.getBoundingClientRect().height; var zoomScale = Math.min( svgWidth / g.graph().width, @@ -278,8 +278,8 @@ export default { .style("stroke-width", 2); inner.selectAll("g.node text").attr("y", this.nodeHeight / 2 + 10); - var svgWidth = +container.node().getBoundingClientRect().width; - var svgHeight = +container.node().getBoundingClientRect().height; + var svgWidth = +container.node()?.getBoundingClientRect().width; + var svgHeight = +container.node()?.getBoundingClientRect().height; var zoomScale = 0.9 * Math.min(svgWidth / g.graph().width, svgHeight / g.graph().height); diff --git a/chaos/front/src/view/fault-injection/components/ScenceDetail.vue b/chaos/front/src/view/fault-injection/components/ScenceDetail.vue index 81dd58bd838309ef7a444e240e112f798efcf7a5..a29f2bbd9b327485dafc95c9b62842297a9ff1a6 100644 --- a/chaos/front/src/view/fault-injection/components/ScenceDetail.vue +++ b/chaos/front/src/view/fault-injection/components/ScenceDetail.vue @@ -122,8 +122,8 @@ export default defineComponent({ }; const formatTimestampToHHMM = (timestamp: number) => { const date = new Date(timestamp); - console.log(timestamp); - console.log(date); + // console.log(timestamp); + // console.log(date); var hours = date.getHours().toString().padStart(2, "0"); var minutes = date.getMinutes().toString().padStart(2, "0"); var formattedTime = hours + ":" + minutes; @@ -173,11 +173,10 @@ export default defineComponent({ return formatTimestampToHHMM(parsedTimestamp); } ); - - const sortedValuesArray = sortedLatenciesArray.map(([, value]) => - props.tabInfo?.key !== "throughputs" + const sortedValuesArray = sortedLatenciesArray.map(([, value]) =>{ + return props.tabInfo?.key !== "throughputs" ? (value / 1000000).toFixed(2) - : value.toFixed(2) + : value.toFixed(2)} ); xAxisData.value = sortedTimestampsArray; const yAxisItem = { diff --git a/chaos/front/src/view/fault-injection/components/TabNodeInfo.vue b/chaos/front/src/view/fault-injection/components/TabNodeInfo.vue new file mode 100644 index 0000000000000000000000000000000000000000..e61c784cbd804d655bdd14f0592903e125194882 --- /dev/null +++ b/chaos/front/src/view/fault-injection/components/TabNodeInfo.vue @@ -0,0 +1,46 @@ + + + (activeKey = key)" + > + + + + + + diff --git a/chaos/front/src/view/fault-injection/components/TopologyDetail.vue b/chaos/front/src/view/fault-injection/components/TopologyDetail.vue index eff5d6001752ee774071d6d982fbd1833c75c062..3df2ea63e12c251ad007774b0869613fae1eedcf 100644 --- a/chaos/front/src/view/fault-injection/components/TopologyDetail.vue +++ b/chaos/front/src/view/fault-injection/components/TopologyDetail.vue @@ -1,10 +1,6 @@ - + + - {{ injectedChaos.params[0].value }} + {{ injectedChaos?.params[0]?.value }} {{ injectedChaos.describe }} - {{ selectedChaosNote }} + {{ + selectedChaosNote + }} {{ getInstanceStatusDescribe(injectedChaos.status) }} - 解除故障 + 解除故障 - {{ selectedChaosNote }} + {{ + selectedChaosNote + }} 注入故障 - + + diff --git a/chaos/manifests/deploy/2chaos-backend-deploy.yaml b/chaos/manifests/deploy/2chaos-backend-deploy.yaml index ecc03f6fb299ea82b6b9390e0d82921a9fca44b7..c064f7af4350ba0a66ed35af52160116cb393824 100644 --- a/chaos/manifests/deploy/2chaos-backend-deploy.yaml +++ b/chaos/manifests/deploy/2chaos-backend-deploy.yaml @@ -19,25 +19,26 @@ spec: spec: serviceAccount: chaos-backend containers: - - name: chaos-backend - command: - - /app/chaos-backend - - --authType=serviceAccount - - --skywalkingUIAddr=http://skywalking.train-ticket:12800/graphql - - --prometheusUIAddr=http://prometheus-k8s.monitoring:9090 - - --metricSource=skywalking - image: docker.io/kindlingproject/chaos-backend:latest - imagePullPolicy: IfNotPresent - ports: - - name: http - containerPort: 8080 - protocol: TCP - volumeMounts: - - name: chaos-backend-config - mountPath: /app/config/chaos_template.yaml - subPath: chaos_template.yaml - volumes: + - name: chaos-backend + command: + - /app/chaos-backend + - --authType=serviceAccount + - --skywalkingUIAddr=http://skywalking.train-ticket:12800/graphql + - --prometheusUIAddr=http://prometheus-k8s.monitoring:9090 + - --trainTicketUIAddr=http://ts-gateway-service.train-ticket:18888 + - --metricSource=skywalking + image: docker.io/kindlingproject/chaos-backend:latest + imagePullPolicy: IfNotPresent + ports: + - name: http + containerPort: 8080 + protocol: TCP + volumeMounts: - name: chaos-backend-config - configMap: - name: chaos-backend-config - defaultMode: 420 \ No newline at end of file + mountPath: /app/config/chaos_template.yaml + subPath: chaos_template.yaml + volumes: + - name: chaos-backend-config + configMap: + name: chaos-backend-config + defaultMode: 420 diff --git a/chaos/manifests/deploy/4chaos-front-cfg.yaml b/chaos/manifests/deploy/4chaos-front-cfg.yaml index 1c92cc3490083177badfc92db60beb4a232b84fd..c3a54df3b4b3527f2d4a586f767963a629df584e 100644 --- a/chaos/manifests/deploy/4chaos-front-cfg.yaml +++ b/chaos/manifests/deploy/4chaos-front-cfg.yaml @@ -23,7 +23,7 @@ data: } location /api { - proxy_pass http://chaos-backend-svc.kindling:8080; + proxy_pass http://chaos-backend-svc:8080; } #error_page 404 /404.html;