├── .dockerignore ├── .github └── workflows │ └── docker-image.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── cmd └── main.go ├── craw.sh ├── go.mod ├── go.sum ├── internal ├── app │ ├── crawlhighcpustack.go │ ├── handler │ │ └── grafana │ │ │ ├── alerthookhandler.go │ │ │ └── alertmodel.go │ ├── nodelock │ │ ├── nodelocker.go │ │ └── nodelockmanager.go │ └── stackstorage │ │ ├── filestackstorage.go │ │ └── stackstorage.go ├── defaultvalue.go └── util │ └── util.go └── stacks └── .gitkeep /.dockerignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | .idea 3 | .gitignore 4 | Makefile 5 | README.md -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - "v*" 9 | 10 | jobs: 11 | 12 | build: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - name: Set up Go 18 | uses: actions/setup-go@v2 19 | with: 20 | go-version: 1.17 21 | 22 | - name: Build 23 | run: go build -o jdd cmd/main.go 24 | 25 | - name: Generate Dockerfile 26 | run: | 27 | echo 'FROM ubuntu:focal' >> Dockerfile 28 | echo 'WORKDIR /app' >> Dockerfile 29 | echo 'COPY ./craw.sh .' >> Dockerfile 30 | echo 'RUN apt update && apt install -y tzdata --no-install-recommends && rm -rf /var/lib/apt/lists/*' >> Dockerfile 31 | echo 'COPY ./jdd .' >> Dockerfile 32 | echo 'CMD ["./jdd"]' >> Dockerfile 33 | 34 | - name: Docker Login 35 | uses: docker/login-action@v1.10.0 36 | with: 37 | username: ${{ secrets.DOCKER_USERNAME }} 38 | password: ${{ secrets.DOCKER_PASSWORD }} 39 | 40 | - name: Get the version 41 | id: get_version 42 | run: | 43 | VERSION=${GITHUB_REF#refs/tags/} 44 | if [[ ${GITHUB_REF} == "refs/heads/master" ]]; then 45 | VERSION=latest 46 | fi 47 | echo ::set-output name=VERSION::${VERSION} 48 | 49 | - name: Build and push Docker images 50 | uses: docker/build-push-action@v2.7.0 51 | with: 52 | push: true 53 | tags: majian159/java-debug-daemon:${{ steps.get_version.outputs.VERSION }} 54 | context: . 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | .idea 25 | .DS_Store -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # pkg cache 2 | FROM golang:1.17-alpine as go_dep 3 | WORKDIR /source 4 | COPY go.* ./ 5 | RUN go mod download 6 | 7 | # build 8 | FROM golang:1.17-alpine as builder 9 | WORKDIR /source 10 | COPY --from=go_dep /go /go 11 | COPY . . 12 | 13 | RUN go build -o target/jdd cmd/main.go 14 | RUN cp craw.sh target/ \ 15 | && chmod +x target/craw.sh \ 16 | && mkdir target/stacks 17 | 18 | # main 19 | FROM ubuntu:xenial 20 | WORKDIR /app 21 | RUN apt update && apt install -y tzdata --no-install-recommends && rm -rf /var/lib/apt/lists/* 22 | COPY --from=builder /source/target . 23 | CMD [ "./jdd" ] 24 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | IMAGE?="majian159/java-debug-daemon" 2 | GOOS?=$(shell uname -s) 3 | override GOOS:=$(shell echo ${GOOS} | tr '[A-Z]' '[a-z]') 4 | TARGET?="jdd-${GOOS}" 5 | 6 | build: 7 | echo ${GOOS} 8 | GOOS=${GOOS} go build -o ${TARGET} cmd/main.go 9 | docker: 10 | make build GOOS=linux 11 | docker build . -t ${IMAGE} 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java高CPU自动抓取堆栈信息 2 | 利用了 Grafana 的告警机制,配合阿里的 arthas,来完成高CPU使用率线程的堆栈抓取。 3 | 整体流程如下: 4 | 1. 为 Grafana 添加 webhook 类型的告警通知渠道,地址为该程序的 url(默认的hooks路径为 /hooks)。 5 | 2. 配置Grafana图表,并设置告警阈值 6 | 3. 当 webhook 触发时,程序会自动将 craw.sh 脚本拷贝到对应 Pod 的容器中并执行。 7 | 4. 程序将 stdout 保存到本地文件。 8 | 9 | ## 效果预览 10 | ![](https://cdn.jsdelivr.net/gh/majian159/blogs@master/images/2020_04_27_15_53_bH3y0o%20.png) 11 | ![](https://cdn.jsdelivr.net/gh/majian159/blogs@master/images/2020_04_27_15_54_XrXVpk%20.png) 12 | 13 | ## 默认行为 14 | - 每 node 同时运行执行数为10 15 | 可以在 `./internal/defaultvalue.go` 中更改 16 | ```go 17 | var defaultNodeLockManager = nodelock.NewLockManager(10) 18 | ``` 19 | - 默认使用集群内的Master配置 20 | 可以在 `./internal/defaultvalue.go` 中更改 21 | ```go 22 | func DefaultKubernetesClient(){} 23 | 24 | // default 25 | func getConfigByInCluster(){} 26 | 27 | func getConfigByOutOfCluster(){} 28 | ``` 29 | - 默认使用并实现了一个基于本地文件的堆栈存储器, 路径位于工作路径下的 `stacks`中 30 | 可以在 `./internal/defaultvalue.go` 中更改 31 | ```go 32 | func GetDefaultNodeLockManager(){} 33 | ``` 34 | - 默认取最繁忙的前50个线程的堆栈信息 (可在 `craw.sh` 中修改) 35 | - 采集样本时间为2秒 (可在 `craw.sh` 中修改) 36 | 37 | ## 如何使用 38 | ### Docker Image 39 | [majian159/java-debug-daemon](https://hub.docker.com/r/majian159/java-debug-daemon) 40 | 41 | ### 为 Grafana 新建一个通知频道 42 | ![](https://cdn.jsdelivr.net/gh/majian159/blogs@master/images/2020_04_27_15_08_ID8XfL%20.png) 43 | #### 注意点 44 | 1. 需要打开 Send reminders, 不然 Grafana 默认在触发告警后一直没有解决不会重复发送告警 45 | 2. Send reminder every 可以控制最快多久告警一次 46 | 47 | ### 为 Grafana 新建一个告警图表 48 | 如果嫌麻烦可以直接导入以下配置, 在自行更改 49 | ```json 50 | { 51 | "datasource": "prometheus", 52 | "alert": { 53 | "alertRuleTags": {}, 54 | "conditions": [ 55 | { 56 | "evaluator": { 57 | "params": [ 58 | 1 59 | ], 60 | "type": "gt" 61 | }, 62 | "operator": { 63 | "type": "and" 64 | }, 65 | "query": { 66 | "params": [ 67 | "A", 68 | "5m", 69 | "now" 70 | ] 71 | }, 72 | "reducer": { 73 | "params": [], 74 | "type": "last" 75 | }, 76 | "type": "query" 77 | } 78 | ], 79 | "executionErrorState": "keep_state", 80 | "for": "10s", 81 | "frequency": "30s", 82 | "handler": 1, 83 | "name": "Pod 高CPU堆栈抓取", 84 | "noDataState": "no_data", 85 | "notifications": [ 86 | { 87 | "uid": "AGOJRCqWz" 88 | } 89 | ] 90 | }, 91 | "aliasColors": {}, 92 | "bars": false, 93 | "dashLength": 10, 94 | "dashes": false, 95 | "fill": 1, 96 | "fillGradient": 0, 97 | "gridPos": { 98 | "h": 9, 99 | "w": 24, 100 | "x": 0, 101 | "y": 2 102 | }, 103 | "hiddenSeries": false, 104 | "id": 14, 105 | "legend": { 106 | "alignAsTable": true, 107 | "avg": true, 108 | "current": true, 109 | "max": true, 110 | "min": false, 111 | "rightSide": true, 112 | "show": true, 113 | "total": false, 114 | "values": true 115 | }, 116 | "lines": true, 117 | "linewidth": 1, 118 | "nullPointMode": "null", 119 | "options": { 120 | "dataLinks": [] 121 | }, 122 | "percentage": false, 123 | "pointradius": 2, 124 | "points": false, 125 | "renderer": "flot", 126 | "seriesOverrides": [], 127 | "spaceLength": 10, 128 | "stack": false, 129 | "steppedLine": false, 130 | "targets": [ 131 | { 132 | "expr": "container_memory_working_set_bytes{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\", image!=\"\", container!=\"POD\"}* on (namespace, pod) group_left(node) max by(namespace, pod, node, container) (kube_pod_info)", 133 | "legendFormat": "{{node}} - {{namespace}} - {{pod}} - {{container}}", 134 | "refId": "A" 135 | } 136 | ], 137 | "thresholds": [ 138 | { 139 | "colorMode": "critical", 140 | "fill": true, 141 | "line": true, 142 | "op": "gt", 143 | "value": 1 144 | } 145 | ], 146 | "timeFrom": null, 147 | "timeRegions": [], 148 | "timeShift": null, 149 | "title": "Pod CPU", 150 | "tooltip": { 151 | "shared": true, 152 | "sort": 0, 153 | "value_type": "individual" 154 | }, 155 | "type": "graph", 156 | "xaxis": { 157 | "buckets": null, 158 | "mode": "time", 159 | "name": null, 160 | "show": true, 161 | "values": [] 162 | }, 163 | "yaxes": [ 164 | { 165 | "format": "short", 166 | "label": null, 167 | "logBase": 1, 168 | "max": null, 169 | "min": null, 170 | "show": true 171 | }, 172 | { 173 | "format": "short", 174 | "label": null, 175 | "logBase": 1, 176 | "max": null, 177 | "min": null, 178 | "show": true 179 | } 180 | ], 181 | "yaxis": { 182 | "align": false, 183 | "alignLevel": null 184 | } 185 | } 186 | ``` 187 | 188 | #### Queries配置 189 | Metrics 中填写 190 | ```text 191 | container_memory_working_set_bytes{job="kubelet", metrics_path="/metrics/cadvisor", image!="", container!="POD"} * on (namespace, pod) group_left(node) max by(namespace, pod, node, container) (kube_pod_info) 192 | ``` 193 | Legend 中填写 194 | ```text 195 | {{node}} - {{namespace}} - {{pod}} - {{container}} 196 | ``` 197 | 198 | 配置完如下: 199 | ![](https://cdn.jsdelivr.net/gh/majian159/blogs@master/images/2020_04_27_15_23_l95PjW%20.jpg) 200 | 201 | #### Alert配置 202 | **IS ABOVE** 203 | CPU使用值,这边配置的是超过1核CPU就报警, 可以根据需要自己调节 204 | **Evaluate every** 205 | 每多久计算一次 206 | **For** 207 | Pedding时间 208 | 209 | 配置完应该如下: 210 | ![](https://cdn.jsdelivr.net/gh/majian159/blogs@master/images/2020_04_27_15_26_xOjjLk%20.jpg) 211 | 212 | ## 构建 213 | ### 二进制 214 | ```sh 215 | # 为当前系统平台构建 216 | make 217 | 218 | # 指定目标系统, GOOS: linux darwin window freebsd 219 | make GOOS=linux 220 | 221 | ``` 222 | 223 | ### Docker镜像 224 | ```sh 225 | make docker 226 | 227 | # 自定义镜像tag 228 | make docker IMAGE=test 229 | ``` -------------------------------------------------------------------------------- /cmd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "javaDebugDaemon/internal/app/handler/grafana" 5 | "net/http" 6 | 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | func main() { 11 | handler, err := grafana.NewAlertHookHandler() 12 | if err != nil { 13 | panic(err) 14 | } 15 | 16 | router := gin.Default() 17 | 18 | router.POST("/hooks", handler) 19 | router.StaticFS("/", http.Dir("stacks")) 20 | err = router.Run() 21 | 22 | if err != nil { 23 | panic(err) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /craw.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 指定最忙的前N个线程并打印堆栈 3 | max_thread_count=50 4 | # 指定cpu占比统计的采样间隔,单位为毫秒 5 | interval=2000 6 | # arthas的下载地址 7 | arthas_boot_download_url="https://arthas.gitee.io/arthas-boot.jar" 8 | 9 | # jps命令不存在代表非java应用或没有jdk相关工具 10 | if [ ! "$(type jps)" ]; then 11 | exit 0 12 | fi 13 | 14 | cd ~/ || exit 15 | 16 | # arthas-boot.jar 不存在则下载 17 | if [ ! -f "arthas-boot.jar" ]; then 18 | curl -sO "$arthas_boot_download_url" 19 | fi 20 | 21 | unset JAVA_TOOL_OPTIONS 22 | # 处理pid 1非java应用的情况 23 | pid=$(jps -l | grep -v "Jps" | grep -v "arthas-boot.jar" | grep -v "process information unavailable" | awk '{print $1}') 24 | 25 | # 获取繁忙的前20个线程 26 | java -jar arthas-boot.jar "${pid}" -c "thread -n ${max_thread_count} -i ${interval}" 27 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module javaDebugDaemon 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.7.7 7 | github.com/golang/protobuf v1.4.0 // indirect 8 | golang.org/x/sys v0.2.0 // indirect 9 | k8s.io/api v0.17.0 10 | k8s.io/client-go v0.17.0 11 | ) 12 | 13 | require ( 14 | github.com/davecgh/go-spew v1.1.1 // indirect 15 | github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 // indirect 16 | github.com/gin-contrib/sse v0.1.0 // indirect 17 | github.com/go-playground/locales v0.13.0 // indirect 18 | github.com/go-playground/universal-translator v0.17.0 // indirect 19 | github.com/go-playground/validator/v10 v10.4.1 // indirect 20 | github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d // indirect 21 | github.com/google/gofuzz v1.0.0 // indirect 22 | github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d // indirect 23 | github.com/imdario/mergo v0.3.5 // indirect 24 | github.com/json-iterator/go v1.1.9 // indirect 25 | github.com/leodido/go-urn v1.2.0 // indirect 26 | github.com/mattn/go-isatty v0.0.12 // indirect 27 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 28 | github.com/modern-go/reflect2 v1.0.1 // indirect 29 | github.com/spf13/pflag v1.0.5 // indirect 30 | github.com/ugorji/go/codec v1.1.7 // indirect 31 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect 32 | golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 // indirect 33 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect 34 | golang.org/x/text v0.3.2 // indirect 35 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect 36 | google.golang.org/appengine v1.5.0 // indirect 37 | google.golang.org/protobuf v1.21.0 // indirect 38 | gopkg.in/inf.v0 v0.9.1 // indirect 39 | gopkg.in/yaml.v2 v2.2.8 // indirect 40 | k8s.io/apimachinery v0.17.0 // indirect 41 | k8s.io/klog v1.0.0 // indirect 42 | k8s.io/utils v0.0.0-20191114184206-e782cd3c129f // indirect 43 | sigs.k8s.io/yaml v1.1.0 // indirect 44 | ) 45 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 4 | github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= 5 | github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= 6 | github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= 7 | github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= 8 | github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= 9 | github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= 10 | github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= 11 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 12 | github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= 13 | github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= 14 | github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= 15 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 16 | github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 17 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 18 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 19 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 20 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 21 | github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 h1:cenwrSVm+Z7QLSV/BsnenAOcDXdX4cMv4wP0B/5QbPg= 22 | github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= 23 | github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e h1:p1yVGRW3nmb85p1Sh1ZJSDm4A4iKLS5QNbvUHMgGu/M= 24 | github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= 25 | github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= 26 | github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= 27 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 28 | github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 29 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 30 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 31 | github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs= 32 | github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= 33 | github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= 34 | github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= 35 | github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= 36 | github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= 37 | github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= 38 | github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= 39 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 40 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= 41 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 42 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 43 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 44 | github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= 45 | github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= 46 | github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I= 47 | github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= 48 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 49 | github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 50 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 51 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 52 | github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 53 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 54 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 55 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 56 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 57 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 58 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 59 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 60 | github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ= 61 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 62 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 63 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 64 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 65 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 66 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 67 | github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= 68 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 69 | github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= 70 | github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= 71 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 72 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 73 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 74 | github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 75 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 76 | github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d h1:7XGaL1e6bYS1yIonGp9761ExpPPV1ui0SAC59Yube9k= 77 | github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= 78 | github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= 79 | github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= 80 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 81 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 82 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 83 | github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q= 84 | github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= 85 | github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 86 | github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 87 | github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= 88 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 89 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 90 | github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= 91 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 92 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 93 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 94 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 95 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 96 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 97 | github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 98 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 99 | github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= 100 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 101 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 102 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 103 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 104 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 105 | github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 106 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 107 | github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= 108 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 109 | github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= 110 | github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= 111 | github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 112 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 113 | github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 114 | github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= 115 | github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= 116 | github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= 117 | github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 118 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 119 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 120 | github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= 121 | github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 122 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 123 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 124 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 125 | github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 126 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 127 | github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= 128 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 129 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 130 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 131 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 132 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 133 | golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 134 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 135 | golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 136 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= 137 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 138 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 139 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 140 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 141 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 142 | golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 143 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 144 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 145 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 146 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 147 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 148 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 149 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 150 | golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI= 151 | golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 152 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 153 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 154 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= 155 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 156 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 157 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 158 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 159 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 160 | golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 161 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 162 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 163 | golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 164 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 165 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 166 | golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 167 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 168 | golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= 169 | golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 170 | golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 171 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 172 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 173 | golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= 174 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 175 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 176 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= 177 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 178 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 179 | golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 180 | golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 181 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 182 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 183 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 184 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 185 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 186 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 187 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 188 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 189 | google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c= 190 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 191 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 192 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 193 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 194 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 195 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 196 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 197 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 198 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 199 | google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw= 200 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 201 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 202 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 203 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 204 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 205 | gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= 206 | gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= 207 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 208 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 209 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 210 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 211 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 212 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 213 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 214 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 215 | k8s.io/api v0.17.0 h1:H9d/lw+VkZKEVIUc8F3wgiQ+FUXTTr21M87jXLU7yqM= 216 | k8s.io/api v0.17.0/go.mod h1:npsyOePkeP0CPwyGfXDHxvypiYMJxBWAMpQxCaJ4ZxI= 217 | k8s.io/apimachinery v0.17.0 h1:xRBnuie9rXcPxUkDizUsGvPf1cnlZCFu210op7J7LJo= 218 | k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg= 219 | k8s.io/client-go v0.17.0 h1:8QOGvUGdqDMFrm9sD6IUFl256BcffynGoe80sxgTEDg= 220 | k8s.io/client-go v0.17.0/go.mod h1:TYgR6EUHs6k45hb6KWjVD6jFZvJV4gHDikv/It0xz+k= 221 | k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= 222 | k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= 223 | k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= 224 | k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= 225 | k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= 226 | k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= 227 | k8s.io/utils v0.0.0-20191114184206-e782cd3c129f h1:GiPwtSzdP43eI1hpPCbROQCCIgCuiMMNF8YUVLF3vJo= 228 | k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= 229 | sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= 230 | sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= 231 | sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= 232 | -------------------------------------------------------------------------------- /internal/app/crawlhighcpustack.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "javaDebugDaemon/internal/util" 7 | "os" 8 | "strings" 9 | ) 10 | 11 | type CrawlContext struct { 12 | Namespace string 13 | PodName string 14 | ContainerName string 15 | Node string 16 | } 17 | 18 | const shellFile = "craw.sh" 19 | const targetFile = "/root/craw.sh" 20 | 21 | func CrawlString(client util.KubernetesClient, context CrawlContext) (string, error) { 22 | data, err := crawl(client, context) 23 | 24 | if err != nil { 25 | return "", err 26 | } 27 | 28 | str := string(data) 29 | 30 | const startKey = "| plaintext" 31 | startIndex := strings.Index(str, startKey) + len(startKey) + 2 32 | 33 | str = str[startIndex:] 34 | 35 | const endKey = "[arthas@" 36 | endIndex := strings.LastIndex(str, endKey) - 2 37 | str = str[:endIndex] 38 | 39 | return str, nil 40 | } 41 | 42 | func crawl(client util.KubernetesClient, context CrawlContext) (stdoutBytes []byte, err error) { 43 | namespace, podName, containerName, node := context.Namespace, context.PodName, context.ContainerName, context.Node 44 | _ = node 45 | 46 | commands := []string{"/bin/bash", "-c"} 47 | 48 | commands = append(commands, fmt.Sprintf("cp -f /dev/stdin %[1]s;chmod +x %[1]s;%[1]s", targetFile)) 49 | 50 | scriptData, err := os.ReadFile(shellFile) 51 | if err != nil { 52 | return nil, fmt.Errorf("read file error: %v", err) 53 | } 54 | 55 | stdin := bytes.NewReader(scriptData) 56 | var stdout bytes.Buffer 57 | stderr, err := client.Exec(namespace, podName, containerName, commands, stdin, &stdout) 58 | 59 | if len(stderr) != 0 && !strings.HasPrefix(string(stderr), "Picked up JAVA_TOOL_OPTIONS:") { 60 | return nil, fmt.Errorf("STDERR: " + string(stderr)) 61 | } 62 | 63 | if err != nil { 64 | return nil, err 65 | } 66 | 67 | return stdout.Bytes(), nil 68 | } 69 | -------------------------------------------------------------------------------- /internal/app/handler/grafana/alerthookhandler.go: -------------------------------------------------------------------------------- 1 | package grafana 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io" 7 | "javaDebugDaemon/internal" 8 | "javaDebugDaemon/internal/app" 9 | "javaDebugDaemon/internal/app/stackstorage" 10 | "javaDebugDaemon/internal/util" 11 | "log" 12 | "net/http" 13 | 14 | "github.com/gin-gonic/gin" 15 | ) 16 | 17 | var kubernetesClient *util.KubernetesClient 18 | var stackStorage stackstorage.StackStorage = stackstorage.NewFileStackStorage() 19 | 20 | func NewAlertHookHandler() (func(ctx *gin.Context), error) { 21 | client, err := internal.DefaultKubernetesClient() 22 | if err != nil { 23 | return nil, fmt.Errorf("create k8s client error: %v", err) 24 | } 25 | 26 | if client == nil { 27 | log.Printf("get k8s client return nil: %v\n", err) 28 | return nil, fmt.Errorf("k8s client is nil") 29 | } 30 | 31 | kubernetesClient = client 32 | return HookHandler, nil 33 | } 34 | 35 | func HookHandler(c *gin.Context) { 36 | body := c.Request.Body 37 | if body == nil { 38 | c.String(http.StatusBadRequest, "not found body.") 39 | return 40 | } 41 | defer body.Close() 42 | 43 | data, err := io.ReadAll(body) 44 | 45 | if err != nil { 46 | log.Printf("read all error: %v\n", err) 47 | c.String(http.StatusBadRequest, "read body error.") 48 | return 49 | } 50 | 51 | if len(data) <= 0 { 52 | c.String(http.StatusBadRequest, "body is empty.") 53 | return 54 | } 55 | 56 | var model AlertModel 57 | err = json.Unmarshal(data, &model) 58 | 59 | if err != nil { 60 | log.Printf("unmarshal error: %v\n", err) 61 | c.String(http.StatusBadRequest, "unmarshal error") 62 | return 63 | } 64 | 65 | go doHandle(model) 66 | 67 | c.Status(http.StatusAccepted) 68 | } 69 | 70 | func doHandle(model AlertModel) { 71 | // 忽略正常告警 72 | if model.IsOk() { 73 | return 74 | } 75 | 76 | matches := model.EvalMatches 77 | for _, e := range matches { 78 | go doHandleEvalMatch(e) 79 | } 80 | } 81 | 82 | func doHandleEvalMatch(model EvalMatchModel) { 83 | tag := model.Tags 84 | node := tag.Node 85 | 86 | nodeLockManager := *internal.GetDefaultNodeLockManager() 87 | locker := nodeLockManager.GetLock(node) 88 | 89 | locker.Lock() 90 | defer locker.Unlock() 91 | 92 | namespace, podName, containerName := tag.Namespace, tag.Pod, tag.Container 93 | stack, err := app.CrawlString(*kubernetesClient, app.CrawlContext{ 94 | Namespace: namespace, 95 | PodName: podName, 96 | ContainerName: containerName, 97 | Node: node, 98 | }) 99 | 100 | if err != nil { 101 | log.Printf("crawString tag: %v, error: %v\n", tag, err) 102 | return 103 | } 104 | 105 | err = storeStack(stack, model) 106 | 107 | if err != nil { 108 | log.Printf("store stack error: tag:%v, stack:%s, %v\n", tag, stack, err) 109 | } 110 | 111 | } 112 | 113 | func storeStack(stack string, model EvalMatchModel) error { 114 | tags := model.Tags 115 | namespace, podName, containerName, node := tags.Namespace, tags.Pod, tags.Container, tags.Node 116 | err := stackStorage.Store(stackstorage.ContainerStackModel{ 117 | Namespace: namespace, 118 | PodName: podName, 119 | ContainerName: containerName, 120 | Node: node, 121 | Stack: stack, 122 | }) 123 | 124 | return err 125 | } 126 | -------------------------------------------------------------------------------- /internal/app/handler/grafana/alertmodel.go: -------------------------------------------------------------------------------- 1 | package grafana 2 | 3 | type AlertModel struct { 4 | State string 5 | EvalMatches []EvalMatchModel 6 | } 7 | 8 | type EvalMatchModel struct { 9 | Value float64 10 | Tags EvalMatchModelTag 11 | } 12 | type EvalMatchModelTag struct { 13 | Namespace string 14 | Pod string 15 | Container string 16 | Node string 17 | } 18 | 19 | func (m AlertModel) IsOk() bool { 20 | return m.State == "ok" 21 | } 22 | 23 | func (m AlertModel) IsAlerting() bool { 24 | return m.State == "alerting" 25 | } 26 | -------------------------------------------------------------------------------- /internal/app/nodelock/nodelocker.go: -------------------------------------------------------------------------------- 1 | package nodelock 2 | 3 | import "sync" 4 | 5 | type Locker struct { 6 | locks chan int 7 | } 8 | 9 | func (l *Locker) Lock() { 10 | l.locks <- 0 11 | } 12 | 13 | func (l *Locker) Unlock() { 14 | <-l.locks 15 | } 16 | 17 | func NewLocker(permits uint) sync.Locker { 18 | return &Locker{locks: make(chan int, permits)} 19 | } 20 | -------------------------------------------------------------------------------- /internal/app/nodelock/nodelockmanager.go: -------------------------------------------------------------------------------- 1 | package nodelock 2 | 3 | import "sync" 4 | 5 | type LockManager interface { 6 | GetLock(node string) sync.Locker 7 | } 8 | 9 | type DefaultLockManager struct { 10 | permits uint 11 | maps sync.Map 12 | } 13 | 14 | func NewLockManager(permits uint) LockManager { 15 | return DefaultLockManager{permits: permits, maps: sync.Map{}} 16 | } 17 | 18 | func (m DefaultLockManager) GetLock(node string) sync.Locker { 19 | maps := m.maps 20 | 21 | value, ok := maps.Load(node) 22 | 23 | if ok { 24 | return value.(sync.Locker) 25 | } 26 | 27 | var locker sync.Locker 28 | locker = NewLocker(m.permits) 29 | maps.Store(node, locker) 30 | 31 | return locker 32 | } 33 | -------------------------------------------------------------------------------- /internal/app/stackstorage/filestackstorage.go: -------------------------------------------------------------------------------- 1 | package stackstorage 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | "time" 8 | ) 9 | 10 | type FileStackStorage struct { 11 | } 12 | 13 | func NewFileStackStorage() FileStackStorage { 14 | return FileStackStorage{} 15 | } 16 | 17 | func (s FileStackStorage) Store(model ContainerStackModel) error { 18 | now := time.Now() 19 | dirName := filepath.Join("stacks", now.Format("2006-01-02"), model.Namespace) 20 | 21 | err := os.MkdirAll(dirName, os.ModePerm) 22 | 23 | if err != nil { 24 | return fmt.Errorf("mkdir '%s', error:%v", dirName, err) 25 | } 26 | 27 | fileName := fmt.Sprintf("%s-%s-%s.log", model.PodName, model.ContainerName, now.Format("15-04-05")) 28 | 29 | filePath := filepath.Join(dirName, fileName) 30 | 31 | err = os.WriteFile(filePath, []byte(model.Stack), 0644) 32 | 33 | if err != nil { 34 | return fmt.Errorf("write file '%s', error:%v", filePath, err) 35 | } 36 | 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /internal/app/stackstorage/stackstorage.go: -------------------------------------------------------------------------------- 1 | package stackstorage 2 | 3 | type ContainerStackModel struct { 4 | Namespace string 5 | PodName string 6 | ContainerName string 7 | Node string 8 | Stack string 9 | } 10 | 11 | type StackStorage interface { 12 | Store(model ContainerStackModel) error 13 | } 14 | -------------------------------------------------------------------------------- /internal/defaultvalue.go: -------------------------------------------------------------------------------- 1 | package internal 2 | 3 | import ( 4 | "fmt" 5 | "javaDebugDaemon/internal/app/nodelock" 6 | "javaDebugDaemon/internal/app/stackstorage" 7 | "javaDebugDaemon/internal/util" 8 | "k8s.io/client-go/kubernetes" 9 | "k8s.io/client-go/rest" 10 | "k8s.io/client-go/tools/clientcmd" 11 | "os" 12 | "path/filepath" 13 | ) 14 | 15 | var kubernetesClient *util.KubernetesClient 16 | 17 | func DefaultKubernetesClient() (*util.KubernetesClient, error) { 18 | if kubernetesClient != nil { 19 | return kubernetesClient, nil 20 | } 21 | 22 | config, err := getConfigByInCluster() 23 | 24 | if err != nil { 25 | panic(err) 26 | } 27 | 28 | clientSet, err := kubernetes.NewForConfig(config) 29 | 30 | if err != nil { 31 | return nil, fmt.Errorf("new k8s client instance error: %v", err) 32 | } 33 | 34 | kubernetesClient = &util.KubernetesClient{ClientSet: clientSet, Config: config} 35 | return kubernetesClient, nil 36 | } 37 | 38 | func getConfigByInCluster() (*rest.Config, error) { 39 | config, err := rest.InClusterConfig() 40 | if err != nil { 41 | return nil, err 42 | } 43 | return config, nil 44 | } 45 | 46 | func getConfigByOutOfCluster() (*rest.Config, error) { 47 | configFile := filepath.Join(homeDir(), ".kube", "config") 48 | config, err := clientcmd.BuildConfigFromFlags("", configFile) 49 | 50 | if err != nil { 51 | return nil, fmt.Errorf("build config error: %v", err) 52 | } 53 | 54 | return config, nil 55 | } 56 | 57 | func homeDir() string { 58 | if h := os.Getenv("HOME"); h != "" { 59 | return h 60 | } 61 | return os.Getenv("USERPROFILE") // windows 62 | } 63 | 64 | var stackStorage stackstorage.StackStorage = stackstorage.NewFileStackStorage() 65 | 66 | func DefaultStackStorage() stackstorage.StackStorage { 67 | return stackStorage 68 | } 69 | 70 | var defaultNodeLockManager = nodelock.NewLockManager(10) 71 | 72 | func GetDefaultNodeLockManager() *nodelock.LockManager { 73 | return &defaultNodeLockManager 74 | } 75 | -------------------------------------------------------------------------------- /internal/util/util.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "k8s.io/client-go/rest" 8 | "k8s.io/client-go/tools/remotecommand" 9 | 10 | v12 "k8s.io/api/core/v1" 11 | "k8s.io/client-go/kubernetes/scheme" 12 | 13 | "k8s.io/client-go/kubernetes" 14 | ) 15 | 16 | type KubernetesClient struct { 17 | ClientSet *kubernetes.Clientset 18 | Config *rest.Config 19 | } 20 | 21 | func (client KubernetesClient) Exec(namespace, podName, containerName string, command []string, stdin io.Reader, stdout io.Writer) ([]byte, error) { 22 | clientSet, config := client.ClientSet, client.Config 23 | 24 | req := clientSet.CoreV1().RESTClient().Post(). 25 | Resource("pods"). 26 | Name(podName). 27 | Namespace(namespace). 28 | SubResource("exec"). 29 | VersionedParams( 30 | &v12.PodExecOptions{ 31 | Container: containerName, 32 | Command: command, 33 | Stdin: stdin != nil, 34 | Stdout: stdout != nil, 35 | Stderr: true, 36 | TTY: false, 37 | }, scheme.ParameterCodec) 38 | 39 | exec, err := remotecommand.NewSPDYExecutor(config, "POST", req.URL()) 40 | 41 | if err != nil { 42 | return nil, fmt.Errorf("error while creating Executor: %v", err) 43 | } 44 | 45 | var stderr bytes.Buffer 46 | err = exec.Stream(remotecommand.StreamOptions{ 47 | Stdin: stdin, 48 | Stdout: stdout, 49 | Stderr: &stderr, 50 | Tty: false, 51 | }) 52 | 53 | if err != nil { 54 | return stderr.Bytes(), fmt.Errorf("error in Stream: %v", err) 55 | } 56 | 57 | return stderr.Bytes(), nil 58 | } 59 | -------------------------------------------------------------------------------- /stacks/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majian159/k8s-java-debug-daemon/9697f7f6f963a471ada6ca92b88d3592326ab9b7/stacks/.gitkeep --------------------------------------------------------------------------------