Skip to content

Commit 1d2dc01

Browse files
authored
Merge pull request #20 from persona-id/kuzmik/update-docs-and-modules
docs: updated the README and CHANGELOG files
2 parents cfc0f40 + e2de7c2 commit 1d2dc01

File tree

6 files changed

+48
-36
lines changed

6 files changed

+48
-36
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 1.0.0
2+
3+
- Go module updates, fixed a breaking change that Viper introduced
4+
- Followed some guides on go project layouts to redo the project layout
5+
- Enabled some extra golangci checks and addressed as many of the findings as possible
6+
- fix: add a configurable namespace to the core pod selector. We have several proxysql namespaces,
7+
so being able to configure it at runtime is important
8+
- Add goreleaser config and workflow
9+
- Added a config flag for logging format, defaults to json structured logs
10+
- Added restapi for proxysql healthcheck endpoints
11+
- Added the /shutdown rest api endpoint to gracefully drain traffic from ProxySQL before killing the container and pod
12+
113
## 0.9.0
214

315
Initial beta release.

README.md

+22-19
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
[![Go Report Card](https://goreportcard.com/badge/github.com/persona-id/proxysql-agent)](https://goreportcard.com/report/github.com/persona-id/proxysql-agent)
44

5+
56
## About
67

7-
A small, statically compiled go binary for use in maintaining the state of a [ProxySQL](https://github.com/sysown/proxysql) cluster, for use as a kubernetes sidecar container. The repo includes a [Dockerfile](build/Dockerfile) to generate an alpine based image.
8+
The ProxySQL agent is a small, statically compiled go binary for use in maintaining the state of a [ProxySQL](https://github.com/sysown/proxysql) cluster, for use as a kubernetes sidecar container. The repo includes a [Dockerfile](build/Dockerfile) to generate an alpine based image, or you can use the version in the [GitHub Container Registry]().
9+
10+
There exists relatively little tooling around ProxySQL, so we hope that this is useful to others out there, even if it's just to learn how to maintain a cluster.
11+
812

913
### "Self healing" the ProxySQL cluster
1014

@@ -17,25 +21,25 @@ Some examples of where this is necessary:
1721
- If _all_ core pods recycle, the satellite pods will run `LOAD PROXYSQL SERVERS FROM CONFIG` which points them to the `proxysql-core` service, and once the core pods are up the satellites should receive configuration again
1822
- Note that if your cluster is running fine and the core pods all go away, the satellites will continue to function with the settings they already had; in other words, even if the core pods vanish, you will still serve proxied MySQL traffic as long as the satellites have fetched the configuration once
1923

24+
2025
### Why did you pick golang, if you work at a Ruby shop?
2126

22-
I looked into using ruby, and in fact the "agents" we are currently running **are** written in ruby, but there have been some issues:
27+
We looked into using ruby, and in fact the "agents" we are currently running **are** written in ruby, but there have been some issues:
2328

24-
- If the proxysql admin interface gets wedged, the ruby and mysl processes still continue to spawn and spin, which will eventually lead to either inode exhaustion or a container OOM
29+
- If the ProxySQL admin interface gets wedged, the ruby and mysl processes still continue to spawn and spin, which will eventually lead to either inode exhaustion or a container OOM
2530
- The scheduler spawns a new ruby process every 10s
2631
- Each ruby process shells out to the mysql binary several times times per script invocation
2732
- In addition to the scheduler process, the health probes is a separate ruby script that also spawns several mysql processes per run
2833
- Two script invocations every 10s, one for liveness and one for readiness
2934

30-
31-
We wanted to avoid having to install a bunch of ruby gems in the container, so we decided shelling out to mysql was fine; we got most of the patterns from existing ProxySQL tooling and figured it'd work short term. The ruby has worked fine, though there have been enough instances of OOM'd containers that it's become worrisome. This usually happens if someone is in a pod doing any kind of work (modifying mysql query rules, etc), but we haven't been able to figure out what causes the admin interface to become wedged.
35+
We wanted to avoid having to install a bunch of ruby gems in the container, so we decided shelling out to mysql was fine; we got most of the patterns from existing ProxySQL tooling and figured it'd work short term. And it has worked fine, though there have been enough instances of OOM'd containers that it's become worrisome. This usually happens if someone is in a pod doing any kind of work (modifying mysql query rules, etc), but we haven't been able to figure out what causes the admin interface to become wedged.
3236

3337
Because k8s tooling is generally written in Golang, the ruby k8s gems didn't seem to be as maintained or as easy to use as the golang libraries. And because the go process is statically compiled, and we won't need to deal with a bunch of external dependencies at runtime.
3438

3539

3640
## Design
3741

38-
In the [example repo](https://github.com/kuzmik/local-proxysql), there are two separate deployments; the `core` and the `satellite` deployments. The agent is responsible for maintaining this cluster.
42+
In the [example repo](https://github.com/kuzmik/local-proxysql), there are two separate deployments; the `core` and the `satellite` deployments. The agent is responsible for maintaining the state of this cluster.
3943

4044
![image](docs/infra.png)
4145

@@ -44,11 +48,6 @@ On boot, the agent will connect to the ProxySQL admin interface on `127.0.0.1:60
4448
Additionally, the agent also exposes a simple HTTP API used for k8s health checks for the pod, as well as the /shutdown endpoint, which can be used in a `container.lifecycle.preStop.httpGet` hook to gracefully drain traffic from a pod before stopping it.
4549

4650

47-
## Status - Beta
48-
49-
This is currently in beta, but we are running it in production.
50-
51-
5251
## TODOs
5352

5453
There are some internal linear tickets, but here's a high level overview of what we have in mind.
@@ -74,24 +73,28 @@ There are some internal linear tickets, but here's a high level overview of what
7473
rpc error: code = Unknown desc = Error: No such container: e3153c34e0ad525c280dd26695b78d917b1cb377a545744bffb9b31ad1c90670%
7574
```
7675
77-
### MVP Requirements
78-
79-
1. ✅ Cluster management (ie: core and satellite agents)
80-
1. ✅ Health checks via an HTTP endpoint, specifically for the ProxySQL container
81-
1. ✅ Pre-stop hook replacement
82-
8376
### Done
8477
8578
- *P1* - ~~Dump the contents of `stats_mysql_query_digests` to a file on disk; will be used to get the data into snowflake. File format is CSV~~
8679
- *P1* - ~~Health checks; replace the ruby health probe with this~~
8780
- *P2* - ~~Replace the pre-stop ruby script with this~~
8881
8982
83+
### MVP Requirements
84+
85+
1. ✅ Cluster management (ie: core and satellite agents)
86+
1. ✅ Health checks via an HTTP endpoint, specifically for the ProxySQL container
87+
1. ✅ Pre-stop hook replacement
88+
89+
9090
## Releasing a new version
9191
92-
1. Update version in Makefile (and anywhere that calls `go build`, like pipelines)
93-
1. Update the CHANGELOG.md with the changes
92+
We are using [goreleaser](https://goreleaser.com/), so it's as simple as pushing to a new tag:
93+
94+
1. `git tag vX.X.X`
95+
1. `git push origin vX.X.X`
9496
97+
This will cause goreleaser to run and output the artifacts; currently we are only shipping a linuix amd64 binary and a Docker image.
9598
9699
## See also
97100

cmd/proxysql-agent/main.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
54
"log/slog"
65
"os"
76
"runtime/debug"
@@ -35,8 +34,6 @@ func getVersionInfo() {
3534
continue
3635
}
3736

38-
fmt.Println(kv)
39-
4037
switch kv.Key {
4138
case "vcs.revision":
4239
Revision = kv.Value
@@ -111,7 +108,7 @@ func setupLogger(settings *configuration.Config) {
111108
}
112109

113110
opts := &slog.HandlerOptions{
114-
AddSource: false,
111+
AddSource: true,
115112
Level: level,
116113
}
117114

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
require (
66
github.com/go-sql-driver/mysql v1.7.1
77
github.com/spf13/pflag v1.0.5
8-
github.com/spf13/viper v1.17.0
8+
github.com/spf13/viper v1.18.0
99
k8s.io/apimachinery v0.28.4
1010
k8s.io/client-go v0.28.4
1111
)
@@ -35,15 +35,15 @@ require (
3535
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
3636
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
3737
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
38-
github.com/sagikazarmark/locafero v0.3.0 // indirect
38+
github.com/sagikazarmark/locafero v0.4.0 // indirect
3939
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
4040
github.com/sourcegraph/conc v0.3.0 // indirect
4141
github.com/spf13/afero v1.11.0 // indirect
4242
github.com/spf13/cast v1.6.0 // indirect
4343
github.com/stretchr/testify v1.8.4
4444
github.com/subosito/gotenv v1.6.0 // indirect
4545
go.uber.org/multierr v1.11.0 // indirect
46-
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
46+
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
4747
golang.org/x/net v0.19.0 // indirect
4848
golang.org/x/oauth2 v0.15.0 // indirect
4949
golang.org/x/sys v0.15.0 // indirect
@@ -59,7 +59,7 @@ require (
5959
gopkg.in/yaml.v3 v3.0.1 // indirect
6060
k8s.io/api v0.28.4 // indirect
6161
k8s.io/klog/v2 v2.110.1 // indirect
62-
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e // indirect
62+
k8s.io/kube-openapi v0.0.0-20231206194836-bf4651e18aa8 // indirect
6363
k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect
6464
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
6565
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect

go.sum

+8-8
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
8181
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8282
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
8383
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
84-
github.com/sagikazarmark/locafero v0.3.0 h1:zT7VEGWC2DTflmccN/5T1etyKvxSxpHsjb9cJvm4SvQ=
85-
github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U=
84+
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
85+
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
8686
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
8787
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
8888
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
@@ -93,8 +93,8 @@ github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
9393
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
9494
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
9595
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
96-
github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI=
97-
github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI=
96+
github.com/spf13/viper v1.18.0 h1:pN6W1ub/G4OfnM+NR9p7xP9R6TltLUzp5JG9yZD3Qg0=
97+
github.com/spf13/viper v1.18.0/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
9898
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
9999
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
100100
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -115,8 +115,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
115115
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
116116
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
117117
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
118-
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
119-
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
118+
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8=
119+
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
120120
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
121121
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
122122
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
@@ -195,8 +195,8 @@ k8s.io/client-go v0.28.4 h1:Np5ocjlZcTrkyRJ3+T3PkXDpe4UpatQxj85+xjaD2wY=
195195
k8s.io/client-go v0.28.4/go.mod h1:0VDZFpgoZfelyP5Wqu0/r/TRYcLYuJ2U1KEeoaPa1N4=
196196
k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=
197197
k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo=
198-
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e h1:snPmy96t93RredGRjKfMFt+gvxuVAncqSAyBveJtr4Q=
199-
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
198+
k8s.io/kube-openapi v0.0.0-20231206194836-bf4651e18aa8 h1:vzKzxN5uyJZLY8HL1/OovW7BJefnsBIWt8T7Gjh2boQ=
199+
k8s.io/kube-openapi v0.0.0-20231206194836-bf4651e18aa8/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
200200
k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI=
201201
k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
202202
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=

internal/configuration/configuration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func Configure() (*Config, error) {
152152

153153
settings := &Config{}
154154

155-
err = viper.Unmarshal(&settings)
155+
err = viper.Unmarshal(settings)
156156
if err != nil {
157157
return nil, err
158158
}

0 commit comments

Comments
 (0)