# 如何少一行 Code 搞爆整個 K8S Cluster
Special thank: Raymond Liu
Infra team のあにき
---
## 起源

### 教練,我想來點 Get AWS S3 object
---
## Code 不會寫怎麼辦?
抄呀,抄官方範例呀

---
## It works!
可以動了,Unit test 過!
沒有流量的 test 環境過!
只有一點點流量的 stag 環境過!
上線! GO Prodution Go !
---
## Hello ~~world~~ P0

---
### Prometheus & Grafana 我救我!
Node Exporter Prometheus metrics: `node_sockstat_TCP_mem`
Let's see what happen.

---
### What Happend ?
For k8s work nodes 不只CPU Mem要觀察, 網路連線狀態也必須注意
```shell
# Current usage:
cat /proc/net/sockstat
sockets: used 23752
TCP: inuse 51 orphan 0 tw 263 alloc 21481 mem 771586
UDP: inuse 4 mem 42
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0
```
```shell
cat /proc/sys/net/ipv4/tcp_mem
# min pressure max
374535 499381 749070
```
可發現 771586 已經超過 749070
---
### 影響範圍?
這是屬於 Common library 的功能,幾乎每個 service 都會用,所以幾乎每個 Node 的 TCP Memory 都吃滿了。
---
### 我依稀記得...
之前在用 pprof 的時候看過這篇...

---
### 關鍵字
第一眼就是

---
### Will AWS-GO-SDK close it for me?
~~不可能,Go 沒有解構子,AWS SDK 不知道我什麼時候會讀取 http.resp.body,當然沒辦法幫我 close。~~
[Why we have to close request body by ourself](https://golang.org/src/net/http/response.go)
---
### 求證
開始寫 Testing too.....當然是直接問 Google 比較快呀

---
### AWS 真有你的
原來 [Developer guide](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/making-requests.html) 有寫
**always be sure to Close the field**

這麼重要為什麼不寫在 API document 的 example 上 QAQ
---
### Hotfix !!!

---
## Who am I
Rance Jen
現為 TrendMicro 孤兒院保母
~~最近正在努力尋求 Have my own son 的機會~~
會生又會養的好保母,有人喜歡嗎?
{"metaMigratedAt":"2023-06-15T15:45:35.268Z","metaMigratedFrom":"Content","title":"如何少一行 Code 搞爆整個 K8S Cluster","breaks":true,"contributors":"[{\"id\":\"d1772779-b7a0-43d5-923b-0f7edbff5f95\",\"add\":1841,\"del\":444},{\"id\":\"40f17693-e2cc-47a4-90fa-a1ef51eea534\",\"add\":461,\"del\":0}]"}